@bymax-one/nest-auth 1.1.0 → 1.2.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 +141 -1
- package/README.md +75 -5
- package/dist/client/index.cjs +8 -1
- package/dist/client/index.mjs +8 -1
- package/dist/nextjs/index.cjs +7 -17
- package/dist/nextjs/index.d.cts +27 -8
- package/dist/nextjs/index.d.ts +27 -8
- package/dist/nextjs/index.mjs +7 -17
- package/dist/react/index.cjs +8 -0
- package/dist/react/index.mjs +8 -0
- package/dist/server/index.cjs +928 -363
- package/dist/server/index.d.cts +344 -81
- package/dist/server/index.d.ts +344 -81
- package/dist/server/index.mjs +928 -363
- package/package.json +4 -14
package/dist/server/index.d.ts
CHANGED
|
@@ -501,6 +501,27 @@ interface BymaxAuthModuleOptions {
|
|
|
501
501
|
* @throws {Error} When the value fails validation at module initialisation.
|
|
502
502
|
*/
|
|
503
503
|
costFactor?: number;
|
|
504
|
+
/**
|
|
505
|
+
* Minimum password length the deployment accepts. Default: `15`.
|
|
506
|
+
*
|
|
507
|
+
* NIST SP 800-63B-4 §3.1.1.1 requires 15 characters for a password used as a SINGLE
|
|
508
|
+
* authentication factor, and permits 8 only when the password is part of multi-factor
|
|
509
|
+
* authentication. MFA in this library is opt-in per user, so the default deployment is
|
|
510
|
+
* single-factor and 15 is the number that applies. Lower it to 8 — the structural floor the
|
|
511
|
+
* DTOs enforce, and the lowest the standard allows under any circumstance — only in a
|
|
512
|
+
* deployment that makes MFA mandatory.
|
|
513
|
+
*
|
|
514
|
+
* @remarks
|
|
515
|
+
* `costFactor` sets the price of one guess; this sets how many guesses there are. Only the
|
|
516
|
+
* second is what an offline attacker actually runs out of, and the breach and common-password
|
|
517
|
+
* screens remove passwords that are already *known*, not short ones nobody has seen yet.
|
|
518
|
+
*
|
|
519
|
+
* Deliberately not paired with any composition rule: the same clause says verifiers SHALL
|
|
520
|
+
* NOT impose them, and none of the password DTOs carries one.
|
|
521
|
+
*
|
|
522
|
+
* @throws {Error} When the value is not an integer in `[8, 128]`.
|
|
523
|
+
*/
|
|
524
|
+
minLength?: number;
|
|
504
525
|
/**
|
|
505
526
|
* scrypt block size parameter (r).
|
|
506
527
|
* Default: `8`
|
|
@@ -539,19 +560,38 @@ interface BymaxAuthModuleOptions {
|
|
|
539
560
|
* Default: `'cookie'`
|
|
540
561
|
*/
|
|
541
562
|
tokenDelivery?: 'cookie' | 'bearer' | 'both';
|
|
563
|
+
/**
|
|
564
|
+
* The deployment environment, supplied explicitly.
|
|
565
|
+
*
|
|
566
|
+
* This is the ONLY input that answers "is this production". The library never reads the
|
|
567
|
+
* ambient `process.env`, and it is secure by default: an unset value is `'production'`, so
|
|
568
|
+
* `secureCookies` resolves to `true` and the production-gated OAuth-redirect checks apply
|
|
569
|
+
* unless the host opts into `'development'` or `'test'`.
|
|
570
|
+
*
|
|
571
|
+
* Default: `'production'`.
|
|
572
|
+
*
|
|
573
|
+
* @remarks
|
|
574
|
+
* This replaces reading `process.env['NODE_ENV'] === 'production'`. That test decided cookie
|
|
575
|
+
* `Secure`, OAuth callback HTTPS enforcement and three redirect validations, and it failed
|
|
576
|
+
* open on every near miss — unset, `'staging'`, `'prod'`, or `'production '` with a trailing
|
|
577
|
+
* space each silently took the insecure branch. Whether a deployment is production is
|
|
578
|
+
* something the deployer knows and the process environment only hints at, so it is now passed
|
|
579
|
+
* in rather than sniffed. Matches `Environment` in rust-auth.
|
|
580
|
+
*/
|
|
581
|
+
environment?: 'production' | 'development' | 'test';
|
|
542
582
|
/**
|
|
543
583
|
* Whether to set the `Secure` flag on auth cookies.
|
|
544
584
|
*
|
|
545
585
|
* When `true`, cookies are only sent over HTTPS. When `false`, cookies are
|
|
546
586
|
* sent over HTTP as well (useful for local development).
|
|
547
587
|
*
|
|
548
|
-
* Default: `
|
|
549
|
-
*
|
|
588
|
+
* Default: `true`, unless {@link BymaxAuthModuleOptions.environment} is
|
|
589
|
+
* `'development'` or `'test'`. Evaluated once at module startup via
|
|
590
|
+
* `resolveOptions()` — not re-evaluated per request.
|
|
550
591
|
*
|
|
551
592
|
* @remarks
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
* marked Secure regardless of the environment variable.
|
|
593
|
+
* Set this explicitly to `true` in a non-production environment that is nonetheless served
|
|
594
|
+
* over HTTPS, so the cookies are marked `Secure` there too.
|
|
555
595
|
*/
|
|
556
596
|
secureCookies?: boolean;
|
|
557
597
|
/**
|
|
@@ -1316,7 +1356,7 @@ declare const BYMAX_AUTH_REDIS_CLIENT: unique symbol;
|
|
|
1316
1356
|
* interface-extension compatibility check with `exactOptionalPropertyTypes`,
|
|
1317
1357
|
* which rejects intersection widening of optional function properties.
|
|
1318
1358
|
*/
|
|
1319
|
-
type ResolvedOptions = Omit<BymaxAuthModuleOptions, 'jwt' | 'password' | 'tokenDelivery' | 'cookies' | 'sessions' | 'bruteForce' | 'passwordReset' | 'emailVerification' | 'platform' | 'invitations' | 'controllers' | 'blockedStatuses' | 'redisNamespace' | 'routePrefix' | 'userStatusCacheTtlSeconds' | 'secureCookies' | 'mfa' | 'rateLimit'> & {
|
|
1359
|
+
type ResolvedOptions = Omit<BymaxAuthModuleOptions, 'jwt' | 'password' | 'tokenDelivery' | 'cookies' | 'sessions' | 'bruteForce' | 'passwordReset' | 'emailVerification' | 'platform' | 'invitations' | 'controllers' | 'blockedStatuses' | 'redisNamespace' | 'routePrefix' | 'userStatusCacheTtlSeconds' | 'environment' | 'secureCookies' | 'mfa' | 'rateLimit'> & {
|
|
1320
1360
|
jwt: Required<Omit<BymaxAuthModuleOptions['jwt'], 'previousSecrets' | 'issuer' | 'audience'>> & Pick<BymaxAuthModuleOptions['jwt'], 'previousSecrets' | 'issuer' | 'audience'>;
|
|
1321
1361
|
password: Required<NonNullable<BymaxAuthModuleOptions['password']>>;
|
|
1322
1362
|
tokenDelivery: NonNullable<BymaxAuthModuleOptions['tokenDelivery']>;
|
|
@@ -1337,6 +1377,12 @@ type ResolvedOptions = Omit<BymaxAuthModuleOptions, 'jwt' | 'password' | 'tokenD
|
|
|
1337
1377
|
redisNamespace: string;
|
|
1338
1378
|
routePrefix: string;
|
|
1339
1379
|
userStatusCacheTtlSeconds: number;
|
|
1380
|
+
/**
|
|
1381
|
+
* The deployment environment as the host declared it. The only input that answers "is this
|
|
1382
|
+
* production"; the library never reads `process.env`. See
|
|
1383
|
+
* {@link BymaxAuthModuleOptions.environment}.
|
|
1384
|
+
*/
|
|
1385
|
+
environment: 'production' | 'development' | 'test';
|
|
1340
1386
|
/** `true` if auth cookies should carry the `Secure` flag. */
|
|
1341
1387
|
secureCookies: boolean;
|
|
1342
1388
|
/**
|
|
@@ -2193,18 +2239,30 @@ interface IEmailProvider {
|
|
|
2193
2239
|
*/
|
|
2194
2240
|
sendMfaDisabledNotification(email: string, locale?: string): Promise<void>;
|
|
2195
2241
|
/**
|
|
2196
|
-
* Sends a security alert
|
|
2197
|
-
* device or location.
|
|
2242
|
+
* Sends a security alert about a newly established session.
|
|
2198
2243
|
*
|
|
2199
|
-
*
|
|
2200
|
-
*
|
|
2201
|
-
*
|
|
2244
|
+
* **This library never calls it.** The method is optional, and it is here as a typed
|
|
2245
|
+
* signature for you to call from the {@link IAuthHooks.onNewSession} hook — which the
|
|
2246
|
+
* library does fire, on every session it creates, with the same {@link SessionInfo} this
|
|
2247
|
+
* takes.
|
|
2248
|
+
*
|
|
2249
|
+
* The alert deliberately does not live inside the library, because the library cannot send
|
|
2250
|
+
* it well. Without device recognition it fires on *every* login, and an alert that arrives
|
|
2251
|
+
* on every login is one the user learns to dismiss — at which point the control has stopped
|
|
2252
|
+
* existing while still appearing to be in place. Recognizing a device means keeping a
|
|
2253
|
+
* per-user device history, and the consumer already has one (or can key it to their own
|
|
2254
|
+
* user record); the library would have to invent that state in the Redis keyspace it shares
|
|
2255
|
+
* with rust-auth, which is a contract change to solve a problem the caller is better placed
|
|
2256
|
+
* to solve.
|
|
2257
|
+
*
|
|
2258
|
+
* So: decide in your `onNewSession` hook whether the session is worth alerting about, and
|
|
2259
|
+
* call this when it is.
|
|
2202
2260
|
*
|
|
2203
2261
|
* @param email - Recipient's email address.
|
|
2204
2262
|
* @param sessionInfo - Device, IP, and session identifier details.
|
|
2205
2263
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2206
2264
|
*/
|
|
2207
|
-
sendNewSessionAlert(email: string, sessionInfo: SessionInfo$1, locale?: string): Promise<void>;
|
|
2265
|
+
sendNewSessionAlert?(email: string, sessionInfo: SessionInfo$1, locale?: string): Promise<void>;
|
|
2208
2266
|
/**
|
|
2209
2267
|
* Sends a tenant invitation email to a prospective member.
|
|
2210
2268
|
*
|
|
@@ -3420,7 +3478,16 @@ declare function reduceToBaseWord(password: string): string;
|
|
|
3420
3478
|
* runs, and any decorated form of those — but it is not the full top-3000, and it knows
|
|
3421
3479
|
* nothing about breach corpora. A deployment that wants that should either extend it through
|
|
3422
3480
|
* `password.blocklist` or supply {@link HibpBreachChecker}, which checks a real breach corpus
|
|
3423
|
-
* over the network.
|
|
3481
|
+
* over the network.
|
|
3482
|
+
*
|
|
3483
|
+
* **The shipped base words are ASCII.** The reduction preserves letters and numbers in any
|
|
3484
|
+
* script — a strong Cyrillic, Han, Kana, Hangul, Greek, Arabic, Hebrew or Thai passphrase is
|
|
3485
|
+
* admitted, and used to be refused outright with the "commonly used" error, which pushed those
|
|
3486
|
+
* users onto the smaller ASCII keyspace. But the list itself has no entries in those scripts,
|
|
3487
|
+
* so the equivalent of `password` in one of them passes this screen. A deployment serving
|
|
3488
|
+
* those users should add the common ones for its locale to `password.blocklist`; entries are
|
|
3489
|
+
* normalized through the same reduction, so a non-Latin entry matches a decorated form of
|
|
3490
|
+
* itself the way an ASCII one does. This checker being the default is what makes the *baseline* honest; the
|
|
3424
3491
|
* network check remains opt-in, because a library should not start talking to a third party
|
|
3425
3492
|
* because it was upgraded.
|
|
3426
3493
|
*
|
|
@@ -3726,6 +3793,22 @@ declare class AuthRedisService {
|
|
|
3726
3793
|
* (`reused`, carrying the compromised family), or never-issued (`invalid`).
|
|
3727
3794
|
*/
|
|
3728
3795
|
rotateRefreshSession(params: RefreshRotationParams): Promise<RefreshRotationOutcome>;
|
|
3796
|
+
/**
|
|
3797
|
+
* Writes a freshly-issued refresh session atomically — record, session-index member and
|
|
3798
|
+
* family membership, each carrying the refresh TTL.
|
|
3799
|
+
*
|
|
3800
|
+
* See {@link CREATE_SESSION_LUA} for the two windows the loose form left open.
|
|
3801
|
+
*
|
|
3802
|
+
* @param params - The session to store and the keys it belongs under.
|
|
3803
|
+
*/
|
|
3804
|
+
writeNewSession(params: {
|
|
3805
|
+
kind: 'dashboard' | 'platform';
|
|
3806
|
+
tokenHash: string;
|
|
3807
|
+
sessionJson: string;
|
|
3808
|
+
familyId: string;
|
|
3809
|
+
userId: string;
|
|
3810
|
+
refreshTtl: number;
|
|
3811
|
+
}): Promise<void>;
|
|
3729
3812
|
/**
|
|
3730
3813
|
* Writes the session a grace recovery produced, atomically with the check that the account
|
|
3731
3814
|
* has not been swept out from under it.
|
|
@@ -3823,6 +3906,60 @@ declare class AuthRedisService {
|
|
|
3823
3906
|
* @returns `true` if the key was newly set, `false` if it already existed.
|
|
3824
3907
|
*/
|
|
3825
3908
|
setIfAbsent(key: string, value: string, ttl: number): Promise<boolean>;
|
|
3909
|
+
/**
|
|
3910
|
+
* Drops the grace-pointer members whose keys have already expired.
|
|
3911
|
+
*
|
|
3912
|
+
* A rotation removes `rt:{old}` from the index and adds two members: `rt:{new}` and
|
|
3913
|
+
* `rp:{old}`. The `rp:` KEY dies with the grace window — 30 seconds by default — but the
|
|
3914
|
+
* MEMBER was only ever removed by a full revoke-all, so the index gained one permanent
|
|
3915
|
+
* ~68-byte entry per rotation, and the rotation re-arms the set's own TTL each time. The set
|
|
3916
|
+
* never aged out while the account was in use.
|
|
3917
|
+
*
|
|
3918
|
+
* That is not merely untidy. Every reader of the index is linear in its size:
|
|
3919
|
+
* `listSessions` ships the whole set over the wire, `revokeAllExceptCurrent` issues two
|
|
3920
|
+
* sequential round trips per grace member, and `invalidateUserSessions` iterates it inside a
|
|
3921
|
+
* Lua script, which blocks the whole single-threaded store. An attacker holding one stolen
|
|
3922
|
+
* refresh token and rotating at the route limit adds ~14k members a day to their own index,
|
|
3923
|
+
* with no ceiling; a merely active user accrues thousands a year.
|
|
3924
|
+
*
|
|
3925
|
+
* Called from the two paths that already walk the index — a login enforcing the session cap
|
|
3926
|
+
* and a session listing — so the growth is bounded by how long an account can go between
|
|
3927
|
+
* them, and any legitimate interaction heals it. The rotation path deliberately does NOT
|
|
3928
|
+
* call this: it is the hot path, and an O(n) sweep there would trade a slow leak for a slow
|
|
3929
|
+
* refresh.
|
|
3930
|
+
*
|
|
3931
|
+
* Grace members whose key is still live are left alone. They are what lets a revoke-all also
|
|
3932
|
+
* kill a token that was rotated away moments earlier but can still be recovered.
|
|
3933
|
+
*
|
|
3934
|
+
* @param setKey - The un-namespaced index key (`sess:{id}` or `psess:{id}`).
|
|
3935
|
+
* @param gracePrefix - Member prefix for rotation grace pointers (`rp:` or `prp:`).
|
|
3936
|
+
* @returns How many dead members were dropped.
|
|
3937
|
+
*/
|
|
3938
|
+
pruneExpiredGraceMembers(setKey: string, gracePrefix: string): Promise<number>;
|
|
3939
|
+
/**
|
|
3940
|
+
* Drops index members whose own key is gone, and leaves every other member in place.
|
|
3941
|
+
*
|
|
3942
|
+
* A reader that walks `sess:{userId}` learns a session is stale from something *about* the
|
|
3943
|
+
* session — a detail record that is missing, unreadable or malformed. None of those facts is
|
|
3944
|
+
* the session. The credential is the `rt:{hash}` key, and only its absence means the member
|
|
3945
|
+
* names nothing: a live `rt:` with no `sd:` is a session that still opens the account.
|
|
3946
|
+
*
|
|
3947
|
+
* Removing such a member is not a tidy-up, it is a revocation bypass. `invalidateUserSessions`
|
|
3948
|
+
* revokes what the index names, so a member dropped while its `rt:` key lives produces a
|
|
3949
|
+
* session that survives "sign out everywhere" and keeps rotating, while the user is told every
|
|
3950
|
+
* device was signed out — and the un-indexing is triggered by the user's own session listing.
|
|
3951
|
+
*
|
|
3952
|
+
* So the caller supplies candidates and this decides, with `EXISTS` as the only evidence
|
|
3953
|
+
* admitted. The check and the `SREM` share one script because they must: a candidate whose
|
|
3954
|
+
* `rt:` key is written between the two would otherwise be dropped anyway. A Redis fault makes
|
|
3955
|
+
* the whole script fail rather than prune, which is the safe direction — an index that keeps a
|
|
3956
|
+
* dead member costs a wasted read, an index that loses a live one costs the revocation.
|
|
3957
|
+
*
|
|
3958
|
+
* @param setKey - The un-namespaced index key (`sess:{id}` or `psess:{id}`).
|
|
3959
|
+
* @param members - Candidate members, each a full key suffix (`rt:{hash}`).
|
|
3960
|
+
* @returns How many candidates were actually dropped.
|
|
3961
|
+
*/
|
|
3962
|
+
pruneDeadMembers(setKey: string, members: string[]): Promise<number>;
|
|
3826
3963
|
/**
|
|
3827
3964
|
* Atomically deletes every refresh session belonging to one identity plane.
|
|
3828
3965
|
*
|
|
@@ -4914,7 +5051,14 @@ declare class AcceptInvitationDto {
|
|
|
4914
5051
|
* Plaintext password for the new account.
|
|
4915
5052
|
*
|
|
4916
5053
|
* @remarks
|
|
4917
|
-
*
|
|
5054
|
+
* The 8-character floor here is STRUCTURAL, not the deployment's policy: it is the lowest
|
|
5055
|
+
* NIST SP 800-63B-4 §3.1.1.1 permits under any circumstance, and it is what a decorator
|
|
5056
|
+
* can express — decorators are evaluated when the class is defined, before any
|
|
5057
|
+
* configuration exists. The policy floor is `password.minLength` (default 15, as the
|
|
5058
|
+
* standard requires of a single-factor password), enforced by `PasswordService` and
|
|
5059
|
+
* answering this same `auth.validation` code and details shape.
|
|
5060
|
+
*
|
|
5061
|
+
* Maximum 128 characters as a practical
|
|
4918
5062
|
* input bound to prevent DoS via pathological scrypt inputs.
|
|
4919
5063
|
* The service layer hashes this value immediately — it is never logged or
|
|
4920
5064
|
* persisted in plaintext.
|
|
@@ -5208,7 +5352,14 @@ declare class RegisterDto {
|
|
|
5208
5352
|
* Plaintext password supplied by the user.
|
|
5209
5353
|
*
|
|
5210
5354
|
* @remarks
|
|
5211
|
-
*
|
|
5355
|
+
* The 8-character floor here is STRUCTURAL, not the deployment's policy: it is the lowest
|
|
5356
|
+
* NIST SP 800-63B-4 §3.1.1.1 permits under any circumstance, and it is what a decorator
|
|
5357
|
+
* can express — decorators are evaluated when the class is defined, before any
|
|
5358
|
+
* configuration exists. The policy floor is `password.minLength` (default 15, as the
|
|
5359
|
+
* standard requires of a single-factor password), enforced by `PasswordService` and
|
|
5360
|
+
* answering this same `auth.validation` code and details shape.
|
|
5361
|
+
*
|
|
5362
|
+
* Maximum 128 characters as a practical
|
|
5212
5363
|
* input bound. The service layer hashes this value immediately after receipt —
|
|
5213
5364
|
* it is never logged or persisted in plaintext.
|
|
5214
5365
|
*/
|
|
@@ -5296,7 +5447,14 @@ declare class ChangePasswordDto {
|
|
|
5296
5447
|
currentPassword: string;
|
|
5297
5448
|
/**
|
|
5298
5449
|
* New plaintext password chosen by the user.
|
|
5299
|
-
*
|
|
5450
|
+
* The 8-character floor here is STRUCTURAL, not the deployment's policy: it is the lowest
|
|
5451
|
+
* NIST SP 800-63B-4 §3.1.1.1 permits under any circumstance, and it is what a decorator
|
|
5452
|
+
* can express — decorators are evaluated when the class is defined, before any
|
|
5453
|
+
* configuration exists. The policy floor is `password.minLength` (default 15, as the
|
|
5454
|
+
* standard requires of a single-factor password), enforced by `PasswordService` and
|
|
5455
|
+
* answering this same `auth.validation` code and details shape.
|
|
5456
|
+
*
|
|
5457
|
+
* Maximum 128 characters as a practical bound.
|
|
5300
5458
|
* Hashed immediately by the service layer — never persisted in plaintext.
|
|
5301
5459
|
*/
|
|
5302
5460
|
newPassword: string;
|
|
@@ -5325,7 +5483,14 @@ declare class ResetPasswordDto {
|
|
|
5325
5483
|
email: string;
|
|
5326
5484
|
/**
|
|
5327
5485
|
* New plaintext password chosen by the user.
|
|
5328
|
-
*
|
|
5486
|
+
* The 8-character floor here is STRUCTURAL, not the deployment's policy: it is the lowest
|
|
5487
|
+
* NIST SP 800-63B-4 §3.1.1.1 permits under any circumstance, and it is what a decorator
|
|
5488
|
+
* can express — decorators are evaluated when the class is defined, before any
|
|
5489
|
+
* configuration exists. The policy floor is `password.minLength` (default 15, as the
|
|
5490
|
+
* standard requires of a single-factor password), enforced by `PasswordService` and
|
|
5491
|
+
* answering this same `auth.validation` code and details shape.
|
|
5492
|
+
*
|
|
5493
|
+
* Maximum 128 characters as a practical bound.
|
|
5329
5494
|
* Hashed immediately by the service layer — never persisted in plaintext.
|
|
5330
5495
|
*/
|
|
5331
5496
|
newPassword: string;
|
|
@@ -5547,10 +5712,41 @@ declare class OtpService {
|
|
|
5547
5712
|
verify(purpose: string, identifier: string, code: string): Promise<void>;
|
|
5548
5713
|
}
|
|
5549
5714
|
|
|
5715
|
+
/**
|
|
5716
|
+
* Password hashing and verification service using `node:crypto` scrypt.
|
|
5717
|
+
*
|
|
5718
|
+
* Uses scrypt (RFC 7914) — a memory-hard key derivation function designed to
|
|
5719
|
+
* resist brute-force and GPU/ASIC attacks. **Never use SHA-256, MD5, or
|
|
5720
|
+
* unsalted hashes for passwords.**
|
|
5721
|
+
*
|
|
5722
|
+
* Wire format: PHC — `$scrypt$ln={log2(N)},r={r},p={p}${saltB64}${derivedB64}`
|
|
5723
|
+
* - `saltB64` — 16 random bytes in PHC "B64" (standard base64, no padding)
|
|
5724
|
+
* - `derivedB64` — 64 derived bytes in the same encoding
|
|
5725
|
+
*
|
|
5726
|
+
* The only encoding, read and written. rust-auth writes the same, and the format is pinned by
|
|
5727
|
+
* `conformance/wire-contract.json` with a known-answer vector from each implementation.
|
|
5728
|
+
*
|
|
5729
|
+
* @remarks
|
|
5730
|
+
* **Cost parameters:** Taken from `options.password` at construction time.
|
|
5731
|
+
* Defaults are `costFactor = 131072 (2^17)`, `blockSize = 8`, `parallelization = 1` — OWASP's
|
|
5732
|
+
* recommended minimum for scrypt. Override in
|
|
5733
|
+
* `BymaxAuthModule.forRoot({ password: { costFactor: 65536 } })`.
|
|
5734
|
+
* Validated at startup by `resolveOptions()` — values below `16384 (2^14)` are rejected.
|
|
5735
|
+
*
|
|
5736
|
+
* **Security:** Comparison uses `crypto.timingSafeEqual` to prevent timing
|
|
5737
|
+
* attacks. All comparison failures return `false` — never throw on bad input.
|
|
5738
|
+
*
|
|
5739
|
+
* **Thread safety:** scrypt is CPU-intensive. In production, calls will block
|
|
5740
|
+
* the Node.js event loop for ~100–200 ms. Consider running behind a worker
|
|
5741
|
+
* thread or rate-limiting authentication endpoints.
|
|
5742
|
+
*
|
|
5743
|
+
* @layer Service
|
|
5744
|
+
*/
|
|
5550
5745
|
declare class PasswordService {
|
|
5551
5746
|
private readonly breachChecker;
|
|
5552
5747
|
private readonly logger;
|
|
5553
5748
|
private readonly N;
|
|
5749
|
+
private readonly minLength;
|
|
5554
5750
|
private readonly r;
|
|
5555
5751
|
private readonly p;
|
|
5556
5752
|
private readonly maxmem;
|
|
@@ -5559,14 +5755,51 @@ declare class PasswordService {
|
|
|
5559
5755
|
* Hashes a plaintext password using scrypt with a random salt.
|
|
5560
5756
|
*
|
|
5561
5757
|
* @param plain - Plaintext password (UTF-8 string).
|
|
5562
|
-
* @returns Hashed password
|
|
5758
|
+
* @returns Hashed password as a PHC string.
|
|
5563
5759
|
*
|
|
5564
5760
|
* @example
|
|
5565
5761
|
* ```typescript
|
|
5566
5762
|
* const hash = await passwordService.hash('my-password')
|
|
5567
|
-
* // 'scrypt
|
|
5763
|
+
* // '$scrypt$ln=17,r=8,p=1$YmFzZTY0c2FsdA$…'
|
|
5568
5764
|
* ```
|
|
5569
5765
|
*/
|
|
5766
|
+
/**
|
|
5767
|
+
* The whole password policy, applied wherever a password is being *set*.
|
|
5768
|
+
*
|
|
5769
|
+
* One entry point so the four call sites — registration, reset, authenticated change and
|
|
5770
|
+
* invitation acceptance — cannot drift into applying different halves of it.
|
|
5771
|
+
*
|
|
5772
|
+
* Order matters: length first, because it is decided locally and for free, and the breach
|
|
5773
|
+
* check may reach a network corpus. A password refused for being short should not cost a
|
|
5774
|
+
* round trip, and should not be sent anywhere first.
|
|
5775
|
+
*
|
|
5776
|
+
* @param plain - The plaintext password the user is trying to set.
|
|
5777
|
+
* @param field - The request field to name in a length failure's `details`.
|
|
5778
|
+
* @throws {@link AuthException} with `VALIDATION` when it is too short, or
|
|
5779
|
+
* `PASSWORD_COMPROMISED` when the corpus knows it.
|
|
5780
|
+
*/
|
|
5781
|
+
assertAcceptable(plain: string, field: string): Promise<void>;
|
|
5782
|
+
/**
|
|
5783
|
+
* Rejects a password shorter than the configured minimum.
|
|
5784
|
+
*
|
|
5785
|
+
* The DTOs carry a structural `@MinLength(8)` — the lowest NIST SP 800-63B-4 permits under any
|
|
5786
|
+
* circumstance — and this is the deployment's policy on top of it, which is configurable and
|
|
5787
|
+
* defaults to 15 because that is what §3.1.1.1 requires of a single-factor password. The check
|
|
5788
|
+
* lives here rather than in a decorator because a decorator is evaluated when the class is
|
|
5789
|
+
* defined, before any configuration exists.
|
|
5790
|
+
*
|
|
5791
|
+
* It answers the same `auth.validation` code and the same `{ field, message }[]` details the
|
|
5792
|
+
* validation pipe produces for a length failure, so a client already handling a short password
|
|
5793
|
+
* sees no new shape and the shared error catalog gains no entry. The breach and
|
|
5794
|
+
* common-password screens run after: they remove passwords that are already *known*, which is
|
|
5795
|
+
* a different question from how many guesses the password is worth.
|
|
5796
|
+
*
|
|
5797
|
+
* @param plain - The plaintext password the user is trying to set.
|
|
5798
|
+
* @param field - The request field to name in `details`, so the message points at the input
|
|
5799
|
+
* the caller actually sent (`password` on registration, `newPassword` on a reset).
|
|
5800
|
+
* @throws {@link AuthException} with `VALIDATION` when the password is too short.
|
|
5801
|
+
*/
|
|
5802
|
+
assertLongEnough(plain: string, field: string): void;
|
|
5570
5803
|
/**
|
|
5571
5804
|
* Rejects a password that appears in a known-breach corpus.
|
|
5572
5805
|
*
|
|
@@ -5608,7 +5841,7 @@ declare class PasswordService {
|
|
|
5608
5841
|
* Verifies a plaintext password against a stored scrypt hash.
|
|
5609
5842
|
*
|
|
5610
5843
|
* @param plain - Plaintext password supplied by the user.
|
|
5611
|
-
* @param hash - Stored hash
|
|
5844
|
+
* @param hash - Stored hash, as a PHC string.
|
|
5612
5845
|
* @returns `true` if the password matches, `false` otherwise.
|
|
5613
5846
|
*
|
|
5614
5847
|
* @remarks
|
|
@@ -5716,9 +5949,11 @@ declare class SessionService {
|
|
|
5716
5949
|
*
|
|
5717
5950
|
* Reads all `rt:`-prefixed members from `sess:{userId}`, fetches the
|
|
5718
5951
|
* corresponding `sd:{hash}` detail records, and marks the caller's own
|
|
5719
|
-
* session via `isCurrent`.
|
|
5720
|
-
*
|
|
5721
|
-
* and
|
|
5952
|
+
* session via `isCurrent`. A member whose detail record is missing, unreadable
|
|
5953
|
+
* or malformed is excluded from the result, and removed from the SET
|
|
5954
|
+
* asynchronously (fire-and-forget) only if its `rt:` key is also gone — see
|
|
5955
|
+
* {@link AuthRedisService.pruneDeadMembers} for why the detail record alone
|
|
5956
|
+
* does not settle it.
|
|
5722
5957
|
*
|
|
5723
5958
|
* Results are sorted by `createdAt` descending (newest session first).
|
|
5724
5959
|
*
|
|
@@ -6017,6 +6252,14 @@ declare class TokenManagerService {
|
|
|
6017
6252
|
* @throws {@link AuthException} with `REFRESH_TOKEN_INVALID` if no valid session found.
|
|
6018
6253
|
*/
|
|
6019
6254
|
reissueTokens(oldRefresh: string, ip: string, userAgent: string): Promise<RotatedTokenResult>;
|
|
6255
|
+
/**
|
|
6256
|
+
* Emits {@link IAuthHooks.onRefreshTokenReuseDetected}, fire-and-forget.
|
|
6257
|
+
*
|
|
6258
|
+
* The owner is read from the stored session where it can be — a replay of a token whose live
|
|
6259
|
+
* key is already gone leaves nothing to read, and the hook is skipped rather than fired with
|
|
6260
|
+
* an empty identity that a consumer would have to guess about.
|
|
6261
|
+
*/
|
|
6262
|
+
private emitReuseDetected;
|
|
6020
6263
|
/**
|
|
6021
6264
|
* Refuses a rotation once the login it descends from has outlived the absolute cap.
|
|
6022
6265
|
*
|
|
@@ -6034,14 +6277,6 @@ declare class TokenManagerService {
|
|
|
6034
6277
|
* remedy is the same (sign in again) and the difference would only tell a holder of a
|
|
6035
6278
|
* stolen token how old the account's session is.
|
|
6036
6279
|
*/
|
|
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
6280
|
private assertWithinAbsoluteLifetime;
|
|
6046
6281
|
/**
|
|
6047
6282
|
* Reads the presented token's live record to seed the rotated one.
|
|
@@ -6195,20 +6430,6 @@ declare class TokenManagerService {
|
|
|
6195
6430
|
* @returns The re-signed platform access token.
|
|
6196
6431
|
*/
|
|
6197
6432
|
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
6433
|
/**
|
|
6213
6434
|
* Verifies an access token's signature under the pinned algorithm while **ignoring its
|
|
6214
6435
|
* expiry**, returning the payload.
|
|
@@ -6237,7 +6458,6 @@ declare class TokenManagerService {
|
|
|
6237
6458
|
* @throws Whatever the verifier throws when no configured secret accepts the token.
|
|
6238
6459
|
*/
|
|
6239
6460
|
verifyPlatformIgnoringExpiry(token: string): PlatformJwtPayload;
|
|
6240
|
-
decodeToken(token: string): DashboardJwtPayload | PlatformJwtPayload | MfaTempPayload;
|
|
6241
6461
|
/**
|
|
6242
6462
|
* Issues a short-lived MFA challenge token and stores it in Redis for
|
|
6243
6463
|
* single-use enforcement.
|
|
@@ -6566,6 +6786,22 @@ declare class AuthService {
|
|
|
6566
6786
|
* @param tenantId - The tenant the account belongs to.
|
|
6567
6787
|
*/
|
|
6568
6788
|
unlockAccount(email: string, tenantId: string): Promise<void>;
|
|
6789
|
+
/**
|
|
6790
|
+
* Derives the OTP-record identifier for a `tenantId + email` pair.
|
|
6791
|
+
*
|
|
6792
|
+
* HMAC rather than a bare digest because an address is low-entropy: a bare SHA-256 of one is
|
|
6793
|
+
* reversible by dictionary, and these identifiers are the Redis key an operator can read.
|
|
6794
|
+
* The preimage is pinned by `conformance/wire-contract.json` and shared byte-for-byte with
|
|
6795
|
+
* rust-auth, which keys the same records in the same Redis.
|
|
6796
|
+
*
|
|
6797
|
+
* Deliberately distinct from {@link lockoutIdentifier}: that one namespaces the login
|
|
6798
|
+
* keyspace with a `dashboard:` prefix, and the two must never collide.
|
|
6799
|
+
*
|
|
6800
|
+
* @param tenantId - Tenant scope.
|
|
6801
|
+
* @param email - The canonicalized address.
|
|
6802
|
+
* @returns Hex HMAC-SHA-256 identifier.
|
|
6803
|
+
*/
|
|
6804
|
+
private otpIdentifier;
|
|
6569
6805
|
/**
|
|
6570
6806
|
* The brute-force counter key for a dashboard account.
|
|
6571
6807
|
*
|
|
@@ -6586,22 +6822,6 @@ declare class AuthService {
|
|
|
6586
6822
|
* @param email - The address, already normalized by the caller.
|
|
6587
6823
|
* @returns The HMAC identifier, opaque and non-reversible.
|
|
6588
6824
|
*/
|
|
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
6825
|
private lockoutIdentifier;
|
|
6606
6826
|
private resolveTenantId;
|
|
6607
6827
|
private buildHookContext;
|
|
@@ -6688,7 +6908,9 @@ declare class ConfirmEmailChangeDto {
|
|
|
6688
6908
|
*
|
|
6689
6909
|
* **The current password is re-proved.** A stolen access token alone cannot move the recovery
|
|
6690
6910
|
* address — the thief has to already hold the credential that would let them take the account
|
|
6691
|
-
* anyway.
|
|
6911
|
+
* anyway. It is also why no session is revoked here: anyone who can complete this flow could
|
|
6912
|
+
* already sign in, so ending the caller's other sessions would cost the user their devices and
|
|
6913
|
+
* buy nothing. A password *change* does revoke, because there the factor itself moved.
|
|
6692
6914
|
*
|
|
6693
6915
|
* **The new address is proved before it is adopted.** A token goes to it and nowhere else, so
|
|
6694
6916
|
* a typo cannot lock the owner out of their own account and an attacker cannot point the
|
|
@@ -7119,6 +7341,45 @@ declare class MfaService {
|
|
|
7119
7341
|
* @throws `MFA_INVALID_CODE` if the submitted TOTP code is incorrect.
|
|
7120
7342
|
*/
|
|
7121
7343
|
disable(userId: string, code: string, ip: string, userAgent: string, context?: 'dashboard' | 'platform'): Promise<void>;
|
|
7344
|
+
/**
|
|
7345
|
+
* Removes a user's second factor without their TOTP code, for a support desk facing a user
|
|
7346
|
+
* who has lost their authenticator AND their recovery codes.
|
|
7347
|
+
*
|
|
7348
|
+
* Every self-service exit from MFA needs the factor itself: {@link disable} wants a valid
|
|
7349
|
+
* TOTP code, and the recovery codes want the codes. A user who has lost both is locked out
|
|
7350
|
+
* permanently, by the control that exists to protect them — ASVS v5 §6.1.1 asks for an
|
|
7351
|
+
* administrative path out for exactly that reason.
|
|
7352
|
+
*
|
|
7353
|
+
* **Authorising the caller is the consumer's job.** The library deliberately ships no route
|
|
7354
|
+
* for this, the same decision and for the same reason as {@link AuthService.unlockAccount}:
|
|
7355
|
+
* who may reset whom is a question only the host application can answer, and all 39 routes
|
|
7356
|
+
* this library does ship are scoped to the caller's own account.
|
|
7357
|
+
*
|
|
7358
|
+
* Idempotent: resetting an account that has no second factor is a no-op, so a support desk
|
|
7359
|
+
* retrying does not get an error for a job already done.
|
|
7360
|
+
*
|
|
7361
|
+
* Three things happen beyond clearing the record, and none of them are optional:
|
|
7362
|
+
*
|
|
7363
|
+
* - **Sessions are invalidated and the token epoch is bumped**, so access tokens carrying
|
|
7364
|
+
* `mfaVerified: true` die with the factor rather than outliving it.
|
|
7365
|
+
* - **The user is notified**, through the same channel {@link disable} uses. An
|
|
7366
|
+
* administrative reset that the account holder cannot see is an account-takeover path:
|
|
7367
|
+
* an attacker who reaches the support desk removes the second factor silently. The
|
|
7368
|
+
* notification is what makes it an event the owner can detect and dispute.
|
|
7369
|
+
* - **It is logged** under its own prefix, so an administrative removal is distinguishable
|
|
7370
|
+
* from a user-initiated one in the library's own log.
|
|
7371
|
+
*
|
|
7372
|
+
* The `afterMfaDisabled` hook fires too, so consumer-side alerting keeps working. It is not
|
|
7373
|
+
* given a separate hook: the consumer is the one calling this method, so they already know
|
|
7374
|
+
* an administrative reset happened — the hook exists to tell them about the paths they do
|
|
7375
|
+
* not initiate.
|
|
7376
|
+
*
|
|
7377
|
+
* @param userId - Internal ID of the user whose second factor is being removed.
|
|
7378
|
+
* @param context - Which identity plane the user belongs to: `'dashboard'` (default) or
|
|
7379
|
+
* `'platform'`. Must match the plane the account lives in, or the lookup misses.
|
|
7380
|
+
* @throws `TOKEN_INVALID` if no user with that ID exists in the given plane.
|
|
7381
|
+
*/
|
|
7382
|
+
resetMfa(userId: string, context?: 'dashboard' | 'platform'): Promise<void>;
|
|
7122
7383
|
/**
|
|
7123
7384
|
* Regenerates the user's MFA recovery codes after verifying a current TOTP code.
|
|
7124
7385
|
*
|
|
@@ -7770,23 +8031,6 @@ declare class PlatformAuthService {
|
|
|
7770
8031
|
* @throws {@link AuthException} with `TOKEN_INVALID` if the admin no longer exists.
|
|
7771
8032
|
*/
|
|
7772
8033
|
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
8034
|
/**
|
|
7791
8035
|
* Derives the brute-force identifier for a platform login: `hmac('platform:{email}')`.
|
|
7792
8036
|
*
|
|
@@ -7806,6 +8050,23 @@ declare class PlatformAuthService {
|
|
|
7806
8050
|
* @returns Hex HMAC-SHA-256 identifier.
|
|
7807
8051
|
*/
|
|
7808
8052
|
private lockoutIdentifier;
|
|
8053
|
+
/**
|
|
8054
|
+
* Revokes all active platform sessions for the given admin.
|
|
8055
|
+
*
|
|
8056
|
+
* Delegates to {@link AuthRedisService.invalidateUserSessions} which uses an atomic
|
|
8057
|
+
* Lua script to read the `psess:{userId}` SET, delete all session and grace-pointer
|
|
8058
|
+
* keys, and remove the SET itself in a single Redis round-trip. This prevents the
|
|
8059
|
+
* TOCTOU race that would arise from a non-atomic SMEMBERS + loop + DEL approach.
|
|
8060
|
+
*
|
|
8061
|
+
* The token epoch is then advanced, so outstanding platform **access** tokens die with
|
|
8062
|
+
* the refresh sessions rather than working on to expiry — "log out everywhere" that
|
|
8063
|
+
* leaves every access token alive is not what those words promise. Bumped after the
|
|
8064
|
+
* sweep for the same reason the dashboard flow bumps last: a failure in the sweep
|
|
8065
|
+
* leaves the epoch untouched and the operation visibly incomplete, instead of the
|
|
8066
|
+
* reverse, which would read as done while the sessions live on.
|
|
8067
|
+
*
|
|
8068
|
+
* @param userId - The platform admin's internal ID.
|
|
8069
|
+
*/
|
|
7809
8070
|
revokeAllPlatformSessions(userId: string): Promise<void>;
|
|
7810
8071
|
}
|
|
7811
8072
|
|
|
@@ -7851,7 +8112,9 @@ declare class OAuthService {
|
|
|
7851
8112
|
* Sequence:
|
|
7852
8113
|
* 1. Validates the `provider` format and resolves the named plugin.
|
|
7853
8114
|
* 2. Generates a 32-byte (64 hex char) cryptographically random state nonce.
|
|
7854
|
-
* 3. Stores `os:{sha256(state)} → { tenantId }` in Redis with a
|
|
8115
|
+
* 3. Stores `os:{sha256(state)} → { provider, tenantId, codeVerifier }` in Redis with a
|
|
8116
|
+
* 10-minute TTL. `provider` is what the callback checks itself against (RFC 9700
|
|
8117
|
+
* mix-up defence).
|
|
7855
8118
|
* 4. Constructs the provider's authorization URL via `plugin.authorizeUrl(state)`.
|
|
7856
8119
|
* 5. Issues a 302 redirect via the Express `res` object.
|
|
7857
8120
|
*
|