@bymax-one/nest-auth 1.5.5 → 1.5.7
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 +77 -1
- package/README.md +7 -1
- package/dist/react/index.cjs +3 -1
- package/dist/react/index.d.cts +3 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.mjs +3 -1
- package/dist/server/index.cjs +236 -112
- package/dist/server/index.d.cts +97 -23
- package/dist/server/index.d.ts +97 -23
- package/dist/server/index.mjs +236 -113
- package/dist/shared/index.d.cts +8 -0
- package/dist/shared/index.d.ts +8 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -18,6 +18,79 @@ what moves, and that note is the compatibility contract until strict SemVer begi
|
|
|
18
18
|
|
|
19
19
|
## [Unreleased]
|
|
20
20
|
|
|
21
|
+
## [1.5.7] - 2026-11-17
|
|
22
|
+
|
|
23
|
+
A patch release.
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
|
|
27
|
+
- **`isServiceUnavailable(error)` is exported from the package.** It is a type guard for the `503 auth.service_unavailable`
|
|
28
|
+
the library answers during a Redis outage: it returns `true` for an `AuthException` carrying that code and narrows the
|
|
29
|
+
value to `AuthException`. A host filter or interceptor can now tell the outage apart from every other `AuthException`
|
|
30
|
+
without comparing codes by hand.
|
|
31
|
+
|
|
32
|
+
### Fixed
|
|
33
|
+
|
|
34
|
+
- **A login no longer leaves a live session behind when a later write fails.** The recent-authentication mark and
|
|
35
|
+
the session detail (`sd:` on the dashboard plane, `psd:` on the platform plane) used to be written after the session
|
|
36
|
+
itself, so a failure between the two answered an error while a refresh session nobody held stayed live. They are now
|
|
37
|
+
written in the same Redis script as the session, each keeping its own lifetime (the mark five minutes, the detail the
|
|
38
|
+
refresh lifetime). The script runs the commands that can fail on a wrong-typed key before it writes the refresh
|
|
39
|
+
record, so a failed login leaves no live session. The records and their bytes are unchanged.
|
|
40
|
+
- **A failed release of the MFA transition lock no longer changes what the transition answers.** The lock is released in a
|
|
41
|
+
`finally`; when the store could not answer the release after the repository write had committed, the rejection replaced
|
|
42
|
+
the result, so the caller was told an MFA change had failed that was in fact written, and a transition's own error was
|
|
43
|
+
hidden. The release failure is now logged and swallowed. The lock's ten-second TTL ends it on its own; a second
|
|
44
|
+
transition on the account is refused with `MFA_STATE_CONFLICT` until then.
|
|
45
|
+
- **A failed write to the account-status cache no longer decides the check.** On a cache miss the account is read from the
|
|
46
|
+
repository and the cache is filled; a store that could not take the write rejected a check the repository had already
|
|
47
|
+
decided, answering an outage for an active account and the store's error instead of its own refusal for a blocked one.
|
|
48
|
+
The write is now best effort: the decision is taken from the record just read, and the next request reads the repository
|
|
49
|
+
again. A failing cache read is still an outage.
|
|
50
|
+
|
|
51
|
+
- **A tiny `revalidateInterval` is no longer honoured.** `AuthProvider` polled `GET /me` at whatever positive period it was
|
|
52
|
+
given, so a value such as `1.5` (or `5` written as seconds) issued a request every few milliseconds from every open tab.
|
|
53
|
+
A positive value below 5000 milliseconds is now read as 5000. `0` still disables the loop, and a value that is not a
|
|
54
|
+
number from 0 to 2147483647 is still read as the default (five minutes).
|
|
55
|
+
|
|
56
|
+
### Apply to a derived backend
|
|
57
|
+
|
|
58
|
+
- **`SessionService.createSession` no longer writes `sd:{hash}`.** With `sessions.enabled`, `TokenManagerService.issueTokens`
|
|
59
|
+
writes it with the session; `createSession` keeps the session-limit enforcement and the `onNewSession` hook. A host that
|
|
60
|
+
calls `createSession` for a session it did not create through `issueTokens` gets no detail record from it.
|
|
61
|
+
- **Redis Cluster is not supported**, as it never was: the session scripts touch keys in different slots. The README now
|
|
62
|
+
says so.
|
|
63
|
+
- **Nothing is required for `isServiceUnavailable`.** The export is new; import it from `@bymax-one/nest-auth` where a
|
|
64
|
+
handler needs it.
|
|
65
|
+
- **A positive `revalidateInterval` below 5000 runs at 5000.** A test that gives `AuthProvider` a small interval to exercise
|
|
66
|
+
the loop must advance 5 seconds, or pass `0` to turn the loop off.
|
|
67
|
+
|
|
68
|
+
## [1.5.6] - 2026-11-15
|
|
69
|
+
|
|
70
|
+
A patch release. The wire contract is at version 8.
|
|
71
|
+
|
|
72
|
+
### Changed
|
|
73
|
+
|
|
74
|
+
- **The recent-authentication mark belongs to the session that earned it.** Access tokens carry a new signed `sid`
|
|
75
|
+
claim, the refresh family id of the session, kept through every rotation. The mark is written under
|
|
76
|
+
`ra:{hmac_sha256(hmacKey, userSubject)}:{sid}` and read under the caller's own `sid`, so another session of the same
|
|
77
|
+
account cannot use a mark it did not earn. The TTL is unchanged (300 seconds). The mark expires with its TTL and is not deleted by
|
|
78
|
+
logout or session revocation; only a token carrying its `sid` can read it.
|
|
79
|
+
- **Mixed deployments fail closed.** A mark written under the older account-wide key is not honoured after the upgrade, a
|
|
80
|
+
token minted before `sid` existed earns no proof, and a reader that does not know `sid` never finds the new key.
|
|
81
|
+
In each case the answer is a request to re-authenticate, never a pass.
|
|
82
|
+
|
|
83
|
+
### Apply to a derived backend
|
|
84
|
+
|
|
85
|
+
- **A user with no local password is asked to re-authenticate once** for a sensitive action (enrolling MFA, and the
|
|
86
|
+
workspace actions that re-prove the account) after the upgrade: until the session's next sign-in or refresh the token
|
|
87
|
+
has no `sid`, and a mark written before the upgrade is not read.
|
|
88
|
+
- **A host that signs its own access tokens must add `sid`.** Set it to the refresh family id of the session, 36
|
|
89
|
+
characters of lowercase hexadecimal and hyphens in 8-4-4-4-12; a token without a usable `sid` never satisfies the
|
|
90
|
+
re-authentication gate. A host that calls `TokenManagerService.issueTokens` needs no change, because the token it
|
|
91
|
+
returns carries `sid`. `MfaService.setup` takes the caller's `sid` as a trailing argument, and
|
|
92
|
+
`ReauthenticationService.assertReauthenticated` takes it after `tenantId`.
|
|
93
|
+
|
|
21
94
|
## [1.5.5] - 2026-11-14
|
|
22
95
|
|
|
23
96
|
A patch release.
|
|
@@ -25,6 +98,7 @@ A patch release.
|
|
|
25
98
|
### Fixed
|
|
26
99
|
|
|
27
100
|
- `issueTokensForUserId` no longer marks the session it issues as recently authenticated, matching rust-auth.
|
|
101
|
+
- Security advisory: [GHSA-93hv-9p5j-f5xp](https://github.com/bymaxone/nest-auth/security/advisories/GHSA-93hv-9p5j-f5xp).
|
|
28
102
|
|
|
29
103
|
### Apply to a derived backend
|
|
30
104
|
|
|
@@ -5149,7 +5223,9 @@ ever installable.
|
|
|
5149
5223
|
- 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
|
|
5150
5224
|
- 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
|
|
5151
5225
|
|
|
5152
|
-
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.
|
|
5226
|
+
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.7...HEAD
|
|
5227
|
+
[1.5.7]: https://github.com/bymaxone/nest-auth/compare/v1.5.6...v1.5.7
|
|
5228
|
+
[1.5.6]: https://github.com/bymaxone/nest-auth/compare/v1.5.5...v1.5.6
|
|
5153
5229
|
[1.5.5]: https://github.com/bymaxone/nest-auth/compare/v1.5.4...v1.5.5
|
|
5154
5230
|
[1.5.4]: https://github.com/bymaxone/nest-auth/compare/v1.5.3...v1.5.4
|
|
5155
5231
|
[1.5.3]: https://github.com/bymaxone/nest-auth/compare/v1.5.2...v1.5.3
|
package/README.md
CHANGED
|
@@ -155,6 +155,10 @@ pnpm add react
|
|
|
155
155
|
pnpm add next react server-only
|
|
156
156
|
```
|
|
157
157
|
|
|
158
|
+
> [!NOTE]
|
|
159
|
+
> The server subpath needs one Redis that every request reaches: a single node, a Sentinel setup or a replica set.
|
|
160
|
+
> Redis Cluster is not supported, because the scripts that write a session touch keys that hash to different slots.
|
|
161
|
+
|
|
158
162
|
> [!NOTE]
|
|
159
163
|
> `server-only` is what makes importing the Next.js JWT helper from a Client Component a
|
|
160
164
|
> **build error**. That module receives the HS256 secret, and a secret in a client chunk is a
|
|
@@ -989,7 +993,9 @@ auth.service_unavailable`, never admitted. What the library cannot do is bound h
|
|
|
989
993
|
> not loaded, a key of the wrong type) is a defect and stays `500 auth.internal`.
|
|
990
994
|
>
|
|
991
995
|
> The 503 is an `AuthException` whose `cause` is the ioredis error, so a host filter that logs 5xx
|
|
992
|
-
> answers (nest-core's, for one) records the real reason
|
|
996
|
+
> answers (nest-core's, for one) records the real reason; `isServiceUnavailable(error)`, exported from
|
|
997
|
+
> the package, tells that 503 apart from every other `AuthException` and narrows it, so a host filter
|
|
998
|
+
> or interceptor can handle it without comparing codes. The library's own `AuthExceptionFilter`
|
|
993
999
|
> writes no log line for it: your readiness probe, not the request log, is the signal that Redis is
|
|
994
1000
|
> down, so put a Redis health check next to it. Two answers keep their meaning: a password-reset
|
|
995
1001
|
> request refused because the cooldown store cannot answer is the same `503` for every address, and the
|
package/dist/react/index.cjs
CHANGED
|
@@ -6,6 +6,7 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
6
6
|
// src/react/AuthProvider.tsx
|
|
7
7
|
var AuthContext = react.createContext(null);
|
|
8
8
|
var DEFAULT_REVALIDATE_INTERVAL_MS = 3e5;
|
|
9
|
+
var MIN_REVALIDATE_INTERVAL_MS = 5e3;
|
|
9
10
|
var HTTP_STATUS_MIN = 100;
|
|
10
11
|
function clientErrorStatus(error) {
|
|
11
12
|
if (typeof error !== "object" || error === null) return void 0;
|
|
@@ -43,7 +44,8 @@ function isSessionExpiredError(error) {
|
|
|
43
44
|
return clientErrorStatus(error) === 401;
|
|
44
45
|
}
|
|
45
46
|
function useRevalidationLoop(revalidate, interval) {
|
|
46
|
-
const
|
|
47
|
+
const inRange = interval >= 0 && interval <= 2147483647;
|
|
48
|
+
const period = inRange ? Math.max(interval, interval > 0 ? MIN_REVALIDATE_INTERVAL_MS : 0) : DEFAULT_REVALIDATE_INTERVAL_MS;
|
|
47
49
|
react.useEffect(() => {
|
|
48
50
|
if (period <= 0) {
|
|
49
51
|
return void 0;
|
package/dist/react/index.d.cts
CHANGED
|
@@ -47,6 +47,9 @@ interface AuthProviderProps {
|
|
|
47
47
|
* A value that is not a number from `0` to `2147483647` (the largest delay a timer honors, so
|
|
48
48
|
* `NaN` and `Infinity` too) is read as the default, never as a 1 ms loop.
|
|
49
49
|
*
|
|
50
|
+
* A positive value below `5000` (5 seconds) is read as `5000`: a background poll has no use for a
|
|
51
|
+
* shorter period, and a value in the wrong unit would otherwise be a request every few milliseconds.
|
|
52
|
+
*
|
|
50
53
|
* Set to `0` to disable the loop entirely — useful for short-lived
|
|
51
54
|
* flows (sign-up wizards, kiosk screens) where the overhead of a
|
|
52
55
|
* background poll is not worth the freshness guarantee.
|
package/dist/react/index.d.ts
CHANGED
|
@@ -47,6 +47,9 @@ interface AuthProviderProps {
|
|
|
47
47
|
* A value that is not a number from `0` to `2147483647` (the largest delay a timer honors, so
|
|
48
48
|
* `NaN` and `Infinity` too) is read as the default, never as a 1 ms loop.
|
|
49
49
|
*
|
|
50
|
+
* A positive value below `5000` (5 seconds) is read as `5000`: a background poll has no use for a
|
|
51
|
+
* shorter period, and a value in the wrong unit would otherwise be a request every few milliseconds.
|
|
52
|
+
*
|
|
50
53
|
* Set to `0` to disable the loop entirely — useful for short-lived
|
|
51
54
|
* flows (sign-up wizards, kiosk screens) where the overhead of a
|
|
52
55
|
* background poll is not worth the freshness guarantee.
|
package/dist/react/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
4
4
|
// src/react/AuthProvider.tsx
|
|
5
5
|
var AuthContext = createContext(null);
|
|
6
6
|
var DEFAULT_REVALIDATE_INTERVAL_MS = 3e5;
|
|
7
|
+
var MIN_REVALIDATE_INTERVAL_MS = 5e3;
|
|
7
8
|
var HTTP_STATUS_MIN = 100;
|
|
8
9
|
function clientErrorStatus(error) {
|
|
9
10
|
if (typeof error !== "object" || error === null) return void 0;
|
|
@@ -41,7 +42,8 @@ function isSessionExpiredError(error) {
|
|
|
41
42
|
return clientErrorStatus(error) === 401;
|
|
42
43
|
}
|
|
43
44
|
function useRevalidationLoop(revalidate, interval) {
|
|
44
|
-
const
|
|
45
|
+
const inRange = interval >= 0 && interval <= 2147483647;
|
|
46
|
+
const period = inRange ? Math.max(interval, interval > 0 ? MIN_REVALIDATE_INTERVAL_MS : 0) : DEFAULT_REVALIDATE_INTERVAL_MS;
|
|
45
47
|
useEffect(() => {
|
|
46
48
|
if (period <= 0) {
|
|
47
49
|
return void 0;
|