@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.cjs CHANGED
@@ -11480,7 +11480,7 @@ var PairTokenStore = class {
11480
11480
  };
11481
11481
  }
11482
11482
  /**
11483
- * Whether `consume` would succeed right now, WITHOUT spending the token.
11483
+ * What `consume` would answer right now, WITHOUT spending the token.
11484
11484
  *
11485
11485
  * Exists so a caller can reject a bad token before doing any work, and still
11486
11486
  * spend the token only once the work has succeeded. A pair token is
@@ -11489,10 +11489,14 @@ var PairTokenStore = class {
11489
11489
  * indistinguishable from an attacker replaying a photographed code, which is
11490
11490
  * the one signal `design.md` §2.6 designates as replay detection.
11491
11491
  *
11492
- * Advisory, not a reservation: it takes no lock and holds nothing. The
11493
- * authoritative answer is still `consume`'s.
11492
+ * **Named for its relationship to `consume`, deliberately.** It reserves
11493
+ * nothing and takes no lock, so two callers can both be told `{ ok: true }`
11494
+ * for the same token. A name like `verify` would read as a gate that had
11495
+ * decided something, and inviting a caller to act on this alone is precisely
11496
+ * the misuse the ordering it enables exists to prevent. A reader who sees
11497
+ * `wouldConsume` asks where the `consume` is, which is the right question.
11494
11498
  */
11495
- verify(token) {
11499
+ wouldConsume(token) {
11496
11500
  const result = this.check(token);
11497
11501
  return result.ok ? { ok: true } : result;
11498
11502
  }
@@ -16351,8 +16355,14 @@ var StreamerServer = class {
16351
16355
  json(res, 400, { error: "Missing token or clientPublicKey" });
16352
16356
  return;
16353
16357
  }
16354
- const precheck = this.pairTokens.verify(token);
16358
+ const precheck = this.pairTokens.wouldConsume(token);
16355
16359
  if (!precheck.ok) {
16360
+ if (precheck.reason === "used") {
16361
+ this.log.warn(
16362
+ "[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.",
16363
+ { event: "pair.token_replayed", ip }
16364
+ );
16365
+ }
16356
16366
  json(res, 401, { error: `Pair token ${precheck.reason}` });
16357
16367
  return;
16358
16368
  }