@bymax-one/nest-auth 1.4.11 → 1.4.12

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,37 @@ what moves, and that note is the compatibility contract until strict SemVer begi
18
18
 
19
19
  ## [Unreleased]
20
20
 
21
+ ## [1.4.12] - 2026-11-01
22
+
23
+ ### Apply to a derived backend
24
+
25
+ - **The refresh cookie is `SameSite=Strict` unless you configure `cookies.sameSite: 'none'`.**
26
+ Until now it followed `cookies.sameSite`, so under the default (`lax`) it was issued `Lax`. It is
27
+ now `Strict` under `lax` and `strict`, and `None` only when `none` is configured, which is
28
+ unchanged. Only the attribute changes: the access and session-signal cookies still follow
29
+ `cookies.sameSite`, so the OAuth return trip is unaffected, and the cookie that ends a session
30
+ is cleared with the same attribute it was issued with. Nothing a user could do stops working:
31
+ the silent-refresh route already refused every caller stating a `Sec-Fetch-Site` other
32
+ than `same-origin` or `none`. Measured in Chromium 140 with the real proxy and route handler, a
33
+ `Lax` refresh cookie does reach that route on a cross-site link, and the route answers before
34
+ reading it, so a `Strict` cookie changes the outcome of no navigation. A deployment that
35
+ proxies the refresh call from a frontend on another site must already be on `none`.
36
+ - **A cross-site entry to the silent-refresh route now redirects to the login page.** A user
37
+ who follows a link into the app from another site (or from another origin on the same site)
38
+ after the access token expired used to land on a bare `403`. The route now answers `307` to
39
+ `loginPath?reason=expired`, the same target a failed refresh uses, so the login page can show
40
+ its expired-session message. The refusal keeps its property: no refresh is attempted and no
41
+ `Set-Cookie` is written, so a cross-site caller still causes nothing. The logout and
42
+ client-refresh routes are unchanged and still answer `403`. A page that treated a `403` from
43
+ the silent-refresh route as a signal sees a redirect instead.
44
+
45
+ ### Fixed
46
+
47
+ - **The refresh cookie was issued `Lax` under the default configuration.** See the Apply note
48
+ above.
49
+ - **A cross-site entry to the silent-refresh route showed a bare `403`.** See the Apply note
50
+ above.
51
+
21
52
  ## [1.4.11] - 2026-11-01
22
53
 
23
54
  ### Apply to a derived backend
@@ -4154,7 +4185,8 @@ ever installable.
4154
4185
  - 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
4155
4186
  - 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
4156
4187
 
