@bymax-one/nest-auth 1.5.2 → 1.5.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/CHANGELOG.md CHANGED
@@ -18,6 +18,138 @@ what moves, and that note is the compatibility contract until strict SemVer begi
18
18
 
19
19
  ## [Unreleased]
20
20
 
21
+ ## [1.5.3] - 2026-11-14
22
+
23
+ A patch release for workspaces, MFA and the proxy: the paging cursor is a codec the library now exports and
24
+ bounds, the owner role is bounded by length instead of a charset, the websocket guard holds a header credential
25
+ to the chain a request is held to, MFA state and its failure counters are keyed by the tenant only, the module
26
+ probes Redis at startup, a provider plugin's calls have a deadline, the Next.js proxy checks the backend's issuer,
27
+ audience and retired secrets, and the wire contract is at version 6.
28
+
29
+ ### Apply to a derived backend
30
+
31
+ - **`workspaces.roles.ownerRole` is checked at startup.** It must be 1 to 32 code points of well-formed
32
+ text with no control character, the rule an id follows, and its characters are free: `owner`,
33
+ `org:admin`, `team lead` and `proprietário` all pass. The owner role is part of the key a
34
+ `listSoleOwned` cursor is bound to, and only an empty name, one of more than 32 code points, or one with a control
35
+ character or an unpaired surrogate, is refused, naming the option and the rule. Only the owner role is
36
+ checked: the other roles of the hierarchy keep any name.
37
+ - **A workspace page cursor may now be up to 4096 characters, not 512.** The wire contract is at version 6:
38
+ `requestFieldBounds.pageLimit.cursor` and the published `WorkspacePageQueryDto` schema say 4096, and the
39
+ contract states the owner-role rule as a new `workspaceOwnerRole` section. During a rolling deploy an
40
+ instance still on 1.5.2 or earlier answers `400` to a cursor longer than 512 characters that this
41
+ release issued, which needs ids of about 105 characters or more (see Fixed), and only until every
42
+ instance has been replaced.
43
+ - **A host adapter can drop its own cursor codec.** A cursor in the format the template's hand-written
44
+ codec writes (base64url of the JSON of the query key and the position) keeps reading, which the spec
45
+ pins with cursors that codec issued. Replace `keyOf`, `positionOf`, `encodeCursor`, `decodeCursor` and
46
+ `readPosition` with `workspaceQueryKey`, `workspacePositionOf`, `encodeWorkspaceCursor`,
47
+ `decodeWorkspaceCursor` and `readWorkspacePosition`, and delete the local copy and its spec.
48
+ `workspaceQueryKey` is
49
+ `JSON.stringify` of its parts, byte for byte, so a lock or map key built from it does not move.
50
+ `encodeWorkspaceCursor` throws a `RangeError` for a position the decoder would read as none and for a
51
+ cursor over 4096 characters (a key part over 128 code points), instead of issuing a cursor the next
52
+ request could never follow. Every id you issue must be 1 to 128 code points of well-formed text with no
53
+ control character.
54
+ - **`verifyAccessToken` with a `workspaceId` while workspaces are off now throws `AuthException` (validation),
55
+ not a `TypeError`, and only after the token is verified: an invalid, expired or revoked token still gets
56
+ `TOKEN_INVALID`.** The refusal names the field `workspaceId`, so a handler maps it to a `400` like any
57
+ other refused input. A platform-plane token still throws a `TypeError`, which is a programming error.
58
+ - **The wire contract is at version 6: the two password re-proof counters are pinned.** `userSubjectDerivedKeys`
59
+ gains `changePasswordFailureCounter` and `emailChangeFailureCounter` (`lf:` over `reauth:change-password:` or
60
+ `reauth:email-change:` and the tenant-scoped user subject), and the new `reproofCounterVectors` section gives
61
+ known answers for them, including an accented tenant, a tenant containing `:` and the pair a bare delimiter would
62
+ merge, so a library that derived the counter from the bare user id would fail its own test instead of splitting a
63
+ budget unnoticed. This library already derived both counters this way, so nothing changes at runtime here; the
64
+ derivation moved into one function, `reproofCounterId`, that the two flows call. A backend that reads the contract
65
+ must adopt version 6 and derive the same bytes.
66
+ - **MFA state and its failure counters are keyed by the tenant on the dashboard plane, and the tenant-less
67
+ duplicates are gone.** Five keys also took a second, tenant-less form that two tenants' user `1` shared:
68
+ the MFA transition lock (`mfalock:`), the TOTP replay marker (`tu:`), and the failure counters of the
69
+ `challenge`, `disable` and `reauth` flows. With them, failures counted against user `1` of one tenant
70
+ locked user `1` of another out of those flows with no credential, a success in one cleared the
71
+ other's count, a transition in one answered `MFA_STATE_CONFLICT` in the other, and one tenant's TOTP
72
+ code burnt the other's. A host whose user ids are unique across tenants (UUIDs) was never affected.
73
+ Only the length-prefixed forms (`userSubject`) are read and written now, the ones the shared keyspace
74
+ contract names. The tenant-less keys were the compatibility arm of a rolling deploy that the code
75
+ already said could not be made safe, so drain old instances before new ones serve, as the keyspace
76
+ contract requires; a lockout counted under a tenant-less key before the upgrade does not carry over.
77
+ - **A provider plugin's code exchange and profile fetch are bounded to 10 seconds together.** The
78
+ callback awaited the plugin with no deadline, so a token or profile endpoint that accepted the
79
+ connection and went silent held the request open with its state already consumed. Past the deadline
80
+ the callback is answered `OAUTH_FAILED` and the plugin's pending request is abandoned, not cancelled,
81
+ so a plugin should bound its own requests too. A plugin may set `timeoutMs` (a whole number from 1
82
+ to 120000; anything else is read as 10000). The bundled Google plugin sets 20000, the sum of the 10
83
+ seconds its two requests are each bounded at.
84
+ - **The Next.js proxy can hold a token to the backend's issuer, audience and retired secrets.** Set
85
+ `jwtIssuer`, `jwtAudience` and `jwtPreviousSecrets` on `createAuthProxy` to the backend's
86
+ `jwt.issuer`, `jwt.audience` and `jwt.previousSecrets`. With an issuer or audience set, a token
87
+ without exactly that `iss`, or whose `aud` is not or does not contain that value, is not
88
+ authenticated; with retired secrets set, a token signed under one is verified, as the backend still
89
+ accepts it while a rotation drains. Unset, the proxy checks the signature and the expiry only, as
90
+ before, so a backend that sets an issuer or audience today has a proxy that admits a token the
91
+ backend refuses: set the three to match. `verifyJwtToken` takes the same values as an optional third
92
+ argument, `VerifyJwtOptions`. The README and the JSDoc now say what the proxy is: a routing hint that
93
+ cannot see revocation, an account's current status, the MFA state or a workspace membership, never the
94
+ access decision for data or an action.
95
+
96
+ - **The module sends `PING` to your Redis client at bootstrap and refuses to start when it never answers.** It
97
+ retries every 250 ms for up to 5 seconds, so a Redis still starting during a rolling deploy, or a client
98
+ built with `lazyConnect` or `enableOfflineQueue: false` whose first command is rejected, passes once
99
+ the connection is up. A refused connection, a wrong password or a silent Redis for the whole budget
100
+ stops the application with `[BymaxAuthModule] Redis at <host>:<port> did not answer PING within 5000 ms`,
101
+ naming only the host and port the client was built with, never a password, a URL or the error ioredis
102
+ raised; a client that has ended fails at once. Before, a mis-pointed address started fine and failed
103
+ on the first request. A host whose tests build the module with a client that has no `ping` fails with
104
+ `BYMAX_AUTH_REDIS_CLIENT must be an ioredis client`; `ioredis-mock` answers it. A client with no
105
+ `commandTimeout` is warned about at startup, and the README's Configuration section says what to set:
106
+ with ioredis defaults an unreachable Redis holds each request until the client gives up, which reads
107
+ as a hang, though every decision still fails closed.
108
+ - **`WsJwtGuard` holds a handshake `Authorization` header to the chain a request is held to.** It now
109
+ verifies through `AuthTokenVerifierService`, so a token with a `jti` that is not a UUID, or with no
110
+ `tenantId`, is refused at the guard, and two gates that were absent are on by default: the account's
111
+ **current** status (a blocked or suspended account answers its `ACCOUNT_*` code) and the MFA policy (a
112
+ token with `mfaEnabled` and no `mfaVerified` answers `MFA_REQUIRED`). A socket stayed open for as long
113
+ as its client wished, and a token issued before MFA was enabled mid-session opened it without the second
114
+ factor. `@SkipMfa()` on a gateway handler or class lifts the MFA gate, as it does on HTTP, for the
115
+ handler that has to work while a factor is being set up; the status gate has no opt-out. The ticket path
116
+ is unchanged: a ticket is minted from a session that already passed both. The constructor takes
117
+ `AuthTokenVerifierService` and `Reflector` in place of `JwtService` and `AuthRevocationService`, so a
118
+ host that subclasses or constructs the guard by hand must update the call; a host that applies it with
119
+ `@UseGuards(WsJwtGuard)` needs nothing, because the module already exports the verifier.
120
+
121
+ ### Added
122
+
123
+ - **`AUTH_SECRET_MIN_LENGTH`** (32), the floor the boot check applies to every secret option,
124
+ exported so a host that generates secrets can size them from the same constant.
125
+ - **`assertWorkspaceId` and `WORKSPACE_ID_MAX_LENGTH`** (128 code points), the refusal the request edge
126
+ applies to a workspace id, exported for a host that reads the id itself. It matches the cursor's rule for
127
+ an id except that it does not refuse an unpaired surrogate.
128
+ - **Workspace cursor codec**, exported next to the membership port: `workspaceQueryKey`,
129
+ `workspacePositionOf`, `readWorkspacePosition`, `encodeWorkspaceCursor`, `decodeWorkspaceCursor` and the
130
+ constants `WORKSPACE_CURSOR_MAX_LENGTH`, `WORKSPACE_CURSOR_PART_MAX_LENGTH`,
131
+ `WORKSPACE_OWNER_ROLE_MAX_LENGTH`, with `isWorkspaceOwnerRole` for the owner-role rule. Decoding implements the rule the
132
+ port states of every cursor: one that is malformed, longer than the bound, not exactly the bytes the
133
+ encoder writes, not a pair of two strings, issued for another query, or whose position is not an
134
+ instant followed by a well-formed id of 1 to 128 code points without control characters reads as the
135
+ first page and never widens the scope. A value that is not a string reads the same way. The scope always
136
+ comes from the query the store builds, never from the cursor, and a cursor is a bookmark, not a
137
+ signature: a well-formed position another instant names moves within the same scope and nowhere else.
138
+ The cursor is readable by the client, so its key holds only what the caller already knows.
139
+
140
+ ### Fixed
141
+
142
+ - **The library answered `400` to its own `nextCursor` on page 2** when the tenant, the member and the row
143
+ id were each about 105 to 109 characters or more (the first length at which a cursor passes 512 is 109
144
+ for `listForUser`, 108 for `listForWorkspace` and 105 for `listSoleOwned` with the role `owner`): the
145
+ workspace page query refused a cursor over 512 characters, and a cursor for such ids is longer. The
146
+ bound is now 4096, sized from the longest cursor that ids and tenants of 128 code points and an owner role of 32
147
+ can produce (2306 characters), and the page query and the decoder share one constant.
148
+ - **A weak retired signing secret is reported under its own name.** A `jwt.previousSecrets` entry that is
149
+ empty, shorter than 32 characters or too repetitive was refused with an error that named `jwt.secret`,
150
+ so an operator fixed the current secret while the retired one stayed broken. The error now names
151
+ `jwt.previousSecrets[<index>]`. The rules are unchanged.
152
+
21
153
  ## [1.5.2] - 2026-11-12
22
154
 
23
155
  A patch release for workspaces: the bundled email provider can deliver a workspace invitation, and a
@@ -4951,7 +5083,8 @@ ever installable.
4951
5083
  - 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
4952
5084
  - 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
4953
5085
 
4954
- [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.2...HEAD
5086
+ [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.3...HEAD
5087
+ [1.5.3]: https://github.com/bymaxone/nest-auth/compare/v1.5.2...v1.5.3
4955
5088
  [1.5.2]: https://github.com/bymaxone/nest-auth/compare/v1.5.1...v1.5.2
4956
5089
  [1.5.1]: https://github.com/bymaxone/nest-auth/compare/v1.5.0...v1.5.1
4957
5090
  [1.5.0]: https://github.com/bymaxone/nest-auth/compare/v1.4.22...v1.5.0