@threadbase-sh/streamer 1.58.2 → 1.58.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -11435,7 +11435,7 @@ var PairTokenStore = class {
11435
11435
  };
11436
11436
  }
11437
11437
  /**
11438
- * Whether `consume` would succeed right now, WITHOUT spending the token.
11438
+ * What `consume` would answer right now, WITHOUT spending the token.
11439
11439
  *
11440
11440
  * Exists so a caller can reject a bad token before doing any work, and still
11441
11441
  * spend the token only once the work has succeeded. A pair token is
@@ -11444,10 +11444,14 @@ var PairTokenStore = class {
11444
11444
  * indistinguishable from an attacker replaying a photographed code, which is
11445
11445
  * the one signal `design.md` §2.6 designates as replay detection.
11446
11446
  *
11447
- * Advisory, not a reservation: it takes no lock and holds nothing. The
11448
- * authoritative answer is still `consume`'s.
11447
+ * **Named for its relationship to `consume`, deliberately.** It reserves
11448
+ * nothing and takes no lock, so two callers can both be told `{ ok: true }`
11449
+ * for the same token. A name like `verify` would read as a gate that had
11450
+ * decided something, and inviting a caller to act on this alone is precisely
11451
+ * the misuse the ordering it enables exists to prevent. A reader who sees
11452
+ * `wouldConsume` asks where the `consume` is, which is the right question.
11449
11453
  */
11450
- verify(token) {
11454
+ wouldConsume(token) {
11451
11455
  const result = this.check(token);
11452
11456
  return result.ok ? { ok: true } : result;
11453
11457
  }
@@ -16308,8 +16312,14 @@ var StreamerServer = class {
16308
16312
  json(res, 400, { error: "Missing token or clientPublicKey" });
16309
16313
  return;
16310
16314
  }
16311
- const precheck = this.pairTokens.verify(token);
16315
+ const precheck = this.pairTokens.wouldConsume(token);
16312
16316
  if (!precheck.ok) {
16317
+ if (precheck.reason === "used") {
16318
+ this.log.warn(
16319
+ "[pair] a pair token was replayed. If you did not just pair a device, check the paired-devices list and revoke anything you do not recognise.",
16320
+ { event: "pair.token_replayed", ip }
16321
+ );
16322
+ }
16313
16323
  json(res, 401, { error: `Pair token ${precheck.reason}` });
16314
16324
  return;
16315
16325
  }