@bymax-one/nest-auth 1.5.2 → 1.5.4
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 +187 -1
- package/README.md +232 -1116
- package/dist/client/index.cjs +18 -1
- package/dist/client/index.d.cts +2 -1
- package/dist/client/index.d.ts +2 -1
- package/dist/client/index.mjs +18 -1
- package/dist/nextjs/index.cjs +30 -9
- package/dist/nextjs/index.d.cts +58 -6
- package/dist/nextjs/index.d.ts +58 -6
- package/dist/nextjs/index.mjs +30 -9
- package/dist/react/index.cjs +16 -12
- package/dist/react/index.d.cts +3 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.mjs +16 -12
- package/dist/server/index.cjs +593 -228
- package/dist/server/index.d.cts +1305 -1146
- package/dist/server/index.d.ts +1305 -1146
- package/dist/server/index.mjs +582 -229
- package/dist/shared/index.cjs +8 -2
- package/dist/shared/index.d.cts +5 -0
- package/dist/shared/index.d.ts +5 -0
- package/dist/shared/index.mjs +8 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -18,6 +18,190 @@ what moves, and that note is the compatibility contract until strict SemVer begi
|
|
|
18
18
|
|
|
19
19
|
## [Unreleased]
|
|
20
20
|
|
|
21
|
+
## [1.5.4] - 2026-11-14
|
|
22
|
+
|
|
23
|
+
A patch release for outages and browsers: a Redis outage answers `503 auth.service_unavailable` instead of
|
|
24
|
+
`500`, a background revalidation no longer signs a signed-in user out on a failure that says nothing about the
|
|
25
|
+
session, an option-fed timer cannot be given a delay it cannot honor, and the wire contract is at version 7.
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- **A Redis outage answers `503 auth.service_unavailable`, not `500 auth.internal`.** With Redis paused or
|
|
30
|
+
stopped, login, refresh, logout, `GET /me`, every guarded route, MFA, registration and the rate-limited
|
|
31
|
+
routes answered `500` with a raw ioredis error in the log. Every Redis call of the library now goes through
|
|
32
|
+
one wrapper: a command that times out, a closed or refused connection, a client that gave up its retries, and
|
|
33
|
+
a server that replies it cannot serve (`READONLY`, `LOADING`, `MASTERDOWN`, `CLUSTERDOWN`, `TRYAGAIN`) raise
|
|
34
|
+
an `AuthException` with the new code, the ioredis error as its `cause` and nothing of it in the body. Any
|
|
35
|
+
other Redis reply error (`NOSCRIPT`, `WRONGTYPE`) stays a `500`. No `Retry-After` is sent.
|
|
36
|
+
- **A background revalidation no longer signs a signed-in user out on a failure that says nothing about the
|
|
37
|
+
session.** `AuthProvider` kept `SET_ERROR` for every non-401 failure, so a `503`, a `500`, a `429` or a
|
|
38
|
+
network error dropped the user to `unauthenticated`. Now only a final answer (a 4xx other than 429) does;
|
|
39
|
+
the user and the state stay through the rest and the next tick tries again. The first check of a page load
|
|
40
|
+
is unchanged.
|
|
41
|
+
- **An option-fed timer can no longer be given a delay a timer cannot honor.** `createAuthFetch({ timeout })`
|
|
42
|
+
throws a `TypeError` at creation for a value that is not a number from `0` to `2147483647`
|
|
43
|
+
(`NaN` and `Infinity` armed every request's abort timer at 1 ms), and `AuthProvider` reads a
|
|
44
|
+
`revalidateInterval` outside that range as the 5-minute default (it was a revalidation request every
|
|
45
|
+
millisecond).
|
|
46
|
+
|
|
47
|
+
### Changed
|
|
48
|
+
|
|
49
|
+
- **Wire contract version 7.** It adds `auth.service_unavailable` (503), pins that a password-reset request
|
|
50
|
+
whose cooldown store cannot answer answers `503` after the timing floor, the same for every address, and
|
|
51
|
+
pins that a `beforeWorkspaceCreate` hook that fails without refusing creates nothing and answers `500
|
|
52
|
+
auth.internal`. A new `serviceUnavailable` section lists where the 503 is answered, the rule for what the library
|
|
53
|
+
absorbs, and which store failures count as an outage; the classifier's spec reads the outage part.
|
|
54
|
+
- `AuthException` takes an optional third argument `{ cause }`, kept on the exception and never serialized.
|
|
55
|
+
- `supertest` devDependency floor is `^7.3.1`, and the e2e suite binds its port-only listeners to
|
|
56
|
+
`127.0.0.1`.
|
|
57
|
+
- The release workflow builds, verifies and packs once without a publish credential, and the publish job
|
|
58
|
+
checks the tarball's digest and publishes exactly that file with provenance.
|
|
59
|
+
|
|
60
|
+
### Apply to a derived backend
|
|
61
|
+
|
|
62
|
+
- **A client that switched on `500` to detect an outage must read `503` and `error.code`
|
|
63
|
+
`auth.service_unavailable`.** The status table in the README gains the `503` row. A host filter that renders
|
|
64
|
+
`HttpException`s answers it with its own envelope; one that logs 5xx now logs the real reason through `cause`.
|
|
65
|
+
`AuthExceptionFilter` writes no log line for it, so keep a Redis health check next to your readiness probe.
|
|
66
|
+
- **A password-reset request or resend whose cooldown store cannot answer answers `503` instead of `500`.** A failure
|
|
67
|
+
after the account is known (storing the code) still answers `200`.
|
|
68
|
+
- **The OAuth callback redirects with `error=auth.service_unavailable`** when `oauth.errorRedirectUrl` is set and
|
|
69
|
+
Redis is down, as it does for any other `AuthException`.
|
|
70
|
+
- **`createAuthFetch` throws at creation for an out-of-range `timeout`.** Pass a number of milliseconds from `0`
|
|
71
|
+
(no timeout) to `2147483647`, or omit it.
|
|
72
|
+
|
|
73
|
+
## [1.5.3] - 2026-11-14
|
|
74
|
+
|
|
75
|
+
A patch release for workspaces, MFA and the proxy: the paging cursor is a codec the library now exports and
|
|
76
|
+
bounds, the owner role is bounded by length instead of a charset, the websocket guard holds a header credential
|
|
77
|
+
to the chain a request is held to, MFA state and its failure counters are keyed by the tenant only, the module
|
|
78
|
+
probes Redis at startup, a provider plugin's calls have a deadline, the Next.js proxy checks the backend's issuer,
|
|
79
|
+
audience and retired secrets, and the wire contract is at version 6.
|
|
80
|
+
|
|
81
|
+
### Apply to a derived backend
|
|
82
|
+
|
|
83
|
+
- **`workspaces.roles.ownerRole` is checked at startup.** It must be 1 to 32 code points of well-formed
|
|
84
|
+
text with no control character, the rule an id follows, and its characters are free: `owner`,
|
|
85
|
+
`org:admin`, `team lead` and `proprietário` all pass. The owner role is part of the key a
|
|
86
|
+
`listSoleOwned` cursor is bound to, and only an empty name, one of more than 32 code points, or one with a control
|
|
87
|
+
character or an unpaired surrogate, is refused, naming the option and the rule. Only the owner role is
|
|
88
|
+
checked: the other roles of the hierarchy keep any name.
|
|
89
|
+
- **A workspace page cursor may now be up to 4096 characters, not 512.** The wire contract is at version 6:
|
|
90
|
+
`requestFieldBounds.pageLimit.cursor` and the published `WorkspacePageQueryDto` schema say 4096, and the
|
|
91
|
+
contract states the owner-role rule as a new `workspaceOwnerRole` section. During a rolling deploy an
|
|
92
|
+
instance still on 1.5.2 or earlier answers `400` to a cursor longer than 512 characters that this
|
|
93
|
+
release issued, which needs ids of about 105 characters or more (see Fixed), and only until every
|
|
94
|
+
instance has been replaced.
|
|
95
|
+
- **A host adapter can drop its own cursor codec.** A cursor in the format the template's hand-written
|
|
96
|
+
codec writes (base64url of the JSON of the query key and the position) keeps reading, which the spec
|
|
97
|
+
pins with cursors that codec issued. Replace `keyOf`, `positionOf`, `encodeCursor`, `decodeCursor` and
|
|
98
|
+
`readPosition` with `workspaceQueryKey`, `workspacePositionOf`, `encodeWorkspaceCursor`,
|
|
99
|
+
`decodeWorkspaceCursor` and `readWorkspacePosition`, and delete the local copy and its spec.
|
|
100
|
+
`workspaceQueryKey` is
|
|
101
|
+
`JSON.stringify` of its parts, byte for byte, so a lock or map key built from it does not move.
|
|
102
|
+
`encodeWorkspaceCursor` throws a `RangeError` for a position the decoder would read as none and for a
|
|
103
|
+
cursor over 4096 characters (a key part over 128 code points), instead of issuing a cursor the next
|
|
104
|
+
request could never follow. Every id you issue must be 1 to 128 code points of well-formed text with no
|
|
105
|
+
control character.
|
|
106
|
+
- **`verifyAccessToken` with a `workspaceId` while workspaces are off now throws `AuthException` (validation),
|
|
107
|
+
not a `TypeError`, and only after the token is verified: an invalid, expired or revoked token still gets
|
|
108
|
+
`TOKEN_INVALID`.** The refusal names the field `workspaceId`, so a handler maps it to a `400` like any
|
|
109
|
+
other refused input. A platform-plane token still throws a `TypeError`, which is a programming error.
|
|
110
|
+
- **The wire contract is at version 6: the two password re-proof counters are pinned.** `userSubjectDerivedKeys`
|
|
111
|
+
gains `changePasswordFailureCounter` and `emailChangeFailureCounter` (`lf:` over `reauth:change-password:` or
|
|
112
|
+
`reauth:email-change:` and the tenant-scoped user subject), and the new `reproofCounterVectors` section gives
|
|
113
|
+
known answers for them, including an accented tenant, a tenant containing `:` and the pair a bare delimiter would
|
|
114
|
+
merge, so a library that derived the counter from the bare user id would fail its own test instead of splitting a
|
|
115
|
+
budget unnoticed. This library already derived both counters this way, so nothing changes at runtime here; the
|
|
116
|
+
derivation moved into one function, `reproofCounterId`, that the two flows call. A backend that reads the contract
|
|
117
|
+
must adopt version 6 and derive the same bytes.
|
|
118
|
+
- **MFA state and its failure counters are keyed by the tenant on the dashboard plane, and the tenant-less
|
|
119
|
+
duplicates are gone.** Five keys also took a second, tenant-less form that two tenants' user `1` shared:
|
|
120
|
+
the MFA transition lock (`mfalock:`), the TOTP replay marker (`tu:`), and the failure counters of the
|
|
121
|
+
`challenge`, `disable` and `reauth` flows. With them, failures counted against user `1` of one tenant
|
|
122
|
+
locked user `1` of another out of those flows with no credential, a success in one cleared the
|
|
123
|
+
other's count, a transition in one answered `MFA_STATE_CONFLICT` in the other, and one tenant's TOTP
|
|
124
|
+
code burnt the other's. A host whose user ids are unique across tenants (UUIDs) was never affected.
|
|
125
|
+
Only the length-prefixed forms (`userSubject`) are read and written now, the ones the shared keyspace
|
|
126
|
+
contract names. The tenant-less keys were the compatibility arm of a rolling deploy that the code
|
|
127
|
+
already said could not be made safe, so drain old instances before new ones serve, as the keyspace
|
|
128
|
+
contract requires; a lockout counted under a tenant-less key before the upgrade does not carry over.
|
|
129
|
+
- **A provider plugin's code exchange and profile fetch are bounded to 10 seconds together.** The
|
|
130
|
+
callback awaited the plugin with no deadline, so a token or profile endpoint that accepted the
|
|
131
|
+
connection and went silent held the request open with its state already consumed. Past the deadline
|
|
132
|
+
the callback is answered `OAUTH_FAILED` and the plugin's pending request is abandoned, not cancelled,
|
|
133
|
+
so a plugin should bound its own requests too. A plugin may set `timeoutMs` (a whole number from 1
|
|
134
|
+
to 120000; anything else is read as 10000). The bundled Google plugin sets 20000, the sum of the 10
|
|
135
|
+
seconds its two requests are each bounded at.
|
|
136
|
+
- **The Next.js proxy can hold a token to the backend's issuer, audience and retired secrets.** Set
|
|
137
|
+
`jwtIssuer`, `jwtAudience` and `jwtPreviousSecrets` on `createAuthProxy` to the backend's
|
|
138
|
+
`jwt.issuer`, `jwt.audience` and `jwt.previousSecrets`. With an issuer or audience set, a token
|
|
139
|
+
without exactly that `iss`, or whose `aud` is not or does not contain that value, is not
|
|
140
|
+
authenticated; with retired secrets set, a token signed under one is verified, as the backend still
|
|
141
|
+
accepts it while a rotation drains. Unset, the proxy checks the signature and the expiry only, as
|
|
142
|
+
before, so a backend that sets an issuer or audience today has a proxy that admits a token the
|
|
143
|
+
backend refuses: set the three to match. `verifyJwtToken` takes the same values as an optional third
|
|
144
|
+
argument, `VerifyJwtOptions`. The README and the JSDoc now say what the proxy is: a routing hint that
|
|
145
|
+
cannot see revocation, an account's current status, the MFA state or a workspace membership, never the
|
|
146
|
+
access decision for data or an action.
|
|
147
|
+
|
|
148
|
+
- **The module sends `PING` to your Redis client at bootstrap and refuses to start when it never answers.** It
|
|
149
|
+
retries every 250 ms for up to 5 seconds, so a Redis still starting during a rolling deploy, or a client
|
|
150
|
+
built with `lazyConnect` or `enableOfflineQueue: false` whose first command is rejected, passes once
|
|
151
|
+
the connection is up. A refused connection, a wrong password or a silent Redis for the whole budget
|
|
152
|
+
stops the application with `[BymaxAuthModule] Redis at <host>:<port> did not answer PING within 5000 ms`,
|
|
153
|
+
naming only the host and port the client was built with, never a password, a URL or the error ioredis
|
|
154
|
+
raised; a client that has ended fails at once. Before, a mis-pointed address started fine and failed
|
|
155
|
+
on the first request. A host whose tests build the module with a client that has no `ping` fails with
|
|
156
|
+
`BYMAX_AUTH_REDIS_CLIENT must be an ioredis client`; `ioredis-mock` answers it. A client with no
|
|
157
|
+
`commandTimeout` is warned about at startup, and the README's Configuration section says what to set:
|
|
158
|
+
with ioredis defaults an unreachable Redis holds each request until the client gives up, which reads
|
|
159
|
+
as a hang, though every decision still fails closed.
|
|
160
|
+
- **`WsJwtGuard` holds a handshake `Authorization` header to the chain a request is held to.** It now
|
|
161
|
+
verifies through `AuthTokenVerifierService`, so a token with a `jti` that is not a UUID, or with no
|
|
162
|
+
`tenantId`, is refused at the guard, and two gates that were absent are on by default: the account's
|
|
163
|
+
**current** status (a blocked or suspended account answers its `ACCOUNT_*` code) and the MFA policy (a
|
|
164
|
+
token with `mfaEnabled` and no `mfaVerified` answers `MFA_REQUIRED`). A socket stayed open for as long
|
|
165
|
+
as its client wished, and a token issued before MFA was enabled mid-session opened it without the second
|
|
166
|
+
factor. `@SkipMfa()` on a gateway handler or class lifts the MFA gate, as it does on HTTP, for the
|
|
167
|
+
handler that has to work while a factor is being set up; the status gate has no opt-out. The ticket path
|
|
168
|
+
is unchanged: a ticket is minted from a session that already passed both. The constructor takes
|
|
169
|
+
`AuthTokenVerifierService` and `Reflector` in place of `JwtService` and `AuthRevocationService`, so a
|
|
170
|
+
host that subclasses or constructs the guard by hand must update the call; a host that applies it with
|
|
171
|
+
`@UseGuards(WsJwtGuard)` needs nothing, because the module already exports the verifier.
|
|
172
|
+
|
|
173
|
+
### Added
|
|
174
|
+
|
|
175
|
+
- **`AUTH_SECRET_MIN_LENGTH`** (32), the floor the boot check applies to every secret option,
|
|
176
|
+
exported so a host that generates secrets can size them from the same constant.
|
|
177
|
+
- **`assertWorkspaceId` and `WORKSPACE_ID_MAX_LENGTH`** (128 code points), the refusal the request edge
|
|
178
|
+
applies to a workspace id, exported for a host that reads the id itself. It matches the cursor's rule for
|
|
179
|
+
an id except that it does not refuse an unpaired surrogate.
|
|
180
|
+
- **Workspace cursor codec**, exported next to the membership port: `workspaceQueryKey`,
|
|
181
|
+
`workspacePositionOf`, `readWorkspacePosition`, `encodeWorkspaceCursor`, `decodeWorkspaceCursor` and the
|
|
182
|
+
constants `WORKSPACE_CURSOR_MAX_LENGTH`, `WORKSPACE_CURSOR_PART_MAX_LENGTH`,
|
|
183
|
+
`WORKSPACE_OWNER_ROLE_MAX_LENGTH`, with `isWorkspaceOwnerRole` for the owner-role rule. Decoding implements the rule the
|
|
184
|
+
port states of every cursor: one that is malformed, longer than the bound, not exactly the bytes the
|
|
185
|
+
encoder writes, not a pair of two strings, issued for another query, or whose position is not an
|
|
186
|
+
instant followed by a well-formed id of 1 to 128 code points without control characters reads as the
|
|
187
|
+
first page and never widens the scope. A value that is not a string reads the same way. The scope always
|
|
188
|
+
comes from the query the store builds, never from the cursor, and a cursor is a bookmark, not a
|
|
189
|
+
signature: a well-formed position another instant names moves within the same scope and nowhere else.
|
|
190
|
+
The cursor is readable by the client, so its key holds only what the caller already knows.
|
|
191
|
+
|
|
192
|
+
### Fixed
|
|
193
|
+
|
|
194
|
+
- **The library answered `400` to its own `nextCursor` on page 2** when the tenant, the member and the row
|
|
195
|
+
id were each about 105 to 109 characters or more (the first length at which a cursor passes 512 is 109
|
|
196
|
+
for `listForUser`, 108 for `listForWorkspace` and 105 for `listSoleOwned` with the role `owner`): the
|
|
197
|
+
workspace page query refused a cursor over 512 characters, and a cursor for such ids is longer. The
|
|
198
|
+
bound is now 4096, sized from the longest cursor that ids and tenants of 128 code points and an owner role of 32
|
|
199
|
+
can produce (2306 characters), and the page query and the decoder share one constant.
|
|
200
|
+
- **A weak retired signing secret is reported under its own name.** A `jwt.previousSecrets` entry that is
|
|
201
|
+
empty, shorter than 32 characters or too repetitive was refused with an error that named `jwt.secret`,
|
|
202
|
+
so an operator fixed the current secret while the retired one stayed broken. The error now names
|
|
203
|
+
`jwt.previousSecrets[<index>]`. The rules are unchanged.
|
|
204
|
+
|
|
21
205
|
## [1.5.2] - 2026-11-12
|
|
22
206
|
|
|
23
207
|
A patch release for workspaces: the bundled email provider can deliver a workspace invitation, and a
|
|
@@ -4951,7 +5135,9 @@ ever installable.
|
|
|
4951
5135
|
- 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
5136
|
- 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
5137
|
|
|
4954
|
-
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.
|
|
5138
|
+
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.4...HEAD
|
|
5139
|
+
[1.5.4]: https://github.com/bymaxone/nest-auth/compare/v1.5.3...v1.5.4
|
|
5140
|
+
[1.5.3]: https://github.com/bymaxone/nest-auth/compare/v1.5.2...v1.5.3
|
|
4955
5141
|
[1.5.2]: https://github.com/bymaxone/nest-auth/compare/v1.5.1...v1.5.2
|
|
4956
5142
|
[1.5.1]: https://github.com/bymaxone/nest-auth/compare/v1.5.0...v1.5.1
|
|
4957
5143
|
[1.5.0]: https://github.com/bymaxone/nest-auth/compare/v1.4.22...v1.5.0
|