@bymax-one/nest-auth 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/README.md +6 -1
- package/dist/client/index.cjs +8 -1
- package/dist/client/index.mjs +8 -1
- package/dist/nextjs/index.d.cts +15 -3
- package/dist/nextjs/index.d.ts +15 -3
- package/dist/react/index.cjs +8 -0
- package/dist/react/index.mjs +8 -0
- package/dist/server/index.cjs +526 -313
- package/dist/server/index.d.cts +130 -60
- package/dist/server/index.d.ts +130 -60
- package/dist/server/index.mjs +526 -313
- package/package.json +3 -13
package/dist/server/index.d.cts
CHANGED
|
@@ -3420,7 +3420,16 @@ declare function reduceToBaseWord(password: string): string;
|
|
|
3420
3420
|
* runs, and any decorated form of those — but it is not the full top-3000, and it knows
|
|
3421
3421
|
* nothing about breach corpora. A deployment that wants that should either extend it through
|
|
3422
3422
|
* `password.blocklist` or supply {@link HibpBreachChecker}, which checks a real breach corpus
|
|
3423
|
-
* over the network.
|
|
3423
|
+
* over the network.
|
|
3424
|
+
*
|
|
3425
|
+
* **The shipped base words are ASCII.** The reduction preserves letters and numbers in any
|
|
3426
|
+
* script — a strong Cyrillic, Han, Kana, Hangul, Greek, Arabic, Hebrew or Thai passphrase is
|
|
3427
|
+
* admitted, and used to be refused outright with the "commonly used" error, which pushed those
|
|
3428
|
+
* users onto the smaller ASCII keyspace. But the list itself has no entries in those scripts,
|
|
3429
|
+
* so the equivalent of `password` in one of them passes this screen. A deployment serving
|
|
3430
|
+
* those users should add the common ones for its locale to `password.blocklist`; entries are
|
|
3431
|
+
* normalized through the same reduction, so a non-Latin entry matches a decorated form of
|
|
3432
|
+
* itself the way an ASCII one does. This checker being the default is what makes the *baseline* honest; the
|
|
3424
3433
|
* network check remains opt-in, because a library should not start talking to a third party
|
|
3425
3434
|
* because it was upgraded.
|
|
3426
3435
|
*
|
|
@@ -3726,6 +3735,22 @@ declare class AuthRedisService {
|
|
|
3726
3735
|
* (`reused`, carrying the compromised family), or never-issued (`invalid`).
|
|
3727
3736
|
*/
|
|
3728
3737
|
rotateRefreshSession(params: RefreshRotationParams): Promise<RefreshRotationOutcome>;
|
|
3738
|
+
/**
|
|
3739
|
+
* Writes a freshly-issued refresh session atomically — record, session-index member and
|
|
3740
|
+
* family membership, each carrying the refresh TTL.
|
|
3741
|
+
*
|
|
3742
|
+
* See {@link CREATE_SESSION_LUA} for the two windows the loose form left open.
|
|
3743
|
+
*
|
|
3744
|
+
* @param params - The session to store and the keys it belongs under.
|
|
3745
|
+
*/
|
|
3746
|
+
writeNewSession(params: {
|
|
3747
|
+
kind: 'dashboard' | 'platform';
|
|
3748
|
+
tokenHash: string;
|
|
3749
|
+
sessionJson: string;
|
|
3750
|
+
familyId: string;
|
|
3751
|
+
userId: string;
|
|
3752
|
+
refreshTtl: number;
|
|
3753
|
+
}): Promise<void>;
|
|
3729
3754
|
/**
|
|
3730
3755
|
* Writes the session a grace recovery produced, atomically with the check that the account
|
|
3731
3756
|
* has not been swept out from under it.
|
|
@@ -3823,6 +3848,36 @@ declare class AuthRedisService {
|
|
|
3823
3848
|
* @returns `true` if the key was newly set, `false` if it already existed.
|
|
3824
3849
|
*/
|
|
3825
3850
|
setIfAbsent(key: string, value: string, ttl: number): Promise<boolean>;
|
|
3851
|
+
/**
|
|
3852
|
+
* Drops the grace-pointer members whose keys have already expired.
|
|
3853
|
+
*
|
|
3854
|
+
* A rotation removes `rt:{old}` from the index and adds two members: `rt:{new}` and
|
|
3855
|
+
* `rp:{old}`. The `rp:` KEY dies with the grace window — 30 seconds by default — but the
|
|
3856
|
+
* MEMBER was only ever removed by a full revoke-all, so the index gained one permanent
|
|
3857
|
+
* ~68-byte entry per rotation, and the rotation re-arms the set's own TTL each time. The set
|
|
3858
|
+
* never aged out while the account was in use.
|
|
3859
|
+
*
|
|
3860
|
+
* That is not merely untidy. Every reader of the index is linear in its size:
|
|
3861
|
+
* `listSessions` ships the whole set over the wire, `revokeAllExceptCurrent` issues two
|
|
3862
|
+
* sequential round trips per grace member, and `invalidateUserSessions` iterates it inside a
|
|
3863
|
+
* Lua script, which blocks the whole single-threaded store. An attacker holding one stolen
|
|
3864
|
+
* refresh token and rotating at the route limit adds ~14k members a day to their own index,
|
|
3865
|
+
* with no ceiling; a merely active user accrues thousands a year.
|
|
3866
|
+
*
|
|
3867
|
+
* Called from the two paths that already walk the index — a login enforcing the session cap
|
|
3868
|
+
* and a session listing — so the growth is bounded by how long an account can go between
|
|
3869
|
+
* them, and any legitimate interaction heals it. The rotation path deliberately does NOT
|
|
3870
|
+
* call this: it is the hot path, and an O(n) sweep there would trade a slow leak for a slow
|
|
3871
|
+
* refresh.
|
|
3872
|
+
*
|
|
3873
|
+
* Grace members whose key is still live are left alone. They are what lets a revoke-all also
|
|
3874
|
+
* kill a token that was rotated away moments earlier but can still be recovered.
|
|
3875
|
+
*
|
|
3876
|
+
* @param setKey - The un-namespaced index key (`sess:{id}` or `psess:{id}`).
|
|
3877
|
+
* @param gracePrefix - Member prefix for rotation grace pointers (`rp:` or `prp:`).
|
|
3878
|
+
* @returns How many dead members were dropped.
|
|
3879
|
+
*/
|
|
3880
|
+
pruneExpiredGraceMembers(setKey: string, gracePrefix: string): Promise<number>;
|
|
3826
3881
|
/**
|
|
3827
3882
|
* Atomically deletes every refresh session belonging to one identity plane.
|
|
3828
3883
|
*
|
|
@@ -5547,6 +5602,36 @@ declare class OtpService {
|
|
|
5547
5602
|
verify(purpose: string, identifier: string, code: string): Promise<void>;
|
|
5548
5603
|
}
|
|
5549
5604
|
|
|
5605
|
+
/**
|
|
5606
|
+
* Password hashing and verification service using `node:crypto` scrypt.
|
|
5607
|
+
*
|
|
5608
|
+
* Uses scrypt (RFC 7914) — a memory-hard key derivation function designed to
|
|
5609
|
+
* resist brute-force and GPU/ASIC attacks. **Never use SHA-256, MD5, or
|
|
5610
|
+
* unsalted hashes for passwords.**
|
|
5611
|
+
*
|
|
5612
|
+
* Wire format: PHC — `$scrypt$ln={log2(N)},r={r},p={p}${saltB64}${derivedB64}`
|
|
5613
|
+
* - `saltB64` — 16 random bytes in PHC "B64" (standard base64, no padding)
|
|
5614
|
+
* - `derivedB64` — 64 derived bytes in the same encoding
|
|
5615
|
+
*
|
|
5616
|
+
* The only encoding, read and written. rust-auth writes the same, and the format is pinned by
|
|
5617
|
+
* `conformance/wire-contract.json` with a known-answer vector from each implementation.
|
|
5618
|
+
*
|
|
5619
|
+
* @remarks
|
|
5620
|
+
* **Cost parameters:** Taken from `options.password` at construction time.
|
|
5621
|
+
* Defaults are `costFactor = 131072 (2^17)`, `blockSize = 8`, `parallelization = 1` — OWASP's
|
|
5622
|
+
* recommended minimum for scrypt. Override in
|
|
5623
|
+
* `BymaxAuthModule.forRoot({ password: { costFactor: 65536 } })`.
|
|
5624
|
+
* Validated at startup by `resolveOptions()` — values below `16384 (2^14)` are rejected.
|
|
5625
|
+
*
|
|
5626
|
+
* **Security:** Comparison uses `crypto.timingSafeEqual` to prevent timing
|
|
5627
|
+
* attacks. All comparison failures return `false` — never throw on bad input.
|
|
5628
|
+
*
|
|
5629
|
+
* **Thread safety:** scrypt is CPU-intensive. In production, calls will block
|
|
5630
|
+
* the Node.js event loop for ~100–200 ms. Consider running behind a worker
|
|
5631
|
+
* thread or rate-limiting authentication endpoints.
|
|
5632
|
+
*
|
|
5633
|
+
* @layer Service
|
|
5634
|
+
*/
|
|
5550
5635
|
declare class PasswordService {
|
|
5551
5636
|
private readonly breachChecker;
|
|
5552
5637
|
private readonly logger;
|
|
@@ -5559,12 +5644,12 @@ declare class PasswordService {
|
|
|
5559
5644
|
* Hashes a plaintext password using scrypt with a random salt.
|
|
5560
5645
|
*
|
|
5561
5646
|
* @param plain - Plaintext password (UTF-8 string).
|
|
5562
|
-
* @returns Hashed password
|
|
5647
|
+
* @returns Hashed password as a PHC string.
|
|
5563
5648
|
*
|
|
5564
5649
|
* @example
|
|
5565
5650
|
* ```typescript
|
|
5566
5651
|
* const hash = await passwordService.hash('my-password')
|
|
5567
|
-
* // 'scrypt
|
|
5652
|
+
* // '$scrypt$ln=17,r=8,p=1$YmFzZTY0c2FsdA$…'
|
|
5568
5653
|
* ```
|
|
5569
5654
|
*/
|
|
5570
5655
|
/**
|
|
@@ -5608,7 +5693,7 @@ declare class PasswordService {
|
|
|
5608
5693
|
* Verifies a plaintext password against a stored scrypt hash.
|
|
5609
5694
|
*
|
|
5610
5695
|
* @param plain - Plaintext password supplied by the user.
|
|
5611
|
-
* @param hash - Stored hash
|
|
5696
|
+
* @param hash - Stored hash, as a PHC string.
|
|
5612
5697
|
* @returns `true` if the password matches, `false` otherwise.
|
|
5613
5698
|
*
|
|
5614
5699
|
* @remarks
|
|
@@ -6017,6 +6102,14 @@ declare class TokenManagerService {
|
|
|
6017
6102
|
* @throws {@link AuthException} with `REFRESH_TOKEN_INVALID` if no valid session found.
|
|
6018
6103
|
*/
|
|
6019
6104
|
reissueTokens(oldRefresh: string, ip: string, userAgent: string): Promise<RotatedTokenResult>;
|
|
6105
|
+
/**
|
|
6106
|
+
* Emits {@link IAuthHooks.onRefreshTokenReuseDetected}, fire-and-forget.
|
|
6107
|
+
*
|
|
6108
|
+
* The owner is read from the stored session where it can be — a replay of a token whose live
|
|
6109
|
+
* key is already gone leaves nothing to read, and the hook is skipped rather than fired with
|
|
6110
|
+
* an empty identity that a consumer would have to guess about.
|
|
6111
|
+
*/
|
|
6112
|
+
private emitReuseDetected;
|
|
6020
6113
|
/**
|
|
6021
6114
|
* Refuses a rotation once the login it descends from has outlived the absolute cap.
|
|
6022
6115
|
*
|
|
@@ -6034,14 +6127,6 @@ declare class TokenManagerService {
|
|
|
6034
6127
|
* remedy is the same (sign in again) and the difference would only tell a holder of a
|
|
6035
6128
|
* stolen token how old the account's session is.
|
|
6036
6129
|
*/
|
|
6037
|
-
/**
|
|
6038
|
-
* Emits {@link IAuthHooks.onRefreshTokenReuseDetected}, fire-and-forget.
|
|
6039
|
-
*
|
|
6040
|
-
* The owner is read from the stored session where it can be — a replay of a token whose live
|
|
6041
|
-
* key is already gone leaves nothing to read, and the hook is skipped rather than fired with
|
|
6042
|
-
* an empty identity that a consumer would have to guess about.
|
|
6043
|
-
*/
|
|
6044
|
-
private emitReuseDetected;
|
|
6045
6130
|
private assertWithinAbsoluteLifetime;
|
|
6046
6131
|
/**
|
|
6047
6132
|
* Reads the presented token's live record to seed the rotated one.
|
|
@@ -6195,20 +6280,6 @@ declare class TokenManagerService {
|
|
|
6195
6280
|
* @returns The re-signed platform access token.
|
|
6196
6281
|
*/
|
|
6197
6282
|
reissuePlatformAccessWithAuthority(claims: PlatformJwtPayload, role: string, mfaEnabled: boolean): Promise<string>;
|
|
6198
|
-
/**
|
|
6199
|
-
* Decodes a JWT without validating its expiration or signature.
|
|
6200
|
-
*
|
|
6201
|
-
* @internal
|
|
6202
|
-
* **WARNING:** This method does NOT verify the token signature or expiry.
|
|
6203
|
-
* It must only be used for internal diagnostic purposes (e.g. reading the
|
|
6204
|
-
* `sub` claim from an expired token to look up a session for revocation).
|
|
6205
|
-
* Never use it to authorize requests — use `JwtService.verify()` in guards.
|
|
6206
|
-
*
|
|
6207
|
-
* @param token - Raw JWT string.
|
|
6208
|
-
* @returns Decoded payload.
|
|
6209
|
-
* @throws {@link AuthException} with `TOKEN_INVALID` if the payload is not an
|
|
6210
|
-
* object or lacks required `jti` (string) and `sub` (string) claims.
|
|
6211
|
-
*/
|
|
6212
6283
|
/**
|
|
6213
6284
|
* Verifies an access token's signature under the pinned algorithm while **ignoring its
|
|
6214
6285
|
* expiry**, returning the payload.
|
|
@@ -6237,7 +6308,6 @@ declare class TokenManagerService {
|
|
|
6237
6308
|
* @throws Whatever the verifier throws when no configured secret accepts the token.
|
|
6238
6309
|
*/
|
|
6239
6310
|
verifyPlatformIgnoringExpiry(token: string): PlatformJwtPayload;
|
|
6240
|
-
decodeToken(token: string): DashboardJwtPayload | PlatformJwtPayload | MfaTempPayload;
|
|
6241
6311
|
/**
|
|
6242
6312
|
* Issues a short-lived MFA challenge token and stores it in Redis for
|
|
6243
6313
|
* single-use enforcement.
|
|
@@ -6566,6 +6636,22 @@ declare class AuthService {
|
|
|
6566
6636
|
* @param tenantId - The tenant the account belongs to.
|
|
6567
6637
|
*/
|
|
6568
6638
|
unlockAccount(email: string, tenantId: string): Promise<void>;
|
|
6639
|
+
/**
|
|
6640
|
+
* Derives the OTP-record identifier for a `tenantId + email` pair.
|
|
6641
|
+
*
|
|
6642
|
+
* HMAC rather than a bare digest because an address is low-entropy: a bare SHA-256 of one is
|
|
6643
|
+
* reversible by dictionary, and these identifiers are the Redis key an operator can read.
|
|
6644
|
+
* The preimage is pinned by `conformance/wire-contract.json` and shared byte-for-byte with
|
|
6645
|
+
* rust-auth, which keys the same records in the same Redis.
|
|
6646
|
+
*
|
|
6647
|
+
* Deliberately distinct from {@link lockoutIdentifier}: that one namespaces the login
|
|
6648
|
+
* keyspace with a `dashboard:` prefix, and the two must never collide.
|
|
6649
|
+
*
|
|
6650
|
+
* @param tenantId - Tenant scope.
|
|
6651
|
+
* @param email - The canonicalized address.
|
|
6652
|
+
* @returns Hex HMAC-SHA-256 identifier.
|
|
6653
|
+
*/
|
|
6654
|
+
private otpIdentifier;
|
|
6569
6655
|
/**
|
|
6570
6656
|
* The brute-force counter key for a dashboard account.
|
|
6571
6657
|
*
|
|
@@ -6586,22 +6672,6 @@ declare class AuthService {
|
|
|
6586
6672
|
* @param email - The address, already normalized by the caller.
|
|
6587
6673
|
* @returns The HMAC identifier, opaque and non-reversible.
|
|
6588
6674
|
*/
|
|
6589
|
-
/**
|
|
6590
|
-
* Derives the OTP-record identifier for a `tenantId + email` pair.
|
|
6591
|
-
*
|
|
6592
|
-
* HMAC rather than a bare digest because an address is low-entropy: a bare SHA-256 of one is
|
|
6593
|
-
* reversible by dictionary, and these identifiers are the Redis key an operator can read.
|
|
6594
|
-
* The preimage is pinned by `conformance/wire-contract.json` and shared byte-for-byte with
|
|
6595
|
-
* rust-auth, which keys the same records in the same Redis.
|
|
6596
|
-
*
|
|
6597
|
-
* Deliberately distinct from {@link lockoutIdentifier}: that one namespaces the login
|
|
6598
|
-
* keyspace with a `dashboard:` prefix, and the two must never collide.
|
|
6599
|
-
*
|
|
6600
|
-
* @param tenantId - Tenant scope.
|
|
6601
|
-
* @param email - The canonicalized address.
|
|
6602
|
-
* @returns Hex HMAC-SHA-256 identifier.
|
|
6603
|
-
*/
|
|
6604
|
-
private otpIdentifier;
|
|
6605
6675
|
private lockoutIdentifier;
|
|
6606
6676
|
private resolveTenantId;
|
|
6607
6677
|
private buildHookContext;
|
|
@@ -7770,23 +7840,6 @@ declare class PlatformAuthService {
|
|
|
7770
7840
|
* @throws {@link AuthException} with `TOKEN_INVALID` if the admin no longer exists.
|
|
7771
7841
|
*/
|
|
7772
7842
|
getMe(userId: string): Promise<SafeAuthPlatformUser>;
|
|
7773
|
-
/**
|
|
7774
|
-
* Revokes all active platform sessions for the given admin.
|
|
7775
|
-
*
|
|
7776
|
-
* Delegates to {@link AuthRedisService.invalidateUserSessions} which uses an atomic
|
|
7777
|
-
* Lua script to read the `psess:{userId}` SET, delete all session and grace-pointer
|
|
7778
|
-
* keys, and remove the SET itself in a single Redis round-trip. This prevents the
|
|
7779
|
-
* TOCTOU race that would arise from a non-atomic SMEMBERS + loop + DEL approach.
|
|
7780
|
-
*
|
|
7781
|
-
* The token epoch is then advanced, so outstanding platform **access** tokens die with
|
|
7782
|
-
* the refresh sessions rather than working on to expiry — "log out everywhere" that
|
|
7783
|
-
* leaves every access token alive is not what those words promise. Bumped after the
|
|
7784
|
-
* sweep for the same reason the dashboard flow bumps last: a failure in the sweep
|
|
7785
|
-
* leaves the epoch untouched and the operation visibly incomplete, instead of the
|
|
7786
|
-
* reverse, which would read as done while the sessions live on.
|
|
7787
|
-
*
|
|
7788
|
-
* @param userId - The platform admin's internal ID.
|
|
7789
|
-
*/
|
|
7790
7843
|
/**
|
|
7791
7844
|
* Derives the brute-force identifier for a platform login: `hmac('platform:{email}')`.
|
|
7792
7845
|
*
|
|
@@ -7806,6 +7859,23 @@ declare class PlatformAuthService {
|
|
|
7806
7859
|
* @returns Hex HMAC-SHA-256 identifier.
|
|
7807
7860
|
*/
|
|
7808
7861
|
private lockoutIdentifier;
|
|
7862
|
+
/**
|
|
7863
|
+
* Revokes all active platform sessions for the given admin.
|
|
7864
|
+
*
|
|
7865
|
+
* Delegates to {@link AuthRedisService.invalidateUserSessions} which uses an atomic
|
|
7866
|
+
* Lua script to read the `psess:{userId}` SET, delete all session and grace-pointer
|
|
7867
|
+
* keys, and remove the SET itself in a single Redis round-trip. This prevents the
|
|
7868
|
+
* TOCTOU race that would arise from a non-atomic SMEMBERS + loop + DEL approach.
|
|
7869
|
+
*
|
|
7870
|
+
* The token epoch is then advanced, so outstanding platform **access** tokens die with
|
|
7871
|
+
* the refresh sessions rather than working on to expiry — "log out everywhere" that
|
|
7872
|
+
* leaves every access token alive is not what those words promise. Bumped after the
|
|
7873
|
+
* sweep for the same reason the dashboard flow bumps last: a failure in the sweep
|
|
7874
|
+
* leaves the epoch untouched and the operation visibly incomplete, instead of the
|
|
7875
|
+
* reverse, which would read as done while the sessions live on.
|
|
7876
|
+
*
|
|
7877
|
+
* @param userId - The platform admin's internal ID.
|
|
7878
|
+
*/
|
|
7809
7879
|
revokeAllPlatformSessions(userId: string): Promise<void>;
|
|
7810
7880
|
}
|
|
7811
7881
|
|
package/dist/server/index.d.ts
CHANGED
|
@@ -3420,7 +3420,16 @@ declare function reduceToBaseWord(password: string): string;
|
|
|
3420
3420
|
* runs, and any decorated form of those — but it is not the full top-3000, and it knows
|
|
3421
3421
|
* nothing about breach corpora. A deployment that wants that should either extend it through
|
|
3422
3422
|
* `password.blocklist` or supply {@link HibpBreachChecker}, which checks a real breach corpus
|
|
3423
|
-
* over the network.
|
|
3423
|
+
* over the network.
|
|
3424
|
+
*
|
|
3425
|
+
* **The shipped base words are ASCII.** The reduction preserves letters and numbers in any
|
|
3426
|
+
* script — a strong Cyrillic, Han, Kana, Hangul, Greek, Arabic, Hebrew or Thai passphrase is
|
|
3427
|
+
* admitted, and used to be refused outright with the "commonly used" error, which pushed those
|
|
3428
|
+
* users onto the smaller ASCII keyspace. But the list itself has no entries in those scripts,
|
|
3429
|
+
* so the equivalent of `password` in one of them passes this screen. A deployment serving
|
|
3430
|
+
* those users should add the common ones for its locale to `password.blocklist`; entries are
|
|
3431
|
+
* normalized through the same reduction, so a non-Latin entry matches a decorated form of
|
|
3432
|
+
* itself the way an ASCII one does. This checker being the default is what makes the *baseline* honest; the
|
|
3424
3433
|
* network check remains opt-in, because a library should not start talking to a third party
|
|
3425
3434
|
* because it was upgraded.
|
|
3426
3435
|
*
|
|
@@ -3726,6 +3735,22 @@ declare class AuthRedisService {
|
|
|
3726
3735
|
* (`reused`, carrying the compromised family), or never-issued (`invalid`).
|
|
3727
3736
|
*/
|
|
3728
3737
|
rotateRefreshSession(params: RefreshRotationParams): Promise<RefreshRotationOutcome>;
|
|
3738
|
+
/**
|
|
3739
|
+
* Writes a freshly-issued refresh session atomically — record, session-index member and
|
|
3740
|
+
* family membership, each carrying the refresh TTL.
|
|
3741
|
+
*
|
|
3742
|
+
* See {@link CREATE_SESSION_LUA} for the two windows the loose form left open.
|
|
3743
|
+
*
|
|
3744
|
+
* @param params - The session to store and the keys it belongs under.
|
|
3745
|
+
*/
|
|
3746
|
+
writeNewSession(params: {
|
|
3747
|
+
kind: 'dashboard' | 'platform';
|
|
3748
|
+
tokenHash: string;
|
|
3749
|
+
sessionJson: string;
|
|
3750
|
+
familyId: string;
|
|
3751
|
+
userId: string;
|
|
3752
|
+
refreshTtl: number;
|
|
3753
|
+
}): Promise<void>;
|
|
3729
3754
|
/**
|
|
3730
3755
|
* Writes the session a grace recovery produced, atomically with the check that the account
|
|
3731
3756
|
* has not been swept out from under it.
|
|
@@ -3823,6 +3848,36 @@ declare class AuthRedisService {
|
|
|
3823
3848
|
* @returns `true` if the key was newly set, `false` if it already existed.
|
|
3824
3849
|
*/
|
|
3825
3850
|
setIfAbsent(key: string, value: string, ttl: number): Promise<boolean>;
|
|
3851
|
+
/**
|
|
3852
|
+
* Drops the grace-pointer members whose keys have already expired.
|
|
3853
|
+
*
|
|
3854
|
+
* A rotation removes `rt:{old}` from the index and adds two members: `rt:{new}` and
|
|
3855
|
+
* `rp:{old}`. The `rp:` KEY dies with the grace window — 30 seconds by default — but the
|
|
3856
|
+
* MEMBER was only ever removed by a full revoke-all, so the index gained one permanent
|
|
3857
|
+
* ~68-byte entry per rotation, and the rotation re-arms the set's own TTL each time. The set
|
|
3858
|
+
* never aged out while the account was in use.
|
|
3859
|
+
*
|
|
3860
|
+
* That is not merely untidy. Every reader of the index is linear in its size:
|
|
3861
|
+
* `listSessions` ships the whole set over the wire, `revokeAllExceptCurrent` issues two
|
|
3862
|
+
* sequential round trips per grace member, and `invalidateUserSessions` iterates it inside a
|
|
3863
|
+
* Lua script, which blocks the whole single-threaded store. An attacker holding one stolen
|
|
3864
|
+
* refresh token and rotating at the route limit adds ~14k members a day to their own index,
|
|
3865
|
+
* with no ceiling; a merely active user accrues thousands a year.
|
|
3866
|
+
*
|
|
3867
|
+
* Called from the two paths that already walk the index — a login enforcing the session cap
|
|
3868
|
+
* and a session listing — so the growth is bounded by how long an account can go between
|
|
3869
|
+
* them, and any legitimate interaction heals it. The rotation path deliberately does NOT
|
|
3870
|
+
* call this: it is the hot path, and an O(n) sweep there would trade a slow leak for a slow
|
|
3871
|
+
* refresh.
|
|
3872
|
+
*
|
|
3873
|
+
* Grace members whose key is still live are left alone. They are what lets a revoke-all also
|
|
3874
|
+
* kill a token that was rotated away moments earlier but can still be recovered.
|
|
3875
|
+
*
|
|
3876
|
+
* @param setKey - The un-namespaced index key (`sess:{id}` or `psess:{id}`).
|
|
3877
|
+
* @param gracePrefix - Member prefix for rotation grace pointers (`rp:` or `prp:`).
|
|
3878
|
+
* @returns How many dead members were dropped.
|
|
3879
|
+
*/
|
|
3880
|
+
pruneExpiredGraceMembers(setKey: string, gracePrefix: string): Promise<number>;
|
|
3826
3881
|
/**
|
|
3827
3882
|
* Atomically deletes every refresh session belonging to one identity plane.
|
|
3828
3883
|
*
|
|
@@ -5547,6 +5602,36 @@ declare class OtpService {
|
|
|
5547
5602
|
verify(purpose: string, identifier: string, code: string): Promise<void>;
|
|
5548
5603
|
}
|
|
5549
5604
|
|
|
5605
|
+
/**
|
|
5606
|
+
* Password hashing and verification service using `node:crypto` scrypt.
|
|
5607
|
+
*
|
|
5608
|
+
* Uses scrypt (RFC 7914) — a memory-hard key derivation function designed to
|
|
5609
|
+
* resist brute-force and GPU/ASIC attacks. **Never use SHA-256, MD5, or
|
|
5610
|
+
* unsalted hashes for passwords.**
|
|
5611
|
+
*
|
|
5612
|
+
* Wire format: PHC — `$scrypt$ln={log2(N)},r={r},p={p}${saltB64}${derivedB64}`
|
|
5613
|
+
* - `saltB64` — 16 random bytes in PHC "B64" (standard base64, no padding)
|
|
5614
|
+
* - `derivedB64` — 64 derived bytes in the same encoding
|
|
5615
|
+
*
|
|
5616
|
+
* The only encoding, read and written. rust-auth writes the same, and the format is pinned by
|
|
5617
|
+
* `conformance/wire-contract.json` with a known-answer vector from each implementation.
|
|
5618
|
+
*
|
|
5619
|
+
* @remarks
|
|
5620
|
+
* **Cost parameters:** Taken from `options.password` at construction time.
|
|
5621
|
+
* Defaults are `costFactor = 131072 (2^17)`, `blockSize = 8`, `parallelization = 1` — OWASP's
|
|
5622
|
+
* recommended minimum for scrypt. Override in
|
|
5623
|
+
* `BymaxAuthModule.forRoot({ password: { costFactor: 65536 } })`.
|
|
5624
|
+
* Validated at startup by `resolveOptions()` — values below `16384 (2^14)` are rejected.
|
|
5625
|
+
*
|
|
5626
|
+
* **Security:** Comparison uses `crypto.timingSafeEqual` to prevent timing
|
|
5627
|
+
* attacks. All comparison failures return `false` — never throw on bad input.
|
|
5628
|
+
*
|
|
5629
|
+
* **Thread safety:** scrypt is CPU-intensive. In production, calls will block
|
|
5630
|
+
* the Node.js event loop for ~100–200 ms. Consider running behind a worker
|
|
5631
|
+
* thread or rate-limiting authentication endpoints.
|
|
5632
|
+
*
|
|
5633
|
+
* @layer Service
|
|
5634
|
+
*/
|
|
5550
5635
|
declare class PasswordService {
|
|
5551
5636
|
private readonly breachChecker;
|
|
5552
5637
|
private readonly logger;
|
|
@@ -5559,12 +5644,12 @@ declare class PasswordService {
|
|
|
5559
5644
|
* Hashes a plaintext password using scrypt with a random salt.
|
|
5560
5645
|
*
|
|
5561
5646
|
* @param plain - Plaintext password (UTF-8 string).
|
|
5562
|
-
* @returns Hashed password
|
|
5647
|
+
* @returns Hashed password as a PHC string.
|
|
5563
5648
|
*
|
|
5564
5649
|
* @example
|
|
5565
5650
|
* ```typescript
|
|
5566
5651
|
* const hash = await passwordService.hash('my-password')
|
|
5567
|
-
* // 'scrypt
|
|
5652
|
+
* // '$scrypt$ln=17,r=8,p=1$YmFzZTY0c2FsdA$…'
|
|
5568
5653
|
* ```
|
|
5569
5654
|
*/
|
|
5570
5655
|
/**
|
|
@@ -5608,7 +5693,7 @@ declare class PasswordService {
|
|
|
5608
5693
|
* Verifies a plaintext password against a stored scrypt hash.
|
|
5609
5694
|
*
|
|
5610
5695
|
* @param plain - Plaintext password supplied by the user.
|
|
5611
|
-
* @param hash - Stored hash
|
|
5696
|
+
* @param hash - Stored hash, as a PHC string.
|
|
5612
5697
|
* @returns `true` if the password matches, `false` otherwise.
|
|
5613
5698
|
*
|
|
5614
5699
|
* @remarks
|
|
@@ -6017,6 +6102,14 @@ declare class TokenManagerService {
|
|
|
6017
6102
|
* @throws {@link AuthException} with `REFRESH_TOKEN_INVALID` if no valid session found.
|
|
6018
6103
|
*/
|
|
6019
6104
|
reissueTokens(oldRefresh: string, ip: string, userAgent: string): Promise<RotatedTokenResult>;
|
|
6105
|
+
/**
|
|
6106
|
+
* Emits {@link IAuthHooks.onRefreshTokenReuseDetected}, fire-and-forget.
|
|
6107
|
+
*
|
|
6108
|
+
* The owner is read from the stored session where it can be — a replay of a token whose live
|
|
6109
|
+
* key is already gone leaves nothing to read, and the hook is skipped rather than fired with
|
|
6110
|
+
* an empty identity that a consumer would have to guess about.
|
|
6111
|
+
*/
|
|
6112
|
+
private emitReuseDetected;
|
|
6020
6113
|
/**
|
|
6021
6114
|
* Refuses a rotation once the login it descends from has outlived the absolute cap.
|
|
6022
6115
|
*
|
|
@@ -6034,14 +6127,6 @@ declare class TokenManagerService {
|
|
|
6034
6127
|
* remedy is the same (sign in again) and the difference would only tell a holder of a
|
|
6035
6128
|
* stolen token how old the account's session is.
|
|
6036
6129
|
*/
|
|
6037
|
-
/**
|
|
6038
|
-
* Emits {@link IAuthHooks.onRefreshTokenReuseDetected}, fire-and-forget.
|
|
6039
|
-
*
|
|
6040
|
-
* The owner is read from the stored session where it can be — a replay of a token whose live
|
|
6041
|
-
* key is already gone leaves nothing to read, and the hook is skipped rather than fired with
|
|
6042
|
-
* an empty identity that a consumer would have to guess about.
|
|
6043
|
-
*/
|
|
6044
|
-
private emitReuseDetected;
|
|
6045
6130
|
private assertWithinAbsoluteLifetime;
|
|
6046
6131
|
/**
|
|
6047
6132
|
* Reads the presented token's live record to seed the rotated one.
|
|
@@ -6195,20 +6280,6 @@ declare class TokenManagerService {
|
|
|
6195
6280
|
* @returns The re-signed platform access token.
|
|
6196
6281
|
*/
|
|
6197
6282
|
reissuePlatformAccessWithAuthority(claims: PlatformJwtPayload, role: string, mfaEnabled: boolean): Promise<string>;
|
|
6198
|
-
/**
|
|
6199
|
-
* Decodes a JWT without validating its expiration or signature.
|
|
6200
|
-
*
|
|
6201
|
-
* @internal
|
|
6202
|
-
* **WARNING:** This method does NOT verify the token signature or expiry.
|
|
6203
|
-
* It must only be used for internal diagnostic purposes (e.g. reading the
|
|
6204
|
-
* `sub` claim from an expired token to look up a session for revocation).
|
|
6205
|
-
* Never use it to authorize requests — use `JwtService.verify()` in guards.
|
|
6206
|
-
*
|
|
6207
|
-
* @param token - Raw JWT string.
|
|
6208
|
-
* @returns Decoded payload.
|
|
6209
|
-
* @throws {@link AuthException} with `TOKEN_INVALID` if the payload is not an
|
|
6210
|
-
* object or lacks required `jti` (string) and `sub` (string) claims.
|
|
6211
|
-
*/
|
|
6212
6283
|
/**
|
|
6213
6284
|
* Verifies an access token's signature under the pinned algorithm while **ignoring its
|
|
6214
6285
|
* expiry**, returning the payload.
|
|
@@ -6237,7 +6308,6 @@ declare class TokenManagerService {
|
|
|
6237
6308
|
* @throws Whatever the verifier throws when no configured secret accepts the token.
|
|
6238
6309
|
*/
|
|
6239
6310
|
verifyPlatformIgnoringExpiry(token: string): PlatformJwtPayload;
|
|
6240
|
-
decodeToken(token: string): DashboardJwtPayload | PlatformJwtPayload | MfaTempPayload;
|
|
6241
6311
|
/**
|
|
6242
6312
|
* Issues a short-lived MFA challenge token and stores it in Redis for
|
|
6243
6313
|
* single-use enforcement.
|
|
@@ -6566,6 +6636,22 @@ declare class AuthService {
|
|
|
6566
6636
|
* @param tenantId - The tenant the account belongs to.
|
|
6567
6637
|
*/
|
|
6568
6638
|
unlockAccount(email: string, tenantId: string): Promise<void>;
|
|
6639
|
+
/**
|
|
6640
|
+
* Derives the OTP-record identifier for a `tenantId + email` pair.
|
|
6641
|
+
*
|
|
6642
|
+
* HMAC rather than a bare digest because an address is low-entropy: a bare SHA-256 of one is
|
|
6643
|
+
* reversible by dictionary, and these identifiers are the Redis key an operator can read.
|
|
6644
|
+
* The preimage is pinned by `conformance/wire-contract.json` and shared byte-for-byte with
|
|
6645
|
+
* rust-auth, which keys the same records in the same Redis.
|
|
6646
|
+
*
|
|
6647
|
+
* Deliberately distinct from {@link lockoutIdentifier}: that one namespaces the login
|
|
6648
|
+
* keyspace with a `dashboard:` prefix, and the two must never collide.
|
|
6649
|
+
*
|
|
6650
|
+
* @param tenantId - Tenant scope.
|
|
6651
|
+
* @param email - The canonicalized address.
|
|
6652
|
+
* @returns Hex HMAC-SHA-256 identifier.
|
|
6653
|
+
*/
|
|
6654
|
+
private otpIdentifier;
|
|
6569
6655
|
/**
|
|
6570
6656
|
* The brute-force counter key for a dashboard account.
|
|
6571
6657
|
*
|
|
@@ -6586,22 +6672,6 @@ declare class AuthService {
|
|
|
6586
6672
|
* @param email - The address, already normalized by the caller.
|
|
6587
6673
|
* @returns The HMAC identifier, opaque and non-reversible.
|
|
6588
6674
|
*/
|
|
6589
|
-
/**
|
|
6590
|
-
* Derives the OTP-record identifier for a `tenantId + email` pair.
|
|
6591
|
-
*
|
|
6592
|
-
* HMAC rather than a bare digest because an address is low-entropy: a bare SHA-256 of one is
|
|
6593
|
-
* reversible by dictionary, and these identifiers are the Redis key an operator can read.
|
|
6594
|
-
* The preimage is pinned by `conformance/wire-contract.json` and shared byte-for-byte with
|
|
6595
|
-
* rust-auth, which keys the same records in the same Redis.
|
|
6596
|
-
*
|
|
6597
|
-
* Deliberately distinct from {@link lockoutIdentifier}: that one namespaces the login
|
|
6598
|
-
* keyspace with a `dashboard:` prefix, and the two must never collide.
|
|
6599
|
-
*
|
|
6600
|
-
* @param tenantId - Tenant scope.
|
|
6601
|
-
* @param email - The canonicalized address.
|
|
6602
|
-
* @returns Hex HMAC-SHA-256 identifier.
|
|
6603
|
-
*/
|
|
6604
|
-
private otpIdentifier;
|
|
6605
6675
|
private lockoutIdentifier;
|
|
6606
6676
|
private resolveTenantId;
|
|
6607
6677
|
private buildHookContext;
|
|
@@ -7770,23 +7840,6 @@ declare class PlatformAuthService {
|
|
|
7770
7840
|
* @throws {@link AuthException} with `TOKEN_INVALID` if the admin no longer exists.
|
|
7771
7841
|
*/
|
|
7772
7842
|
getMe(userId: string): Promise<SafeAuthPlatformUser>;
|
|
7773
|
-
/**
|
|
7774
|
-
* Revokes all active platform sessions for the given admin.
|
|
7775
|
-
*
|
|
7776
|
-
* Delegates to {@link AuthRedisService.invalidateUserSessions} which uses an atomic
|
|
7777
|
-
* Lua script to read the `psess:{userId}` SET, delete all session and grace-pointer
|
|
7778
|
-
* keys, and remove the SET itself in a single Redis round-trip. This prevents the
|
|
7779
|
-
* TOCTOU race that would arise from a non-atomic SMEMBERS + loop + DEL approach.
|
|
7780
|
-
*
|
|
7781
|
-
* The token epoch is then advanced, so outstanding platform **access** tokens die with
|
|
7782
|
-
* the refresh sessions rather than working on to expiry — "log out everywhere" that
|
|
7783
|
-
* leaves every access token alive is not what those words promise. Bumped after the
|
|
7784
|
-
* sweep for the same reason the dashboard flow bumps last: a failure in the sweep
|
|
7785
|
-
* leaves the epoch untouched and the operation visibly incomplete, instead of the
|
|
7786
|
-
* reverse, which would read as done while the sessions live on.
|
|
7787
|
-
*
|
|
7788
|
-
* @param userId - The platform admin's internal ID.
|
|
7789
|
-
*/
|
|
7790
7843
|
/**
|
|
7791
7844
|
* Derives the brute-force identifier for a platform login: `hmac('platform:{email}')`.
|
|
7792
7845
|
*
|
|
@@ -7806,6 +7859,23 @@ declare class PlatformAuthService {
|
|
|
7806
7859
|
* @returns Hex HMAC-SHA-256 identifier.
|
|
7807
7860
|
*/
|
|
7808
7861
|
private lockoutIdentifier;
|
|
7862
|
+
/**
|
|
7863
|
+
* Revokes all active platform sessions for the given admin.
|
|
7864
|
+
*
|
|
7865
|
+
* Delegates to {@link AuthRedisService.invalidateUserSessions} which uses an atomic
|
|
7866
|
+
* Lua script to read the `psess:{userId}` SET, delete all session and grace-pointer
|
|
7867
|
+
* keys, and remove the SET itself in a single Redis round-trip. This prevents the
|
|
7868
|
+
* TOCTOU race that would arise from a non-atomic SMEMBERS + loop + DEL approach.
|
|
7869
|
+
*
|
|
7870
|
+
* The token epoch is then advanced, so outstanding platform **access** tokens die with
|
|
7871
|
+
* the refresh sessions rather than working on to expiry — "log out everywhere" that
|
|
7872
|
+
* leaves every access token alive is not what those words promise. Bumped after the
|
|
7873
|
+
* sweep for the same reason the dashboard flow bumps last: a failure in the sweep
|
|
7874
|
+
* leaves the epoch untouched and the operation visibly incomplete, instead of the
|
|
7875
|
+
* reverse, which would read as done while the sessions live on.
|
|
7876
|
+
*
|
|
7877
|
+
* @param userId - The platform admin's internal ID.
|
|
7878
|
+
*/
|
|
7809
7879
|
revokeAllPlatformSessions(userId: string): Promise<void>;
|
|
7810
7880
|
}
|
|
7811
7881
|
|