4157
- [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.11...HEAD
4188
+ [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.12...HEAD
4189
+ [1.4.12]: https://github.com/bymaxone/nest-auth/compare/v1.4.11...v1.4.12
4158
4190
  [1.4.11]: https://github.com/bymaxone/nest-auth/compare/v1.4.10...v1.4.11
4159
4191
  [1.4.10]: https://github.com/bymaxone/nest-auth/compare/v1.4.9...v1.4.10
4160
4192
  [1.4.9]: https://github.com/bymaxone/nest-auth/compare/v1.4.8...v1.4.9
package/README.md CHANGED
@@ -1461,8 +1461,10 @@ When integrating `@bymax-one/nest-auth` in production, verify each of the follow
1461
1461
  - `@MaxLength(128)` on password DTOs prevents algorithmic-DoS via oversized scrypt inputs
1462
1462
  - JWT algorithm pinning to HS256 prevents algorithm-confusion attacks
1463
1463
  - Constant-time comparisons via `crypto.timingSafeEqual` for all secret comparisons
1464
- - HttpOnly cookies; `Secure` enforced in production; `SameSite=Lax` by default on every auth
1465
- cookie, so the OAuth provider's cross-site redirect back to your app still carries them.
1464
+ - HttpOnly cookies; `Secure` enforced in production; `SameSite=Lax` by default on the access and
1465
+ session-signal cookies, so the OAuth provider's cross-site redirect back to your app still
1466
+ carries them. The refresh cookie is `Strict` under `lax` and `strict`, and `None` only when
1467
+ you configure `cookies.sameSite: 'none'`.
1466
1468
  Deployments that do not need that redirect can take the stricter posture with
1467
1469
  `cookies.sameSite: 'strict'`. CSRF does not rest on this setting — `TrustedOriginGuard` is
1468
1470
  applied to every controller and runs before authentication.
@@ -1492,7 +1494,7 @@ it is the one guarantee cookie delivery exists for and the one no server-side te
1492
1494
  | Token Generation | `crypto.randomBytes(32)` — 256 bits of entropy |
1493
1495
  | Secret Comparison | `crypto.timingSafeEqual` (constant-time) |
1494
1496
  | JWT | HS256 via `@nestjs/jwt`, JTI blacklist via Redis |
1495
- | Cookies | HttpOnly, Secure, SameSite=Lax (override to `strict`), path-scoped |
1497
+ | Cookies | HttpOnly, Secure, SameSite=Lax (override to `strict`), refresh cookie Strict, path-scoped |
1496
1498
  | Brute-Force | Redis atomic counters per HMAC(email, identifier key) |
1497
1499
  | CSRF (OAuth) | 64-char hex state nonce, single-use via `getdel()` |
1498
1500
  | Refresh Rotation | Single-use tokens with a grace window; a replay past it revokes that login's whole family lineage |
@@ -936,12 +936,7 @@ function createSilentRefreshHandler(config) {
936
936
  const refreshUrl = buildRefreshUrl(config.apiBase, config.refreshPath);
937
937
  return /* @__PURE__ */ __name(async function silentRefreshHandler(request) {
938
938
  if (isCrossSiteRequest(request)) {
939
- return new server.NextResponse(null, {
940
- status: 403,
941
- headers: {
942
- "Cache-Control": "no-store, no-cache"
943
- }
944
- });
939
+ return buildLoginRedirect(config);
945
940
  }
946
941
  const origin = request.nextUrl.origin;
947
942
  const rawDestination = request.nextUrl.searchParams.get("redirect");
@@ -1005,8 +1000,7 @@ function buildSuccessRedirect(destination, rawSetCookies) {
1005
1000
  }
1006
1001
  __name(buildSuccessRedirect, "buildSuccessRedirect");
1007
1002
  function buildLogoutRedirect(config) {
1008
- const response = redirectToPath(withQueryParam(config.loginPath, "reason", "expired"));
1009
- response.headers.set("Cache-Control", "no-store, no-cache");
1003
+ const response = buildLoginRedirect(config);
1010
1004
  const clearCookies = [
1011
1005
  serializeClearCookie(config.cookieNames.access, "/", config.cookieDomain),
1012
1006
  serializeClearCookie(config.cookieNames.refresh, config.refreshCookiePath ?? DEFAULT_REFRESH_COOKIE_PATH, config.cookieDomain),
@@ -1018,6 +1012,12 @@ function buildLogoutRedirect(config) {
1018
1012
  return response;
1019
1013
  }
1020
1014
  __name(buildLogoutRedirect, "buildLogoutRedirect");
1015
+ function buildLoginRedirect(config) {
1016
+ const response = redirectToPath(withQueryParam(config.loginPath, "reason", "expired"));
1017
+ response.headers.set("Cache-Control", "no-store, no-cache");
1018
+ return response;
1019
+ }
1020
+ __name(buildLoginRedirect, "buildLoginRedirect");
1021
1021
  var SILENT_REFRESH_ROUTE = shared.AUTH_PROXY_ROUTES.silentRefresh;
1022
1022
  function createClientRefreshHandler(config) {
1023
1023
  assertValidApiBase(config.apiBase, "createClientRefreshHandler");
@@ -862,6 +862,8 @@ type SilentRefreshHandler = (request: NextRequest) => Promise<NextResponse>;
862
862
  * Create a GET handler for `/api/auth/silent-refresh`.
863
863
  *
864
864
  * The returned handler:
865
+ * 0. Redirects a caller whose `Sec-Fetch-Site` is not `same-origin` or `none` to
866
+ * `loginPath?reason=expired` with no refresh and no `Set-Cookie`.
865
867
  * 1. Resolves a safe `redirect` destination (see open-redirect
866
868
  * defence above).
867
869
  * 2. Forwards the incoming cookies to the upstream refresh endpoint.
@@ -862,6 +862,8 @@ type SilentRefreshHandler = (request: NextRequest) => Promise<NextResponse>;
862
862
  * Create a GET handler for `/api/auth/silent-refresh`.
863
863
  *
864
864
  * The returned handler:
865
+ * 0. Redirects a caller whose `Sec-Fetch-Site` is not `same-origin` or `none` to
866
+ * `loginPath?reason=expired` with no refresh and no `Set-Cookie`.
865
867
  * 1. Resolves a safe `redirect` destination (see open-redirect
866
868
  * defence above).
867
869
  * 2. Forwards the incoming cookies to the upstream refresh endpoint.
@@ -934,12 +934,7 @@ function createSilentRefreshHandler(config) {
934
934
  const refreshUrl = buildRefreshUrl(config.apiBase, config.refreshPath);
935
935
  return /* @__PURE__ */ __name(async function silentRefreshHandler(request) {
936
936
  if (isCrossSiteRequest(request)) {
937
- return new NextResponse(null, {
938
- status: 403,
939
- headers: {
940
- "Cache-Control": "no-store, no-cache"
941
- }
942
- });
937
+ return buildLoginRedirect(config);
943
938
  }
944
939
  const origin = request.nextUrl.origin;
945
940
  const rawDestination = request.nextUrl.searchParams.get("redirect");
@@ -1003,8 +998,7 @@ function buildSuccessRedirect(destination, rawSetCookies) {
1003
998
  }
1004
999
  __name(buildSuccessRedirect, "buildSuccessRedirect");
1005
1000
  function buildLogoutRedirect(config) {
1006
- const response = redirectToPath(withQueryParam(config.loginPath, "reason", "expired"));
1007
- response.headers.set("Cache-Control", "no-store, no-cache");
1001
+ const response = buildLoginRedirect(config);
1008
1002
  const clearCookies = [
1009
1003
  serializeClearCookie(config.cookieNames.access, "/", config.cookieDomain),
1010
1004
  serializeClearCookie(config.cookieNames.refresh, config.refreshCookiePath ?? DEFAULT_REFRESH_COOKIE_PATH, config.cookieDomain),
@@ -1016,6 +1010,12 @@ function buildLogoutRedirect(config) {
1016
1010
  return response;
1017
1011
  }
1018
1012
  __name(buildLogoutRedirect, "buildLogoutRedirect");
1013
+ function buildLoginRedirect(config) {
1014
+ const response = redirectToPath(withQueryParam(config.loginPath, "reason", "expired"));
1015
+ response.headers.set("Cache-Control", "no-store, no-cache");
1016
+ return response;
1017
+ }
1018
+ __name(buildLoginRedirect, "buildLoginRedirect");
1019
1019
  var SILENT_REFRESH_ROUTE = AUTH_PROXY_ROUTES.silentRefresh;
1020
1020
  function createClientRefreshHandler(config) {
1021
1021
  assertValidApiBase(config.apiBase, "createClientRefreshHandler");
@@ -3511,6 +3511,7 @@ exports.TokenDeliveryService = class TokenDeliveryService {
3511
3511
  res.clearCookie(this.options.cookies.accessTokenName, cookieOpts);
3512
3512
  res.clearCookie(this.options.cookies.refreshTokenName, {
3513
3513
  ...cookieOpts,
3514
+ sameSite: this.refreshSameSite(),
3514
3515
  path: this.options.cookies.refreshCookiePath
3515
3516
  });
3516
3517
  res.clearCookie(this.options.cookies.sessionSignalName, {
@@ -3577,6 +3578,7 @@ exports.TokenDeliveryService = class TokenDeliveryService {
3577
3578
  });
3578
3579
  res.cookie(this.options.cookies.refreshTokenName, rawRefreshToken, {
3579
3580
  ...base,
3581
+ sameSite: this.refreshSameSite(),
3580
3582
  httpOnly: true,
3581
3583
  secure: isProd,
3582
3584
  path: this.options.cookies.refreshCookiePath,
@@ -3589,6 +3591,18 @@ exports.TokenDeliveryService = class TokenDeliveryService {
3589
3591
  maxAge: refreshMaxAge
3590
3592
  });
3591
3593
  }
3594
+ /**
3595
+ * `SameSite` of the refresh cookie: Strict unless the deployment is cross-site (`none`).
3596
+ *
3597
+ * Only the refresh route reads this cookie, and a browser sends it there on the app's own
3598
+ * requests; withholding it from every cross-site request costs nothing, whereas the access and
3599
+ * session-signal cookies follow `cookies.sameSite` because the OAuth return trip needs them on
3600
+ * a cross-site top-level navigation. A `none` deployment must keep `none`, or its refresh call
3601
+ * would carry no credential.
3602
+ */
3603
+ refreshSameSite() {
3604
+ return this.options.cookies.sameSite === "none" ? "none" : "strict";
3605
+ }
3592
3606
  /** Returns base Set-Cookie options for auth cookies, optionally scoped to a domain. */
3593
3607
  baseCookieOptions(domain) {
3594
3608
  return {
@@ -820,8 +820,13 @@ interface BymaxAuthModuleOptions {
820
820
  */
821
821
  resolveDomains?: (requestDomain: string) => string[];
822
822
  /**
823
- * `SameSite` attribute applied to every cookie issued by the module
824
- * (access token, refresh token, session signal). Default: `'lax'`.
823
+ * `SameSite` attribute applied to the access-token and session-signal cookies issued by
824
+ * the module. Default: `'lax'`.
825
+ *
826
+ * The refresh-token cookie does not follow this value except for `'none'`: it is issued
827
+ * `Strict` under `'lax'` and `'strict'`, because only the refresh route reads it and no
828
+ * cross-site request needs it. Under `'none'` it is `None` too, since a cross-site
829
+ * frontend's refresh call would otherwise carry no credential.
825
830
  *
826
831
  * Trade-offs:
827
832
  * - `'lax'` (default): cookies travel on top-level cross-site GET navigations.
@@ -5188,7 +5193,8 @@ interface PlatformBearerAuthResponse {
5188
5193
  * set. Use this for mobile/native clients or SPA with cross-origin APIs.
5189
5194
  * - `'both'`: Tokens are set as cookies AND returned in the response body.
5190
5195
  *
5191
- * Cookie security: HttpOnly, Secure (production), SameSite=Strict.
5196
+ * Cookie security: HttpOnly, Secure (production). The access and session-signal cookies follow
5197
+ * `cookies.sameSite`; the refresh cookie is SameSite=Strict unless `none` is configured.
5192
5198
  * Refresh cookies use the configured `cookies.refreshCookiePath`.
5193
5199
  *
5194
5200
  * @layer Service
@@ -5314,6 +5320,16 @@ declare class TokenDeliveryService {
5314
5320
  */
5315
5321
  extractDomain(req: Request): string | undefined;
5316
5322
  private setAuthCookies;
5323
+ /**
5324
+ * `SameSite` of the refresh cookie: Strict unless the deployment is cross-site (`none`).
5325
+ *
5326
+ * Only the refresh route reads this cookie, and a browser sends it there on the app's own
5327
+ * requests; withholding it from every cross-site request costs nothing, whereas the access and
5328
+ * session-signal cookies follow `cookies.sameSite` because the OAuth return trip needs them on
5329
+ * a cross-site top-level navigation. A `none` deployment must keep `none`, or its refresh call
5330
+ * would carry no credential.
5331
+ */
5332
+ private refreshSameSite;
5317
5333
  /** Returns base Set-Cookie options for auth cookies, optionally scoped to a domain. */
5318
5334
  private baseCookieOptions;
5319
5335
  /** Reads the value of the cookie identified by `name` from the request. */
@@ -820,8 +820,13 @@ interface BymaxAuthModuleOptions {
820
820
  */
821
821
  resolveDomains?: (requestDomain: string) => string[];
822
822
  /**
823
- * `SameSite` attribute applied to every cookie issued by the module
824
- * (access token, refresh token, session signal). Default: `'lax'`.
823
+ * `SameSite` attribute applied to the access-token and session-signal cookies issued by
824
+ * the module. Default: `'lax'`.
825
+ *
826
+ * The refresh-token cookie does not follow this value except for `'none'`: it is issued
827
+ * `Strict` under `'lax'` and `'strict'`, because only the refresh route reads it and no
828
+ * cross-site request needs it. Under `'none'` it is `None` too, since a cross-site
829
+ * frontend's refresh call would otherwise carry no credential.
825
830
  *
826
831
  * Trade-offs:
827
832
  * - `'lax'` (default): cookies travel on top-level cross-site GET navigations.
@@ -5188,7 +5193,8 @@ interface PlatformBearerAuthResponse {
5188
5193
  * set. Use this for mobile/native clients or SPA with cross-origin APIs.
5189
5194
  * - `'both'`: Tokens are set as cookies AND returned in the response body.
5190
5195
  *
5191
- * Cookie security: HttpOnly, Secure (production), SameSite=Strict.
5196
+ * Cookie security: HttpOnly, Secure (production). The access and session-signal cookies follow
5197
+ * `cookies.sameSite`; the refresh cookie is SameSite=Strict unless `none` is configured.
5192
5198
  * Refresh cookies use the configured `cookies.refreshCookiePath`.
5193
5199
  *
5194
5200
  * @layer Service
@@ -5314,6 +5320,16 @@ declare class TokenDeliveryService {
5314
5320
  */
5315
5321
  extractDomain(req: Request): string | undefined;
5316
5322
  private setAuthCookies;
5323
+ /**
5324
+ * `SameSite` of the refresh cookie: Strict unless the deployment is cross-site (`none`).
5325
+ *
5326
+ * Only the refresh route reads this cookie, and a browser sends it there on the app's own
5327
+ * requests; withholding it from every cross-site request costs nothing, whereas the access and
5328
+ * session-signal cookies follow `cookies.sameSite` because the OAuth return trip needs them on
5329
+ * a cross-site top-level navigation. A `none` deployment must keep `none`, or its refresh call
5330
+ * would carry no credential.
5331
+ */
5332
+ private refreshSameSite;
5317
5333
  /** Returns base Set-Cookie options for auth cookies, optionally scoped to a domain. */
5318
5334
  private baseCookieOptions;
5319
5335
  /** Reads the value of the cookie identified by `name` from the request. */
@@ -3509,6 +3509,7 @@ var TokenDeliveryService = class {
3509
3509
  res.clearCookie(this.options.cookies.accessTokenName, cookieOpts);
3510
3510
  res.clearCookie(this.options.cookies.refreshTokenName, {
3511
3511
  ...cookieOpts,
3512
+ sameSite: this.refreshSameSite(),
3512
3513
  path: this.options.cookies.refreshCookiePath
3513
3514
  });
3514
3515
  res.clearCookie(this.options.cookies.sessionSignalName, {
@@ -3575,6 +3576,7 @@ var TokenDeliveryService = class {
3575
3576
  });
3576
3577
  res.cookie(this.options.cookies.refreshTokenName, rawRefreshToken, {
3577
3578
  ...base,
3579
+ sameSite: this.refreshSameSite(),
3578
3580
  httpOnly: true,
3579
3581
  secure: isProd,
3580
3582
  path: this.options.cookies.refreshCookiePath,
@@ -3587,6 +3589,18 @@ var TokenDeliveryService = class {
3587
3589
  maxAge: refreshMaxAge
3588
3590
  });
3589
3591
  }
3592
+ /**
3593
+ * `SameSite` of the refresh cookie: Strict unless the deployment is cross-site (`none`).
3594
+ *
3595
+ * Only the refresh route reads this cookie, and a browser sends it there on the app's own
3596
+ * requests; withholding it from every cross-site request costs nothing, whereas the access and
3597
+ * session-signal cookies follow `cookies.sameSite` because the OAuth return trip needs them on
3598
+ * a cross-site top-level navigation. A `none` deployment must keep `none`, or its refresh call
3599
+ * would carry no credential.
3600
+ */
3601
+ refreshSameSite() {
3602
+ return this.options.cookies.sameSite === "none" ? "none" : "strict";
3603
+ }
3590
3604
  /** Returns base Set-Cookie options for auth cookies, optionally scoped to a domain. */
3591
3605
  baseCookieOptions(domain) {
3592
3606
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-auth",
3
- "version": "1.4.11",
3
+ "version": "1.4.12",
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",