@bymax-one/nest-auth 1.4.18 → 1.4.20
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 +120 -1
- package/README.md +29 -1
- package/dist/nextjs/index.cjs +22 -3
- package/dist/nextjs/index.d.cts +23 -8
- package/dist/nextjs/index.d.ts +23 -8
- package/dist/nextjs/index.mjs +22 -3
- package/dist/react/index.cjs +29 -8
- package/dist/react/index.d.cts +28 -8
- package/dist/react/index.d.ts +28 -8
- package/dist/react/index.mjs +29 -8
- package/dist/server/index.cjs +298 -328
- package/dist/server/index.d.cts +52 -136
- package/dist/server/index.d.ts +52 -136
- package/dist/server/index.mjs +298 -328
- package/package.json +3 -1
package/dist/server/index.d.cts
CHANGED
|
@@ -276,6 +276,11 @@ interface IUserRepository {
|
|
|
276
276
|
/**
|
|
277
277
|
* Finds a user by email address within a specific tenant.
|
|
278
278
|
*
|
|
279
|
+
* **Keep this call well under the password-reset resend cooldown (60 seconds).** The reset flows
|
|
280
|
+
* claim the cooldown before they call this, and release it by key when this call throws. A call
|
|
281
|
+
* that takes longer than the cooldown and then fails releases a key that may by then belong to a
|
|
282
|
+
* later request, whose cooldown is removed early. The library does not guard against it.
|
|
283
|
+
*
|
|
279
284
|
* @returns The matching user record, or null if not found.
|
|
280
285
|
*/
|
|
281
286
|
findByEmail(params: FindUserByEmailParams): Promise<AuthUser | null>;
|
|
@@ -312,6 +317,15 @@ interface IUserRepository {
|
|
|
312
317
|
* spent recovery code in the account's list. An implementation MUST scope the update by both the
|
|
313
318
|
* id and the tenant, exactly as its read does.
|
|
314
319
|
*
|
|
320
|
+
* **Keep this call well under the MFA transition lock's lifetime.** The library serializes MFA
|
|
321
|
+
* state changes per account with a lock that expires on its own after
|
|
322
|
+
* `MFA_TRANSITION_LOCK_TTL_SECONDS` (10 seconds), so a process that dies mid-write cannot strand
|
|
323
|
+
* the account. A write still running when the lock expires is overtaken: a second change takes
|
|
324
|
+
* the lock, reads the record and writes it, and this write then lands after it and overwrites it.
|
|
325
|
+
* The interface has no compare-and-set for the library to use, so it cannot detect that. The
|
|
326
|
+
* parameters carry only the new values, so a guard inside this method can narrow the window only
|
|
327
|
+
* for a stall after its own read; closing it would need the values the library read passed in.
|
|
328
|
+
*
|
|
315
329
|
* @param params - See {@link UpdateMfaParams}.
|
|
316
330
|
*/
|
|
317
331
|
updateMfa(params: UpdateMfaParams): Promise<void>;
|
|
@@ -3796,6 +3810,15 @@ interface IPlatformUserRepository {
|
|
|
3796
3810
|
* `mfaSecret` with AES-256-GCM and hash `mfaRecoveryCodes` with SHA-256
|
|
3797
3811
|
* before passing them here.
|
|
3798
3812
|
*
|
|
3813
|
+
* **Keep this call well under the MFA transition lock's lifetime.** The library serializes MFA
|
|
3814
|
+
* state changes per account with a lock that expires on its own after
|
|
3815
|
+
* `MFA_TRANSITION_LOCK_TTL_SECONDS` (10 seconds), so a process that dies mid-write cannot strand
|
|
3816
|
+
* the account. A write still running when the lock expires is overtaken: a second change takes
|
|
3817
|
+
* the lock, reads the record and writes it, and this write then lands after it and overwrites it.
|
|
3818
|
+
* The interface has no compare-and-set for the library to use, so it cannot detect that. The
|
|
3819
|
+
* parameters carry only the new values, so a guard inside this method can narrow the window only
|
|
3820
|
+
* for a stall after its own read; closing it would need the values the library read passed in.
|
|
3821
|
+
*
|
|
3799
3822
|
* @param id - The platform administrator's unique identifier.
|
|
3800
3823
|
* @param data - New MFA state. See {@link UpdatePlatformMfaData}.
|
|
3801
3824
|
*/
|
|
@@ -5603,11 +5626,25 @@ declare class RolesGuard implements CanActivate {
|
|
|
5603
5626
|
* `req.user` before this guard runs.
|
|
5604
5627
|
*
|
|
5605
5628
|
* @remarks
|
|
5606
|
-
* **
|
|
5607
|
-
*
|
|
5608
|
-
*
|
|
5609
|
-
*
|
|
5610
|
-
*
|
|
5629
|
+
* **Tenant boundary:** when the route captures the tenant under `tenantId`, `tenant_id` or
|
|
5630
|
+
* `tenant`, every capture present must equal the token's `tenantId`; otherwise the request is
|
|
5631
|
+
* refused with `INSUFFICIENT_ROLE` before the self-or-admin decision is made. An id is only
|
|
5632
|
+
* unique within a tenant, and the `admin` role is held inside one, so neither identity nor role
|
|
5633
|
+
* reaches across the boundary. Captures that disagree with one another, are empty, or are arrays
|
|
5634
|
+
* name no tenant the token can equal and are refused; a wildcard capture arrives as an array of
|
|
5635
|
+
* the segments it matched, so it is refused even for an admin.
|
|
5636
|
+
*
|
|
5637
|
+
* **What the tenant check cannot see:** only those three capture names are read. A route that
|
|
5638
|
+
* names the tenant any other way, `{org}` for instance, is decided by identity and role alone, and
|
|
5639
|
+
* the handler must bind that capture to the token's tenant itself, as must a route with no tenant
|
|
5640
|
+
* capture. Where Express resolves a capture name used at two nesting levels, the inner value wins
|
|
5641
|
+
* (measured on Express 5, with or without `mergeParams`), and a capture on a parent router
|
|
5642
|
+
* mounted without `mergeParams` is not visible to the inner route, so the guard sees none.
|
|
5643
|
+
* Nest controllers compose the full path on one route and are not affected by the second.
|
|
5644
|
+
*
|
|
5645
|
+
* **The id:** the `userId` or `id` capture must be one non-empty path segment. An empty value or
|
|
5646
|
+
* one carrying a slash (a decoded `%2F`) is refused with `INSUFFICIENT_ROLE`, for an admin too and
|
|
5647
|
+
* for an owner whose own id contains a slash.
|
|
5611
5648
|
*
|
|
5612
5649
|
* **Admin role convention:** The literal `'admin'` role is checked against the
|
|
5613
5650
|
* configured hierarchy. If the consuming application uses a different convention
|
|
@@ -9002,97 +9039,6 @@ declare class MfaService {
|
|
|
9002
9039
|
* @throws {@link AuthException} `MFA_STATE_CONFLICT` when another transition holds the lock.
|
|
9003
9040
|
*/
|
|
9004
9041
|
private transitionMfaRecord;
|
|
9005
|
-
/**
|
|
9006
|
-
* Whether `stored` decrypts, under the current or a retired key, to `secretBase32`.
|
|
9007
|
-
*
|
|
9008
|
-
* Compares plaintext, so a record that was only re-encrypted still matches and one holding a
|
|
9009
|
-
* different secret does not. A ciphertext no key opens does not match either.
|
|
9010
|
-
*/
|
|
9011
|
-
private holdsSecret;
|
|
9012
|
-
/**
|
|
9013
|
-
* Encrypts a TOTP secret for storage in the database using AES-256-GCM.
|
|
9014
|
-
*/
|
|
9015
|
-
private encryptSecret;
|
|
9016
|
-
/**
|
|
9017
|
-
* Decrypts a stored TOTP secret, falling back to keys retired by a rotation.
|
|
9018
|
-
*
|
|
9019
|
-
* The ciphertext records no key identifier, so without the retired keys, changing
|
|
9020
|
-
* `mfa.encryptionKey` makes every stored secret undecryptable — every enrolled user's
|
|
9021
|
-
* authenticator stops matching at once, with no way back. AES-GCM authenticates, so a wrong
|
|
9022
|
-
* key fails unambiguously rather than returning garbage; trying them in order is safe.
|
|
9023
|
-
*
|
|
9024
|
-
* Re-throws any decryption failure as an opaque `TOKEN_INVALID` to prevent
|
|
9025
|
-
* error-type oracle attacks (callers cannot distinguish format vs. tamper errors).
|
|
9026
|
-
*/
|
|
9027
|
-
private decryptSecret;
|
|
9028
|
-
/**
|
|
9029
|
-
* Decrypt under the current key, then under each retired one.
|
|
9030
|
-
*
|
|
9031
|
-
* @param encrypted - The stored ciphertext.
|
|
9032
|
-
* @returns The plaintext and whether a retired key produced it — the signal that the record
|
|
9033
|
-
* should be re-encrypted under the current key.
|
|
9034
|
-
* @throws {@link AuthException} `TOKEN_INVALID` when no key decrypts it.
|
|
9035
|
-
*/
|
|
9036
|
-
private decryptWithRotation;
|
|
9037
|
-
/**
|
|
9038
|
-
* Safely parses a Redis-stored {@link MfaSetupData} JSON payload.
|
|
9039
|
-
*
|
|
9040
|
-
* A corrupted or tampered Redis value would otherwise raise an unhandled
|
|
9041
|
-
* `SyntaxError` from the service boundary (uncaught 500). We translate the
|
|
9042
|
-
* failure into an opaque `MFA_SETUP_REQUIRED`, which mirrors the response
|
|
9043
|
-
* the caller would receive if the key were absent — preventing an attacker
|
|
9044
|
-
* with Redis write access from distinguishing "no setup pending" from
|
|
9045
|
-
* "setup payload corrupted".
|
|
9046
|
-
*/
|
|
9047
|
-
private parseSetupData;
|
|
9048
|
-
/**
|
|
9049
|
-
* Safely parses the AES-decrypted JSON array of plain-text recovery codes.
|
|
9050
|
-
*
|
|
9051
|
-
* A decrypted value that fails JSON parsing indicates either a downgrade of
|
|
9052
|
-
* the stored payload (highly unlikely, since AES-GCM authenticates the
|
|
9053
|
-
* ciphertext) or an internal bug. Both cases are surfaced opaquely as
|
|
9054
|
-
* `MFA_SETUP_REQUIRED` so callers do not learn structural details of the
|
|
9055
|
-
* encrypted payload.
|
|
9056
|
-
*/
|
|
9057
|
-
private parsePlainRecoveryCodes;
|
|
9058
|
-
/**
|
|
9059
|
-
* Generates `count` recovery codes in `XXXX-XXXX-XXXX-XXXX-XXXX-XXXX` format
|
|
9060
|
-
* (96 bits of entropy per code, hex-encoded).
|
|
9061
|
-
*
|
|
9062
|
-
* Returns both the plain-text (shown once to the user) and scrypt-hashed
|
|
9063
|
-
* versions (stored in the database).
|
|
9064
|
-
*
|
|
9065
|
-
* @remarks
|
|
9066
|
-
* Each code carries 96 bits of entropy (12 random bytes → 24 hex chars grouped
|
|
9067
|
-
* as 6 × 4). This is well above the NIST SP 800-63B recommendation for
|
|
9068
|
-
* offline-resistant credentials. The previous 12-digit decimal format offered
|
|
9069
|
-
* ~40 bits, which relied entirely on the scrypt hash for offline resistance —
|
|
9070
|
-
* any database leak would have put the raw codes within offline reach.
|
|
9071
|
-
*/
|
|
9072
|
-
private hashRecoveryCodes;
|
|
9073
|
-
/**
|
|
9074
|
-
* Derives the stored digest for a recovery code: a keyed HMAC-SHA-256, hex encoded.
|
|
9075
|
-
*
|
|
9076
|
-
* A recovery code is 96 bits of CSPRNG output, not a human-chosen password, so a
|
|
9077
|
-
* memory-hard KDF buys nothing against it — there is no dictionary to walk and brute
|
|
9078
|
-
* forcing 2^96 is out of reach whatever the hash costs. What the KDF did buy was an
|
|
9079
|
-
* attacker-reachable CPU amplifier: a challenge submitting a wrong recovery code scanned
|
|
9080
|
-
* every stored digest, so one request cost as many scrypt derivations as the user had
|
|
9081
|
-
* codes. The keyed MAC is the right primitive here — the secret key is what stops an
|
|
9082
|
-
* offline attacker precomputing digests from a leaked table, and it costs microseconds.
|
|
9083
|
-
*/
|
|
9084
|
-
private digestRecoveryCode;
|
|
9085
|
-
/**
|
|
9086
|
-
* Compares a submitted recovery code against every stored digest.
|
|
9087
|
-
*
|
|
9088
|
-
* One storage format only: a keyed MAC over the code. Every digest is compared in constant
|
|
9089
|
-
* time and the scan always runs to completion — including the step that picks the winner out
|
|
9090
|
-
* of the recorded results — so neither the position of a match nor the number of codes still
|
|
9091
|
-
* unused is observable in the response time.
|
|
9092
|
-
*
|
|
9093
|
-
* @returns Index of the first matching digest, or `-1` if none match.
|
|
9094
|
-
*/
|
|
9095
|
-
private verifyRecoveryCode;
|
|
9096
9042
|
/**
|
|
9097
9043
|
* Claims a matched recovery code for exactly one challenge.
|
|
9098
9044
|
*
|
|
@@ -9120,41 +9066,6 @@ declare class MfaService {
|
|
|
9120
9066
|
* @returns `true` when this challenge is the one that claimed it.
|
|
9121
9067
|
*/
|
|
9122
9068
|
private claimRecoveryCode;
|
|
9123
|
-
/**
|
|
9124
|
-
* Returns a `SafeAuthUser` projection of a dashboard user, stripping credentials
|
|
9125
|
-
* and MFA secret fields before passing to hooks or email providers.
|
|
9126
|
-
*/
|
|
9127
|
-
private toSafeUser;
|
|
9128
|
-
/**
|
|
9129
|
-
* Returns a `SafeAuthPlatformUser` projection of a platform admin, stripping
|
|
9130
|
-
* credentials and MFA secret fields.
|
|
9131
|
-
*/
|
|
9132
|
-
private toSafePlatformUser;
|
|
9133
|
-
/**
|
|
9134
|
-
* Constructs a `SafeAuthUser`-compatible object from a `SafeAuthPlatformUser` so
|
|
9135
|
-
* that it can be passed to hooks typed for `SafeAuthUser`.
|
|
9136
|
-
*
|
|
9137
|
-
* Platform admins have no `tenantId` or `emailVerified` fields. These are filled
|
|
9138
|
-
* with sentinel values (`''` and `true` respectively) since platform admins are
|
|
9139
|
-
* provisioned directly and do not participate in the tenant/email-verification flow.
|
|
9140
|
-
*/
|
|
9141
|
-
private platformUserAsSafeUser;
|
|
9142
|
-
/**
|
|
9143
|
-
* The account a hook is handed after an MFA transition, projected from the state the transition
|
|
9144
|
-
* wrote.
|
|
9145
|
-
*
|
|
9146
|
-
* The record in hand was read before the transition, so its `mfaEnabled` still describes the
|
|
9147
|
-
* state the transition replaced; the hooks run after the write and must be told what it
|
|
9148
|
-
* produced. Only the flag is overridden. The secret and recovery-code fields are stripped by
|
|
9149
|
-
* the same projections every other hook payload uses, and the repository's own record is not
|
|
9150
|
-
* modified.
|
|
9151
|
-
*
|
|
9152
|
-
* @param context - The identity plane the account belongs to.
|
|
9153
|
-
* @param user - The record read before the transition.
|
|
9154
|
-
* @param mfaEnabled - Whether the transition left the second factor enabled.
|
|
9155
|
-
* @returns The projection for the plane, with `mfaEnabled` as written.
|
|
9156
|
-
*/
|
|
9157
|
-
private committedSafeUser;
|
|
9158
9069
|
/**
|
|
9159
9070
|
* Initiates the MFA setup flow for a dashboard user or platform administrator.
|
|
9160
9071
|
*
|
|
@@ -9793,12 +9704,14 @@ declare class PasswordResetService {
|
|
|
9793
9704
|
* inactive, or suspended), issues a reset token or OTP (depending on
|
|
9794
9705
|
* `options.passwordReset.method`) and sends it via the email provider.
|
|
9795
9706
|
*
|
|
9796
|
-
* **
|
|
9707
|
+
* **Resolves the same way** whether or not the account exists:
|
|
9797
9708
|
* - The email does not exist in the tenant.
|
|
9798
9709
|
* - The account is blocked.
|
|
9799
|
-
* -
|
|
9710
|
+
* - Issuing or storing the code, or the email provider, fails for an account that exists.
|
|
9800
9711
|
*
|
|
9801
|
-
*
|
|
9712
|
+
* A failure that is the same for every address, the resend-cooldown store or the account
|
|
9713
|
+
* lookup, throws `INTERNAL` (500) after the floor, and the cooldown this call took is
|
|
9714
|
+
* released. This anti-enumeration design ensures the response cannot be used to probe
|
|
9802
9715
|
* whether an email address is registered.
|
|
9803
9716
|
*
|
|
9804
9717
|
* Timing normalization: the method always takes at least {@link ANTI_ENUM_MIN_MS}
|
|
@@ -9850,14 +9763,17 @@ declare class PasswordResetService {
|
|
|
9850
9763
|
* Requests a new password-reset OTP for the given email address.
|
|
9851
9764
|
*
|
|
9852
9765
|
* Subject to an atomic 60-second cooldown enforced via a Redis NX key to
|
|
9853
|
-
* prevent OTP flooding.
|
|
9854
|
-
*
|
|
9766
|
+
* prevent OTP flooding. Resolves the same way whether or not the user exists —
|
|
9767
|
+
* anti-enumeration principle; a failure of the cooldown store or the account lookup
|
|
9768
|
+
* throws `INTERNAL` (500) after the floor and releases the cooldown.
|
|
9855
9769
|
*
|
|
9856
9770
|
* Timing normalization: always takes at least {@link ANTI_ENUM_MIN_MS} ms.
|
|
9857
9771
|
*
|
|
9858
9772
|
* @param dto - Validated DTO with `email` and `tenantId`.
|
|
9859
9773
|
*/
|
|
9860
9774
|
resendOtp(dto: ResendOtpDto, req: Request): Promise<void>;
|
|
9775
|
+
/** Runs one `forgot-password` or `resend-otp` request through the shared failure rule. */
|
|
9776
|
+
private answerResetRequest;
|
|
9861
9777
|
/**
|
|
9862
9778
|
* Token-based reset path: atomically consumes the token from Redis and updates
|
|
9863
9779
|
* the password.
|
package/dist/server/index.d.ts
CHANGED
|
@@ -276,6 +276,11 @@ interface IUserRepository {
|
|
|
276
276
|
/**
|
|
277
277
|
* Finds a user by email address within a specific tenant.
|
|
278
278
|
*
|
|
279
|
+
* **Keep this call well under the password-reset resend cooldown (60 seconds).** The reset flows
|
|
280
|
+
* claim the cooldown before they call this, and release it by key when this call throws. A call
|
|
281
|
+
* that takes longer than the cooldown and then fails releases a key that may by then belong to a
|
|
282
|
+
* later request, whose cooldown is removed early. The library does not guard against it.
|
|
283
|
+
*
|
|
279
284
|
* @returns The matching user record, or null if not found.
|
|
280
285
|
*/
|
|
281
286
|
findByEmail(params: FindUserByEmailParams): Promise<AuthUser | null>;
|
|
@@ -312,6 +317,15 @@ interface IUserRepository {
|
|
|
312
317
|
* spent recovery code in the account's list. An implementation MUST scope the update by both the
|
|
313
318
|
* id and the tenant, exactly as its read does.
|
|
314
319
|
*
|
|
320
|
+
* **Keep this call well under the MFA transition lock's lifetime.** The library serializes MFA
|
|
321
|
+
* state changes per account with a lock that expires on its own after
|
|
322
|
+
* `MFA_TRANSITION_LOCK_TTL_SECONDS` (10 seconds), so a process that dies mid-write cannot strand
|
|
323
|
+
* the account. A write still running when the lock expires is overtaken: a second change takes
|
|
324
|
+
* the lock, reads the record and writes it, and this write then lands after it and overwrites it.
|
|
325
|
+
* The interface has no compare-and-set for the library to use, so it cannot detect that. The
|
|
326
|
+
* parameters carry only the new values, so a guard inside this method can narrow the window only
|
|
327
|
+
* for a stall after its own read; closing it would need the values the library read passed in.
|
|
328
|
+
*
|
|
315
329
|
* @param params - See {@link UpdateMfaParams}.
|
|
316
330
|
*/
|
|
317
331
|
updateMfa(params: UpdateMfaParams): Promise<void>;
|
|
@@ -3796,6 +3810,15 @@ interface IPlatformUserRepository {
|
|
|
3796
3810
|
* `mfaSecret` with AES-256-GCM and hash `mfaRecoveryCodes` with SHA-256
|
|
3797
3811
|
* before passing them here.
|
|
3798
3812
|
*
|
|
3813
|
+
* **Keep this call well under the MFA transition lock's lifetime.** The library serializes MFA
|
|
3814
|
+
* state changes per account with a lock that expires on its own after
|
|
3815
|
+
* `MFA_TRANSITION_LOCK_TTL_SECONDS` (10 seconds), so a process that dies mid-write cannot strand
|
|
3816
|
+
* the account. A write still running when the lock expires is overtaken: a second change takes
|
|
3817
|
+
* the lock, reads the record and writes it, and this write then lands after it and overwrites it.
|
|
3818
|
+
* The interface has no compare-and-set for the library to use, so it cannot detect that. The
|
|
3819
|
+
* parameters carry only the new values, so a guard inside this method can narrow the window only
|
|
3820
|
+
* for a stall after its own read; closing it would need the values the library read passed in.
|
|
3821
|
+
*
|
|
3799
3822
|
* @param id - The platform administrator's unique identifier.
|
|
3800
3823
|
* @param data - New MFA state. See {@link UpdatePlatformMfaData}.
|
|
3801
3824
|
*/
|
|
@@ -5603,11 +5626,25 @@ declare class RolesGuard implements CanActivate {
|
|
|
5603
5626
|
* `req.user` before this guard runs.
|
|
5604
5627
|
*
|
|
5605
5628
|
* @remarks
|
|
5606
|
-
* **
|
|
5607
|
-
*
|
|
5608
|
-
*
|
|
5609
|
-
*
|
|
5610
|
-
*
|
|
5629
|
+
* **Tenant boundary:** when the route captures the tenant under `tenantId`, `tenant_id` or
|
|
5630
|
+
* `tenant`, every capture present must equal the token's `tenantId`; otherwise the request is
|
|
5631
|
+
* refused with `INSUFFICIENT_ROLE` before the self-or-admin decision is made. An id is only
|
|
5632
|
+
* unique within a tenant, and the `admin` role is held inside one, so neither identity nor role
|
|
5633
|
+
* reaches across the boundary. Captures that disagree with one another, are empty, or are arrays
|
|
5634
|
+
* name no tenant the token can equal and are refused; a wildcard capture arrives as an array of
|
|
5635
|
+
* the segments it matched, so it is refused even for an admin.
|
|
5636
|
+
*
|
|
5637
|
+
* **What the tenant check cannot see:** only those three capture names are read. A route that
|
|
5638
|
+
* names the tenant any other way, `{org}` for instance, is decided by identity and role alone, and
|
|
5639
|
+
* the handler must bind that capture to the token's tenant itself, as must a route with no tenant
|
|
5640
|
+
* capture. Where Express resolves a capture name used at two nesting levels, the inner value wins
|
|
5641
|
+
* (measured on Express 5, with or without `mergeParams`), and a capture on a parent router
|
|
5642
|
+
* mounted without `mergeParams` is not visible to the inner route, so the guard sees none.
|
|
5643
|
+
* Nest controllers compose the full path on one route and are not affected by the second.
|
|
5644
|
+
*
|
|
5645
|
+
* **The id:** the `userId` or `id` capture must be one non-empty path segment. An empty value or
|
|
5646
|
+
* one carrying a slash (a decoded `%2F`) is refused with `INSUFFICIENT_ROLE`, for an admin too and
|
|
5647
|
+
* for an owner whose own id contains a slash.
|
|
5611
5648
|
*
|
|
5612
5649
|
* **Admin role convention:** The literal `'admin'` role is checked against the
|
|
5613
5650
|
* configured hierarchy. If the consuming application uses a different convention
|
|
@@ -9002,97 +9039,6 @@ declare class MfaService {
|
|
|
9002
9039
|
* @throws {@link AuthException} `MFA_STATE_CONFLICT` when another transition holds the lock.
|
|
9003
9040
|
*/
|
|
9004
9041
|
private transitionMfaRecord;
|
|
9005
|
-
/**
|
|
9006
|
-
* Whether `stored` decrypts, under the current or a retired key, to `secretBase32`.
|
|
9007
|
-
*
|
|
9008
|
-
* Compares plaintext, so a record that was only re-encrypted still matches and one holding a
|
|
9009
|
-
* different secret does not. A ciphertext no key opens does not match either.
|
|
9010
|
-
*/
|
|
9011
|
-
private holdsSecret;
|
|
9012
|
-
/**
|
|
9013
|
-
* Encrypts a TOTP secret for storage in the database using AES-256-GCM.
|
|
9014
|
-
*/
|
|
9015
|
-
private encryptSecret;
|
|
9016
|
-
/**
|
|
9017
|
-
* Decrypts a stored TOTP secret, falling back to keys retired by a rotation.
|
|
9018
|
-
*
|
|
9019
|
-
* The ciphertext records no key identifier, so without the retired keys, changing
|
|
9020
|
-
* `mfa.encryptionKey` makes every stored secret undecryptable — every enrolled user's
|
|
9021
|
-
* authenticator stops matching at once, with no way back. AES-GCM authenticates, so a wrong
|
|
9022
|
-
* key fails unambiguously rather than returning garbage; trying them in order is safe.
|
|
9023
|
-
*
|
|
9024
|
-
* Re-throws any decryption failure as an opaque `TOKEN_INVALID` to prevent
|
|
9025
|
-
* error-type oracle attacks (callers cannot distinguish format vs. tamper errors).
|
|
9026
|
-
*/
|
|
9027
|
-
private decryptSecret;
|
|
9028
|
-
/**
|
|
9029
|
-
* Decrypt under the current key, then under each retired one.
|
|
9030
|
-
*
|
|
9031
|
-
* @param encrypted - The stored ciphertext.
|
|
9032
|
-
* @returns The plaintext and whether a retired key produced it — the signal that the record
|
|
9033
|
-
* should be re-encrypted under the current key.
|
|
9034
|
-
* @throws {@link AuthException} `TOKEN_INVALID` when no key decrypts it.
|
|
9035
|
-
*/
|
|
9036
|
-
private decryptWithRotation;
|
|
9037
|
-
/**
|
|
9038
|
-
* Safely parses a Redis-stored {@link MfaSetupData} JSON payload.
|
|
9039
|
-
*
|
|
9040
|
-
* A corrupted or tampered Redis value would otherwise raise an unhandled
|
|
9041
|
-
* `SyntaxError` from the service boundary (uncaught 500). We translate the
|
|
9042
|
-
* failure into an opaque `MFA_SETUP_REQUIRED`, which mirrors the response
|
|
9043
|
-
* the caller would receive if the key were absent — preventing an attacker
|
|
9044
|
-
* with Redis write access from distinguishing "no setup pending" from
|
|
9045
|
-
* "setup payload corrupted".
|
|
9046
|
-
*/
|
|
9047
|
-
private parseSetupData;
|
|
9048
|
-
/**
|
|
9049
|
-
* Safely parses the AES-decrypted JSON array of plain-text recovery codes.
|
|
9050
|
-
*
|
|
9051
|
-
* A decrypted value that fails JSON parsing indicates either a downgrade of
|
|
9052
|
-
* the stored payload (highly unlikely, since AES-GCM authenticates the
|
|
9053
|
-
* ciphertext) or an internal bug. Both cases are surfaced opaquely as
|
|
9054
|
-
* `MFA_SETUP_REQUIRED` so callers do not learn structural details of the
|
|
9055
|
-
* encrypted payload.
|
|
9056
|
-
*/
|
|
9057
|
-
private parsePlainRecoveryCodes;
|
|
9058
|
-
/**
|
|
9059
|
-
* Generates `count` recovery codes in `XXXX-XXXX-XXXX-XXXX-XXXX-XXXX` format
|
|
9060
|
-
* (96 bits of entropy per code, hex-encoded).
|
|
9061
|
-
*
|
|
9062
|
-
* Returns both the plain-text (shown once to the user) and scrypt-hashed
|
|
9063
|
-
* versions (stored in the database).
|
|
9064
|
-
*
|
|
9065
|
-
* @remarks
|
|
9066
|
-
* Each code carries 96 bits of entropy (12 random bytes → 24 hex chars grouped
|
|
9067
|
-
* as 6 × 4). This is well above the NIST SP 800-63B recommendation for
|
|
9068
|
-
* offline-resistant credentials. The previous 12-digit decimal format offered
|
|
9069
|
-
* ~40 bits, which relied entirely on the scrypt hash for offline resistance —
|
|
9070
|
-
* any database leak would have put the raw codes within offline reach.
|
|
9071
|
-
*/
|
|
9072
|
-
private hashRecoveryCodes;
|
|
9073
|
-
/**
|
|
9074
|
-
* Derives the stored digest for a recovery code: a keyed HMAC-SHA-256, hex encoded.
|
|
9075
|
-
*
|
|
9076
|
-
* A recovery code is 96 bits of CSPRNG output, not a human-chosen password, so a
|
|
9077
|
-
* memory-hard KDF buys nothing against it — there is no dictionary to walk and brute
|
|
9078
|
-
* forcing 2^96 is out of reach whatever the hash costs. What the KDF did buy was an
|
|
9079
|
-
* attacker-reachable CPU amplifier: a challenge submitting a wrong recovery code scanned
|
|
9080
|
-
* every stored digest, so one request cost as many scrypt derivations as the user had
|
|
9081
|
-
* codes. The keyed MAC is the right primitive here — the secret key is what stops an
|
|
9082
|
-
* offline attacker precomputing digests from a leaked table, and it costs microseconds.
|
|
9083
|
-
*/
|
|
9084
|
-
private digestRecoveryCode;
|
|
9085
|
-
/**
|
|
9086
|
-
* Compares a submitted recovery code against every stored digest.
|
|
9087
|
-
*
|
|
9088
|
-
* One storage format only: a keyed MAC over the code. Every digest is compared in constant
|
|
9089
|
-
* time and the scan always runs to completion — including the step that picks the winner out
|
|
9090
|
-
* of the recorded results — so neither the position of a match nor the number of codes still
|
|
9091
|
-
* unused is observable in the response time.
|
|
9092
|
-
*
|
|
9093
|
-
* @returns Index of the first matching digest, or `-1` if none match.
|
|
9094
|
-
*/
|
|
9095
|
-
private verifyRecoveryCode;
|
|
9096
9042
|
/**
|
|
9097
9043
|
* Claims a matched recovery code for exactly one challenge.
|
|
9098
9044
|
*
|
|
@@ -9120,41 +9066,6 @@ declare class MfaService {
|
|
|
9120
9066
|
* @returns `true` when this challenge is the one that claimed it.
|
|
9121
9067
|
*/
|
|
9122
9068
|
private claimRecoveryCode;
|
|
9123
|
-
/**
|
|
9124
|
-
* Returns a `SafeAuthUser` projection of a dashboard user, stripping credentials
|
|
9125
|
-
* and MFA secret fields before passing to hooks or email providers.
|
|
9126
|
-
*/
|
|
9127
|
-
private toSafeUser;
|
|
9128
|
-
/**
|
|
9129
|
-
* Returns a `SafeAuthPlatformUser` projection of a platform admin, stripping
|
|
9130
|
-
* credentials and MFA secret fields.
|
|
9131
|
-
*/
|
|
9132
|
-
private toSafePlatformUser;
|
|
9133
|
-
/**
|
|
9134
|
-
* Constructs a `SafeAuthUser`-compatible object from a `SafeAuthPlatformUser` so
|
|
9135
|
-
* that it can be passed to hooks typed for `SafeAuthUser`.
|
|
9136
|
-
*
|
|
9137
|
-
* Platform admins have no `tenantId` or `emailVerified` fields. These are filled
|
|
9138
|
-
* with sentinel values (`''` and `true` respectively) since platform admins are
|
|
9139
|
-
* provisioned directly and do not participate in the tenant/email-verification flow.
|
|
9140
|
-
*/
|
|
9141
|
-
private platformUserAsSafeUser;
|
|
9142
|
-
/**
|
|
9143
|
-
* The account a hook is handed after an MFA transition, projected from the state the transition
|
|
9144
|
-
* wrote.
|
|
9145
|
-
*
|
|
9146
|
-
* The record in hand was read before the transition, so its `mfaEnabled` still describes the
|
|
9147
|
-
* state the transition replaced; the hooks run after the write and must be told what it
|
|
9148
|
-
* produced. Only the flag is overridden. The secret and recovery-code fields are stripped by
|
|
9149
|
-
* the same projections every other hook payload uses, and the repository's own record is not
|
|
9150
|
-
* modified.
|
|
9151
|
-
*
|
|
9152
|
-
* @param context - The identity plane the account belongs to.
|
|
9153
|
-
* @param user - The record read before the transition.
|
|
9154
|
-
* @param mfaEnabled - Whether the transition left the second factor enabled.
|
|
9155
|
-
* @returns The projection for the plane, with `mfaEnabled` as written.
|
|
9156
|
-
*/
|
|
9157
|
-
private committedSafeUser;
|
|
9158
9069
|
/**
|
|
9159
9070
|
* Initiates the MFA setup flow for a dashboard user or platform administrator.
|
|
9160
9071
|
*
|
|
@@ -9793,12 +9704,14 @@ declare class PasswordResetService {
|
|
|
9793
9704
|
* inactive, or suspended), issues a reset token or OTP (depending on
|
|
9794
9705
|
* `options.passwordReset.method`) and sends it via the email provider.
|
|
9795
9706
|
*
|
|
9796
|
-
* **
|
|
9707
|
+
* **Resolves the same way** whether or not the account exists:
|
|
9797
9708
|
* - The email does not exist in the tenant.
|
|
9798
9709
|
* - The account is blocked.
|
|
9799
|
-
* -
|
|
9710
|
+
* - Issuing or storing the code, or the email provider, fails for an account that exists.
|
|
9800
9711
|
*
|
|
9801
|
-
*
|
|
9712
|
+
* A failure that is the same for every address, the resend-cooldown store or the account
|
|
9713
|
+
* lookup, throws `INTERNAL` (500) after the floor, and the cooldown this call took is
|
|
9714
|
+
* released. This anti-enumeration design ensures the response cannot be used to probe
|
|
9802
9715
|
* whether an email address is registered.
|
|
9803
9716
|
*
|
|
9804
9717
|
* Timing normalization: the method always takes at least {@link ANTI_ENUM_MIN_MS}
|
|
@@ -9850,14 +9763,17 @@ declare class PasswordResetService {
|
|
|
9850
9763
|
* Requests a new password-reset OTP for the given email address.
|
|
9851
9764
|
*
|
|
9852
9765
|
* Subject to an atomic 60-second cooldown enforced via a Redis NX key to
|
|
9853
|
-
* prevent OTP flooding.
|
|
9854
|
-
*
|
|
9766
|
+
* prevent OTP flooding. Resolves the same way whether or not the user exists —
|
|
9767
|
+
* anti-enumeration principle; a failure of the cooldown store or the account lookup
|
|
9768
|
+
* throws `INTERNAL` (500) after the floor and releases the cooldown.
|
|
9855
9769
|
*
|
|
9856
9770
|
* Timing normalization: always takes at least {@link ANTI_ENUM_MIN_MS} ms.
|
|
9857
9771
|
*
|
|
9858
9772
|
* @param dto - Validated DTO with `email` and `tenantId`.
|
|
9859
9773
|
*/
|
|
9860
9774
|
resendOtp(dto: ResendOtpDto, req: Request): Promise<void>;
|
|
9775
|
+
/** Runs one `forgot-password` or `resend-otp` request through the shared failure rule. */
|
|
9776
|
+
private answerResetRequest;
|
|
9861
9777
|
/**
|
|
9862
9778
|
* Token-based reset path: atomically consumes the token from Redis and updates
|
|
9863
9779
|
* the password.
|