@bymax-one/nest-auth 1.4.13 → 1.4.15
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 +75 -1
- package/README.md +29 -1
- package/dist/nextjs/index.d.cts +3 -0
- package/dist/nextjs/index.d.ts +3 -0
- package/dist/server/index.cjs +108 -37
- package/dist/server/index.d.cts +38 -1
- package/dist/server/index.d.ts +38 -1
- package/dist/server/index.mjs +108 -37
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -18,6 +18,78 @@ what moves, and that note is the compatibility contract until strict SemVer begi
|
|
|
18
18
|
|
|
19
19
|
## [Unreleased]
|
|
20
20
|
|
|
21
|
+
## [1.4.15] - 2026-11-01
|
|
22
|
+
|
|
23
|
+
### Apply to a derived backend
|
|
24
|
+
|
|
25
|
+
- **`POST /password/forgot-password` and `POST /password/resend-otp` now answer `200` with an
|
|
26
|
+
empty JSON object, `{}`, where they answered `200` with no body.** The status and the
|
|
27
|
+
anti-enumeration behaviour are unchanged, and the body is the same for a known and an unknown
|
|
28
|
+
account. The wire contract now pins it. A client that asserted an empty body must accept JSON;
|
|
29
|
+
the bundled client discards the body and is unaffected.
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- **`POST /password/change` refuses an empty `refreshToken` and accepts a long one.** The field is
|
|
34
|
+
the caller's own refresh token, sent in the body under bearer delivery. It was capped at 512
|
|
35
|
+
characters and an empty string passed validation, so a present-but-empty value was read as "no
|
|
36
|
+
token" and the request silently degraded. It is now held to the wire contract's opaque-token
|
|
37
|
+
bound: 1 to 2048 characters, answered `400 auth.validation` outside it. An absent field is
|
|
38
|
+
unchanged.
|
|
39
|
+
- **`registerAsync` with `imports` and `inject` from a non-global module failed at boot.** The
|
|
40
|
+
options factory was run a second time to configure the internal JWT registration, and that
|
|
41
|
+
registration was given `inject` but not `imports`, so Nest could not resolve the injected
|
|
42
|
+
provider. It worked only
|
|
43
|
+
when the module providing the injected token, typically `ConfigModule`, was global. The internal
|
|
44
|
+
registration now receives the same `imports`.
|
|
45
|
+
|
|
46
|
+
### Documentation
|
|
47
|
+
|
|
48
|
+
- **The Quick Start now runs as written.** A test executes its repository, email provider,
|
|
49
|
+
module, `main.ts` and controller blocks in a real application. Three gaps it found are closed:
|
|
50
|
+
the module block did not bind the email provider the previous step told the reader to bind, so a
|
|
51
|
+
verification code never reached the reader's mailer; it did not say which of the modules it
|
|
52
|
+
uses are the reader's own; and `tokenDelivery: 'cookie'` needs `cookie-parser` mounted, without
|
|
53
|
+
which a signed-in user is answered `401 auth.token_invalid` on every protected route.
|
|
54
|
+
|
|
55
|
+
## [1.4.14] - 2026-11-01
|
|
56
|
+
|
|
57
|
+
### Apply to a derived backend
|
|
58
|
+
|
|
59
|
+
- **A dashboard MFA temp token presented at `POST /platform/mfa/challenge` is refused before
|
|
60
|
+
anything is spent.** The route answered `401 auth.platform_auth_required` as documented, but only
|
|
61
|
+
after the challenge had run: it consumed the token, burned the TOTP code, stored a dashboard
|
|
62
|
+
session whose refresh token nobody received, stamped the last login and fired the login hooks.
|
|
63
|
+
That orphan session counted against the per-user session limit and could evict a real one, the
|
|
64
|
+
hooks reported a login that never answered, and the user had to start over because the token was
|
|
65
|
+
spent. The plane is now read from the token first, so the refusal spends nothing, and the same
|
|
66
|
+
token and code still complete at the dashboard challenge route. A refused attempt does not count toward the
|
|
67
|
+
brute-force counter either. The error code is unchanged, and the dashboard route keeps serving
|
|
68
|
+
both planes. A handler that relied on `afterLogin` or `onNewSession` firing for such a request
|
|
69
|
+
no longer sees it.
|
|
70
|
+
- **`MfaService` has a new public member, `challengePlatformOnly(mfaTempToken, code, ip,
|
|
71
|
+
userAgent)`.** It is the challenge for an entry point that serves the platform plane only: it
|
|
72
|
+
refuses a non-platform plane with `PLATFORM_AUTH_REQUIRED` before any side effect, then runs the
|
|
73
|
+
challenge and returns a `PlatformAuthResult`. A host that mounts its own platform challenge route
|
|
74
|
+
can call it to get the same refusal. `challenge()` is unchanged.
|
|
75
|
+
- **Logout fails when it cannot revoke.** `POST /auth/logout` and `POST /platform/logout` used to
|
|
76
|
+
answer success even when the store refused one of the writes that revoke the caller's
|
|
77
|
+
credentials. Every credential write is now attempted, whatever the earlier ones did, and the first
|
|
78
|
+
failure is raised once the rest have run. The route answers a 5xx instead of `204` and does not
|
|
79
|
+
clear the caller's cookies, so the client can retry. On the platform route, a session's index entry
|
|
80
|
+
is removed only after the credential it names is deleted, so a later sign-out-everywhere can still
|
|
81
|
+
find a session that logout could not end. A token that cannot be verified (absent, expired, forged) still logs out as
|
|
82
|
+
before, and a store that cannot answer the initial read still fails closed. A host that treated a
|
|
83
|
+
`204` from logout as proof of revocation now sees a 5xx during a store outage. The logout hook
|
|
84
|
+
(`afterLogout`, `afterPlatformLogout`) is fired by the call that finds the session record: when an
|
|
85
|
+
earlier attempt deleted the record and failed another write, it answered a 5xx without the hook,
|
|
86
|
+
and the retry that completes the logout finds no record and does not fire it.
|
|
87
|
+
|
|
88
|
+
### Fixed
|
|
89
|
+
|
|
90
|
+
- **A refused cross-plane MFA challenge left an orphan session behind.** See the Apply note above.
|
|
91
|
+
- **Logout reported success when a revocation write was refused.** See the Apply note above.
|
|
92
|
+
|
|
21
93
|
## [1.4.13] - 2026-11-01
|
|
22
94
|
|
|
23
95
|
### Apply to a derived backend
|
|
@@ -4221,7 +4293,9 @@ ever installable.
|
|
|
4221
4293
|
- Phase 4 password-reset tests cover: both `token` and `otp` flows, mutual exclusivity validation, `verifiedToken` exchange, resend cooldown, anti-enumeration (no error on unknown email), and session invalidation on reset
|
|
4222
4294
|
- Phase 5 tests cover: platform login with MFA path and brute-force lockout, `JwtPlatformGuard` cross-context rejection, `PlatformRolesGuard` hierarchy enforcement, OAuth CSRF state lifecycle, `onOAuthLogin` hook resolution strategies, and invitation role-authorization + acceptance single-use enforcement
|
|
4223
4295
|
|
|
4224
|
-
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.
|
|
4296
|
+
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.4.15...HEAD
|
|
4297
|
+
[1.4.15]: https://github.com/bymaxone/nest-auth/compare/v1.4.14...v1.4.15
|
|
4298
|
+
[1.4.14]: https://github.com/bymaxone/nest-auth/compare/v1.4.13...v1.4.14
|
|
4225
4299
|
[1.4.13]: https://github.com/bymaxone/nest-auth/compare/v1.4.12...v1.4.13
|
|
4226
4300
|
[1.4.12]: https://github.com/bymaxone/nest-auth/compare/v1.4.11...v1.4.12
|
|
4227
4301
|
[1.4.11]: https://github.com/bymaxone/nest-auth/compare/v1.4.10...v1.4.11
|
package/README.md
CHANGED
|
@@ -143,6 +143,9 @@ yarn add @bymax-one/nest-auth
|
|
|
143
143
|
# Server subpath (required)
|
|
144
144
|
pnpm add @nestjs/common @nestjs/core @nestjs/jwt @nestjs/throttler @nestjs/websockets ioredis class-validator class-transformer reflect-metadata
|
|
145
145
|
|
|
146
|
+
# Also needed with `tokenDelivery: 'cookie'` or `'both'` (see step 4): the library reads `req.cookies`
|
|
147
|
+
pnpm add cookie-parser
|
|
148
|
+
|
|
146
149
|
# React subpath (optional)
|
|
147
150
|
pnpm add react
|
|
148
151
|
|
|
@@ -524,9 +527,14 @@ import { Module } from '@nestjs/common'
|
|
|
524
527
|
import {
|
|
525
528
|
BymaxAuthModule,
|
|
526
529
|
BYMAX_AUTH_USER_REPOSITORY,
|
|
527
|
-
BYMAX_AUTH_REDIS_CLIENT
|
|
530
|
+
BYMAX_AUTH_REDIS_CLIENT,
|
|
531
|
+
BYMAX_AUTH_EMAIL_PROVIDER
|
|
528
532
|
} from '@bymax-one/nest-auth'
|
|
529
533
|
|
|
534
|
+
// Yours, not this library's: `ConfigModule` and `ConfigService` come from `@nestjs/config`,
|
|
535
|
+
// `DatabaseModule` is your module exporting the database client the repository uses, and
|
|
536
|
+
// `RedisModule` is your module exporting `RedisService`, whose `client` is an `ioredis` instance.
|
|
537
|
+
|
|
530
538
|
@Module({
|
|
531
539
|
imports: [
|
|
532
540
|
BymaxAuthModule.registerAsync({
|
|
@@ -556,6 +564,10 @@ import {
|
|
|
556
564
|
provide: BYMAX_AUTH_USER_REPOSITORY,
|
|
557
565
|
useClass: PrismaUserRepository
|
|
558
566
|
},
|
|
567
|
+
{
|
|
568
|
+
provide: BYMAX_AUTH_EMAIL_PROVIDER,
|
|
569
|
+
useClass: ResendEmailProvider
|
|
570
|
+
},
|
|
559
571
|
{
|
|
560
572
|
provide: BYMAX_AUTH_REDIS_CLIENT,
|
|
561
573
|
useFactory: (redis: RedisService) => redis.client,
|
|
@@ -568,6 +580,22 @@ import {
|
|
|
568
580
|
export class AppModule {}
|
|
569
581
|
```
|
|
570
582
|
|
|
583
|
+
With `tokenDelivery: 'cookie'` (or `'both'`) the library reads the credential from `req.cookies`, and it takes no dependency on a parser, so mount one yourself. Without it a correctly signed-in user is answered `401 auth.token_invalid` on every protected route.
|
|
584
|
+
|
|
585
|
+
```typescript
|
|
586
|
+
// main.ts
|
|
587
|
+
import { NestFactory } from '@nestjs/core'
|
|
588
|
+
import cookieParser from 'cookie-parser'
|
|
589
|
+
import { AppModule } from './app.module'
|
|
590
|
+
|
|
591
|
+
async function bootstrap() {
|
|
592
|
+
const app = await NestFactory.create(AppModule)
|
|
593
|
+
app.use(cookieParser())
|
|
594
|
+
await app.listen(3000)
|
|
595
|
+
}
|
|
596
|
+
bootstrap()
|
|
597
|
+
```
|
|
598
|
+
|
|
571
599
|
### 5. Protect Routes
|
|
572
600
|
|
|
573
601
|
```typescript
|
package/dist/nextjs/index.d.cts
CHANGED
|
@@ -1037,6 +1037,9 @@ declare const CLIENT_REFRESH_ROUTE: "/api/auth/client-refresh";
|
|
|
1037
1037
|
* A user who pressed "logout" MUST end up logged out of the browser
|
|
1038
1038
|
* session even if the upstream is unreachable — otherwise a network
|
|
1039
1039
|
* glitch leaves them with cookies they thought they had invalidated.
|
|
1040
|
+
* The upstream's answer is not surfaced to the caller, so a logout the
|
|
1041
|
+
* server could not complete (it answers a 5xx when the store refuses a
|
|
1042
|
+
* revocation write) looks the same as one that did.
|
|
1040
1043
|
*
|
|
1041
1044
|
* Two response modes are supported, expressed as a discriminated
|
|
1042
1045
|
* union on {@link LogoutHandlerConfig}:
|
package/dist/nextjs/index.d.ts
CHANGED
|
@@ -1037,6 +1037,9 @@ declare const CLIENT_REFRESH_ROUTE: "/api/auth/client-refresh";
|
|
|
1037
1037
|
* A user who pressed "logout" MUST end up logged out of the browser
|
|
1038
1038
|
* session even if the upstream is unreachable — otherwise a network
|
|
1039
1039
|
* glitch leaves them with cookies they thought they had invalidated.
|
|
1040
|
+
* The upstream's answer is not surfaced to the caller, so a logout the
|
|
1041
|
+
* server could not complete (it answers a 5xx when the store refuses a
|
|
1042
|
+
* revocation write) looks the same as one that did.
|
|
1040
1043
|
*
|
|
1041
1044
|
* Two response modes are supported, expressed as a discriminated
|
|
1042
1045
|
* union on {@link LogoutHandlerConfig}:
|
package/dist/server/index.cjs
CHANGED
|
@@ -6482,6 +6482,32 @@ function safeLogLine(line, secrets) {
|
|
|
6482
6482
|
}
|
|
6483
6483
|
__name(safeLogLine, "safeLogLine");
|
|
6484
6484
|
|
|
6485
|
+
// src/server/utils/settle-writes.ts
|
|
6486
|
+
async function settleWrites(writes) {
|
|
6487
|
+
const failures = [];
|
|
6488
|
+
for (const write of writes) {
|
|
6489
|
+
try {
|
|
6490
|
+
await write();
|
|
6491
|
+
} catch (err) {
|
|
6492
|
+
failures.push(err);
|
|
6493
|
+
}
|
|
6494
|
+
}
|
|
6495
|
+
return failures;
|
|
6496
|
+
}
|
|
6497
|
+
__name(settleWrites, "settleWrites");
|
|
6498
|
+
function raiseFirst(failures) {
|
|
6499
|
+
const [first] = failures;
|
|
6500
|
+
if (failures.length > 0) throw first;
|
|
6501
|
+
}
|
|
6502
|
+
__name(raiseFirst, "raiseFirst");
|
|
6503
|
+
function settleAfter(first, followUps) {
|
|
6504
|
+
return async () => {
|
|
6505
|
+
await first();
|
|
6506
|
+
raiseFirst(await settleWrites(followUps));
|
|
6507
|
+
};
|
|
6508
|
+
}
|
|
6509
|
+
__name(settleAfter, "settleAfter");
|
|
6510
|
+
|
|
6485
6511
|
// src/server/utils/tenant-scoped.ts
|
|
6486
6512
|
function tenantScoped(user, tenantId) {
|
|
6487
6513
|
if (user === null) return null;
|
|
@@ -6886,17 +6912,22 @@ exports.AuthService = class _AuthService {
|
|
|
6886
6912
|
const sessionHash = sha256(rawRefreshToken);
|
|
6887
6913
|
const { userId, tenantId } = await this.redis.readSessionOwner(`rt:${sessionHash}`);
|
|
6888
6914
|
this.logger.log(`logout: userId=${logSafe(userId || "(no live session)")}`);
|
|
6915
|
+
let blacklist = [];
|
|
6889
6916
|
try {
|
|
6890
6917
|
const payload = this.tokenManager.verifyIgnoringExpiry(accessToken);
|
|
6891
|
-
const
|
|
6892
|
-
const remainingTtl = payload.exp - now;
|
|
6918
|
+
const remainingTtl = payload.exp - Math.floor(Date.now() / 1e3);
|
|
6893
6919
|
if (remainingTtl > 0) {
|
|
6894
|
-
|
|
6920
|
+
blacklist = [
|
|
6921
|
+
() => this.redis.set(`rv:${payload.jti}`, "1", remainingTtl)
|
|
6922
|
+
];
|
|
6895
6923
|
}
|
|
6896
6924
|
} catch {
|
|
6897
6925
|
}
|
|
6898
|
-
await
|
|
6899
|
-
|
|
6926
|
+
const failures = await settleWrites([
|
|
6927
|
+
...blacklist,
|
|
6928
|
+
() => this.redis.del(`rt:${sessionHash}`),
|
|
6929
|
+
() => this.redis.del(`rp:${sessionHash}`)
|
|
6930
|
+
]);
|
|
6900
6931
|
if (this.options.sessions.enabled && userId && tenantId !== void 0) {
|
|
6901
6932
|
await this.sessionService.revokeSession({
|
|
6902
6933
|
userId,
|
|
@@ -6909,6 +6940,7 @@ exports.AuthService = class _AuthService {
|
|
|
6909
6940
|
}
|
|
6910
6941
|
});
|
|
6911
6942
|
}
|
|
6943
|
+
raiseFirst(failures);
|
|
6912
6944
|
this.emitLogout(userId, tenantId);
|
|
6913
6945
|
return userId;
|
|
6914
6946
|
}
|
|
@@ -7796,8 +7828,9 @@ var AuthController = class {
|
|
|
7796
7828
|
* token is the credential that authorizes this, and the service reads the session's owner
|
|
7797
7829
|
* from the stored record rather than from the access token's claims.
|
|
7798
7830
|
*
|
|
7799
|
-
*
|
|
7800
|
-
* cleared and learns nothing about whether a session existed.
|
|
7831
|
+
* A caller presenting a token for an already-gone session gets a 204 with their cookies
|
|
7832
|
+
* cleared and learns nothing about whether a session existed. When the store refuses a
|
|
7833
|
+
* revocation write the route answers a 5xx and leaves the cookies in place, so the client can retry.
|
|
7801
7834
|
*
|
|
7802
7835
|
* @param req - Incoming request (used to extract tokens).
|
|
7803
7836
|
* @param res - Response object (passthrough — used to clear cookies).
|
|
@@ -10429,6 +10462,37 @@ exports.MfaService = class _MfaService {
|
|
|
10429
10462
|
}
|
|
10430
10463
|
return result;
|
|
10431
10464
|
}
|
|
10465
|
+
/**
|
|
10466
|
+
* The challenge for an entry point that serves the platform plane only.
|
|
10467
|
+
*
|
|
10468
|
+
* Reads the plane from the temp token first and refuses a dashboard token with
|
|
10469
|
+
* `PLATFORM_AUTH_REQUIRED` before anything is spent. {@link MfaService.challenge} consumes the
|
|
10470
|
+
* token, burns the TOTP code, stores a session, stamps the last login and fires the hooks, so
|
|
10471
|
+
* refusing after it leaves an orphan session nobody holds a token for. The first verification only
|
|
10472
|
+
* reads: it touches neither the brute-force counter nor the TOTP anti-replay key. The challenge
|
|
10473
|
+
* verifies the token again, and the plane is a signed claim, so both reads see the same one.
|
|
10474
|
+
*
|
|
10475
|
+
* @param mfaTempToken - Short-lived MFA challenge JWT issued at platform login.
|
|
10476
|
+
* @param code - 6-digit TOTP code or `dddd-dddd-dddd` recovery code.
|
|
10477
|
+
* @param ip - Client IP address for session audit.
|
|
10478
|
+
* @param userAgent - User-Agent header for session description.
|
|
10479
|
+
* @returns The platform auth result.
|
|
10480
|
+
* @throws `PLATFORM_AUTH_REQUIRED` if the token is for the dashboard plane.
|
|
10481
|
+
* @throws `MFA_TEMP_TOKEN_INVALID` if the token is invalid or already consumed.
|
|
10482
|
+
* @throws `ACCOUNT_LOCKED` if the brute-force threshold has been reached.
|
|
10483
|
+
* @throws `MFA_INVALID_CODE` if the submitted code is incorrect.
|
|
10484
|
+
*/
|
|
10485
|
+
async challengePlatformOnly(mfaTempToken, code, ip, userAgent) {
|
|
10486
|
+
const { context } = await this.tokenManager.verifyMfaTempToken(mfaTempToken);
|
|
10487
|
+
if (context !== "platform") {
|
|
10488
|
+
throw new AuthException(AUTH_ERROR_CODES.PLATFORM_AUTH_REQUIRED);
|
|
10489
|
+
}
|
|
10490
|
+
const result = await this.challenge(mfaTempToken, code, ip, userAgent);
|
|
10491
|
+
if (!("admin" in result)) {
|
|
10492
|
+
throw new AuthException(AUTH_ERROR_CODES.PLATFORM_AUTH_REQUIRED);
|
|
10493
|
+
}
|
|
10494
|
+
return result;
|
|
10495
|
+
}
|
|
10432
10496
|
// ---------------------------------------------------------------------------
|
|
10433
10497
|
// disable — TOTP-verified MFA deactivation with session invalidation
|
|
10434
10498
|
// ---------------------------------------------------------------------------
|
|
@@ -11325,6 +11389,9 @@ var ChangePasswordDto = class {
|
|
|
11325
11389
|
* `whitelist: true`, which STRIPPED the property before the controller's own pipe could refuse
|
|
11326
11390
|
* it — so the suite exercised a request production never sees. Optional, because under cookie
|
|
11327
11391
|
* delivery the credential arrives in the cookie and no body field exists to declare.
|
|
11392
|
+
*
|
|
11393
|
+
* A present value is held to the contract's opaque-token bound (1 to 2048 characters), so an
|
|
11394
|
+
* empty string is refused instead of being read as "no token".
|
|
11328
11395
|
*/
|
|
11329
11396
|
refreshToken;
|
|
11330
11397
|
};
|
|
@@ -11343,7 +11410,8 @@ _ts_decorate38([
|
|
|
11343
11410
|
_ts_decorate38([
|
|
11344
11411
|
classValidator.IsOptional(),
|
|
11345
11412
|
classValidator.IsString(),
|
|
11346
|
-
classValidator.
|
|
11413
|
+
classValidator.IsNotEmpty(),
|
|
11414
|
+
classValidator.MaxLength(2048),
|
|
11347
11415
|
_ts_metadata37("design:type", String)
|
|
11348
11416
|
], ChangePasswordDto.prototype, "refreshToken", void 0);
|
|
11349
11417
|
function _ts_decorate39(decorators, target, key, desc) {
|
|
@@ -12292,12 +12360,15 @@ var PasswordResetController = class {
|
|
|
12292
12360
|
* Initiates a password reset for the given email address.
|
|
12293
12361
|
*
|
|
12294
12362
|
* Sends a reset token or OTP to the user's email if the account exists and
|
|
12295
|
-
* is eligible. Always returns `200 OK` regardless of outcome
|
|
12363
|
+
* is eligible. Always returns `200 OK` with an empty JSON object regardless of outcome
|
|
12364
|
+
* (anti-enumeration; the body is pinned by the wire contract).
|
|
12296
12365
|
*
|
|
12297
12366
|
* @param dto - Validated DTO with `email` and `tenantId`.
|
|
12367
|
+
* @returns An empty object.
|
|
12298
12368
|
*/
|
|
12299
12369
|
async forgotPassword(dto, req) {
|
|
12300
12370
|
await this.passwordResetService.initiateReset(dto, req);
|
|
12371
|
+
return {};
|
|
12301
12372
|
}
|
|
12302
12373
|
// ---------------------------------------------------------------------------
|
|
12303
12374
|
// POST /password/reset-password
|
|
@@ -12377,12 +12448,15 @@ var PasswordResetController = class {
|
|
|
12377
12448
|
* Re-sends the password-reset OTP for the given email address.
|
|
12378
12449
|
*
|
|
12379
12450
|
* Subject to a 60-second atomic cooldown per `(tenantId, email)` pair.
|
|
12380
|
-
* Always returns `200 OK` regardless of outcome (anti-enumeration
|
|
12451
|
+
* Always returns `200 OK` with an empty JSON object regardless of outcome (anti-enumeration;
|
|
12452
|
+
* the body is pinned by the wire contract).
|
|
12381
12453
|
*
|
|
12382
12454
|
* @param dto - Validated DTO with `email` and `tenantId`.
|
|
12455
|
+
* @returns An empty object.
|
|
12383
12456
|
*/
|
|
12384
12457
|
async resendOtp(dto, req) {
|
|
12385
12458
|
await this.passwordResetService.resendOtp(dto, req);
|
|
12459
|
+
return {};
|
|
12386
12460
|
}
|
|
12387
12461
|
};
|
|
12388
12462
|
_ts_decorate44([
|
|
@@ -12750,22 +12824,30 @@ exports.PlatformAuthService = class _PlatformAuthService {
|
|
|
12750
12824
|
const tokenHash = sha256(rawRefreshToken);
|
|
12751
12825
|
const { userId } = await this.redis.readSessionOwner(`prt:${tokenHash}`);
|
|
12752
12826
|
this.logger.log(`logout: adminId=${logSafe(userId || "(no live session)")}`);
|
|
12827
|
+
let blacklist = [];
|
|
12753
12828
|
try {
|
|
12754
12829
|
const payload = this.tokenManager.verifyPlatformIgnoringExpiry(accessToken);
|
|
12755
12830
|
const remainingTtl = payload.exp - Math.floor(Date.now() / 1e3);
|
|
12756
12831
|
if (remainingTtl > 0) {
|
|
12757
|
-
|
|
12832
|
+
blacklist = [
|
|
12833
|
+
() => this.redis.set(`rv:${payload.jti}`, "1", remainingTtl)
|
|
12834
|
+
];
|
|
12758
12835
|
}
|
|
12759
12836
|
} catch {
|
|
12760
12837
|
}
|
|
12761
|
-
|
|
12762
|
-
|
|
12763
|
-
|
|
12764
|
-
|
|
12765
|
-
|
|
12766
|
-
|
|
12767
|
-
|
|
12768
|
-
|
|
12838
|
+
const index = userId ? sessionIndexKey("platform", userId, this.options.hmacKey, void 0) : "";
|
|
12839
|
+
const prune = /* @__PURE__ */ __name((member) => index === "" ? [] : [
|
|
12840
|
+
() => this.redis.srem(index, member)
|
|
12841
|
+
], "prune");
|
|
12842
|
+
const failures = await settleWrites([
|
|
12843
|
+
...blacklist,
|
|
12844
|
+
settleAfter(() => this.redis.del("prt:" + tokenHash), [
|
|
12845
|
+
...prune("prt:" + tokenHash),
|
|
12846
|
+
() => this.redis.del("psd:" + tokenHash)
|
|
12847
|
+
]),
|
|
12848
|
+
settleAfter(() => this.redis.del("prp:" + tokenHash), prune("prp:" + tokenHash))
|
|
12849
|
+
]);
|
|
12850
|
+
raiseFirst(failures);
|
|
12769
12851
|
this.emitPlatformLogout(userId);
|
|
12770
12852
|
return userId;
|
|
12771
12853
|
}
|
|
@@ -12955,10 +13037,6 @@ function _ts_param27(paramIndex, decorator) {
|
|
|
12955
13037
|
};
|
|
12956
13038
|
}
|
|
12957
13039
|
__name(_ts_param27, "_ts_param");
|
|
12958
|
-
function isPlatformResult2(result) {
|
|
12959
|
-
return "admin" in result;
|
|
12960
|
-
}
|
|
12961
|
-
__name(isPlatformResult2, "isPlatformResult");
|
|
12962
13040
|
function isMfaChallenge2(result) {
|
|
12963
13041
|
return "mfaRequired" in result && result.mfaRequired === true;
|
|
12964
13042
|
}
|
|
@@ -13004,14 +13082,8 @@ var PlatformAuthController = class {
|
|
|
13004
13082
|
* Completes a platform administrator MFA challenge.
|
|
13005
13083
|
*
|
|
13006
13084
|
* Exchanges a short-lived `mfaTempToken` (issued at login) and a TOTP code for
|
|
13007
|
-
* full platform auth tokens
|
|
13008
|
-
*
|
|
13009
|
-
*
|
|
13010
|
-
* Explicitly guards against cross-context token abuse: if a dashboard-context MFA
|
|
13011
|
-
* temp token is submitted here, the response will contain an `AuthResult` (not a
|
|
13012
|
-
* `PlatformAuthResult`). The `isPlatformResult` check detects this and throws
|
|
13013
|
-
* `PLATFORM_AUTH_REQUIRED` rather than silently returning a dashboard-scoped token
|
|
13014
|
-
* as if it were a platform auth response.
|
|
13085
|
+
* full platform auth tokens through {@link MfaService.challengePlatformOnly}, which refuses a
|
|
13086
|
+
* dashboard-context token before anything is spent.
|
|
13015
13087
|
*
|
|
13016
13088
|
* @param dto - Contains the MFA temp token and the TOTP (or recovery) code.
|
|
13017
13089
|
* @param req - Incoming request (provides IP and User-Agent for brute-force tracking).
|
|
@@ -13023,11 +13095,7 @@ var PlatformAuthController = class {
|
|
|
13023
13095
|
if (dto.mfaTempToken === void 0 || dto.mfaTempToken.length === 0) {
|
|
13024
13096
|
throw new AuthException(AUTH_ERROR_CODES.MFA_TEMP_TOKEN_INVALID);
|
|
13025
13097
|
}
|
|
13026
|
-
|
|
13027
|
-
if (!isPlatformResult2(result)) {
|
|
13028
|
-
throw new AuthException(AUTH_ERROR_CODES.PLATFORM_AUTH_REQUIRED);
|
|
13029
|
-
}
|
|
13030
|
-
return this.tokenDelivery.deliverPlatformAuthResponse(result);
|
|
13098
|
+
return this.tokenDelivery.deliverPlatformAuthResponse(await this.mfaService.challengePlatformOnly(dto.mfaTempToken, dto.code, ip, userAgent));
|
|
13031
13099
|
}
|
|
13032
13100
|
// ---------------------------------------------------------------------------
|
|
13033
13101
|
// GET /platform/me
|
|
@@ -15425,7 +15493,8 @@ var REQUEST_SCHEMAS = {
|
|
|
15425
15493
|
},
|
|
15426
15494
|
"refreshToken": {
|
|
15427
15495
|
"type": "string",
|
|
15428
|
-
"maxLength":
|
|
15496
|
+
"maxLength": 2048,
|
|
15497
|
+
"minLength": 1
|
|
15429
15498
|
}
|
|
15430
15499
|
},
|
|
15431
15500
|
"required": [
|
|
@@ -17463,6 +17532,8 @@ exports.BymaxAuthModule = class _BymaxAuthModule {
|
|
|
17463
17532
|
// in the BYMAX_AUTH_OPTIONS provider above.
|
|
17464
17533
|
// expiresIn is omitted — TokenManagerService sets it per-call via accessSignOptions().
|
|
17465
17534
|
jwt.JwtModule.registerAsync({
|
|
17535
|
+
// The factory runs here too, so it needs the modules the consumer's `inject` tokens come from.
|
|
17536
|
+
imports: options.imports ?? [],
|
|
17466
17537
|
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
17467
17538
|
const userOptions = await options.useFactory(...args);
|
|
17468
17539
|
return {
|
package/dist/server/index.d.cts
CHANGED
|
@@ -3112,6 +3112,11 @@ interface IAuthHooks {
|
|
|
3112
3112
|
* Use this hook to clean up session-related state, emit audit events, or
|
|
3113
3113
|
* notify downstream services.
|
|
3114
3114
|
*
|
|
3115
|
+
* Fired by the call that finds the session record and names its owner. If an earlier attempt
|
|
3116
|
+
* deleted the record but failed another revocation write, it answered a 5xx without this hook,
|
|
3117
|
+
* and the retry that completes the logout finds no record, so it names nobody and does not fire
|
|
3118
|
+
* it: that logout is never reported here.
|
|
3119
|
+
*
|
|
3115
3120
|
* @param userId - The internal ID of the user who logged out.
|
|
3116
3121
|
* @param context - Request metadata (IP, user agent, sanitized headers).
|
|
3117
3122
|
*/
|
|
@@ -3129,6 +3134,10 @@ interface IAuthHooks {
|
|
|
3129
3134
|
* the access token stays presentable until it expires, and the session's removal is unobserved.
|
|
3130
3135
|
* That matters most for a live platform stream, which has no other signal to close on.
|
|
3131
3136
|
*
|
|
3137
|
+
* It is fired by the call that finds the session record and names its owner. If an earlier
|
|
3138
|
+
* attempt deleted the record but failed another revocation write, it answered a 5xx without this
|
|
3139
|
+
* hook, and the retry that completes the logout finds no record and does not fire it.
|
|
3140
|
+
*
|
|
3132
3141
|
* @param userId - The internal ID of the administrator who logged out.
|
|
3133
3142
|
* @param context - Request metadata; `plane` is `'platform'` and there is no tenant.
|
|
3134
3143
|
*/
|
|
@@ -4560,7 +4569,11 @@ declare const WS_TICKET_TTL_SECONDS = 30;
|
|
|
4560
4569
|
interface WsTicketSnapshot {
|
|
4561
4570
|
/** The subject — the internal user id. */
|
|
4562
4571
|
sub: string;
|
|
4563
|
-
/**
|
|
4572
|
+
/**
|
|
4573
|
+
* The tenant scope. Optional because the shared `wst:` record can be written by another
|
|
4574
|
+
* backend without one; this library always sets it, and the WebSocket guard refuses a
|
|
4575
|
+
* snapshot that lacks it.
|
|
4576
|
+
*/
|
|
4564
4577
|
tenantId?: string;
|
|
4565
4578
|
/** The user's role at mint time. */
|
|
4566
4579
|
role: string;
|
|
@@ -6798,6 +6811,9 @@ declare class ChangePasswordDto {
|
|
|
6798
6811
|
* `whitelist: true`, which STRIPPED the property before the controller's own pipe could refuse
|
|
6799
6812
|
* it — so the suite exercised a request production never sees. Optional, because under cookie
|
|
6800
6813
|
* delivery the credential arrives in the cookie and no body field exists to declare.
|
|
6814
|
+
*
|
|
6815
|
+
* A present value is held to the contract's opaque-token bound (1 to 2048 characters), so an
|
|
6816
|
+
* empty string is refused instead of being read as "no token".
|
|
6801
6817
|
*/
|
|
6802
6818
|
refreshToken?: string;
|
|
6803
6819
|
}
|
|
@@ -8996,6 +9012,27 @@ declare class MfaService {
|
|
|
8996
9012
|
* @throws `MFA_INVALID_CODE` if the submitted code is incorrect.
|
|
8997
9013
|
*/
|
|
8998
9014
|
challenge(mfaTempToken: string, code: string, ip: string, userAgent: string): Promise<AuthResult | PlatformAuthResult>;
|
|
9015
|
+
/**
|
|
9016
|
+
* The challenge for an entry point that serves the platform plane only.
|
|
9017
|
+
*
|
|
9018
|
+
* Reads the plane from the temp token first and refuses a dashboard token with
|
|
9019
|
+
* `PLATFORM_AUTH_REQUIRED` before anything is spent. {@link MfaService.challenge} consumes the
|
|
9020
|
+
* token, burns the TOTP code, stores a session, stamps the last login and fires the hooks, so
|
|
9021
|
+
* refusing after it leaves an orphan session nobody holds a token for. The first verification only
|
|
9022
|
+
* reads: it touches neither the brute-force counter nor the TOTP anti-replay key. The challenge
|
|
9023
|
+
* verifies the token again, and the plane is a signed claim, so both reads see the same one.
|
|
9024
|
+
*
|
|
9025
|
+
* @param mfaTempToken - Short-lived MFA challenge JWT issued at platform login.
|
|
9026
|
+
* @param code - 6-digit TOTP code or `dddd-dddd-dddd` recovery code.
|
|
9027
|
+
* @param ip - Client IP address for session audit.
|
|
9028
|
+
* @param userAgent - User-Agent header for session description.
|
|
9029
|
+
* @returns The platform auth result.
|
|
9030
|
+
* @throws `PLATFORM_AUTH_REQUIRED` if the token is for the dashboard plane.
|
|
9031
|
+
* @throws `MFA_TEMP_TOKEN_INVALID` if the token is invalid or already consumed.
|
|
9032
|
+
* @throws `ACCOUNT_LOCKED` if the brute-force threshold has been reached.
|
|
9033
|
+
* @throws `MFA_INVALID_CODE` if the submitted code is incorrect.
|
|
9034
|
+
*/
|
|
9035
|
+
challengePlatformOnly(mfaTempToken: string, code: string, ip: string, userAgent: string): Promise<PlatformAuthResult>;
|
|
8999
9036
|
/**
|
|
9000
9037
|
* Disables MFA on a user's account after verifying a current TOTP code.
|
|
9001
9038
|
*
|
package/dist/server/index.d.ts
CHANGED
|
@@ -3112,6 +3112,11 @@ interface IAuthHooks {
|
|
|
3112
3112
|
* Use this hook to clean up session-related state, emit audit events, or
|
|
3113
3113
|
* notify downstream services.
|
|
3114
3114
|
*
|
|
3115
|
+
* Fired by the call that finds the session record and names its owner. If an earlier attempt
|
|
3116
|
+
* deleted the record but failed another revocation write, it answered a 5xx without this hook,
|
|
3117
|
+
* and the retry that completes the logout finds no record, so it names nobody and does not fire
|
|
3118
|
+
* it: that logout is never reported here.
|
|
3119
|
+
*
|
|
3115
3120
|
* @param userId - The internal ID of the user who logged out.
|
|
3116
3121
|
* @param context - Request metadata (IP, user agent, sanitized headers).
|
|
3117
3122
|
*/
|
|
@@ -3129,6 +3134,10 @@ interface IAuthHooks {
|
|
|
3129
3134
|
* the access token stays presentable until it expires, and the session's removal is unobserved.
|
|
3130
3135
|
* That matters most for a live platform stream, which has no other signal to close on.
|
|
3131
3136
|
*
|
|
3137
|
+
* It is fired by the call that finds the session record and names its owner. If an earlier
|
|
3138
|
+
* attempt deleted the record but failed another revocation write, it answered a 5xx without this
|
|
3139
|
+
* hook, and the retry that completes the logout finds no record and does not fire it.
|
|
3140
|
+
*
|
|
3132
3141
|
* @param userId - The internal ID of the administrator who logged out.
|
|
3133
3142
|
* @param context - Request metadata; `plane` is `'platform'` and there is no tenant.
|
|
3134
3143
|
*/
|
|
@@ -4560,7 +4569,11 @@ declare const WS_TICKET_TTL_SECONDS = 30;
|
|
|
4560
4569
|
interface WsTicketSnapshot {
|
|
4561
4570
|
/** The subject — the internal user id. */
|
|
4562
4571
|
sub: string;
|
|
4563
|
-
/**
|
|
4572
|
+
/**
|
|
4573
|
+
* The tenant scope. Optional because the shared `wst:` record can be written by another
|
|
4574
|
+
* backend without one; this library always sets it, and the WebSocket guard refuses a
|
|
4575
|
+
* snapshot that lacks it.
|
|
4576
|
+
*/
|
|
4564
4577
|
tenantId?: string;
|
|
4565
4578
|
/** The user's role at mint time. */
|
|
4566
4579
|
role: string;
|
|
@@ -6798,6 +6811,9 @@ declare class ChangePasswordDto {
|
|
|
6798
6811
|
* `whitelist: true`, which STRIPPED the property before the controller's own pipe could refuse
|
|
6799
6812
|
* it — so the suite exercised a request production never sees. Optional, because under cookie
|
|
6800
6813
|
* delivery the credential arrives in the cookie and no body field exists to declare.
|
|
6814
|
+
*
|
|
6815
|
+
* A present value is held to the contract's opaque-token bound (1 to 2048 characters), so an
|
|
6816
|
+
* empty string is refused instead of being read as "no token".
|
|
6801
6817
|
*/
|
|
6802
6818
|
refreshToken?: string;
|
|
6803
6819
|
}
|
|
@@ -8996,6 +9012,27 @@ declare class MfaService {
|
|
|
8996
9012
|
* @throws `MFA_INVALID_CODE` if the submitted code is incorrect.
|
|
8997
9013
|
*/
|
|
8998
9014
|
challenge(mfaTempToken: string, code: string, ip: string, userAgent: string): Promise<AuthResult | PlatformAuthResult>;
|
|
9015
|
+
/**
|
|
9016
|
+
* The challenge for an entry point that serves the platform plane only.
|
|
9017
|
+
*
|
|
9018
|
+
* Reads the plane from the temp token first and refuses a dashboard token with
|
|
9019
|
+
* `PLATFORM_AUTH_REQUIRED` before anything is spent. {@link MfaService.challenge} consumes the
|
|
9020
|
+
* token, burns the TOTP code, stores a session, stamps the last login and fires the hooks, so
|
|
9021
|
+
* refusing after it leaves an orphan session nobody holds a token for. The first verification only
|
|
9022
|
+
* reads: it touches neither the brute-force counter nor the TOTP anti-replay key. The challenge
|
|
9023
|
+
* verifies the token again, and the plane is a signed claim, so both reads see the same one.
|
|
9024
|
+
*
|
|
9025
|
+
* @param mfaTempToken - Short-lived MFA challenge JWT issued at platform login.
|
|
9026
|
+
* @param code - 6-digit TOTP code or `dddd-dddd-dddd` recovery code.
|
|
9027
|
+
* @param ip - Client IP address for session audit.
|
|
9028
|
+
* @param userAgent - User-Agent header for session description.
|
|
9029
|
+
* @returns The platform auth result.
|
|
9030
|
+
* @throws `PLATFORM_AUTH_REQUIRED` if the token is for the dashboard plane.
|
|
9031
|
+
* @throws `MFA_TEMP_TOKEN_INVALID` if the token is invalid or already consumed.
|
|
9032
|
+
* @throws `ACCOUNT_LOCKED` if the brute-force threshold has been reached.
|
|
9033
|
+
* @throws `MFA_INVALID_CODE` if the submitted code is incorrect.
|
|
9034
|
+
*/
|
|
9035
|
+
challengePlatformOnly(mfaTempToken: string, code: string, ip: string, userAgent: string): Promise<PlatformAuthResult>;
|
|
8999
9036
|
/**
|
|
9000
9037
|
* Disables MFA on a user's account after verifying a current TOTP code.
|
|
9001
9038
|
*
|
package/dist/server/index.mjs
CHANGED
|
@@ -6480,6 +6480,32 @@ function safeLogLine(line, secrets) {
|
|
|
6480
6480
|
}
|
|
6481
6481
|
__name(safeLogLine, "safeLogLine");
|
|
6482
6482
|
|
|
6483
|
+
// src/server/utils/settle-writes.ts
|
|
6484
|
+
async function settleWrites(writes) {
|
|
6485
|
+
const failures = [];
|
|
6486
|
+
for (const write of writes) {
|
|
6487
|
+
try {
|
|
6488
|
+
await write();
|
|
6489
|
+
} catch (err) {
|
|
6490
|
+
failures.push(err);
|
|
6491
|
+
}
|
|
6492
|
+
}
|
|
6493
|
+
return failures;
|
|
6494
|
+
}
|
|
6495
|
+
__name(settleWrites, "settleWrites");
|
|
6496
|
+
function raiseFirst(failures) {
|
|
6497
|
+
const [first] = failures;
|
|
6498
|
+
if (failures.length > 0) throw first;
|
|
6499
|
+
}
|
|
6500
|
+
__name(raiseFirst, "raiseFirst");
|
|
6501
|
+
function settleAfter(first, followUps) {
|
|
6502
|
+
return async () => {
|
|
6503
|
+
await first();
|
|
6504
|
+
raiseFirst(await settleWrites(followUps));
|
|
6505
|
+
};
|
|
6506
|
+
}
|
|
6507
|
+
__name(settleAfter, "settleAfter");
|
|
6508
|
+
|
|
6483
6509
|
// src/server/utils/tenant-scoped.ts
|
|
6484
6510
|
function tenantScoped(user, tenantId) {
|
|
6485
6511
|
if (user === null) return null;
|
|
@@ -6884,17 +6910,22 @@ var AuthService = class _AuthService {
|
|
|
6884
6910
|
const sessionHash = sha256(rawRefreshToken);
|
|
6885
6911
|
const { userId, tenantId } = await this.redis.readSessionOwner(`rt:${sessionHash}`);
|
|
6886
6912
|
this.logger.log(`logout: userId=${logSafe(userId || "(no live session)")}`);
|
|
6913
|
+
let blacklist = [];
|
|
6887
6914
|
try {
|
|
6888
6915
|
const payload = this.tokenManager.verifyIgnoringExpiry(accessToken);
|
|
6889
|
-
const
|
|
6890
|
-
const remainingTtl = payload.exp - now;
|
|
6916
|
+
const remainingTtl = payload.exp - Math.floor(Date.now() / 1e3);
|
|
6891
6917
|
if (remainingTtl > 0) {
|
|
6892
|
-
|
|
6918
|
+
blacklist = [
|
|
6919
|
+
() => this.redis.set(`rv:${payload.jti}`, "1", remainingTtl)
|
|
6920
|
+
];
|
|
6893
6921
|
}
|
|
6894
6922
|
} catch {
|
|
6895
6923
|
}
|
|
6896
|
-
await
|
|
6897
|
-
|
|
6924
|
+
const failures = await settleWrites([
|
|
6925
|
+
...blacklist,
|
|
6926
|
+
() => this.redis.del(`rt:${sessionHash}`),
|
|
6927
|
+
() => this.redis.del(`rp:${sessionHash}`)
|
|
6928
|
+
]);
|
|
6898
6929
|
if (this.options.sessions.enabled && userId && tenantId !== void 0) {
|
|
6899
6930
|
await this.sessionService.revokeSession({
|
|
6900
6931
|
userId,
|
|
@@ -6907,6 +6938,7 @@ var AuthService = class _AuthService {
|
|
|
6907
6938
|
}
|
|
6908
6939
|
});
|
|
6909
6940
|
}
|
|
6941
|
+
raiseFirst(failures);
|
|
6910
6942
|
this.emitLogout(userId, tenantId);
|
|
6911
6943
|
return userId;
|
|
6912
6944
|
}
|
|
@@ -7794,8 +7826,9 @@ var AuthController = class {
|
|
|
7794
7826
|
* token is the credential that authorizes this, and the service reads the session's owner
|
|
7795
7827
|
* from the stored record rather than from the access token's claims.
|
|
7796
7828
|
*
|
|
7797
|
-
*
|
|
7798
|
-
* cleared and learns nothing about whether a session existed.
|
|
7829
|
+
* A caller presenting a token for an already-gone session gets a 204 with their cookies
|
|
7830
|
+
* cleared and learns nothing about whether a session existed. When the store refuses a
|
|
7831
|
+
* revocation write the route answers a 5xx and leaves the cookies in place, so the client can retry.
|
|
7799
7832
|
*
|
|
7800
7833
|
* @param req - Incoming request (used to extract tokens).
|
|
7801
7834
|
* @param res - Response object (passthrough — used to clear cookies).
|
|
@@ -10427,6 +10460,37 @@ var MfaService = class _MfaService {
|
|
|
10427
10460
|
}
|
|
10428
10461
|
return result;
|
|
10429
10462
|
}
|
|
10463
|
+
/**
|
|
10464
|
+
* The challenge for an entry point that serves the platform plane only.
|
|
10465
|
+
*
|
|
10466
|
+
* Reads the plane from the temp token first and refuses a dashboard token with
|
|
10467
|
+
* `PLATFORM_AUTH_REQUIRED` before anything is spent. {@link MfaService.challenge} consumes the
|
|
10468
|
+
* token, burns the TOTP code, stores a session, stamps the last login and fires the hooks, so
|
|
10469
|
+
* refusing after it leaves an orphan session nobody holds a token for. The first verification only
|
|
10470
|
+
* reads: it touches neither the brute-force counter nor the TOTP anti-replay key. The challenge
|
|
10471
|
+
* verifies the token again, and the plane is a signed claim, so both reads see the same one.
|
|
10472
|
+
*
|
|
10473
|
+
* @param mfaTempToken - Short-lived MFA challenge JWT issued at platform login.
|
|
10474
|
+
* @param code - 6-digit TOTP code or `dddd-dddd-dddd` recovery code.
|
|
10475
|
+
* @param ip - Client IP address for session audit.
|
|
10476
|
+
* @param userAgent - User-Agent header for session description.
|
|
10477
|
+
* @returns The platform auth result.
|
|
10478
|
+
* @throws `PLATFORM_AUTH_REQUIRED` if the token is for the dashboard plane.
|
|
10479
|
+
* @throws `MFA_TEMP_TOKEN_INVALID` if the token is invalid or already consumed.
|
|
10480
|
+
* @throws `ACCOUNT_LOCKED` if the brute-force threshold has been reached.
|
|
10481
|
+
* @throws `MFA_INVALID_CODE` if the submitted code is incorrect.
|
|
10482
|
+
*/
|
|
10483
|
+
async challengePlatformOnly(mfaTempToken, code, ip, userAgent) {
|
|
10484
|
+
const { context } = await this.tokenManager.verifyMfaTempToken(mfaTempToken);
|
|
10485
|
+
if (context !== "platform") {
|
|
10486
|
+
throw new AuthException(AUTH_ERROR_CODES.PLATFORM_AUTH_REQUIRED);
|
|
10487
|
+
}
|
|
10488
|
+
const result = await this.challenge(mfaTempToken, code, ip, userAgent);
|
|
10489
|
+
if (!("admin" in result)) {
|
|
10490
|
+
throw new AuthException(AUTH_ERROR_CODES.PLATFORM_AUTH_REQUIRED);
|
|
10491
|
+
}
|
|
10492
|
+
return result;
|
|
10493
|
+
}
|
|
10430
10494
|
// ---------------------------------------------------------------------------
|
|
10431
10495
|
// disable — TOTP-verified MFA deactivation with session invalidation
|
|
10432
10496
|
// ---------------------------------------------------------------------------
|
|
@@ -11323,6 +11387,9 @@ var ChangePasswordDto = class {
|
|
|
11323
11387
|
* `whitelist: true`, which STRIPPED the property before the controller's own pipe could refuse
|
|
11324
11388
|
* it — so the suite exercised a request production never sees. Optional, because under cookie
|
|
11325
11389
|
* delivery the credential arrives in the cookie and no body field exists to declare.
|
|
11390
|
+
*
|
|
11391
|
+
* A present value is held to the contract's opaque-token bound (1 to 2048 characters), so an
|
|
11392
|
+
* empty string is refused instead of being read as "no token".
|
|
11326
11393
|
*/
|
|
11327
11394
|
refreshToken;
|
|
11328
11395
|
};
|
|
@@ -11341,7 +11408,8 @@ _ts_decorate38([
|
|
|
11341
11408
|
_ts_decorate38([
|
|
11342
11409
|
IsOptional(),
|
|
11343
11410
|
IsString(),
|
|
11344
|
-
|
|
11411
|
+
IsNotEmpty(),
|
|
11412
|
+
MaxLength(2048),
|
|
11345
11413
|
_ts_metadata37("design:type", String)
|
|
11346
11414
|
], ChangePasswordDto.prototype, "refreshToken", void 0);
|
|
11347
11415
|
function _ts_decorate39(decorators, target, key, desc) {
|
|
@@ -12290,12 +12358,15 @@ var PasswordResetController = class {
|
|
|
12290
12358
|
* Initiates a password reset for the given email address.
|
|
12291
12359
|
*
|
|
12292
12360
|
* Sends a reset token or OTP to the user's email if the account exists and
|
|
12293
|
-
* is eligible. Always returns `200 OK` regardless of outcome
|
|
12361
|
+
* is eligible. Always returns `200 OK` with an empty JSON object regardless of outcome
|
|
12362
|
+
* (anti-enumeration; the body is pinned by the wire contract).
|
|
12294
12363
|
*
|
|
12295
12364
|
* @param dto - Validated DTO with `email` and `tenantId`.
|
|
12365
|
+
* @returns An empty object.
|
|
12296
12366
|
*/
|
|
12297
12367
|
async forgotPassword(dto, req) {
|
|
12298
12368
|
await this.passwordResetService.initiateReset(dto, req);
|
|
12369
|
+
return {};
|
|
12299
12370
|
}
|
|
12300
12371
|
// ---------------------------------------------------------------------------
|
|
12301
12372
|
// POST /password/reset-password
|
|
@@ -12375,12 +12446,15 @@ var PasswordResetController = class {
|
|
|
12375
12446
|
* Re-sends the password-reset OTP for the given email address.
|
|
12376
12447
|
*
|
|
12377
12448
|
* Subject to a 60-second atomic cooldown per `(tenantId, email)` pair.
|
|
12378
|
-
* Always returns `200 OK` regardless of outcome (anti-enumeration
|
|
12449
|
+
* Always returns `200 OK` with an empty JSON object regardless of outcome (anti-enumeration;
|
|
12450
|
+
* the body is pinned by the wire contract).
|
|
12379
12451
|
*
|
|
12380
12452
|
* @param dto - Validated DTO with `email` and `tenantId`.
|
|
12453
|
+
* @returns An empty object.
|
|
12381
12454
|
*/
|
|
12382
12455
|
async resendOtp(dto, req) {
|
|
12383
12456
|
await this.passwordResetService.resendOtp(dto, req);
|
|
12457
|
+
return {};
|
|
12384
12458
|
}
|
|
12385
12459
|
};
|
|
12386
12460
|
_ts_decorate44([
|
|
@@ -12748,22 +12822,30 @@ var PlatformAuthService = class _PlatformAuthService {
|
|
|
12748
12822
|
const tokenHash = sha256(rawRefreshToken);
|
|
12749
12823
|
const { userId } = await this.redis.readSessionOwner(`prt:${tokenHash}`);
|
|
12750
12824
|
this.logger.log(`logout: adminId=${logSafe(userId || "(no live session)")}`);
|
|
12825
|
+
let blacklist = [];
|
|
12751
12826
|
try {
|
|
12752
12827
|
const payload = this.tokenManager.verifyPlatformIgnoringExpiry(accessToken);
|
|
12753
12828
|
const remainingTtl = payload.exp - Math.floor(Date.now() / 1e3);
|
|
12754
12829
|
if (remainingTtl > 0) {
|
|
12755
|
-
|
|
12830
|
+
blacklist = [
|
|
12831
|
+
() => this.redis.set(`rv:${payload.jti}`, "1", remainingTtl)
|
|
12832
|
+
];
|
|
12756
12833
|
}
|
|
12757
12834
|
} catch {
|
|
12758
12835
|
}
|
|
12759
|
-
|
|
12760
|
-
|
|
12761
|
-
|
|
12762
|
-
|
|
12763
|
-
|
|
12764
|
-
|
|
12765
|
-
|
|
12766
|
-
|
|
12836
|
+
const index = userId ? sessionIndexKey("platform", userId, this.options.hmacKey, void 0) : "";
|
|
12837
|
+
const prune = /* @__PURE__ */ __name((member) => index === "" ? [] : [
|
|
12838
|
+
() => this.redis.srem(index, member)
|
|
12839
|
+
], "prune");
|
|
12840
|
+
const failures = await settleWrites([
|
|
12841
|
+
...blacklist,
|
|
12842
|
+
settleAfter(() => this.redis.del("prt:" + tokenHash), [
|
|
12843
|
+
...prune("prt:" + tokenHash),
|
|
12844
|
+
() => this.redis.del("psd:" + tokenHash)
|
|
12845
|
+
]),
|
|
12846
|
+
settleAfter(() => this.redis.del("prp:" + tokenHash), prune("prp:" + tokenHash))
|
|
12847
|
+
]);
|
|
12848
|
+
raiseFirst(failures);
|
|
12767
12849
|
this.emitPlatformLogout(userId);
|
|
12768
12850
|
return userId;
|
|
12769
12851
|
}
|
|
@@ -12953,10 +13035,6 @@ function _ts_param27(paramIndex, decorator) {
|
|
|
12953
13035
|
};
|
|
12954
13036
|
}
|
|
12955
13037
|
__name(_ts_param27, "_ts_param");
|
|
12956
|
-
function isPlatformResult2(result) {
|
|
12957
|
-
return "admin" in result;
|
|
12958
|
-
}
|
|
12959
|
-
__name(isPlatformResult2, "isPlatformResult");
|
|
12960
13038
|
function isMfaChallenge2(result) {
|
|
12961
13039
|
return "mfaRequired" in result && result.mfaRequired === true;
|
|
12962
13040
|
}
|
|
@@ -13002,14 +13080,8 @@ var PlatformAuthController = class {
|
|
|
13002
13080
|
* Completes a platform administrator MFA challenge.
|
|
13003
13081
|
*
|
|
13004
13082
|
* Exchanges a short-lived `mfaTempToken` (issued at login) and a TOTP code for
|
|
13005
|
-
* full platform auth tokens
|
|
13006
|
-
*
|
|
13007
|
-
*
|
|
13008
|
-
* Explicitly guards against cross-context token abuse: if a dashboard-context MFA
|
|
13009
|
-
* temp token is submitted here, the response will contain an `AuthResult` (not a
|
|
13010
|
-
* `PlatformAuthResult`). The `isPlatformResult` check detects this and throws
|
|
13011
|
-
* `PLATFORM_AUTH_REQUIRED` rather than silently returning a dashboard-scoped token
|
|
13012
|
-
* as if it were a platform auth response.
|
|
13083
|
+
* full platform auth tokens through {@link MfaService.challengePlatformOnly}, which refuses a
|
|
13084
|
+
* dashboard-context token before anything is spent.
|
|
13013
13085
|
*
|
|
13014
13086
|
* @param dto - Contains the MFA temp token and the TOTP (or recovery) code.
|
|
13015
13087
|
* @param req - Incoming request (provides IP and User-Agent for brute-force tracking).
|
|
@@ -13021,11 +13093,7 @@ var PlatformAuthController = class {
|
|
|
13021
13093
|
if (dto.mfaTempToken === void 0 || dto.mfaTempToken.length === 0) {
|
|
13022
13094
|
throw new AuthException(AUTH_ERROR_CODES.MFA_TEMP_TOKEN_INVALID);
|
|
13023
13095
|
}
|
|
13024
|
-
|
|
13025
|
-
if (!isPlatformResult2(result)) {
|
|
13026
|
-
throw new AuthException(AUTH_ERROR_CODES.PLATFORM_AUTH_REQUIRED);
|
|
13027
|
-
}
|
|
13028
|
-
return this.tokenDelivery.deliverPlatformAuthResponse(result);
|
|
13096
|
+
return this.tokenDelivery.deliverPlatformAuthResponse(await this.mfaService.challengePlatformOnly(dto.mfaTempToken, dto.code, ip, userAgent));
|
|
13029
13097
|
}
|
|
13030
13098
|
// ---------------------------------------------------------------------------
|
|
13031
13099
|
// GET /platform/me
|
|
@@ -15423,7 +15491,8 @@ var REQUEST_SCHEMAS = {
|
|
|
15423
15491
|
},
|
|
15424
15492
|
"refreshToken": {
|
|
15425
15493
|
"type": "string",
|
|
15426
|
-
"maxLength":
|
|
15494
|
+
"maxLength": 2048,
|
|
15495
|
+
"minLength": 1
|
|
15427
15496
|
}
|
|
15428
15497
|
},
|
|
15429
15498
|
"required": [
|
|
@@ -17461,6 +17530,8 @@ var BymaxAuthModule = class _BymaxAuthModule {
|
|
|
17461
17530
|
// in the BYMAX_AUTH_OPTIONS provider above.
|
|
17462
17531
|
// expiresIn is omitted — TokenManagerService sets it per-call via accessSignOptions().
|
|
17463
17532
|
JwtModule.registerAsync({
|
|
17533
|
+
// The factory runs here too, so it needs the modules the consumer's `inject` tokens come from.
|
|
17534
|
+
imports: options.imports ?? [],
|
|
17464
17535
|
useFactory: /* @__PURE__ */ __name(async (...args) => {
|
|
17465
17536
|
const userOptions = await options.useFactory(...args);
|
|
17466
17537
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymax-one/nest-auth",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.15",
|
|
4
4
|
"description": "Full-stack authentication and authorization package for NestJS, React and Next.js — JWT, MFA, OAuth, sessions, multi-tenant SaaS ready",
|
|
5
5
|
"author": "Bymax One <support@bymax.one>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
},
|
|
76
76
|
"scripts": {
|
|
77
77
|
"build": "pnpm clean && tsup",
|
|
78
|
+
"check:api": "node scripts/check-api-surface.mjs",
|
|
78
79
|
"check:exports": "node scripts/check-exports.mjs",
|
|
79
80
|
"check:published": "node scripts/check-published-surface.mjs",
|
|
80
81
|
"check:runtime": "node scripts/check-consumer-runtime.mjs",
|