@bymax-one/nest-auth 1.1.0 → 1.1.1
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 +62 -0
- package/README.md +6 -1
- package/dist/client/index.cjs +8 -1
- package/dist/client/index.mjs +8 -1
- package/dist/nextjs/index.d.cts +15 -3
- package/dist/nextjs/index.d.ts +15 -3
- package/dist/react/index.cjs +8 -0
- package/dist/react/index.mjs +8 -0
- package/dist/server/index.cjs +526 -313
- package/dist/server/index.d.cts +130 -60
- package/dist/server/index.d.ts +130 -60
- package/dist/server/index.mjs +526 -313
- package/package.json +3 -13
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,67 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.1.1] - 2026-08-05
|
|
11
|
+
|
|
12
|
+
This release carries the second cross-implementation security audit as well as the dependency-injection fix below. Both landed as separate pull requests; the audit one carried no version of its own, so its account is here.
|
|
13
|
+
|
|
14
|
+
### Security
|
|
15
|
+
|
|
16
|
+
- **The AES key over every stored second factor was enumerable.** `1.1.0` hid `jwt.secret`, its
|
|
17
|
+
rotation predecessors and the derived HMAC keys, but not `mfa.encryptionKey` or
|
|
18
|
+
`mfa.previousEncryptionKeys` — the AES-256-GCM key protecting every enrolled user's TOTP secret
|
|
19
|
+
and their recovery-code set. `JSON.stringify`, object spread and `util.inspect` on the resolved
|
|
20
|
+
options all emitted it, which is what a structured logger does when handed a provider.
|
|
21
|
+
- **Refresh-token reuse was logged anonymously.** The strongest compromise signal this library
|
|
22
|
+
produces reached only a consumer who had wired the hook, and the shipped hooks are no-ops.
|
|
23
|
+
- **A `getMe()` in flight could resurrect a session after logout.** `status` returned to
|
|
24
|
+
`authenticated` and the profile returned to context, so `useAuthStatus().isAuthenticated` — which
|
|
25
|
+
this library's own JSDoc calls safe to gate protected routes on — answered `true` after sign-out.
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- **The two libraries could not read each other's password hashes.** This library wrote
|
|
30
|
+
`scrypt:N:r:p:{saltHex}:{derivedHex}` while `rust-auth` writes PHC. Neither parser accepted the
|
|
31
|
+
other's output, and because verification is total the failure surfaced as `invalid_credentials`
|
|
32
|
+
rather than a parse error — so five correct attempts by the owner tripped the brute-force
|
|
33
|
+
counter the two backends key identically and locked the account out of both.
|
|
34
|
+
- **Every non-Latin password was refused as compromised.** Two ASCII filters in the breach screen:
|
|
35
|
+
`isDecoration` used `\W`, so Cyrillic, Greek, Han, Kana, Arabic, Hebrew and Thai characters all
|
|
36
|
+
counted as decoration and were stripped, and what survived was filtered to `[a-z0-9]`.
|
|
37
|
+
- **`baseUrl: '/api'` sent every request to `/api/api/auth/*`.** The client composed the full URL
|
|
38
|
+
and also handed `baseUrl` to the fetch wrapper it builds — the value the README and
|
|
39
|
+
`AuthProvider`'s own example document for the same-origin/Next-proxy setup.
|
|
40
|
+
- **A new session was written with five loose Redis commands**, where `rust-auth` does the same
|
|
41
|
+
work in one `MULTI/EXEC`. A revoke-all landing between the record write and the index `SADD`
|
|
42
|
+
swept an index the session was not in yet, and a dropped connection between the `SADD` and the
|
|
43
|
+
`EXPIRE` left the index with no expiry at all, permanently.
|
|
44
|
+
- **The session index grew one permanent member per refresh.** A rotation adds `rp:{old}`
|
|
45
|
+
alongside `rt:{new}`, only a full revoke-all ever removed it, and the rotation re-armed the
|
|
46
|
+
set's TTL each time. Every reader is linear in its size, including the script a password reset
|
|
47
|
+
runs, which blocks the whole single-threaded store.
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
|
|
51
|
+
- **Dependency injection no longer depends on a transitive dev dependency.** Seventy-one
|
|
52
|
+
constructor parameters across thirty classes were resolved from `design:paramtypes`,
|
|
53
|
+
the metadata TypeScript emits — and this package emitted it only because `@swc/core`
|
|
54
|
+
happened to be in the tree via `ts-node`. tsup enables its SWC transform when that
|
|
55
|
+
package is present and prints a warning when it is not:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
You have emitDecoratorMetadata enabled but @swc/core was not installed, skipping swc plugin
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Nine sibling packages get that second path and none of their bundles carry the metadata. Had the transitive dependency moved,
|
|
62
|
+
every one of those parameters would have stopped resolving at once — silently wherever
|
|
63
|
+
`@Optional()` is present. They now carry explicit `@Inject`, which writes
|
|
64
|
+
`self:paramtypes` and is independent of any build transform.
|
|
65
|
+
|
|
66
|
+
- `@swc/core` is a declared devDependency. The metadata is still needed — `ValidationPipe`
|
|
67
|
+
finds a DTO class through the reflected parameter type, and thirty-one controller
|
|
68
|
+
parameters here are typed by DTO — so the emission stays. It is now deliberate rather
|
|
69
|
+
than inherited.
|
|
70
|
+
|
|
10
71
|
## [1.1.0] - 2026-08-03
|
|
11
72
|
|
|
12
73
|
The API changes marked **Breaking** below are breaking against `1.0.11`. They are
|
|
@@ -1015,6 +1076,7 @@ ever installable.
|
|
|
1015
1076
|
- 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
|
|
1016
1077
|
|
|
1017
1078
|
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.1.0...HEAD
|
|
1079
|
+
[1.1.1]: https://github.com/bymaxone/nest-auth/compare/v1.1.0...v1.1.1
|
|
1018
1080
|
[1.1.0]: https://github.com/bymaxone/nest-auth/compare/v1.0.11...v1.1.0
|
|
1019
1081
|
[1.0.11]: https://github.com/bymaxone/nest-auth/compare/v1.0.10...v1.0.11
|
|
1020
1082
|
[1.0.10]: https://github.com/bymaxone/nest-auth/compare/v1.0.9...v1.0.10
|
package/README.md
CHANGED
|
@@ -534,7 +534,10 @@ backend.
|
|
|
534
534
|
// proxy.ts — Next.js 16 Edge middleware
|
|
535
535
|
import { createAuthProxy } from '@bymax-one/nest-auth/nextjs'
|
|
536
536
|
|
|
537
|
-
|
|
537
|
+
// Next 16 scans this file for a function exported as `proxy` (or as the default), and it
|
|
538
|
+
// does not recognise a destructuring pattern: `export const { proxy } = ...` fails the build
|
|
539
|
+
// with "The file ./proxy.ts must export a function". Bind first, then export.
|
|
540
|
+
const authProxy = createAuthProxy({
|
|
538
541
|
publicRoutes: ['/', '/auth/login', '/auth/register'],
|
|
539
542
|
publicRoutesRedirectIfAuthenticated: ['/auth/login', '/auth/register'],
|
|
540
543
|
protectedRoutes: [
|
|
@@ -559,6 +562,8 @@ export const { proxy } = createAuthProxy({
|
|
|
559
562
|
blockedUserStatuses: ['BANNED', 'INACTIVE', 'EXPIRED']
|
|
560
563
|
})
|
|
561
564
|
|
|
565
|
+
export const proxy = authProxy.proxy
|
|
566
|
+
|
|
562
567
|
export const config = {
|
|
563
568
|
matcher: ['/((?!_next/static|_next/image|favicon.ico).*)']
|
|
564
569
|
}
|
package/dist/client/index.cjs
CHANGED
|
@@ -282,7 +282,14 @@ function createAuthClient(config) {
|
|
|
282
282
|
const baseUrl = normalizeBaseUrl(config.baseUrl);
|
|
283
283
|
const routePrefix = normalizeRoutePrefix(config.routePrefix ?? "auth");
|
|
284
284
|
const authFetch = config.authFetch ?? createAuthFetch({
|
|
285
|
-
baseUrl,
|
|
285
|
+
// Deliberately NO `baseUrl`. This client composes the full URL itself in `url()` below,
|
|
286
|
+
// and `createAuthFetch` prepends its own `baseUrl` to any input that is not absolute —
|
|
287
|
+
// so passing it here applied the base TWICE. With the documented same-origin setting
|
|
288
|
+
// (`baseUrl: '/api'`, used by the README and by AuthProvider's own example) every call
|
|
289
|
+
// went to `/api/api/auth/*` and 404'd: login, register, logout, refresh and getMe, all
|
|
290
|
+
// of them. An absolute base hid it, because the second prepend is skipped for anything
|
|
291
|
+
// matching `^https?://` — which is why every test in this file, all of which use an
|
|
292
|
+
// absolute base AND inject a stub `authFetch`, stayed green.
|
|
286
293
|
routePrefix,
|
|
287
294
|
// Stryker disable next-line ConditionalExpression: spreading `{ key: undefined }` vs omitting the key is identical — createAuthFetch coalesces each option with `??`/falsy checks downstream
|
|
288
295
|
...config.refreshEndpoint !== void 0 ? {
|
package/dist/client/index.mjs
CHANGED
|
@@ -281,7 +281,14 @@ function createAuthClient(config) {
|
|
|
281
281
|
const baseUrl = normalizeBaseUrl(config.baseUrl);
|
|
282
282
|
const routePrefix = normalizeRoutePrefix(config.routePrefix ?? "auth");
|
|
283
283
|
const authFetch = config.authFetch ?? createAuthFetch({
|
|
284
|
-
baseUrl,
|
|
284
|
+
// Deliberately NO `baseUrl`. This client composes the full URL itself in `url()` below,
|
|
285
|
+
// and `createAuthFetch` prepends its own `baseUrl` to any input that is not absolute —
|
|
286
|
+
// so passing it here applied the base TWICE. With the documented same-origin setting
|
|
287
|
+
// (`baseUrl: '/api'`, used by the README and by AuthProvider's own example) every call
|
|
288
|
+
// went to `/api/api/auth/*` and 404'd: login, register, logout, refresh and getMe, all
|
|
289
|
+
// of them. An absolute base hid it, because the second prepend is skipped for anything
|
|
290
|
+
// matching `^https?://` — which is why every test in this file, all of which use an
|
|
291
|
+
// absolute base AND inject a stub `authFetch`, stayed green.
|
|
285
292
|
routePrefix,
|
|
286
293
|
// Stryker disable next-line ConditionalExpression: spreading `{ key: undefined }` vs omitting the key is identical — createAuthFetch coalesces each option with `??`/falsy checks downstream
|
|
287
294
|
...config.refreshEndpoint !== void 0 ? {
|
package/dist/nextjs/index.d.cts
CHANGED
|
@@ -539,7 +539,7 @@ declare function getTenantId(token: DecodedToken): string | undefined;
|
|
|
539
539
|
* // proxy.ts
|
|
540
540
|
* import { createAuthProxy } from '@bymax-one/nest-auth/nextjs'
|
|
541
541
|
*
|
|
542
|
-
*
|
|
542
|
+
* const authProxy = createAuthProxy({
|
|
543
543
|
* publicRoutes: ['/', '/auth/login'],
|
|
544
544
|
* publicRoutesRedirectIfAuthenticated: ['/auth/login'],
|
|
545
545
|
* protectedRoutes: [
|
|
@@ -554,6 +554,10 @@ declare function getTenantId(token: DecodedToken): string | undefined;
|
|
|
554
554
|
* blockedUserStatuses: ['BANNED', 'INACTIVE', 'EXPIRED']
|
|
555
555
|
* })
|
|
556
556
|
*
|
|
557
|
+
* // Bound first, then exported: Next 16 scans this file for a function exported as `proxy`
|
|
558
|
+
* // and does not recognise `export const { proxy } = ...`, which fails the build.
|
|
559
|
+
* export const proxy = authProxy.proxy
|
|
560
|
+
*
|
|
557
561
|
* export const config = { matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'] }
|
|
558
562
|
* ```
|
|
559
563
|
*
|
|
@@ -682,11 +686,19 @@ interface AuthProxyConfig {
|
|
|
682
686
|
*/
|
|
683
687
|
interface AuthProxyInstance {
|
|
684
688
|
/**
|
|
685
|
-
* The Next.js 16 proxy function.
|
|
689
|
+
* The Next.js 16 proxy function. Bind the instance, then re-export this property:
|
|
686
690
|
*
|
|
687
691
|
* ```ts
|
|
688
|
-
*
|
|
692
|
+
* const authProxy = createAuthProxy({ ... })
|
|
693
|
+
* export const proxy = authProxy.proxy
|
|
689
694
|
* ```
|
|
695
|
+
*
|
|
696
|
+
* NOT `export const { proxy } = createAuthProxy({ ... })`. Next 16 statically scans
|
|
697
|
+
* `proxy.ts` for a function exported under that name and does not recognise a destructuring
|
|
698
|
+
* pattern, so the destructured form fails the production build outright: "The file
|
|
699
|
+
* ./proxy.ts must export a function, either as a default export or as a named 'proxy'
|
|
700
|
+
* export." It was the documented form here and in the README until a real Next build was
|
|
701
|
+
* run against the published artifact.
|
|
690
702
|
*/
|
|
691
703
|
readonly proxy: (request: NextRequest) => Promise<NextResponse>;
|
|
692
704
|
/**
|
package/dist/nextjs/index.d.ts
CHANGED
|
@@ -539,7 +539,7 @@ declare function getTenantId(token: DecodedToken): string | undefined;
|
|
|
539
539
|
* // proxy.ts
|
|
540
540
|
* import { createAuthProxy } from '@bymax-one/nest-auth/nextjs'
|
|
541
541
|
*
|
|
542
|
-
*
|
|
542
|
+
* const authProxy = createAuthProxy({
|
|
543
543
|
* publicRoutes: ['/', '/auth/login'],
|
|
544
544
|
* publicRoutesRedirectIfAuthenticated: ['/auth/login'],
|
|
545
545
|
* protectedRoutes: [
|
|
@@ -554,6 +554,10 @@ declare function getTenantId(token: DecodedToken): string | undefined;
|
|
|
554
554
|
* blockedUserStatuses: ['BANNED', 'INACTIVE', 'EXPIRED']
|
|
555
555
|
* })
|
|
556
556
|
*
|
|
557
|
+
* // Bound first, then exported: Next 16 scans this file for a function exported as `proxy`
|
|
558
|
+
* // and does not recognise `export const { proxy } = ...`, which fails the build.
|
|
559
|
+
* export const proxy = authProxy.proxy
|
|
560
|
+
*
|
|
557
561
|
* export const config = { matcher: ['/((?!_next/static|_next/image|favicon.ico).*)'] }
|
|
558
562
|
* ```
|
|
559
563
|
*
|
|
@@ -682,11 +686,19 @@ interface AuthProxyConfig {
|
|
|
682
686
|
*/
|
|
683
687
|
interface AuthProxyInstance {
|
|
684
688
|
/**
|
|
685
|
-
* The Next.js 16 proxy function.
|
|
689
|
+
* The Next.js 16 proxy function. Bind the instance, then re-export this property:
|
|
686
690
|
*
|
|
687
691
|
* ```ts
|
|
688
|
-
*
|
|
692
|
+
* const authProxy = createAuthProxy({ ... })
|
|
693
|
+
* export const proxy = authProxy.proxy
|
|
689
694
|
* ```
|
|
695
|
+
*
|
|
696
|
+
* NOT `export const { proxy } = createAuthProxy({ ... })`. Next 16 statically scans
|
|
697
|
+
* `proxy.ts` for a function exported under that name and does not recognise a destructuring
|
|
698
|
+
* pattern, so the destructured form fails the production build outright: "The file
|
|
699
|
+
* ./proxy.ts must export a function, either as a default export or as a named 'proxy'
|
|
700
|
+
* export." It was the documented form here and in the README until a real Next build was
|
|
701
|
+
* run against the published artifact.
|
|
690
702
|
*/
|
|
691
703
|
readonly proxy: (request: NextRequest) => Promise<NextResponse>;
|
|
692
704
|
/**
|
package/dist/react/index.cjs
CHANGED
|
@@ -56,6 +56,7 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
56
56
|
const onSessionExpiredRef = React.useRef(onSessionExpired);
|
|
57
57
|
const clientRef = React.useRef(client);
|
|
58
58
|
const statusRef = React.useRef(INITIAL_STATE.status);
|
|
59
|
+
const sessionGenerationRef = React.useRef({});
|
|
59
60
|
React.useEffect(() => {
|
|
60
61
|
onSessionExpiredRef.current = onSessionExpired;
|
|
61
62
|
}, [
|
|
@@ -83,8 +84,10 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
83
84
|
}
|
|
84
85
|
}, []);
|
|
85
86
|
const revalidate = React.useCallback(async (isInitial) => {
|
|
87
|
+
const generation = sessionGenerationRef.current;
|
|
86
88
|
try {
|
|
87
89
|
const user = await clientRef.current.getMe();
|
|
90
|
+
if (sessionGenerationRef.current !== generation) return;
|
|
88
91
|
syncedDispatch({
|
|
89
92
|
type: "SET_USER",
|
|
90
93
|
payload: {
|
|
@@ -93,6 +96,7 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
93
96
|
}
|
|
94
97
|
});
|
|
95
98
|
} catch (error) {
|
|
99
|
+
if (sessionGenerationRef.current !== generation) return;
|
|
96
100
|
const wasAuthenticated = statusRef.current === "authenticated";
|
|
97
101
|
if (isSessionExpiredError(error)) {
|
|
98
102
|
if (!isInitial && wasAuthenticated) {
|
|
@@ -145,11 +149,13 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
145
149
|
tenantId
|
|
146
150
|
});
|
|
147
151
|
if ("mfaRequired" in result) {
|
|
152
|
+
sessionGenerationRef.current = {};
|
|
148
153
|
syncedDispatch({
|
|
149
154
|
type: "CLEAR_SESSION"
|
|
150
155
|
});
|
|
151
156
|
return result;
|
|
152
157
|
}
|
|
158
|
+
sessionGenerationRef.current = {};
|
|
153
159
|
syncedDispatch({
|
|
154
160
|
type: "SET_USER",
|
|
155
161
|
payload: {
|
|
@@ -173,6 +179,7 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
173
179
|
});
|
|
174
180
|
try {
|
|
175
181
|
const result = await clientRef.current.register(data);
|
|
182
|
+
sessionGenerationRef.current = {};
|
|
176
183
|
syncedDispatch({
|
|
177
184
|
type: "SET_USER",
|
|
178
185
|
payload: {
|
|
@@ -194,6 +201,7 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
194
201
|
try {
|
|
195
202
|
await clientRef.current.logout();
|
|
196
203
|
} finally {
|
|
204
|
+
sessionGenerationRef.current = {};
|
|
197
205
|
syncedDispatch({
|
|
198
206
|
type: "CLEAR_SESSION"
|
|
199
207
|
});
|
package/dist/react/index.mjs
CHANGED
|
@@ -50,6 +50,7 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
50
50
|
const onSessionExpiredRef = useRef(onSessionExpired);
|
|
51
51
|
const clientRef = useRef(client);
|
|
52
52
|
const statusRef = useRef(INITIAL_STATE.status);
|
|
53
|
+
const sessionGenerationRef = useRef({});
|
|
53
54
|
useEffect(() => {
|
|
54
55
|
onSessionExpiredRef.current = onSessionExpired;
|
|
55
56
|
}, [
|
|
@@ -77,8 +78,10 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
77
78
|
}
|
|
78
79
|
}, []);
|
|
79
80
|
const revalidate = useCallback(async (isInitial) => {
|
|
81
|
+
const generation = sessionGenerationRef.current;
|
|
80
82
|
try {
|
|
81
83
|
const user = await clientRef.current.getMe();
|
|
84
|
+
if (sessionGenerationRef.current !== generation) return;
|
|
82
85
|
syncedDispatch({
|
|
83
86
|
type: "SET_USER",
|
|
84
87
|
payload: {
|
|
@@ -87,6 +90,7 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
87
90
|
}
|
|
88
91
|
});
|
|
89
92
|
} catch (error) {
|
|
93
|
+
if (sessionGenerationRef.current !== generation) return;
|
|
90
94
|
const wasAuthenticated = statusRef.current === "authenticated";
|
|
91
95
|
if (isSessionExpiredError(error)) {
|
|
92
96
|
if (!isInitial && wasAuthenticated) {
|
|
@@ -139,11 +143,13 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
139
143
|
tenantId
|
|
140
144
|
});
|
|
141
145
|
if ("mfaRequired" in result) {
|
|
146
|
+
sessionGenerationRef.current = {};
|
|
142
147
|
syncedDispatch({
|
|
143
148
|
type: "CLEAR_SESSION"
|
|
144
149
|
});
|
|
145
150
|
return result;
|
|
146
151
|
}
|
|
152
|
+
sessionGenerationRef.current = {};
|
|
147
153
|
syncedDispatch({
|
|
148
154
|
type: "SET_USER",
|
|
149
155
|
payload: {
|
|
@@ -167,6 +173,7 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
167
173
|
});
|
|
168
174
|
try {
|
|
169
175
|
const result = await clientRef.current.register(data);
|
|
176
|
+
sessionGenerationRef.current = {};
|
|
170
177
|
syncedDispatch({
|
|
171
178
|
type: "SET_USER",
|
|
172
179
|
payload: {
|
|
@@ -188,6 +195,7 @@ function AuthProvider({ children, client, onSessionExpired, revalidateInterval =
|
|
|
188
195
|
try {
|
|
189
196
|
await clientRef.current.logout();
|
|
190
197
|
} finally {
|
|
198
|
+
sessionGenerationRef.current = {};
|
|
191
199
|
syncedDispatch({
|
|
192
200
|
type: "CLEAR_SESSION"
|
|
193
201
|
});
|