@bymax-one/nest-auth 1.1.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +121 -1
- package/README.md +101 -28
- package/dist/nextjs/index.cjs +7 -17
- package/dist/nextjs/index.d.cts +12 -5
- package/dist/nextjs/index.d.ts +12 -5
- package/dist/nextjs/index.mjs +7 -17
- package/dist/server/index.cjs +441 -74
- package/dist/server/index.d.cts +240 -38
- package/dist/server/index.d.ts +240 -38
- package/dist/server/index.mjs +442 -75
- package/package.json +2 -2
package/dist/server/index.d.cts
CHANGED
|
@@ -426,7 +426,7 @@ interface BymaxAuthModuleOptions {
|
|
|
426
426
|
refreshExpiresInDays?: number;
|
|
427
427
|
/**
|
|
428
428
|
* Hard cap on how long one login can be extended by rotation, in days.
|
|
429
|
-
* Default: `0`
|
|
429
|
+
* Default: `30`. Set to `0` to disable the cap.
|
|
430
430
|
*
|
|
431
431
|
* `refreshExpiresInDays` bounds how long a single refresh token lives, not how long a
|
|
432
432
|
* *session* lives: a client that rotates every fifteen minutes renews that lifetime
|
|
@@ -435,9 +435,12 @@ interface BymaxAuthModuleOptions {
|
|
|
435
435
|
* carried through every rotation, and once the cap is passed the rotation is refused and
|
|
436
436
|
* the user signs in again.
|
|
437
437
|
*
|
|
438
|
-
*
|
|
439
|
-
*
|
|
440
|
-
*
|
|
438
|
+
* On by default at 30 days, because NIST SP 800-63B-4 §3 makes a definite reauthentication
|
|
439
|
+
* timeout a SHALL and puts it at no more than 30 days for AAL1. Without the cap a refresh
|
|
440
|
+
* token stolen once converts into permanent access: reuse detection only fires if the
|
|
441
|
+
* legitimate client also replays, which it never will once the victim has stopped using
|
|
442
|
+
* that device. Raise it to a value the product can justify asking a user to re-authenticate
|
|
443
|
+
* at, or set `0` to accept unbounded sessions deliberately.
|
|
441
444
|
*
|
|
442
445
|
* Sessions written before this existed carry no birth time and are not capped; they age
|
|
443
446
|
* out under `refreshExpiresInDays` like any other.
|
|
@@ -501,6 +504,27 @@ interface BymaxAuthModuleOptions {
|
|
|
501
504
|
* @throws {Error} When the value fails validation at module initialisation.
|
|
502
505
|
*/
|
|
503
506
|
costFactor?: number;
|
|
507
|
+
/**
|
|
508
|
+
* Minimum password length the deployment accepts. Default: `15`.
|
|
509
|
+
*
|
|
510
|
+
* NIST SP 800-63B-4 §3.1.1.1 requires 15 characters for a password used as a SINGLE
|
|
511
|
+
* authentication factor, and permits 8 only when the password is part of multi-factor
|
|
512
|
+
* authentication. MFA in this library is opt-in per user, so the default deployment is
|
|
513
|
+
* single-factor and 15 is the number that applies. Lower it to 8 — the structural floor the
|
|
514
|
+
* DTOs enforce, and the lowest the standard allows under any circumstance — only in a
|
|
515
|
+
* deployment that makes MFA mandatory.
|
|
516
|
+
*
|
|
517
|
+
* @remarks
|
|
518
|
+
* `costFactor` sets the price of one guess; this sets how many guesses there are. Only the
|
|
519
|
+
* second is what an offline attacker actually runs out of, and the breach and common-password
|
|
520
|
+
* screens remove passwords that are already *known*, not short ones nobody has seen yet.
|
|
521
|
+
*
|
|
522
|
+
* Deliberately not paired with any composition rule: the same clause says verifiers SHALL
|
|
523
|
+
* NOT impose them, and none of the password DTOs carries one.
|
|
524
|
+
*
|
|
525
|
+
* @throws {Error} When the value is not an integer in `[8, 128]`.
|
|
526
|
+
*/
|
|
527
|
+
minLength?: number;
|
|
504
528
|
/**
|
|
505
529
|
* scrypt block size parameter (r).
|
|
506
530
|
* Default: `8`
|
|
@@ -539,19 +563,38 @@ interface BymaxAuthModuleOptions {
|
|
|
539
563
|
* Default: `'cookie'`
|
|
540
564
|
*/
|
|
541
565
|
tokenDelivery?: 'cookie' | 'bearer' | 'both';
|
|
566
|
+
/**
|
|
567
|
+
* The deployment environment, supplied explicitly.
|
|
568
|
+
*
|
|
569
|
+
* This is the ONLY input that answers "is this production". The library never reads the
|
|
570
|
+
* ambient `process.env`, and it is secure by default: an unset value is `'production'`, so
|
|
571
|
+
* `secureCookies` resolves to `true` and the production-gated OAuth-redirect checks apply
|
|
572
|
+
* unless the host opts into `'development'` or `'test'`.
|
|
573
|
+
*
|
|
574
|
+
* Default: `'production'`.
|
|
575
|
+
*
|
|
576
|
+
* @remarks
|
|
577
|
+
* This replaces reading `process.env['NODE_ENV'] === 'production'`. That test decided cookie
|
|
578
|
+
* `Secure`, OAuth callback HTTPS enforcement and three redirect validations, and it failed
|
|
579
|
+
* open on every near miss — unset, `'staging'`, `'prod'`, or `'production '` with a trailing
|
|
580
|
+
* space each silently took the insecure branch. Whether a deployment is production is
|
|
581
|
+
* something the deployer knows and the process environment only hints at, so it is now passed
|
|
582
|
+
* in rather than sniffed. Matches `Environment` in rust-auth.
|
|
583
|
+
*/
|
|
584
|
+
environment?: 'production' | 'development' | 'test';
|
|
542
585
|
/**
|
|
543
586
|
* Whether to set the `Secure` flag on auth cookies.
|
|
544
587
|
*
|
|
545
588
|
* When `true`, cookies are only sent over HTTPS. When `false`, cookies are
|
|
546
589
|
* sent over HTTP as well (useful for local development).
|
|
547
590
|
*
|
|
548
|
-
* Default: `
|
|
549
|
-
*
|
|
591
|
+
* Default: `true`, unless {@link BymaxAuthModuleOptions.environment} is
|
|
592
|
+
* `'development'` or `'test'`. Evaluated once at module startup via
|
|
593
|
+
* `resolveOptions()` — not re-evaluated per request.
|
|
550
594
|
*
|
|
551
595
|
* @remarks
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
* marked Secure regardless of the environment variable.
|
|
596
|
+
* Set this explicitly to `true` in a non-production environment that is nonetheless served
|
|
597
|
+
* over HTTPS, so the cookies are marked `Secure` there too.
|
|
555
598
|
*/
|
|
556
599
|
secureCookies?: boolean;
|
|
557
600
|
/**
|
|
@@ -1023,6 +1066,12 @@ interface BymaxAuthModuleOptions {
|
|
|
1023
1066
|
* **ignores** any `tenantId` field in the request body. This prevents tenant
|
|
1024
1067
|
* spoofing where a client sends a different tenant's ID.
|
|
1025
1068
|
*
|
|
1069
|
+
* Because a configured resolver makes the body's value dead weight, `tenantId` is optional on
|
|
1070
|
+
* every DTO that carries it and a client may omit it entirely. With no resolver configured the
|
|
1071
|
+
* body is the only thing that can name a tenant, and a request naming none is refused with
|
|
1072
|
+
* `auth.validation` — the deployment has to choose one of the two, and neither choice is
|
|
1073
|
+
* guessed on its behalf.
|
|
1074
|
+
*
|
|
1026
1075
|
* @param req - The Express request object
|
|
1027
1076
|
* @returns The tenant ID string, or a Promise resolving to it
|
|
1028
1077
|
*
|
|
@@ -1316,7 +1365,7 @@ declare const BYMAX_AUTH_REDIS_CLIENT: unique symbol;
|
|
|
1316
1365
|
* interface-extension compatibility check with `exactOptionalPropertyTypes`,
|
|
1317
1366
|
* which rejects intersection widening of optional function properties.
|
|
1318
1367
|
*/
|
|
1319
|
-
type ResolvedOptions = Omit<BymaxAuthModuleOptions, 'jwt' | 'password' | 'tokenDelivery' | 'cookies' | 'sessions' | 'bruteForce' | 'passwordReset' | 'emailVerification' | 'platform' | 'invitations' | 'controllers' | 'blockedStatuses' | 'redisNamespace' | 'routePrefix' | 'userStatusCacheTtlSeconds' | 'secureCookies' | 'mfa' | 'rateLimit'> & {
|
|
1368
|
+
type ResolvedOptions = Omit<BymaxAuthModuleOptions, 'jwt' | 'password' | 'tokenDelivery' | 'cookies' | 'sessions' | 'bruteForce' | 'passwordReset' | 'emailVerification' | 'platform' | 'invitations' | 'controllers' | 'blockedStatuses' | 'redisNamespace' | 'routePrefix' | 'userStatusCacheTtlSeconds' | 'environment' | 'secureCookies' | 'mfa' | 'rateLimit'> & {
|
|
1320
1369
|
jwt: Required<Omit<BymaxAuthModuleOptions['jwt'], 'previousSecrets' | 'issuer' | 'audience'>> & Pick<BymaxAuthModuleOptions['jwt'], 'previousSecrets' | 'issuer' | 'audience'>;
|
|
1321
1370
|
password: Required<NonNullable<BymaxAuthModuleOptions['password']>>;
|
|
1322
1371
|
tokenDelivery: NonNullable<BymaxAuthModuleOptions['tokenDelivery']>;
|
|
@@ -1337,6 +1386,12 @@ type ResolvedOptions = Omit<BymaxAuthModuleOptions, 'jwt' | 'password' | 'tokenD
|
|
|
1337
1386
|
redisNamespace: string;
|
|
1338
1387
|
routePrefix: string;
|
|
1339
1388
|
userStatusCacheTtlSeconds: number;
|
|
1389
|
+
/**
|
|
1390
|
+
* The deployment environment as the host declared it. The only input that answers "is this
|
|
1391
|
+
* production"; the library never reads `process.env`. See
|
|
1392
|
+
* {@link BymaxAuthModuleOptions.environment}.
|
|
1393
|
+
*/
|
|
1394
|
+
environment: 'production' | 'development' | 'test';
|
|
1340
1395
|
/** `true` if auth cookies should carry the `Secure` flag. */
|
|
1341
1396
|
secureCookies: boolean;
|
|
1342
1397
|
/**
|
|
@@ -2193,18 +2248,30 @@ interface IEmailProvider {
|
|
|
2193
2248
|
*/
|
|
2194
2249
|
sendMfaDisabledNotification(email: string, locale?: string): Promise<void>;
|
|
2195
2250
|
/**
|
|
2196
|
-
* Sends a security alert
|
|
2197
|
-
* device or location.
|
|
2251
|
+
* Sends a security alert about a newly established session.
|
|
2198
2252
|
*
|
|
2199
|
-
*
|
|
2200
|
-
*
|
|
2201
|
-
*
|
|
2253
|
+
* **This library never calls it.** The method is optional, and it is here as a typed
|
|
2254
|
+
* signature for you to call from the {@link IAuthHooks.onNewSession} hook — which the
|
|
2255
|
+
* library does fire, on every session it creates, with the same {@link SessionInfo} this
|
|
2256
|
+
* takes.
|
|
2257
|
+
*
|
|
2258
|
+
* The alert deliberately does not live inside the library, because the library cannot send
|
|
2259
|
+
* it well. Without device recognition it fires on *every* login, and an alert that arrives
|
|
2260
|
+
* on every login is one the user learns to dismiss — at which point the control has stopped
|
|
2261
|
+
* existing while still appearing to be in place. Recognizing a device means keeping a
|
|
2262
|
+
* per-user device history, and the consumer already has one (or can key it to their own
|
|
2263
|
+
* user record); the library would have to invent that state in the Redis keyspace it shares
|
|
2264
|
+
* with rust-auth, which is a contract change to solve a problem the caller is better placed
|
|
2265
|
+
* to solve.
|
|
2266
|
+
*
|
|
2267
|
+
* So: decide in your `onNewSession` hook whether the session is worth alerting about, and
|
|
2268
|
+
* call this when it is.
|
|
2202
2269
|
*
|
|
2203
2270
|
* @param email - Recipient's email address.
|
|
2204
2271
|
* @param sessionInfo - Device, IP, and session identifier details.
|
|
2205
2272
|
* @param locale - BCP 47 locale tag for email language (e.g. `'en'`, `'pt-BR'`).
|
|
2206
2273
|
*/
|
|
2207
|
-
sendNewSessionAlert(email: string, sessionInfo: SessionInfo$1, locale?: string): Promise<void>;
|
|
2274
|
+
sendNewSessionAlert?(email: string, sessionInfo: SessionInfo$1, locale?: string): Promise<void>;
|
|
2208
2275
|
/**
|
|
2209
2276
|
* Sends a tenant invitation email to a prospective member.
|
|
2210
2277
|
*
|
|
@@ -3878,6 +3945,30 @@ declare class AuthRedisService {
|
|
|
3878
3945
|
* @returns How many dead members were dropped.
|
|
3879
3946
|
*/
|
|
3880
3947
|
pruneExpiredGraceMembers(setKey: string, gracePrefix: string): Promise<number>;
|
|
3948
|
+
/**
|
|
3949
|
+
* Drops index members whose own key is gone, and leaves every other member in place.
|
|
3950
|
+
*
|
|
3951
|
+
* A reader that walks `sess:{userId}` learns a session is stale from something *about* the
|
|
3952
|
+
* session — a detail record that is missing, unreadable or malformed. None of those facts is
|
|
3953
|
+
* the session. The credential is the `rt:{hash}` key, and only its absence means the member
|
|
3954
|
+
* names nothing: a live `rt:` with no `sd:` is a session that still opens the account.
|
|
3955
|
+
*
|
|
3956
|
+
* Removing such a member is not a tidy-up, it is a revocation bypass. `invalidateUserSessions`
|
|
3957
|
+
* revokes what the index names, so a member dropped while its `rt:` key lives produces a
|
|
3958
|
+
* session that survives "sign out everywhere" and keeps rotating, while the user is told every
|
|
3959
|
+
* device was signed out — and the un-indexing is triggered by the user's own session listing.
|
|
3960
|
+
*
|
|
3961
|
+
* So the caller supplies candidates and this decides, with `EXISTS` as the only evidence
|
|
3962
|
+
* admitted. The check and the `SREM` share one script because they must: a candidate whose
|
|
3963
|
+
* `rt:` key is written between the two would otherwise be dropped anyway. A Redis fault makes
|
|
3964
|
+
* the whole script fail rather than prune, which is the safe direction — an index that keeps a
|
|
3965
|
+
* dead member costs a wasted read, an index that loses a live one costs the revocation.
|
|
3966
|
+
*
|
|
3967
|
+
* @param setKey - The un-namespaced index key (`sess:{id}` or `psess:{id}`).
|
|
3968
|
+
* @param members - Candidate members, each a full key suffix (`rt:{hash}`).
|
|
3969
|
+
* @returns How many candidates were actually dropped.
|
|
3970
|
+
*/
|
|
3971
|
+
pruneDeadMembers(setKey: string, members: string[]): Promise<number>;
|
|
3881
3972
|
/**
|
|
3882
3973
|
* Atomically deletes every refresh session belonging to one identity plane.
|
|
3883
3974
|
*
|
|
@@ -4969,7 +5060,14 @@ declare class AcceptInvitationDto {
|
|
|
4969
5060
|
* Plaintext password for the new account.
|
|
4970
5061
|
*
|
|
4971
5062
|
* @remarks
|
|
4972
|
-
*
|
|
5063
|
+
* The 8-character floor here is STRUCTURAL, not the deployment's policy: it is the lowest
|
|
5064
|
+
* NIST SP 800-63B-4 §3.1.1.1 permits under any circumstance, and it is what a decorator
|
|
5065
|
+
* can express — decorators are evaluated when the class is defined, before any
|
|
5066
|
+
* configuration exists. The policy floor is `password.minLength` (default 15, as the
|
|
5067
|
+
* standard requires of a single-factor password), enforced by `PasswordService` and
|
|
5068
|
+
* answering this same `auth.validation` code and details shape.
|
|
5069
|
+
*
|
|
5070
|
+
* Maximum 128 characters as a practical
|
|
4973
5071
|
* input bound to prevent DoS via pathological scrypt inputs.
|
|
4974
5072
|
* The service layer hashes this value immediately — it is never logged or
|
|
4975
5073
|
* persisted in plaintext.
|
|
@@ -5041,7 +5139,7 @@ declare class ForgotPasswordDto {
|
|
|
5041
5139
|
/**
|
|
5042
5140
|
* Tenant identifier that scopes the reset request to a specific organization.
|
|
5043
5141
|
*/
|
|
5044
|
-
tenantId
|
|
5142
|
+
tenantId?: string;
|
|
5045
5143
|
}
|
|
5046
5144
|
|
|
5047
5145
|
/**
|
|
@@ -5085,7 +5183,7 @@ declare class LoginDto {
|
|
|
5085
5183
|
* Bounded to 128 characters — tenant IDs are part of HMAC pre-images and
|
|
5086
5184
|
* Redis keys, so an unbounded string is rejected at the boundary.
|
|
5087
5185
|
*/
|
|
5088
|
-
tenantId
|
|
5186
|
+
tenantId?: string;
|
|
5089
5187
|
}
|
|
5090
5188
|
|
|
5091
5189
|
/**
|
|
@@ -5263,7 +5361,14 @@ declare class RegisterDto {
|
|
|
5263
5361
|
* Plaintext password supplied by the user.
|
|
5264
5362
|
*
|
|
5265
5363
|
* @remarks
|
|
5266
|
-
*
|
|
5364
|
+
* The 8-character floor here is STRUCTURAL, not the deployment's policy: it is the lowest
|
|
5365
|
+
* NIST SP 800-63B-4 §3.1.1.1 permits under any circumstance, and it is what a decorator
|
|
5366
|
+
* can express — decorators are evaluated when the class is defined, before any
|
|
5367
|
+
* configuration exists. The policy floor is `password.minLength` (default 15, as the
|
|
5368
|
+
* standard requires of a single-factor password), enforced by `PasswordService` and
|
|
5369
|
+
* answering this same `auth.validation` code and details shape.
|
|
5370
|
+
*
|
|
5371
|
+
* Maximum 128 characters as a practical
|
|
5267
5372
|
* input bound. The service layer hashes this value immediately after receipt —
|
|
5268
5373
|
* it is never logged or persisted in plaintext.
|
|
5269
5374
|
*/
|
|
@@ -5278,7 +5383,7 @@ declare class RegisterDto {
|
|
|
5278
5383
|
* Tenant identifier that scopes the new user to a specific organization.
|
|
5279
5384
|
* Bounded to 128 characters — part of HMAC pre-images and Redis keys.
|
|
5280
5385
|
*/
|
|
5281
|
-
tenantId
|
|
5386
|
+
tenantId?: string;
|
|
5282
5387
|
}
|
|
5283
5388
|
|
|
5284
5389
|
/**
|
|
@@ -5300,7 +5405,7 @@ declare class ResendOtpDto {
|
|
|
5300
5405
|
/**
|
|
5301
5406
|
* Tenant identifier that scopes the resend request to a specific organization.
|
|
5302
5407
|
*/
|
|
5303
|
-
tenantId
|
|
5408
|
+
tenantId?: string;
|
|
5304
5409
|
}
|
|
5305
5410
|
|
|
5306
5411
|
/**
|
|
@@ -5321,7 +5426,7 @@ declare class ResendVerificationDto {
|
|
|
5321
5426
|
/**
|
|
5322
5427
|
* Tenant identifier that scopes the resend request to a specific organization.
|
|
5323
5428
|
*/
|
|
5324
|
-
tenantId
|
|
5429
|
+
tenantId?: string;
|
|
5325
5430
|
}
|
|
5326
5431
|
|
|
5327
5432
|
/**
|
|
@@ -5351,7 +5456,14 @@ declare class ChangePasswordDto {
|
|
|
5351
5456
|
currentPassword: string;
|
|
5352
5457
|
/**
|
|
5353
5458
|
* New plaintext password chosen by the user.
|
|
5354
|
-
*
|
|
5459
|
+
* The 8-character floor here is STRUCTURAL, not the deployment's policy: it is the lowest
|
|
5460
|
+
* NIST SP 800-63B-4 §3.1.1.1 permits under any circumstance, and it is what a decorator
|
|
5461
|
+
* can express — decorators are evaluated when the class is defined, before any
|
|
5462
|
+
* configuration exists. The policy floor is `password.minLength` (default 15, as the
|
|
5463
|
+
* standard requires of a single-factor password), enforced by `PasswordService` and
|
|
5464
|
+
* answering this same `auth.validation` code and details shape.
|
|
5465
|
+
*
|
|
5466
|
+
* Maximum 128 characters as a practical bound.
|
|
5355
5467
|
* Hashed immediately by the service layer — never persisted in plaintext.
|
|
5356
5468
|
*/
|
|
5357
5469
|
newPassword: string;
|
|
@@ -5380,7 +5492,14 @@ declare class ResetPasswordDto {
|
|
|
5380
5492
|
email: string;
|
|
5381
5493
|
/**
|
|
5382
5494
|
* New plaintext password chosen by the user.
|
|
5383
|
-
*
|
|
5495
|
+
* The 8-character floor here is STRUCTURAL, not the deployment's policy: it is the lowest
|
|
5496
|
+
* NIST SP 800-63B-4 §3.1.1.1 permits under any circumstance, and it is what a decorator
|
|
5497
|
+
* can express — decorators are evaluated when the class is defined, before any
|
|
5498
|
+
* configuration exists. The policy floor is `password.minLength` (default 15, as the
|
|
5499
|
+
* standard requires of a single-factor password), enforced by `PasswordService` and
|
|
5500
|
+
* answering this same `auth.validation` code and details shape.
|
|
5501
|
+
*
|
|
5502
|
+
* Maximum 128 characters as a practical bound.
|
|
5384
5503
|
* Hashed immediately by the service layer — never persisted in plaintext.
|
|
5385
5504
|
*/
|
|
5386
5505
|
newPassword: string;
|
|
@@ -5406,7 +5525,7 @@ declare class ResetPasswordDto {
|
|
|
5406
5525
|
* Validated against the stored tenant in the verifiedToken flow to prevent
|
|
5407
5526
|
* cross-tenant password reset attacks.
|
|
5408
5527
|
*/
|
|
5409
|
-
tenantId
|
|
5528
|
+
tenantId?: string;
|
|
5410
5529
|
}
|
|
5411
5530
|
|
|
5412
5531
|
/**
|
|
@@ -5432,7 +5551,7 @@ declare class VerifyEmailDto {
|
|
|
5432
5551
|
/**
|
|
5433
5552
|
* Tenant identifier that scopes the verification to a specific organization.
|
|
5434
5553
|
*/
|
|
5435
|
-
tenantId
|
|
5554
|
+
tenantId?: string;
|
|
5436
5555
|
}
|
|
5437
5556
|
|
|
5438
5557
|
/**
|
|
@@ -5460,7 +5579,7 @@ declare class VerifyOtpDto {
|
|
|
5460
5579
|
/**
|
|
5461
5580
|
* Tenant identifier that scopes the verification to a specific organization.
|
|
5462
5581
|
*/
|
|
5463
|
-
tenantId
|
|
5582
|
+
tenantId?: string;
|
|
5464
5583
|
}
|
|
5465
5584
|
|
|
5466
5585
|
/**
|
|
@@ -5636,6 +5755,7 @@ declare class PasswordService {
|
|
|
5636
5755
|
private readonly breachChecker;
|
|
5637
5756
|
private readonly logger;
|
|
5638
5757
|
private readonly N;
|
|
5758
|
+
private readonly minLength;
|
|
5639
5759
|
private readonly r;
|
|
5640
5760
|
private readonly p;
|
|
5641
5761
|
private readonly maxmem;
|
|
@@ -5652,6 +5772,43 @@ declare class PasswordService {
|
|
|
5652
5772
|
* // '$scrypt$ln=17,r=8,p=1$YmFzZTY0c2FsdA$…'
|
|
5653
5773
|
* ```
|
|
5654
5774
|
*/
|
|
5775
|
+
/**
|
|
5776
|
+
* The whole password policy, applied wherever a password is being *set*.
|
|
5777
|
+
*
|
|
5778
|
+
* One entry point so the four call sites — registration, reset, authenticated change and
|
|
5779
|
+
* invitation acceptance — cannot drift into applying different halves of it.
|
|
5780
|
+
*
|
|
5781
|
+
* Order matters: length first, because it is decided locally and for free, and the breach
|
|
5782
|
+
* check may reach a network corpus. A password refused for being short should not cost a
|
|
5783
|
+
* round trip, and should not be sent anywhere first.
|
|
5784
|
+
*
|
|
5785
|
+
* @param plain - The plaintext password the user is trying to set.
|
|
5786
|
+
* @param field - The request field to name in a length failure's `details`.
|
|
5787
|
+
* @throws {@link AuthException} with `VALIDATION` when it is too short, or
|
|
5788
|
+
* `PASSWORD_COMPROMISED` when the corpus knows it.
|
|
5789
|
+
*/
|
|
5790
|
+
assertAcceptable(plain: string, field: string): Promise<void>;
|
|
5791
|
+
/**
|
|
5792
|
+
* Rejects a password shorter than the configured minimum.
|
|
5793
|
+
*
|
|
5794
|
+
* The DTOs carry a structural `@MinLength(8)` — the lowest NIST SP 800-63B-4 permits under any
|
|
5795
|
+
* circumstance — and this is the deployment's policy on top of it, which is configurable and
|
|
5796
|
+
* defaults to 15 because that is what §3.1.1.1 requires of a single-factor password. The check
|
|
5797
|
+
* lives here rather than in a decorator because a decorator is evaluated when the class is
|
|
5798
|
+
* defined, before any configuration exists.
|
|
5799
|
+
*
|
|
5800
|
+
* It answers the same `auth.validation` code and the same `{ field, message }[]` details the
|
|
5801
|
+
* validation pipe produces for a length failure, so a client already handling a short password
|
|
5802
|
+
* sees no new shape and the shared error catalog gains no entry. The breach and
|
|
5803
|
+
* common-password screens run after: they remove passwords that are already *known*, which is
|
|
5804
|
+
* a different question from how many guesses the password is worth.
|
|
5805
|
+
*
|
|
5806
|
+
* @param plain - The plaintext password the user is trying to set.
|
|
5807
|
+
* @param field - The request field to name in `details`, so the message points at the input
|
|
5808
|
+
* the caller actually sent (`password` on registration, `newPassword` on a reset).
|
|
5809
|
+
* @throws {@link AuthException} with `VALIDATION` when the password is too short.
|
|
5810
|
+
*/
|
|
5811
|
+
assertLongEnough(plain: string, field: string): void;
|
|
5655
5812
|
/**
|
|
5656
5813
|
* Rejects a password that appears in a known-breach corpus.
|
|
5657
5814
|
*
|
|
@@ -5801,9 +5958,11 @@ declare class SessionService {
|
|
|
5801
5958
|
*
|
|
5802
5959
|
* Reads all `rt:`-prefixed members from `sess:{userId}`, fetches the
|
|
5803
5960
|
* corresponding `sd:{hash}` detail records, and marks the caller's own
|
|
5804
|
-
* session via `isCurrent`.
|
|
5805
|
-
*
|
|
5806
|
-
* and
|
|
5961
|
+
* session via `isCurrent`. A member whose detail record is missing, unreadable
|
|
5962
|
+
* or malformed is excluded from the result, and removed from the SET
|
|
5963
|
+
* asynchronously (fire-and-forget) only if its `rt:` key is also gone — see
|
|
5964
|
+
* {@link AuthRedisService.pruneDeadMembers} for why the detail record alone
|
|
5965
|
+
* does not settle it.
|
|
5807
5966
|
*
|
|
5808
5967
|
* Results are sorted by `createdAt` descending (newest session first).
|
|
5809
5968
|
*
|
|
@@ -6457,7 +6616,7 @@ declare class AuthService {
|
|
|
6457
6616
|
email: string;
|
|
6458
6617
|
password: string;
|
|
6459
6618
|
name: string;
|
|
6460
|
-
tenantId
|
|
6619
|
+
tenantId?: string;
|
|
6461
6620
|
}, req: Request): Promise<AuthResult>;
|
|
6462
6621
|
/**
|
|
6463
6622
|
* Authenticates a dashboard user with email and password.
|
|
@@ -6474,7 +6633,7 @@ declare class AuthService {
|
|
|
6474
6633
|
login(dto: {
|
|
6475
6634
|
email: string;
|
|
6476
6635
|
password: string;
|
|
6477
|
-
tenantId
|
|
6636
|
+
tenantId?: string;
|
|
6478
6637
|
}, req: Request): Promise<AuthResult | MfaChallengeResult>;
|
|
6479
6638
|
/**
|
|
6480
6639
|
* Logs out a dashboard user by revoking the access token and deleting the refresh session.
|
|
@@ -6601,7 +6760,7 @@ declare class AuthService {
|
|
|
6601
6760
|
* or the user does not exist (response shape is identical to prevent
|
|
6602
6761
|
* account enumeration via this endpoint).
|
|
6603
6762
|
*/
|
|
6604
|
-
verifyEmail(tenantId: string, email: string, otp: string, req: Request): Promise<void>;
|
|
6763
|
+
verifyEmail(tenantId: string | undefined, email: string, otp: string, req: Request): Promise<void>;
|
|
6605
6764
|
/**
|
|
6606
6765
|
* Resends an email verification OTP with an atomic cooldown.
|
|
6607
6766
|
*
|
|
@@ -6612,7 +6771,7 @@ declare class AuthService {
|
|
|
6612
6771
|
* @param tenantId - Tenant scope.
|
|
6613
6772
|
* @param email - The email address to re-send to (not validated — always succeeds).
|
|
6614
6773
|
*/
|
|
6615
|
-
resendVerificationEmail(tenantId: string, email: string, req: Request): Promise<void>;
|
|
6774
|
+
resendVerificationEmail(tenantId: string | undefined, email: string, req: Request): Promise<void>;
|
|
6616
6775
|
/**
|
|
6617
6776
|
* Clears an account's brute-force lockout so the next attempt is judged on its merits.
|
|
6618
6777
|
*
|
|
@@ -6758,7 +6917,9 @@ declare class ConfirmEmailChangeDto {
|
|
|
6758
6917
|
*
|
|
6759
6918
|
* **The current password is re-proved.** A stolen access token alone cannot move the recovery
|
|
6760
6919
|
* address — the thief has to already hold the credential that would let them take the account
|
|
6761
|
-
* anyway.
|
|
6920
|
+
* anyway. It is also why no session is revoked here: anyone who can complete this flow could
|
|
6921
|
+
* already sign in, so ending the caller's other sessions would cost the user their devices and
|
|
6922
|
+
* buy nothing. A password *change* does revoke, because there the factor itself moved.
|
|
6762
6923
|
*
|
|
6763
6924
|
* **The new address is proved before it is adopted.** A token goes to it and nowhere else, so
|
|
6764
6925
|
* a typo cannot lock the owner out of their own account and an attacker cannot point the
|
|
@@ -7189,6 +7350,45 @@ declare class MfaService {
|
|
|
7189
7350
|
* @throws `MFA_INVALID_CODE` if the submitted TOTP code is incorrect.
|
|
7190
7351
|
*/
|
|
7191
7352
|
disable(userId: string, code: string, ip: string, userAgent: string, context?: 'dashboard' | 'platform'): Promise<void>;
|
|
7353
|
+
/**
|
|
7354
|
+
* Removes a user's second factor without their TOTP code, for a support desk facing a user
|
|
7355
|
+
* who has lost their authenticator AND their recovery codes.
|
|
7356
|
+
*
|
|
7357
|
+
* Every self-service exit from MFA needs the factor itself: {@link disable} wants a valid
|
|
7358
|
+
* TOTP code, and the recovery codes want the codes. A user who has lost both is locked out
|
|
7359
|
+
* permanently, by the control that exists to protect them — ASVS v5 §6.1.1 asks for an
|
|
7360
|
+
* administrative path out for exactly that reason.
|
|
7361
|
+
*
|
|
7362
|
+
* **Authorising the caller is the consumer's job.** The library deliberately ships no route
|
|
7363
|
+
* for this, the same decision and for the same reason as {@link AuthService.unlockAccount}:
|
|
7364
|
+
* who may reset whom is a question only the host application can answer, and all 39 routes
|
|
7365
|
+
* this library does ship are scoped to the caller's own account.
|
|
7366
|
+
*
|
|
7367
|
+
* Idempotent: resetting an account that has no second factor is a no-op, so a support desk
|
|
7368
|
+
* retrying does not get an error for a job already done.
|
|
7369
|
+
*
|
|
7370
|
+
* Three things happen beyond clearing the record, and none of them are optional:
|
|
7371
|
+
*
|
|
7372
|
+
* - **Sessions are invalidated and the token epoch is bumped**, so access tokens carrying
|
|
7373
|
+
* `mfaVerified: true` die with the factor rather than outliving it.
|
|
7374
|
+
* - **The user is notified**, through the same channel {@link disable} uses. An
|
|
7375
|
+
* administrative reset that the account holder cannot see is an account-takeover path:
|
|
7376
|
+
* an attacker who reaches the support desk removes the second factor silently. The
|
|
7377
|
+
* notification is what makes it an event the owner can detect and dispute.
|
|
7378
|
+
* - **It is logged** under its own prefix, so an administrative removal is distinguishable
|
|
7379
|
+
* from a user-initiated one in the library's own log.
|
|
7380
|
+
*
|
|
7381
|
+
* The `afterMfaDisabled` hook fires too, so consumer-side alerting keeps working. It is not
|
|
7382
|
+
* given a separate hook: the consumer is the one calling this method, so they already know
|
|
7383
|
+
* an administrative reset happened — the hook exists to tell them about the paths they do
|
|
7384
|
+
* not initiate.
|
|
7385
|
+
*
|
|
7386
|
+
* @param userId - Internal ID of the user whose second factor is being removed.
|
|
7387
|
+
* @param context - Which identity plane the user belongs to: `'dashboard'` (default) or
|
|
7388
|
+
* `'platform'`. Must match the plane the account lives in, or the lookup misses.
|
|
7389
|
+
* @throws `TOKEN_INVALID` if no user with that ID exists in the given plane.
|
|
7390
|
+
*/
|
|
7391
|
+
resetMfa(userId: string, context?: 'dashboard' | 'platform'): Promise<void>;
|
|
7192
7392
|
/**
|
|
7193
7393
|
* Regenerates the user's MFA recovery codes after verifying a current TOTP code.
|
|
7194
7394
|
*
|
|
@@ -7921,7 +8121,9 @@ declare class OAuthService {
|
|
|
7921
8121
|
* Sequence:
|
|
7922
8122
|
* 1. Validates the `provider` format and resolves the named plugin.
|
|
7923
8123
|
* 2. Generates a 32-byte (64 hex char) cryptographically random state nonce.
|
|
7924
|
-
* 3. Stores `os:{sha256(state)} → { tenantId }` in Redis with a
|
|
8124
|
+
* 3. Stores `os:{sha256(state)} → { provider, tenantId, codeVerifier }` in Redis with a
|
|
8125
|
+
* 10-minute TTL. `provider` is what the callback checks itself against (RFC 9700
|
|
8126
|
+
* mix-up defence).
|
|
7925
8127
|
* 4. Constructs the provider's authorization URL via `plugin.authorizeUrl(state)`.
|
|
7926
8128
|
* 5. Issues a 302 redirect via the Express `res` object.
|
|
7927
8129
|
*
|
|
@@ -7934,7 +8136,7 @@ declare class OAuthService {
|
|
|
7934
8136
|
* @param res - Express response in passthrough mode (used for the 302 redirect).
|
|
7935
8137
|
* @throws `AuthException(OAUTH_FAILED)` when no plugin is registered for `provider`.
|
|
7936
8138
|
*/
|
|
7937
|
-
initiateOAuth(provider: string, tenantId: string, req: Request, res: Response): Promise<void>;
|
|
8139
|
+
initiateOAuth(provider: string, tenantId: string | undefined, req: Request, res: Response): Promise<void>;
|
|
7938
8140
|
/**
|
|
7939
8141
|
* Processes the OAuth provider callback and issues auth tokens.
|
|
7940
8142
|
*
|