@bymax-one/nest-auth 1.0.8 → 1.0.9
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 +17 -0
- package/dist/server/index.cjs +13 -6
- package/dist/server/index.d.cts +24 -0
- package/dist/server/index.d.ts +24 -0
- package/dist/server/index.mjs +13 -6
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.0.9] - 2026-05-26
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **OAuth + MFA cookie path now configurable for apps with `setGlobalPrefix`** ([`src/server/interfaces/auth-module-options.interface.ts`](src/server/interfaces/auth-module-options.interface.ts), [`src/server/config/default-options.ts`](src/server/config/default-options.ts), [`src/server/oauth/oauth.controller.ts`](src/server/oauth/oauth.controller.ts), [`src/server/controllers/mfa.controller.ts`](src/server/controllers/mfa.controller.ts)). Prior to v1.0.9, the OAuth callback planted the `mfa_temp_token` cookie with `Path` hard-derived from `routePrefix` (`/${routePrefix}/mfa`). When the consuming Nest app calls `app.setGlobalPrefix('api')`, the lib's routes mount at `/api/auth/mfa/challenge` — but the cookie path stayed at `/auth/mfa`, which the browser refuses to send on requests under `/api/auth/mfa/...` per RFC 6265 prefix-match. The OAuth-driven MFA flow was silently broken end-to-end: cookie set, cookie dropped, every subsequent challenge attempt surfaced as `MFA_TEMP_TOKEN_INVALID` ("MFA session expired") because the controller received no token at all. The lib could not detect this — the global prefix is configured on the Nest app instance after the auth module is constructed, so it is not observable at option resolution time.
|
|
15
|
+
|
|
16
|
+
A new `cookies.mfaTempCookiePath?: string` option lets the consumer set the exact `Path` attribute used when the OAuth callback plants the temp cookie and when the MFA challenge controller clears it. Defaults to `'/auth/mfa'` — correct when the lib's routes are mounted at the application root. Apps that call `app.setGlobalPrefix('api')` MUST set this to `'/api/auth/mfa'`. The default keeps existing consumers without a global prefix on the path that worked for them in v1.0.7+; only consumers with a Nest global prefix need to opt in.
|
|
17
|
+
|
|
18
|
+
Both call sites (`OAuthController.setMfaTempCookie` and `MfaController.clearMfaTempCookie`) now read from `options.cookies.mfaTempCookiePath` instead of computing `/${routePrefix}/mfa` inline. This also means the set + clear paths can never diverge — the browser uses the path attribute to scope cookie deletion, so a mismatch between set and clear would leave dead cookies in the jar.
|
|
19
|
+
|
|
20
|
+
**Backward compatibility**: every existing consumer that did NOT use OAuth + MFA continues to work unchanged. Consumers that DID use OAuth + MFA AND did NOT use `setGlobalPrefix` see no change (default `'/auth/mfa'` matches what they had). Consumers that DID use both and ARE using a global prefix had a silently-broken flow before v1.0.9 — setting `cookies.mfaTempCookiePath` fixes it.
|
|
21
|
+
|
|
22
|
+
### Tests
|
|
23
|
+
|
|
24
|
+
- **Updated existing `mfa.controller.spec.ts` and `oauth.controller.spec.ts` fixtures** to surface `cookies.mfaTempCookiePath` on the mocked `ResolvedOptions`. The dedicated path-attribute test that previously pinned the value via `routePrefix: 'api/auth'` is reframed to pin it via `cookies.mfaTempCookiePath: '/api/auth/mfa'`.
|
|
25
|
+
- **104 test suites · 2143 tests · 100% statement / branch / function / line coverage** maintained (verified via `pnpm test:cov:all`).
|
|
26
|
+
|
|
10
27
|
## [1.0.8] - 2026-05-26
|
|
11
28
|
|
|
12
29
|
### Fixed
|
package/dist/server/index.cjs
CHANGED
|
@@ -46,6 +46,12 @@ var DEFAULT_OPTIONS = {
|
|
|
46
46
|
refreshTokenName: "refresh_token",
|
|
47
47
|
sessionSignalName: "has_session",
|
|
48
48
|
refreshCookiePath: "/auth",
|
|
49
|
+
// Default scopes the OAuth-MFA temp cookie to the lib's own `/auth/mfa`
|
|
50
|
+
// tree. Consumers using `app.setGlobalPrefix(...)` MUST override this
|
|
51
|
+
// explicitly (e.g. `'/api/auth/mfa'`) — the lib cannot observe the
|
|
52
|
+
// global prefix at module construction time, and a mismatched path
|
|
53
|
+
// makes the browser silently drop the cookie per RFC 6265 prefix-match.
|
|
54
|
+
mfaTempCookiePath: "/auth/mfa",
|
|
49
55
|
// 'lax' matches Chromium's default for cookies that omit SameSite. It
|
|
50
56
|
// delivers auth cookies on top-level cross-site GET navigations — the
|
|
51
57
|
// case that makes OAuth redirects (Google → callback → dashboard) work
|
|
@@ -5254,7 +5260,7 @@ var MfaController = class {
|
|
|
5254
5260
|
*/
|
|
5255
5261
|
clearMfaTempCookie(res) {
|
|
5256
5262
|
res.clearCookie(MFA_TEMP_COOKIE_NAME, {
|
|
5257
|
-
path:
|
|
5263
|
+
path: this.options.cookies.mfaTempCookiePath,
|
|
5258
5264
|
httpOnly: true,
|
|
5259
5265
|
secure: this.options.secureCookies,
|
|
5260
5266
|
sameSite: this.options.cookies.sameSite
|
|
@@ -7974,10 +7980,11 @@ var OAuthController = class {
|
|
|
7974
7980
|
* server-side challenge route, not by any client code.
|
|
7975
7981
|
* - `Secure`: derived from `secureCookies` (true in production by default).
|
|
7976
7982
|
* - `SameSite`: derived from `cookies.sameSite` (defaults to `'lax'`).
|
|
7977
|
-
* - `Path`:
|
|
7978
|
-
*
|
|
7979
|
-
*
|
|
7980
|
-
*
|
|
7983
|
+
* - `Path`: `cookies.mfaTempCookiePath` (default `/auth/mfa`). Consumers
|
|
7984
|
+
* that call `app.setGlobalPrefix(...)` MUST override this — the lib
|
|
7985
|
+
* cannot observe the global prefix at module construction time, and
|
|
7986
|
+
* a mismatched path makes the browser silently drop the cookie per
|
|
7987
|
+
* RFC 6265 prefix-match.
|
|
7981
7988
|
* - `Max-Age`: 300 seconds — exactly matches the underlying MFA temp JWT
|
|
7982
7989
|
* TTL (`MFA_TEMP_TOKEN_TTL_SECONDS` in `token-manager.service.ts`).
|
|
7983
7990
|
* Keeping the two TTLs identical avoids the failure mode where the
|
|
@@ -7989,7 +7996,7 @@ var OAuthController = class {
|
|
|
7989
7996
|
httpOnly: true,
|
|
7990
7997
|
secure: this.options.secureCookies,
|
|
7991
7998
|
sameSite: this.options.cookies.sameSite,
|
|
7992
|
-
path:
|
|
7999
|
+
path: this.options.cookies.mfaTempCookiePath,
|
|
7993
8000
|
maxAge: MFA_TEMP_COOKIE_MAX_AGE_SECONDS * 1e3
|
|
7994
8001
|
});
|
|
7995
8002
|
}
|
package/dist/server/index.d.cts
CHANGED
|
@@ -414,6 +414,30 @@ interface BymaxAuthModuleOptions {
|
|
|
414
414
|
* A warning is logged at startup if `routePrefix` differs from `'auth'` and this is not set.
|
|
415
415
|
*/
|
|
416
416
|
refreshCookiePath?: string;
|
|
417
|
+
/**
|
|
418
|
+
* `Path` attribute for the short-lived `mfa_temp_token` cookie planted
|
|
419
|
+
* by the OAuth callback (lib v1.0.7+) and cleared by the MFA challenge
|
|
420
|
+
* controller. Defaults to `/${routePrefix}/mfa` — correct when the
|
|
421
|
+
* lib's routes are mounted at the root path (no Nest global prefix).
|
|
422
|
+
*
|
|
423
|
+
* Set this explicitly when the consumer calls `app.setGlobalPrefix(...)`
|
|
424
|
+
* because the library cannot observe the global prefix at module
|
|
425
|
+
* construction time. For example, with `setGlobalPrefix('api')` and
|
|
426
|
+
* default `routePrefix: 'auth'`, the real challenge URL is
|
|
427
|
+
* `/api/auth/mfa/challenge` — but `Path=/auth/mfa` will NOT be sent
|
|
428
|
+
* by the browser (RFC 6265 prefix-match). Set this to `'/api/auth/mfa'`
|
|
429
|
+
* so the cookie scopes to the actual challenge endpoint.
|
|
430
|
+
*
|
|
431
|
+
* Must start with `/` and exactly match the directory portion of the
|
|
432
|
+
* real `/mfa/*` route path. Validated at startup.
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* ```ts
|
|
436
|
+
* // App calls `app.setGlobalPrefix('api')` and uses default routePrefix:
|
|
437
|
+
* { cookies: { mfaTempCookiePath: '/api/auth/mfa' } }
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
mfaTempCookiePath?: string;
|
|
417
441
|
/**
|
|
418
442
|
* Resolves cookie domains from the request's hostname.
|
|
419
443
|
* Useful for multi-domain support (e.g. `api.example.com` and `app.example.com`).
|
package/dist/server/index.d.ts
CHANGED
|
@@ -414,6 +414,30 @@ interface BymaxAuthModuleOptions {
|
|
|
414
414
|
* A warning is logged at startup if `routePrefix` differs from `'auth'` and this is not set.
|
|
415
415
|
*/
|
|
416
416
|
refreshCookiePath?: string;
|
|
417
|
+
/**
|
|
418
|
+
* `Path` attribute for the short-lived `mfa_temp_token` cookie planted
|
|
419
|
+
* by the OAuth callback (lib v1.0.7+) and cleared by the MFA challenge
|
|
420
|
+
* controller. Defaults to `/${routePrefix}/mfa` — correct when the
|
|
421
|
+
* lib's routes are mounted at the root path (no Nest global prefix).
|
|
422
|
+
*
|
|
423
|
+
* Set this explicitly when the consumer calls `app.setGlobalPrefix(...)`
|
|
424
|
+
* because the library cannot observe the global prefix at module
|
|
425
|
+
* construction time. For example, with `setGlobalPrefix('api')` and
|
|
426
|
+
* default `routePrefix: 'auth'`, the real challenge URL is
|
|
427
|
+
* `/api/auth/mfa/challenge` — but `Path=/auth/mfa` will NOT be sent
|
|
428
|
+
* by the browser (RFC 6265 prefix-match). Set this to `'/api/auth/mfa'`
|
|
429
|
+
* so the cookie scopes to the actual challenge endpoint.
|
|
430
|
+
*
|
|
431
|
+
* Must start with `/` and exactly match the directory portion of the
|
|
432
|
+
* real `/mfa/*` route path. Validated at startup.
|
|
433
|
+
*
|
|
434
|
+
* @example
|
|
435
|
+
* ```ts
|
|
436
|
+
* // App calls `app.setGlobalPrefix('api')` and uses default routePrefix:
|
|
437
|
+
* { cookies: { mfaTempCookiePath: '/api/auth/mfa' } }
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
440
|
+
mfaTempCookiePath?: string;
|
|
417
441
|
/**
|
|
418
442
|
* Resolves cookie domains from the request's hostname.
|
|
419
443
|
* Useful for multi-domain support (e.g. `api.example.com` and `app.example.com`).
|
package/dist/server/index.mjs
CHANGED
|
@@ -44,6 +44,12 @@ var DEFAULT_OPTIONS = {
|
|
|
44
44
|
refreshTokenName: "refresh_token",
|
|
45
45
|
sessionSignalName: "has_session",
|
|
46
46
|
refreshCookiePath: "/auth",
|
|
47
|
+
// Default scopes the OAuth-MFA temp cookie to the lib's own `/auth/mfa`
|
|
48
|
+
// tree. Consumers using `app.setGlobalPrefix(...)` MUST override this
|
|
49
|
+
// explicitly (e.g. `'/api/auth/mfa'`) — the lib cannot observe the
|
|
50
|
+
// global prefix at module construction time, and a mismatched path
|
|
51
|
+
// makes the browser silently drop the cookie per RFC 6265 prefix-match.
|
|
52
|
+
mfaTempCookiePath: "/auth/mfa",
|
|
47
53
|
// 'lax' matches Chromium's default for cookies that omit SameSite. It
|
|
48
54
|
// delivers auth cookies on top-level cross-site GET navigations — the
|
|
49
55
|
// case that makes OAuth redirects (Google → callback → dashboard) work
|
|
@@ -5252,7 +5258,7 @@ var MfaController = class {
|
|
|
5252
5258
|
*/
|
|
5253
5259
|
clearMfaTempCookie(res) {
|
|
5254
5260
|
res.clearCookie(MFA_TEMP_COOKIE_NAME, {
|
|
5255
|
-
path:
|
|
5261
|
+
path: this.options.cookies.mfaTempCookiePath,
|
|
5256
5262
|
httpOnly: true,
|
|
5257
5263
|
secure: this.options.secureCookies,
|
|
5258
5264
|
sameSite: this.options.cookies.sameSite
|
|
@@ -7972,10 +7978,11 @@ var OAuthController = class {
|
|
|
7972
7978
|
* server-side challenge route, not by any client code.
|
|
7973
7979
|
* - `Secure`: derived from `secureCookies` (true in production by default).
|
|
7974
7980
|
* - `SameSite`: derived from `cookies.sameSite` (defaults to `'lax'`).
|
|
7975
|
-
* - `Path`:
|
|
7976
|
-
*
|
|
7977
|
-
*
|
|
7978
|
-
*
|
|
7981
|
+
* - `Path`: `cookies.mfaTempCookiePath` (default `/auth/mfa`). Consumers
|
|
7982
|
+
* that call `app.setGlobalPrefix(...)` MUST override this — the lib
|
|
7983
|
+
* cannot observe the global prefix at module construction time, and
|
|
7984
|
+
* a mismatched path makes the browser silently drop the cookie per
|
|
7985
|
+
* RFC 6265 prefix-match.
|
|
7979
7986
|
* - `Max-Age`: 300 seconds — exactly matches the underlying MFA temp JWT
|
|
7980
7987
|
* TTL (`MFA_TEMP_TOKEN_TTL_SECONDS` in `token-manager.service.ts`).
|
|
7981
7988
|
* Keeping the two TTLs identical avoids the failure mode where the
|
|
@@ -7987,7 +7994,7 @@ var OAuthController = class {
|
|
|
7987
7994
|
httpOnly: true,
|
|
7988
7995
|
secure: this.options.secureCookies,
|
|
7989
7996
|
sameSite: this.options.cookies.sameSite,
|
|
7990
|
-
path:
|
|
7997
|
+
path: this.options.cookies.mfaTempCookiePath,
|
|
7991
7998
|
maxAge: MFA_TEMP_COOKIE_MAX_AGE_SECONDS * 1e3
|
|
7992
7999
|
});
|
|
7993
8000
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymax-one/nest-auth",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
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",
|
|
@@ -112,6 +112,7 @@
|
|
|
112
112
|
"@nestjs/testing": "^11.1.20",
|
|
113
113
|
"@nestjs/throttler": "^6.5.0",
|
|
114
114
|
"@nestjs/websockets": "^11.1.20",
|
|
115
|
+
"@size-limit/preset-small-lib": "12.1.0",
|
|
115
116
|
"@stryker-mutator/core": "^9",
|
|
116
117
|
"@stryker-mutator/jest-runner": "^9",
|
|
117
118
|
"@stryker-mutator/typescript-checker": "^9",
|
|
@@ -138,11 +139,13 @@
|
|
|
138
139
|
"ioredis-mock": "^8.13.1",
|
|
139
140
|
"jest": "^30.4.2",
|
|
140
141
|
"jest-environment-jsdom": "^30.4.1",
|
|
142
|
+
"jscpd": "4.2.3",
|
|
141
143
|
"next": "^16.2.6",
|
|
142
144
|
"prettier": "^3.8.3",
|
|
143
145
|
"react": "^19.2.6",
|
|
144
146
|
"react-dom": "^19.2.6",
|
|
145
147
|
"reflect-metadata": "^0.2.2",
|
|
148
|
+
"size-limit": "12.1.0",
|
|
146
149
|
"supertest": "^7.2.2",
|
|
147
150
|
"ts-jest": "^29.4.9",
|
|
148
151
|
"ts-node": "^10.9.2",
|
|
@@ -189,6 +192,7 @@
|
|
|
189
192
|
"mutation:incremental": "stryker run --incremental",
|
|
190
193
|
"mutation:dry-run": "stryker run --dryRunOnly",
|
|
191
194
|
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.server.json",
|
|
195
|
+
"size": "node scripts/check-size.mjs",
|
|
192
196
|
"clean": "rm -rf dist coverage",
|
|
193
197
|
"release": "pnpm publish --provenance"
|
|
194
198
|
}
|