@bymax-one/nest-auth 1.4.4 → 1.4.5

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/CHANGELOG.md CHANGED
@@ -18,6 +18,72 @@ what moves, and that note is the compatibility contract until strict SemVer begi
18
18
 
19
19
  ## [Unreleased]
20
20
 
21
+ ## [1.4.5] - 2026-08-29
22
+
23
+ ### Added
24
+
25
+ - **`AuthRevocationService` now warns when it refuses a dashboard token for carrying no tenant.**
26
+ 1.4.4 made that case fail closed, which was the right call and is unchanged. What it did not do
27
+ is say so: the refusal answers the same `true` a genuinely revoked token answers, reads nothing,
28
+ throws nothing and emits no event, so it is indistinguishable from a revocation that worked.
29
+
30
+ Measured on the caller the 1.4.4 entry names. A consumer's realtime bridge called
31
+ `isAccessTokenRevoked({ jti, sub, epoch }, 'dashboard')` without the tenant; the SSE handshake
32
+ answered `200` and then registered nothing, and the connection registry sat at `count: 0` while
33
+ every stream was silently refused. It reads as a realtime bug rather than an auth one, and every
34
+ gate agreed with that reading: `tsc` passes because `tenantId` is optional on
35
+ `RevocableTokenPayload`, and a unit suite passes at 100% mutation score while asserting the
36
+ forwarded payload is exactly `{ jti, sub, epoch }` — a faithful test of a contract that had moved
37
+ underneath it. Twenty minutes of bisecting, ended by a log line that costs two.
38
+
39
+ The message names the missing field and the remedy, and says the refusal is deliberate so it is
40
+ not filed as a library bug. No identifier is logged: `sub` names an account and `jti` a live
41
+ token, and neither is needed to act on it.
42
+
43
+ **The tenant check also moved ahead of the per-token blacklist read**, which validates the input
44
+ before consulting a channel. The answer is unchanged — `true` either way, indistinguishable to a
45
+ caller — but behind the blacklist read the warn fired only for a token that happened not to be
46
+ blacklisted, so a bridge calling this wrongly on every request could go on doing so unheard, the
47
+ diagnostic coming and going with unrelated state. It also spares a Redis round trip on a request
48
+ that is already refused, and makes "without a store read" true of the path rather than nearly
49
+ true.
50
+
51
+ **A distinct error code was considered and rejected.** `isAccessTokenRevoked` returns a boolean
52
+ and the three guards turn it into a refusal, so giving this case its own `AuthErrorCode` means
53
+ widening the return of an exported service and threading it through all three — and an `auth.*`
54
+ code is wire vocabulary, so it would answer an unauthenticated client with a detail about the
55
+ deployment's own wiring that today's refusal does not leak. The operator's log is the one place
56
+ that can act on it.
57
+
58
+ **Apply to a derived backend.** Nothing to do — behaviour is unchanged, and the only new output
59
+ is a `warn` on a path that was already refusing. If it appears in your logs, a caller is reaching
60
+ the service without the tenant from its verified token; fix the caller rather than the log, and
61
+ consider typing the tenant as REQUIRED on your own port so the omission cannot recur.
62
+
63
+ - **`AuthRevocationService` is documented in the README**, under the API reference. It has been a
64
+ public export since it was extracted from the three JWT guards, and the README never mentioned it
65
+ — so the one thing a caller outside a guard has to know, that a dashboard check must forward
66
+ `tenantId` from the verified token, was reachable only from the JSDoc or from this changelog.
67
+ That is the omission the entry above was measured on. The new section names both revocation
68
+ channels, states the tenant obligation as a requirement rather than a note, and describes the
69
+ symptom to recognise — `true` with nothing thrown, a stream that registers nothing — because it
70
+ does not read as an auth bug from the transport side.
71
+
72
+ It also says what the method is **not**: it answers two channels at the moment it is called, and
73
+ reads no `exp`, holds no subscription, emits no event, and knows nothing about account status,
74
+ roles, tenant binding or the identity plane. It is one check among the many a guarded route
75
+ performs, not a way to authorise a stream.
76
+
77
+ **Guidance on doing that safely was drafted and withdrawn**, and the reasoning is worth recording
78
+ because it is a statement about the library rather than about the prose. Seven successive drafts
79
+ were each found wrong by review — a recipe that would have admitted a pre-MFA token, a bare-id
80
+ fan-out reintroducing the cross-tenant defect 1.4.4 removed, a reconnect that carries neither
81
+ route authorization nor `enforceTenantBinding`, and mitigations that cannot reach a
82
+ ticket-authenticated platform socket at all. The through-line is that this library does not
83
+ export the pieces a consumer would need, so the documentation was describing a hand-rolled
84
+ reproduction of a security chain that has no supported form. That belongs in an issue with the
85
+ gaps named, not in a release: [#172](https://github.com/bymaxone/nest-auth/issues/172).
86
+
21
87
  ## [1.4.4] - 2026-08-19
22
88
 
23
89
  ### Changed
@@ -3382,7 +3448,8 @@ ever installable.
3382
3448
  - Phase 4 password-reset tests cover: both `token` and `otp` flows, mutual exclusivity validation, `verifiedToken` exchange, resend cooldown, anti-enumeration (no error on unknown email), and session invalidation on reset
3383
3449
  - Phase 5 tests cover: platform login with MFA path and brute-force lockout, `JwtPlatformGuard` cross-context rejection, `PlatformRolesGuard` hierarchy enforcement, OAuth CSRF state lifecycle, `onOAuthLogin` hook resolution strategies, and invitation role-authorization + acceptance single-use enforcement
3384
3450
 
3385
- [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.4...HEAD
3451
+ [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.5...HEAD
3452
+ [1.4.5]: https://github.com/bymaxone/nest-auth/compare/v1.4.4...v1.4.5
3386
3453
  [1.4.4]: https://github.com/bymaxone/nest-auth/compare/v1.4.3...v1.4.4
3387
3454
  [1.4.3]: https://github.com/bymaxone/nest-auth/compare/v1.4.2...v1.4.3
3388
3455
  [1.4.2]: https://github.com/bymaxone/nest-auth/compare/v1.4.1...v1.4.2
package/README.md CHANGED
@@ -1646,6 +1646,56 @@ disputable. Idempotent; throws for an id that resolves to nobody, so a typo cann
1646
1646
  > `MfaService` is only registered when `controllers.mfa` or `controllers.platform` is on —
1647
1647
  > otherwise add it to `extraProviders` to inject it.
1648
1648
 
1649
+ ### Checking revocation outside a guard — `AuthRevocationService`
1650
+
1651
+ The three JWT guards do not decide revocation themselves; they delegate to one service, and that
1652
+ service is exported so **you can consult the same two channels from a transport the guards never
1653
+ see** — a WebSocket, an SSE stream, a message consumer. Without it there is no way to ask the
1654
+ question at all outside an HTTP request: a connection whose user logs out keeps its stream until
1655
+ the access token expires, while that user's HTTP calls are refused at once.
1656
+
1657
+ ```ts
1658
+ import { AuthRevocationService } from '@bymax-one/nest-auth'
1659
+
1660
+ const revoked = await this.revocation.isAccessTokenRevoked(
1661
+ { jti: payload.jti, sub: payload.sub, epoch: payload.epoch, tenantId: payload.tenantId },
1662
+ 'dashboard'
1663
+ )
1664
+ ```
1665
+
1666
+ It is registered and exported unconditionally, so it is injectable wherever `BymaxAuthModule` is
1667
+ imported — no `extraProviders` entry and no controller flag to turn on.
1668
+
1669
+ > [!IMPORTANT]
1670
+ > **On the dashboard plane you must forward `tenantId` from the verified token.** It is optional
1671
+ > on `RevocableTokenPayload` because the platform plane genuinely has none — its admins are
1672
+ > cross-tenant — so **`tsc` will not catch the omission**, and a dashboard payload without it is
1673
+ > treated as **revoked** without a store read, with a `warn` naming the missing field.
1674
+ >
1675
+ > Failing closed is deliberate. The epoch key derives from the tenant-scoped subject, so an absent
1676
+ > tenant names a keyspace belonging to no tenant, where nothing has ever been bumped: the read
1677
+ > would answer `0`, `stamped < 0` is false for every token, and a bulk-revoked token would be
1678
+ > reported **valid**. A revocation check that fails open on malformed input is worse than no check.
1679
+ >
1680
+ > **Recognise the symptom, because it does not look like an auth bug.** The refusal answers the
1681
+ > same `true` a genuinely revoked token answers, throws nothing and emits no event — so a
1682
+ > transport that gates a stream on it simply registers nothing. Measured on a consumer's realtime
1683
+ > bridge: the SSE handshake answered `200` and the connection registry stayed at `count: 0`.
1684
+ > Declaring the tenant **required** on your own port type is the stronger fix, because it turns the
1685
+ > next occurrence into a compile error rather than a log line.
1686
+
1687
+ **What this method is and is not.** It answers two channels at the moment you call it: the
1688
+ per-token blacklist and the user's token epoch. It reads no `exp`, holds no subscription, emits no
1689
+ event, and knows nothing about account status, roles, tenant binding or the identity plane. It is
1690
+ therefore **one check among the many a guarded HTTP route performs**, and not a substitute for
1691
+ them.
1692
+
1693
+ Using it to authorise a long-lived transport — a WebSocket, an SSE stream — takes more than this
1694
+ method, and this library does not yet export the pieces that would make that safe. See
1695
+ [#172](https://github.com/bymaxone/nest-auth/issues/172), which records what a stream must
1696
+ establish beyond revocation, the gaps that make each one consumer-built today, and the library
1697
+ changes that would close them.
1698
+
1649
1699
  ### Server Guards
1650
1700
 
1651
1701
  | Guard | Decorator | Purpose |
@@ -3104,11 +3104,12 @@ function _ts_param3(paramIndex, decorator) {
3104
3104
  };
3105
3105
  }
3106
3106
  __name(_ts_param3, "_ts_param");
3107
- exports.AuthRevocationService = class AuthRevocationService {
3107
+ exports.AuthRevocationService = class _AuthRevocationService {
3108
3108
  static {
3109
3109
  __name(this, "AuthRevocationService");
3110
3110
  }
3111
3111
  redis;
3112
+ logger = new common.Logger(_AuthRevocationService.name);
3112
3113
  /**
3113
3114
  * @param redis - The auth module's Redis service, holding both revocation channels.
3114
3115
  */
@@ -3121,13 +3122,15 @@ exports.AuthRevocationService = class AuthRevocationService {
3121
3122
  * @param payload - The verified token's `jti`, `sub` and stamped `epoch`.
3122
3123
  * @param kind - Which plane the token belongs to; selects the epoch namespace, defaulting to the
3123
3124
  * dashboard plane an ordinary user token uses. The per-token blacklist is shared across planes.
3124
- * @returns `true` when the token is on the blacklist or predates the user's current epoch.
3125
+ * @returns `true` when the token is on the blacklist, predates the user's current epoch, or is a
3126
+ * dashboard payload carrying no tenant — the last fails closed without a store read, and warns.
3125
3127
  */
3126
3128
  async isAccessTokenRevoked(payload, kind = "dashboard") {
3127
- if (await this.redis.get(`rv:${payload.jti}`) !== null) {
3129
+ if (kind === "dashboard" && (payload.tenantId === void 0 || payload.tenantId === "")) {
3130
+ this.logger.warn(`isAccessTokenRevoked: dashboard token refused without a store read \u2014 the payload carries no tenantId, so its epoch key cannot be named. Forward the tenant from the verified token; a dashboard check missing it fails closed by design`);
3128
3131
  return true;
3129
3132
  }
3130
- if (kind === "dashboard" && (payload.tenantId === void 0 || payload.tenantId === "")) {
3133
+ if (await this.redis.get(`rv:${payload.jti}`) !== null) {
3131
3134
  return true;
3132
3135
  }
3133
3136
  const epoch = await this.redis.getUserTokenEpoch(payload.sub, payload.tenantId, kind);
@@ -4863,6 +4863,7 @@ interface RevocableTokenPayload {
4863
4863
  */
4864
4864
  declare class AuthRevocationService {
4865
4865
  private readonly redis;
4866
+ private readonly logger;
4866
4867
  /**
4867
4868
  * @param redis - The auth module's Redis service, holding both revocation channels.
4868
4869
  */
@@ -4873,7 +4874,8 @@ declare class AuthRevocationService {
4873
4874
  * @param payload - The verified token's `jti`, `sub` and stamped `epoch`.
4874
4875
  * @param kind - Which plane the token belongs to; selects the epoch namespace, defaulting to the
4875
4876
  * dashboard plane an ordinary user token uses. The per-token blacklist is shared across planes.
4876
- * @returns `true` when the token is on the blacklist or predates the user's current epoch.
4877
+ * @returns `true` when the token is on the blacklist, predates the user's current epoch, or is a
4878
+ * dashboard payload carrying no tenant — the last fails closed without a store read, and warns.
4877
4879
  */
4878
4880
  isAccessTokenRevoked(payload: RevocableTokenPayload, kind?: 'dashboard' | 'platform'): Promise<boolean>;
4879
4881
  }
@@ -4863,6 +4863,7 @@ interface RevocableTokenPayload {
4863
4863
  */
4864
4864
  declare class AuthRevocationService {
4865
4865
  private readonly redis;
4866
+ private readonly logger;
4866
4867
  /**
4867
4868
  * @param redis - The auth module's Redis service, holding both revocation channels.
4868
4869
  */
@@ -4873,7 +4874,8 @@ declare class AuthRevocationService {
4873
4874
  * @param payload - The verified token's `jti`, `sub` and stamped `epoch`.
4874
4875
  * @param kind - Which plane the token belongs to; selects the epoch namespace, defaulting to the
4875
4876
  * dashboard plane an ordinary user token uses. The per-token blacklist is shared across planes.
4876
- * @returns `true` when the token is on the blacklist or predates the user's current epoch.
4877
+ * @returns `true` when the token is on the blacklist, predates the user's current epoch, or is a
4878
+ * dashboard payload carrying no tenant — the last fails closed without a store read, and warns.
4877
4879
  */
4878
4880
  isAccessTokenRevoked(payload: RevocableTokenPayload, kind?: 'dashboard' | 'platform'): Promise<boolean>;
4879
4881
  }
@@ -3102,11 +3102,12 @@ function _ts_param3(paramIndex, decorator) {
3102
3102
  };
3103
3103
  }
3104
3104
  __name(_ts_param3, "_ts_param");
3105
- var AuthRevocationService = class {
3105
+ var AuthRevocationService = class _AuthRevocationService {
3106
3106
  static {
3107
3107
  __name(this, "AuthRevocationService");
3108
3108
  }
3109
3109
  redis;
3110
+ logger = new Logger(_AuthRevocationService.name);
3110
3111
  /**
3111
3112
  * @param redis - The auth module's Redis service, holding both revocation channels.
3112
3113
  */
@@ -3119,13 +3120,15 @@ var AuthRevocationService = class {
3119
3120
  * @param payload - The verified token's `jti`, `sub` and stamped `epoch`.
3120
3121
  * @param kind - Which plane the token belongs to; selects the epoch namespace, defaulting to the
3121
3122
  * dashboard plane an ordinary user token uses. The per-token blacklist is shared across planes.
3122
- * @returns `true` when the token is on the blacklist or predates the user's current epoch.
3123
+ * @returns `true` when the token is on the blacklist, predates the user's current epoch, or is a
3124
+ * dashboard payload carrying no tenant — the last fails closed without a store read, and warns.
3123
3125
  */
3124
3126
  async isAccessTokenRevoked(payload, kind = "dashboard") {
3125
- if (await this.redis.get(`rv:${payload.jti}`) !== null) {
3127
+ if (kind === "dashboard" && (payload.tenantId === void 0 || payload.tenantId === "")) {
3128
+ this.logger.warn(`isAccessTokenRevoked: dashboard token refused without a store read \u2014 the payload carries no tenantId, so its epoch key cannot be named. Forward the tenant from the verified token; a dashboard check missing it fails closed by design`);
3126
3129
  return true;
3127
3130
  }
3128
- if (kind === "dashboard" && (payload.tenantId === void 0 || payload.tenantId === "")) {
3131
+ if (await this.redis.get(`rv:${payload.jti}`) !== null) {
3129
3132
  return true;
3130
3133
  }
3131
3134
  const epoch = await this.redis.getUserTokenEpoch(payload.sub, payload.tenantId, kind);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-auth",
3
- "version": "1.4.4",
3
+ "version": "1.4.5",
4
4
  "description": "Full-stack authentication and authorization package for NestJS, React and Next.js — JWT, MFA, OAuth, sessions, multi-tenant SaaS ready",
5
5
  "author": "Bymax One <support@bymax.one>",
6
6
  "license": "MIT",
@@ -185,7 +185,7 @@
185
185
  "@stryker-mutator/core": "^10.0.0",
186
186
  "@stryker-mutator/jest-runner": "^10.0.0",
187
187
  "@stryker-mutator/typescript-checker": "^10.0.0",
188
- "@swc/core": "1.16.0",
188
+ "@swc/core": "1.16.1",
189
189
  "@testing-library/react": "^16.3.2",
190
190
  "@types/express": "^5.0.6",
191
191
  "@types/jest": "^30.0.0",