@bymax-one/nest-auth 1.1.1 → 1.3.0
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 +121 -1
- package/README.md +101 -28
- package/dist/nextjs/index.cjs +7 -17
- package/dist/nextjs/index.d.cts +12 -5
- package/dist/nextjs/index.d.ts +12 -5
- package/dist/nextjs/index.mjs +7 -17
- package/dist/server/index.cjs +441 -74
- package/dist/server/index.d.cts +240 -38
- package/dist/server/index.d.ts +240 -38
- package/dist/server/index.mjs +442 -75
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,124 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.3.0] - 2026-08-08
|
|
11
|
+
|
|
12
|
+
Minor rather than patch because the API now accepts a request it previously rejected: with a
|
|
13
|
+
`tenantIdResolver` configured, `tenantId` may be omitted from the body. Nothing a consumer sends
|
|
14
|
+
today stops working, and no option changed meaning.
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- **`tenantId` is optional on every DTO that carries it**, so a deployment that configures
|
|
19
|
+
`tenantIdResolver` no longer forces its clients to send a value the server discards. The
|
|
20
|
+
option's whole purpose is that the resolved tenant wins and the body's is ignored, but the nine
|
|
21
|
+
DTOs declared the field with `@IsString() @IsNotEmpty()` and no `@IsOptional()`, so a request
|
|
22
|
+
that omitted it was rejected before any service ran. The two configurations were both wrong in
|
|
23
|
+
opposite directions: without a resolver the body named the tenant and was trusted, and with one
|
|
24
|
+
the body was mandatory and ignored.
|
|
25
|
+
|
|
26
|
+
`resolveTenantId` now refuses a request that no resolver and no body value can scope, answering
|
|
27
|
+
`auth.validation` with the same `{ field, message }[]` shape the validation pipe produces. It is
|
|
28
|
+
refused rather than defaulted deliberately: inventing a tenant name would gather into one scope
|
|
29
|
+
every account a misconfigured deployment created. `null` counts as absent there, because
|
|
30
|
+
`@IsOptional()` skips validation for `null` as well as for `undefined` — a caller may send
|
|
31
|
+
`tenantId: null` past every DTO constraint, and admitting it would carry `null` into the
|
|
32
|
+
tenant-scoped lookups and into the Redis and HMAC keys built from it.
|
|
33
|
+
|
|
34
|
+
Nothing changes for a consumer that sends `tenantId` today, with or without a resolver.
|
|
35
|
+
|
|
36
|
+
- **`jwt.absoluteSessionLifetimeDays` is documented as the 30-day default it actually is.** The
|
|
37
|
+
option's doc comment, the README's option table, the README's "deliberately off by default"
|
|
38
|
+
note and the specification's table all still described the pre-1.2.0 behaviour, where the cap
|
|
39
|
+
was off unless a deployment asked for it. 1.2.0 turned it on at 30 days as a security fix and
|
|
40
|
+
the prose did not follow, so the surface a consumer reads in their editor argued for planning
|
|
41
|
+
around sessions that never end.
|
|
42
|
+
|
|
43
|
+
### Changed
|
|
44
|
+
|
|
45
|
+
- `AuthService.register`, `AuthService.login`, `AuthService.verifyEmail`,
|
|
46
|
+
`AuthService.resendVerificationEmail` and `OAuthService.initiateOAuth` accept `tenantId` as
|
|
47
|
+
optional, matching the DTOs that feed them. The password-reset flows now read the resolved
|
|
48
|
+
tenant from the local binding rather than from the reassigned DTO, which is the same value and
|
|
49
|
+
removes the question of whether the reassignment happened.
|
|
50
|
+
|
|
51
|
+
## [1.2.0] - 2026-08-08
|
|
52
|
+
|
|
53
|
+
Carries the third security audit and the findings that surfaced while driving the mutation
|
|
54
|
+
score, across two pull requests that landed without versions of their own.
|
|
55
|
+
|
|
56
|
+
> **Action required for two deployments.** The Next.js proxy now **requires** `jwtSecret`;
|
|
57
|
+
> the decode-only fallback is gone, so a consumer that never set it fails at boot instead of
|
|
58
|
+
> trusting an unverified token. And the password floor moved from 8 to **15** by default —
|
|
59
|
+
> existing stored passwords keep working, but a set or change below 15 is now refused unless
|
|
60
|
+
> `password.minLength` says otherwise.
|
|
61
|
+
|
|
62
|
+
### Security
|
|
63
|
+
|
|
64
|
+
- **A live session could hide from revoke-all.** Pruning removed members whose `rt:` key was
|
|
65
|
+
still present, so a session survived the call meant to end every session for an account.
|
|
66
|
+
Prune now removes only a member whose `rt:` key is actually gone.
|
|
67
|
+
- **The Next.js proxy fell back to decoding a token without verifying it.** `jwtSecret` is
|
|
68
|
+
required and the decode-only path is removed. An unverified decode answers with whatever
|
|
69
|
+
the token claims.
|
|
70
|
+
- **A crafted password record could OOM-kill the process.** `compare()` derived scrypt's
|
|
71
|
+
`maxmem` from the stored PHC parameters and widened it to fit, so `ln=31` with the shipped
|
|
72
|
+
`r=8` asked for 2 TiB — which does not fail the request, it takes the process and every
|
|
73
|
+
in-flight connection with it. The ceiling is a constant that input cannot widen. A block
|
|
74
|
+
size above the parameter ceiling that the memory ceiling let through is closed with it.
|
|
75
|
+
- **An OTP check could pass on two absent values.** A non-string stored code fell back to
|
|
76
|
+
`''`, and `timingSafeEqual` answers true for two empty buffers, so an empty submitted code
|
|
77
|
+
compared equal to the placeholder and verification succeeded. The non-string record is
|
|
78
|
+
refused instead.
|
|
79
|
+
- **Two guards were exported but unusable.** `UserStatusGuard` was missing
|
|
80
|
+
`BYMAX_AUTH_USER_REPOSITORY` and `WsJwtGuard` was missing `WsTicketService` from the
|
|
81
|
+
module's exports, so `@UseGuards(JwtAuthGuard, UserStatusGuard)` failed a consumer's boot
|
|
82
|
+
and every route on a derived backend was protected by token validity alone — a suspended
|
|
83
|
+
or deleted account kept access for a full access-token lifetime. The ticket handshake was
|
|
84
|
+
likewise unreachable, so realtime authenticators replayed the access-token cookie and never
|
|
85
|
+
consulted the revocation blacklist. All nine guards' constructor deps were audited; these
|
|
86
|
+
were the only gaps.
|
|
87
|
+
- **OAuth `state` was not bound to its provider** (RFC 9700 mix-up). The provider is carried
|
|
88
|
+
in the state record.
|
|
89
|
+
- **A cookie prefix whose attributes cannot satisfy it** is dropped silently by the browser.
|
|
90
|
+
The contract is validated at boot.
|
|
91
|
+
- **The absolute session lifetime inherited no cap.** Capped at 30 days (NIST SP 800-63B-4
|
|
92
|
+
§3).
|
|
93
|
+
- **The rate limit charged a single IPv6 address**, which costs an attacker nothing to move
|
|
94
|
+
within. Charged to the /64.
|
|
95
|
+
- **"Is this production" was sniffed from `NODE_ENV`** in six places. An explicit
|
|
96
|
+
`environment` option decides it, defaulting to production.
|
|
97
|
+
|
|
98
|
+
### Added
|
|
99
|
+
|
|
100
|
+
- **`password.minLength`** — configurable, defaulting to **15**. NIST SP 800-63B-4 §3.1.1.1
|
|
101
|
+
allows 8 only for a password used as part of multi-factor authentication and requires 15
|
|
102
|
+
for a single factor; MFA here is opt-in per user, so the default deployment is
|
|
103
|
+
single-factor. The check moved to `PasswordService.assertAcceptable`, one entry point for
|
|
104
|
+
the four sites that set a password, screening length before the breach corpus — a password
|
|
105
|
+
refused for being short should not cost a round trip nor be sent anywhere first.
|
|
106
|
+
- **`MfaService.resetMfa`** — administrative removal of a second factor, for a user who lost
|
|
107
|
+
both the authenticator and the recovery codes. Every self-service exit needs the factor
|
|
108
|
+
itself, so without it that user is locked out permanently by the control meant to protect
|
|
109
|
+
them (ASVS v5 §6.1.1). It ships as a method and **not** a route, the decision
|
|
110
|
+
`unlockAccount` already made: every route this library exposes is scoped to the caller's
|
|
111
|
+
own account, and who may reset whom is a question only the host can answer. It invalidates
|
|
112
|
+
sessions, bumps the token epoch so `mfaVerified: true` tokens die with the factor, and
|
|
113
|
+
notifies the account holder — an administrative reset the owner cannot see is an
|
|
114
|
+
account-takeover path.
|
|
115
|
+
- Log lines where the response is deliberately uninformative, so the log is the only record
|
|
116
|
+
the event happened: ws-ticket refusals, invitation and revoke-rank refusals, email-change
|
|
117
|
+
and change-password lockouts, MFA re-authentication refusals, and corrupted MFA setup
|
|
118
|
+
payloads.
|
|
119
|
+
|
|
120
|
+
### Changed
|
|
121
|
+
|
|
122
|
+
- **`sendNewSessionAlert` is optional.** It was a required provider method the library never
|
|
123
|
+
called, with a docstring claiming it fired on login. Without device recognition it would
|
|
124
|
+
fire on every login, and an alert on every login is one the user learns to dismiss — the
|
|
125
|
+
control stops existing while appearing to be in place. `onNewSession` already fires on
|
|
126
|
+
every session created; the docs now say what is true.
|
|
127
|
+
|
|
10
128
|
## [1.1.1] - 2026-08-05
|
|
11
129
|
|
|
12
130
|
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.
|
|
@@ -1075,7 +1193,9 @@ ever installable.
|
|
|
1075
1193
|
- 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
|
|
1076
1194
|
- 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
|
|
1077
1195
|
|
|
1078
|
-
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.
|
|
1196
|
+
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.3.0...HEAD
|
|
1197
|
+
[1.3.0]: https://github.com/bymaxone/nest-auth/compare/v1.2.0...v1.3.0
|
|
1198
|
+
[1.2.0]: https://github.com/bymaxone/nest-auth/compare/v1.1.1...v1.2.0
|
|
1079
1199
|
[1.1.1]: https://github.com/bymaxone/nest-auth/compare/v1.1.0...v1.1.1
|
|
1080
1200
|
[1.1.0]: https://github.com/bymaxone/nest-auth/compare/v1.0.11...v1.1.0
|
|
1081
1201
|
[1.0.11]: https://github.com/bymaxone/nest-auth/compare/v1.0.10...v1.0.11
|
package/README.md
CHANGED
|
@@ -66,7 +66,7 @@ pnpm add @bymax-one/nest-auth
|
|
|
66
66
|
|
|
67
67
|
- ✅ **Zero External Crypto** — All cryptography via native `node:crypto` (scrypt, AES-256-GCM, HMAC-SHA1, TOTP)
|
|
68
68
|
- ✅ **Brute-Force Protection** — Configurable rate limiting per email + tenant
|
|
69
|
-
- ✅ **Session Management** — Track active sessions with FIFO eviction and
|
|
69
|
+
- ✅ **Session Management** — Track active sessions with FIFO eviction, and an `onNewSession` hook fired on every session created (alerting on it is yours to decide — see `sendNewSessionAlert`)
|
|
70
70
|
- ✅ **HttpOnly Cookies** — Secure, SameSite, path-scoped refresh tokens by default
|
|
71
71
|
- ✅ **Timing-Safe Comparisons** — All secret comparisons use `crypto.timingSafeEqual`
|
|
72
72
|
- ✅ **JWT Revocation** — Instant access token revocation via Redis JTI blacklist
|
|
@@ -644,28 +644,55 @@ both channels are accepted, and a ticket wins when both are present.
|
|
|
644
644
|
|
|
645
645
|
All options are configurable via `registerAsync()`. Here are the key configuration groups:
|
|
646
646
|
|
|
647
|
-
| Group | Key Options | Default
|
|
648
|
-
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
649
|
-
| **jwt** | `secret` (required), `previousSecrets`, `accessExpiresIn`, `refreshExpiresInDays`, `absoluteSessionLifetimeDays`, `algorithm`, `issuer`, `audience` | `15m`, `7d`,
|
|
650
|
-
| **
|
|
651
|
-
| **
|
|
652
|
-
| **
|
|
653
|
-
| **
|
|
654
|
-
| **
|
|
655
|
-
| **
|
|
656
|
-
| **
|
|
657
|
-
| **
|
|
658
|
-
| **
|
|
659
|
-
| **
|
|
660
|
-
| **
|
|
661
|
-
| **
|
|
662
|
-
| **
|
|
663
|
-
| **
|
|
664
|
-
| **
|
|
647
|
+
| Group | Key Options | Default |
|
|
648
|
+
| --------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- |
|
|
649
|
+
| **jwt** | `secret` (required), `previousSecrets`, `accessExpiresIn`, `refreshExpiresInDays`, `absoluteSessionLifetimeDays`, `algorithm`, `issuer`, `audience` | `15m`, `7d`, `30d` cap, `HS256`, both off |
|
|
650
|
+
| **environment** | `'production'` \| `'development'` \| `'test'` — the only input that answers "is this production" | `'production'` |
|
|
651
|
+
| **password** | `minLength`, `costFactor`, `blockSize`, `parallelization` | `15`, scrypt N=2¹⁷, r=8, p=1 |
|
|
652
|
+
| **tokenDelivery** | `'cookie'` \| `'bearer'` \| `'both'` | `'cookie'` |
|
|
653
|
+
| **cookies** | `accessTokenName`, `refreshTokenName`, `sessionSignalName`, `refreshCookiePath`, `sameSite`, `trustedOrigins`, `resolveDomains` | `'lax'`, `[]` (see cookie section) |
|
|
654
|
+
| **mfa** | `encryptionKey`, `previousEncryptionKeys`, `issuer`, `totpWindow`, `recoveryCodeCount` | — |
|
|
655
|
+
| **sessions** | `enabled`, `defaultMaxSessions`, `maxSessionsResolver` | `false`, `5`, — |
|
|
656
|
+
| **bruteForce** | `maxAttempts`, `windowSeconds` | `5`, `900` |
|
|
657
|
+
| **rateLimit** | `enabled`, `clientIpSource` (`'peer'` \| `'trusted-proxy'`) — per-IP limits over Redis | `true`, **required** |
|
|
658
|
+
| **passwordReset** | `method` (`'token'` \| `'otp'`), `otpLength`, `otpTtlSeconds` | `'token'` |
|
|
659
|
+
| **platform** | `enabled` | `false` |
|
|
660
|
+
| **invitations** | `enabled`, `tokenTtlSeconds` | `false` |
|
|
661
|
+
| **roles** | `hierarchy` (required), `platformHierarchy` | — |
|
|
662
|
+
| **oauth** | `google: { clientId, clientSecret, callbackUrl }` | — |
|
|
663
|
+
| **emailVerification** | `required`, `otpTtlSeconds` | `true`, `600` |
|
|
664
|
+
| **password** (screen) | `blocklist` — extra words the default screen refuses, on top of the ones it ships | `[]` |
|
|
665
|
+
| **controllers** | Toggle individual controllers on/off | `auth`, `passwordReset` on; rest opt-in |
|
|
665
666
|
|
|
666
667
|
> [!NOTE]
|
|
667
668
|
> When a feature is not configured (e.g., `mfa`, `sessions`, `platform`), its controllers and services are **not registered** in the NestJS container — zero overhead.
|
|
668
669
|
|
|
670
|
+
> [!IMPORTANT]
|
|
671
|
+
> **`environment` is how the module decides whether this is production, and it defaults to
|
|
672
|
+
> saying yes.** It drives cookie `Secure`, the HTTPS requirement on the OAuth `callbackUrl`, and
|
|
673
|
+
> three redirect validations. It used to be read from `NODE_ENV`, which failed **open** on every
|
|
674
|
+
> near miss — unset, `'staging'`, `'prod'`, or `'production '` with a trailing space each
|
|
675
|
+
> silently took the insecure branch, in all six places at once. Whether a deployment is
|
|
676
|
+
> production is something the deployer knows and the process environment only hints at, so it is
|
|
677
|
+
> passed in. The consequence to plan for: a local or test setup must now say
|
|
678
|
+
> `environment: 'development'` (or `'test'`) explicitly, or it will be held to production rules —
|
|
679
|
+
> an `http://` callback URL is refused, and cookies are marked `Secure` and never sent over
|
|
680
|
+
> plaintext. That failure is loud, which is the point; the old one was silent. Matches
|
|
681
|
+
> `Environment` in rust-auth.
|
|
682
|
+
|
|
683
|
+
> [!NOTE]
|
|
684
|
+
> **`password.minLength` defaults to 15, not 8.** The DTOs keep a structural floor of 8 — the
|
|
685
|
+
> lowest NIST SP 800-63B-4 §3.1.1.1 permits under any circumstance — and this is the
|
|
686
|
+
> deployment's policy on top of it. §3.1.1.1 allows 8 only for a password used as part of
|
|
687
|
+
> multi-factor authentication and requires 15 for one used as a single factor; MFA here is
|
|
688
|
+
> opt-in per user, so the default deployment **is** single-factor. Configurable to anything in
|
|
689
|
+
> `8..=128`, validated at startup: below 8 changes no outcome (the DTOs refuse the request
|
|
690
|
+
> first), and above 128 is longer than any password the validation layer accepts. It is checked
|
|
691
|
+
> in the service rather than a decorator because a decorator is evaluated when the class is
|
|
692
|
+
> defined, before any configuration exists — and it answers the same `auth.validation` code and
|
|
693
|
+
> the same `{ field, message }[]` details a length failure already produced, so a client
|
|
694
|
+
> handling short passwords sees no new shape.
|
|
695
|
+
|
|
669
696
|
> [!IMPORTANT]
|
|
670
697
|
> **`rateLimit.clientIpSource` is required** whenever rate limiting is enabled — there is no
|
|
671
698
|
> default. The option group is a discriminated union, so TypeScript refuses the omission at
|
|
@@ -738,14 +765,22 @@ All options are configurable via `registerAsync()`. Here are the key configurati
|
|
|
738
765
|
> rather than letting it fail open, and rejects an unreadable time span or a non-positive
|
|
739
766
|
> lifetime on the same pass.
|
|
740
767
|
|
|
741
|
-
|
|
742
|
-
|
|
768
|
+
`jwt.absoluteSessionLifetimeDays` caps how long one login can be extended by rotation, and is
|
|
769
|
+
**on by default at 30 days** — NIST SP 800-63B-4 §3 makes a definite reauthentication timeout a
|
|
770
|
+
SHALL and puts it at no more than 30 days for AAL1. Without a cap, a client refreshing every
|
|
771
|
+
fifteen minutes keeps a session alive forever, and a refresh token stolen once becomes permanent
|
|
772
|
+
access. Raise it to a value the product can justify, or set `0` to accept unbounded sessions
|
|
773
|
+
deliberately.
|
|
774
|
+
|
|
775
|
+
Lowering the value ends sessions that are already older than the new one, at their next rotation;
|
|
776
|
+
raising it or setting `0` ends nothing. Sessions established before the cap existed carry no
|
|
777
|
+
recorded birth time and are never capped, whatever the value — they age out under
|
|
778
|
+
`refreshExpiresInDays` like any other.
|
|
743
779
|
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
cross-site, and it is the only one where the origin check has anything to authorize.
|
|
780
|
+
`cookies.trustedOrigins` is deliberately off by default, because switching it on changes
|
|
781
|
+
behaviour for origins that already exist. It is required as soon as `cookies.sameSite: 'none'`
|
|
782
|
+
is set, and refused otherwise — that posture is the only one where the browser sends the session
|
|
783
|
+
cookie cross-site, and it is the only one where the origin check has anything to authorize.
|
|
749
784
|
|
|
750
785
|
The breach check is opt-in for a different reason: it is the only part of the credential path
|
|
751
786
|
that reaches the network, and a library should not start talking to a third party because it was
|
|
@@ -841,7 +876,11 @@ When integrating `@bymax-one/nest-auth` in production, verify each of the follow
|
|
|
841
876
|
- `@MaxLength(128)` on password DTOs prevents algorithmic-DoS via oversized scrypt inputs
|
|
842
877
|
- JWT algorithm pinning to HS256 prevents algorithm-confusion attacks
|
|
843
878
|
- Constant-time comparisons via `crypto.timingSafeEqual` for all secret comparisons
|
|
844
|
-
- HttpOnly cookies; `Secure` enforced in production; `SameSite=
|
|
879
|
+
- HttpOnly cookies; `Secure` enforced in production; `SameSite=Lax` by default on every auth
|
|
880
|
+
cookie, so the OAuth provider's cross-site redirect back to your app still carries them.
|
|
881
|
+
Deployments that do not need that redirect can take the stricter posture with
|
|
882
|
+
`cookies.sameSite: 'strict'`. CSRF does not rest on this setting — `TrustedOriginGuard` is
|
|
883
|
+
applied to every controller and runs before authentication.
|
|
845
884
|
|
|
846
885
|
---
|
|
847
886
|
|
|
@@ -855,7 +894,7 @@ When integrating `@bymax-one/nest-auth` in production, verify each of the follow
|
|
|
855
894
|
| Token Generation | `crypto.randomBytes(32)` — 256 bits of entropy |
|
|
856
895
|
| Secret Comparison | `crypto.timingSafeEqual` (constant-time) |
|
|
857
896
|
| JWT | HS256 via `@nestjs/jwt`, JTI blacklist via Redis |
|
|
858
|
-
| Cookies | HttpOnly, Secure, SameSite=
|
|
897
|
+
| Cookies | HttpOnly, Secure, SameSite=Lax (override to `strict`), path-scoped |
|
|
859
898
|
| Brute-Force | Redis atomic counters per HMAC(email, jwt.secret) |
|
|
860
899
|
| CSRF (OAuth) | 64-char hex state nonce, single-use via `getdel()` |
|
|
861
900
|
| Refresh Rotation | Single-use tokens with a grace window; a replay past it revokes that login's whole family lineage |
|
|
@@ -950,6 +989,40 @@ Conditionally registered controllers (mfa, sessions, platform, invitations, oaut
|
|
|
950
989
|
> hand a victim a callback URL and have the victim's browser complete the attacker's login.
|
|
951
990
|
> Mount `app.use(cookieParser())` before the module's routes or every callback answers 401.
|
|
952
991
|
|
|
992
|
+
### Administrative operations — methods, deliberately not routes
|
|
993
|
+
|
|
994
|
+
Two support-desk operations ship as **methods with no HTTP route**. Every route above is scoped
|
|
995
|
+
to the caller's own account, and both of these act on somebody else's — so exposing them would
|
|
996
|
+
mean inventing an authorization model ("who is an admin?") that this library does not have and
|
|
997
|
+
your application already does. Call them from your own admin surface, where the caller is
|
|
998
|
+
already authorized.
|
|
999
|
+
|
|
1000
|
+
| Method | Answers |
|
|
1001
|
+
| ------------------------------------------ | --------------------------------------------------- |
|
|
1002
|
+
| `AuthService.unlockAccount(email, tenant)` | "I am locked out and I need in now" |
|
|
1003
|
+
| `MfaService.resetMfa(userId, context?)` | "I lost my authenticator **and** my recovery codes" |
|
|
1004
|
+
|
|
1005
|
+
**`unlockAccount`** clears the brute-force lockout. It grants no access: the password, the
|
|
1006
|
+
status gate, the verification gate and MFA all still apply — it restores the ability to _try_.
|
|
1007
|
+
It exists because the counter is keyed by an HMAC under the library's own `hmacKey`, which no
|
|
1008
|
+
consumer can derive, so until it existed a lockout could only be waited out. It is also the
|
|
1009
|
+
lever an attacker pulls to deny service to one specific account, which makes undoing it part of
|
|
1010
|
+
the defence. Idempotent.
|
|
1011
|
+
|
|
1012
|
+
**`resetMfa`** removes a second factor without one. Every self-service exit needs the factor
|
|
1013
|
+
itself — `disable` wants a valid TOTP code, the recovery codes want the codes — so a user who
|
|
1014
|
+
has lost both is locked out permanently by the control meant to protect them (ASVS v5 §6.1.1
|
|
1015
|
+
asks for this path for exactly that reason). It invalidates every session and bumps the token
|
|
1016
|
+
epoch, so access tokens carrying `mfaVerified: true` die with the factor; it **notifies the
|
|
1017
|
+
account holder** through the same channel a self-service disable uses; and it logs at `warn`
|
|
1018
|
+
under its own prefix. The notification is not optional: an administrative reset the owner
|
|
1019
|
+
cannot see is an account-takeover path, and it is what makes the event detectable and
|
|
1020
|
+
disputable. Idempotent; throws for an id that resolves to nobody, so a typo cannot read as
|
|
1021
|
+
"done".
|
|
1022
|
+
|
|
1023
|
+
> `MfaService` is only registered when `controllers.mfa` or `controllers.platform` is on —
|
|
1024
|
+
> otherwise add it to `extraProviders` to inject it.
|
|
1025
|
+
|
|
953
1026
|
### Server Guards
|
|
954
1027
|
|
|
955
1028
|
| Guard | Decorator | Purpose |
|
package/dist/nextjs/index.cjs
CHANGED
|
@@ -264,9 +264,8 @@ function decodeJwtToken(token) {
|
|
|
264
264
|
}
|
|
265
265
|
__name(decodeJwtToken, "decodeJwtToken");
|
|
266
266
|
async function verifyJwtToken(token, secret) {
|
|
267
|
-
if (secret === void 0 || secret === null
|
|
268
|
-
|
|
269
|
-
}
|
|
267
|
+
if (secret === void 0 || secret === null) return emptyDecoded();
|
|
268
|
+
if (secret.length === 0) return emptyDecoded();
|
|
270
269
|
const parts = token.split(".");
|
|
271
270
|
if (parts.length !== 3) return emptyDecoded();
|
|
272
271
|
const headerSegment = parts[0] ?? "";
|
|
@@ -539,19 +538,11 @@ function resolveConfig(config) {
|
|
|
539
538
|
};
|
|
540
539
|
}
|
|
541
540
|
__name(resolveConfig, "resolveConfig");
|
|
542
|
-
function
|
|
541
|
+
function assertJwtSecretConfigured(config) {
|
|
543
542
|
if (config.jwtSecret !== void 0 && config.jwtSecret.length > 0) return;
|
|
544
|
-
|
|
545
|
-
throw new Error("createAuthProxy: jwtSecret is required in production. Without it the proxy runs in decode-only mode where RBAC and status-blocking trust unverified tokens \u2014 a crafted token with a future `exp` can impersonate any role. Provide `jwtSecret` or move signature verification to an upstream gateway and explicitly opt out by running outside of a production environment.");
|
|
546
|
-
}
|
|
547
|
-
if (typeof console === "undefined" || typeof console.warn !== "function") return;
|
|
548
|
-
console.warn("[@bymax-one/nest-auth] createAuthProxy: jwtSecret is not configured. The proxy is running in decode-only mode \u2014 JWT signatures are NOT verified. Every RBAC and status-blocking decision trusts the raw token contents, and forged tokens with a future `exp` can impersonate any role. Ensure an upstream gateway verifies signatures before requests reach downstream server components that read the injected identity headers. In production this condition throws instead of warning.");
|
|
549
|
-
}
|
|
550
|
-
__name(warnOnInsecureConfiguration, "warnOnInsecureConfiguration");
|
|
551
|
-
function isProductionEnv() {
|
|
552
|
-
return process.env["NODE_ENV"] === "production";
|
|
543
|
+
throw new Error("createAuthProxy: jwtSecret is required. Without it no JWT signature can be verified, so route gating, role checks, status blocking and the identity headers injected into server components would all trust unverified token contents \u2014 a crafted token with a future `exp` can impersonate any role. Provide `jwtSecret`; supply it even when an upstream gateway also verifies signatures.");
|
|
553
544
|
}
|
|
554
|
-
__name(
|
|
545
|
+
__name(assertJwtSecretConfigured, "assertJwtSecretConfigured");
|
|
555
546
|
var FORBIDDEN_IN_PATH = /[\u0000-\u001f\u007f]/;
|
|
556
547
|
function toSameOriginPath(path) {
|
|
557
548
|
if (!path.startsWith("/")) return "/";
|
|
@@ -847,8 +838,7 @@ async function readTokenState(request, config) {
|
|
|
847
838
|
signatureVerified: false
|
|
848
839
|
};
|
|
849
840
|
}
|
|
850
|
-
const
|
|
851
|
-
const decoded = hasSecret ? await verifyJwtToken(raw, config.jwtSecret) : decodeJwtToken(raw);
|
|
841
|
+
const decoded = await verifyJwtToken(raw, config.jwtSecret);
|
|
852
842
|
const isSession = decoded.isValid && isAccessToken(decoded);
|
|
853
843
|
return {
|
|
854
844
|
token: decoded,
|
|
@@ -872,7 +862,7 @@ __name(isAccessToken, "isAccessToken");
|
|
|
872
862
|
function createAuthProxy(config) {
|
|
873
863
|
validateConfig(config);
|
|
874
864
|
const resolved = resolveConfig(config);
|
|
875
|
-
|
|
865
|
+
assertJwtSecretConfigured(resolved);
|
|
876
866
|
return {
|
|
877
867
|
proxy: /* @__PURE__ */ __name((request) => runProxy(request, resolved), "proxy"),
|
|
878
868
|
config: resolved
|
package/dist/nextjs/index.d.cts
CHANGED
|
@@ -462,11 +462,18 @@ declare function decodeJwtToken(token: string): DecodedToken;
|
|
|
462
462
|
* {@link decodeJwtToken} remains the explicit, correctly-named entry
|
|
463
463
|
* point for the non-authoritative read.
|
|
464
464
|
*
|
|
465
|
-
* The empty string
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
465
|
+
* The empty string — `JWT_SECRET=""` in an environment file, the
|
|
466
|
+
* ordinary way a missing secret arrives as a present one — is refused
|
|
467
|
+
* by its own check rather than left to the crypto layer. WebCrypto
|
|
468
|
+
* already rejects zero-length HMAC key material (`importKey` throws
|
|
469
|
+
* `DataError`, which the catch below converts into the same
|
|
470
|
+
* `emptyDecoded()`), so the check changes no outcome here. It is kept
|
|
471
|
+
* because "this function refuses to verify without a secret" should be
|
|
472
|
+
* readable in the function, and should not rest on an exception thrown
|
|
473
|
+
* several layers down and swallowed by a broad `catch` — a `catch` that
|
|
474
|
+
* a later refactor can narrow without knowing it was load-bearing.
|
|
475
|
+
* No test can distinguish the two, so the mutants on it carry a
|
|
476
|
+
* suppression.
|
|
470
477
|
*
|
|
471
478
|
* @param token - JWS compact serialisation.
|
|
472
479
|
* @param secret - HS256 shared secret. A missing or empty value
|
package/dist/nextjs/index.d.ts
CHANGED
|
@@ -462,11 +462,18 @@ declare function decodeJwtToken(token: string): DecodedToken;
|
|
|
462
462
|
* {@link decodeJwtToken} remains the explicit, correctly-named entry
|
|
463
463
|
* point for the non-authoritative read.
|
|
464
464
|
*
|
|
465
|
-
* The empty string
|
|
466
|
-
*
|
|
467
|
-
*
|
|
468
|
-
*
|
|
469
|
-
*
|
|
465
|
+
* The empty string — `JWT_SECRET=""` in an environment file, the
|
|
466
|
+
* ordinary way a missing secret arrives as a present one — is refused
|
|
467
|
+
* by its own check rather than left to the crypto layer. WebCrypto
|
|
468
|
+
* already rejects zero-length HMAC key material (`importKey` throws
|
|
469
|
+
* `DataError`, which the catch below converts into the same
|
|
470
|
+
* `emptyDecoded()`), so the check changes no outcome here. It is kept
|
|
471
|
+
* because "this function refuses to verify without a secret" should be
|
|
472
|
+
* readable in the function, and should not rest on an exception thrown
|
|
473
|
+
* several layers down and swallowed by a broad `catch` — a `catch` that
|
|
474
|
+
* a later refactor can narrow without knowing it was load-bearing.
|
|
475
|
+
* No test can distinguish the two, so the mutants on it carry a
|
|
476
|
+
* suppression.
|
|
470
477
|
*
|
|
471
478
|
* @param token - JWS compact serialisation.
|
|
472
479
|
* @param secret - HS256 shared secret. A missing or empty value
|
package/dist/nextjs/index.mjs
CHANGED
|
@@ -262,9 +262,8 @@ function decodeJwtToken(token) {
|
|
|
262
262
|
}
|
|
263
263
|
__name(decodeJwtToken, "decodeJwtToken");
|
|
264
264
|
async function verifyJwtToken(token, secret) {
|
|
265
|
-
if (secret === void 0 || secret === null
|
|
266
|
-
|
|
267
|
-
}
|
|
265
|
+
if (secret === void 0 || secret === null) return emptyDecoded();
|
|
266
|
+
if (secret.length === 0) return emptyDecoded();
|
|
268
267
|
const parts = token.split(".");
|
|
269
268
|
if (parts.length !== 3) return emptyDecoded();
|
|
270
269
|
const headerSegment = parts[0] ?? "";
|
|
@@ -537,19 +536,11 @@ function resolveConfig(config) {
|
|
|
537
536
|
};
|
|
538
537
|
}
|
|
539
538
|
__name(resolveConfig, "resolveConfig");
|
|
540
|
-
function
|
|
539
|
+
function assertJwtSecretConfigured(config) {
|
|
541
540
|
if (config.jwtSecret !== void 0 && config.jwtSecret.length > 0) return;
|
|
542
|
-
|
|
543
|
-
throw new Error("createAuthProxy: jwtSecret is required in production. Without it the proxy runs in decode-only mode where RBAC and status-blocking trust unverified tokens \u2014 a crafted token with a future `exp` can impersonate any role. Provide `jwtSecret` or move signature verification to an upstream gateway and explicitly opt out by running outside of a production environment.");
|
|
544
|
-
}
|
|
545
|
-
if (typeof console === "undefined" || typeof console.warn !== "function") return;
|
|
546
|
-
console.warn("[@bymax-one/nest-auth] createAuthProxy: jwtSecret is not configured. The proxy is running in decode-only mode \u2014 JWT signatures are NOT verified. Every RBAC and status-blocking decision trusts the raw token contents, and forged tokens with a future `exp` can impersonate any role. Ensure an upstream gateway verifies signatures before requests reach downstream server components that read the injected identity headers. In production this condition throws instead of warning.");
|
|
547
|
-
}
|
|
548
|
-
__name(warnOnInsecureConfiguration, "warnOnInsecureConfiguration");
|
|
549
|
-
function isProductionEnv() {
|
|
550
|
-
return process.env["NODE_ENV"] === "production";
|
|
541
|
+
throw new Error("createAuthProxy: jwtSecret is required. Without it no JWT signature can be verified, so route gating, role checks, status blocking and the identity headers injected into server components would all trust unverified token contents \u2014 a crafted token with a future `exp` can impersonate any role. Provide `jwtSecret`; supply it even when an upstream gateway also verifies signatures.");
|
|
551
542
|
}
|
|
552
|
-
__name(
|
|
543
|
+
__name(assertJwtSecretConfigured, "assertJwtSecretConfigured");
|
|
553
544
|
var FORBIDDEN_IN_PATH = /[\u0000-\u001f\u007f]/;
|
|
554
545
|
function toSameOriginPath(path) {
|
|
555
546
|
if (!path.startsWith("/")) return "/";
|
|
@@ -845,8 +836,7 @@ async function readTokenState(request, config) {
|
|
|
845
836
|
signatureVerified: false
|
|
846
837
|
};
|
|
847
838
|
}
|
|
848
|
-
const
|
|
849
|
-
const decoded = hasSecret ? await verifyJwtToken(raw, config.jwtSecret) : decodeJwtToken(raw);
|
|
839
|
+
const decoded = await verifyJwtToken(raw, config.jwtSecret);
|
|
850
840
|
const isSession = decoded.isValid && isAccessToken(decoded);
|
|
851
841
|
return {
|
|
852
842
|
token: decoded,
|
|
@@ -870,7 +860,7 @@ __name(isAccessToken, "isAccessToken");
|
|
|
870
860
|
function createAuthProxy(config) {
|
|
871
861
|
validateConfig(config);
|
|
872
862
|
const resolved = resolveConfig(config);
|
|
873
|
-
|
|
863
|
+
assertJwtSecretConfigured(resolved);
|
|
874
864
|
return {
|
|
875
865
|
proxy: /* @__PURE__ */ __name((request) => runProxy(request, resolved), "proxy"),
|
|
876
866
|
config: resolved
|