@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.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { Throttle } from '@nestjs/throttler';
|
|
|
5
5
|
import { Transform } from 'class-transformer';
|
|
6
6
|
import { IsEmail, MaxLength, IsString, MinLength, IsNotEmpty, Matches, Length, IsOptional, ValidateIf } from 'class-validator';
|
|
7
7
|
import { Reflector } from '@nestjs/core';
|
|
8
|
+
import { isIPv6 } from 'net';
|
|
8
9
|
import { promisify } from 'util';
|
|
9
10
|
|
|
10
11
|
var __defProp = Object.defineProperty;
|
|
@@ -28,9 +29,13 @@ var DEFAULT_OPTIONS = {
|
|
|
28
29
|
// browser cookies outliving the JWT exp claim.
|
|
29
30
|
accessCookieMaxAgeMs: 9e5,
|
|
30
31
|
refreshExpiresInDays: 7,
|
|
31
|
-
//
|
|
32
|
-
//
|
|
33
|
-
|
|
32
|
+
// 30 days, because NIST SP 800-63B-4 §3 makes a definite reauthentication timeout a SHALL
|
|
33
|
+
// and puts it at no more than 30 days for AAL1. `refreshExpiresInDays` bounds one token,
|
|
34
|
+
// not the login: a client rotating every 15 minutes renews it forever, so without a cap a
|
|
35
|
+
// refresh token stolen once converts into permanent access — reuse detection only fires if
|
|
36
|
+
// the legitimate client also replays, which it never will once the victim has stopped using
|
|
37
|
+
// that device. Set to 0 to disable. Held equal to rust-auth's default.
|
|
38
|
+
absoluteSessionLifetimeDays: 30,
|
|
34
39
|
algorithm: "HS256",
|
|
35
40
|
// Security trade-off: 30 s grace window allows token rotation under slow mobile networks.
|
|
36
41
|
// It also extends the replay window for a stolen refresh token by 30 s beyond expiry.
|
|
@@ -38,6 +43,13 @@ var DEFAULT_OPTIONS = {
|
|
|
38
43
|
refreshGraceWindowSeconds: 30
|
|
39
44
|
},
|
|
40
45
|
password: {
|
|
46
|
+
// 15, because NIST SP 800-63B-4 §3.1.1.1 requires 15 characters for a password used as a
|
|
47
|
+
// SINGLE factor and permits 8 only when it is part of multi-factor authentication. MFA here
|
|
48
|
+
// is opt-in per user, so the default deployment is single-factor and 15 is the number that
|
|
49
|
+
// applies. A deployment that makes MFA mandatory can lower this to 8, which is the floor the
|
|
50
|
+
// DTOs enforce structurally. The KDF cost sets the price of one guess; this sets how many
|
|
51
|
+
// guesses there are, and only the second is what an offline attacker actually runs out of.
|
|
52
|
+
minLength: 15,
|
|
41
53
|
costFactor: 131072,
|
|
42
54
|
blockSize: 8,
|
|
43
55
|
parallelization: 1,
|
|
@@ -264,6 +276,10 @@ function deriveHmacKey(jwtSecret) {
|
|
|
264
276
|
return createHash("sha256").update(`${HMAC_KEY_DERIVATION_LABEL}:${jwtSecret}`, "utf8").digest("hex");
|
|
265
277
|
}
|
|
266
278
|
__name(deriveHmacKey, "deriveHmacKey");
|
|
279
|
+
function isProductionDeployment(userOptions) {
|
|
280
|
+
return (userOptions.environment ?? "production") === "production";
|
|
281
|
+
}
|
|
282
|
+
__name(isProductionDeployment, "isProductionDeployment");
|
|
267
283
|
function shannonEntropy(value) {
|
|
268
284
|
const freq = /* @__PURE__ */ new Map();
|
|
269
285
|
for (const ch of value) {
|
|
@@ -283,11 +299,12 @@ function resolveOptions(userOptions) {
|
|
|
283
299
|
validateRolesHierarchy(userOptions.roles);
|
|
284
300
|
validatePlatformAdmin(userOptions.platform, userOptions.roles);
|
|
285
301
|
validatePasswordResetOtpLength(userOptions.passwordReset);
|
|
302
|
+
validatePasswordMinLength(userOptions.password);
|
|
286
303
|
validatePasswordCostFactor(userOptions.password);
|
|
287
304
|
validatePasswordMemoryParameters(userOptions.password);
|
|
288
305
|
validateMfaVerificationParameters(userOptions.mfa);
|
|
289
306
|
validateBruteForce(userOptions.bruteForce);
|
|
290
|
-
validateOAuthProviders(userOptions.oauth);
|
|
307
|
+
validateOAuthProviders(userOptions.oauth, isProductionDeployment(userOptions));
|
|
291
308
|
validateClientIpSource(userOptions.rateLimit);
|
|
292
309
|
validateOAuthSuccessRedirectUrl(userOptions);
|
|
293
310
|
validateOAuthMfaRedirectUrl(userOptions);
|
|
@@ -295,6 +312,7 @@ function resolveOptions(userOptions) {
|
|
|
295
312
|
validateOAuthErrorRedirectUrl(userOptions);
|
|
296
313
|
validateRefreshCookiePath(userOptions.routePrefix, userOptions.cookies);
|
|
297
314
|
validateSameSiteNoneRequiresSecure(userOptions);
|
|
315
|
+
validateCookiePrefixes(userOptions);
|
|
298
316
|
validateTrustedOrigins(userOptions);
|
|
299
317
|
validateRefreshGraceWindow(userOptions.jwt);
|
|
300
318
|
validateAccessLifetimeAgainstEpochRetention(userOptions.jwt);
|
|
@@ -375,9 +393,13 @@ function resolveOptions(userOptions) {
|
|
|
375
393
|
rateLimit: {
|
|
376
394
|
...DEFAULT_OPTIONS.rateLimit,
|
|
377
395
|
...userOptions.rateLimit,
|
|
396
|
+
// Stryker disable next-line OptionalChaining: unreachable — `validateClientIpSource` has
|
|
397
|
+
// already run, and it only returns without throwing when `rateLimit` is an object (either
|
|
398
|
+
// naming a source or disabling limiting), so `rateLimit` is never undefined here
|
|
378
399
|
clientIpSource: userOptions.rateLimit?.clientIpSource ?? "peer"
|
|
379
400
|
},
|
|
380
|
-
|
|
401
|
+
environment: userOptions.environment ?? "production",
|
|
402
|
+
secureCookies: userOptions.secureCookies ?? isProductionDeployment(userOptions),
|
|
381
403
|
hmacKey: deriveHmacKey(userOptions.jwt.secret),
|
|
382
404
|
previousHmacKeys: (userOptions.jwt.previousSecrets ?? []).map(deriveHmacKey),
|
|
383
405
|
...userOptions.mfa !== void 0 && {
|
|
@@ -407,6 +429,10 @@ function withholdSecrets(resolved) {
|
|
|
407
429
|
withholdFromSerialization(resolved.jwt, "previousSecrets");
|
|
408
430
|
withholdFromSerialization(resolved, "hmacKey");
|
|
409
431
|
withholdFromSerialization(resolved, "previousHmacKeys");
|
|
432
|
+
if (resolved.mfa !== void 0) {
|
|
433
|
+
withholdFromSerialization(resolved.mfa, "encryptionKey");
|
|
434
|
+
withholdFromSerialization(resolved.mfa, "previousEncryptionKeys");
|
|
435
|
+
}
|
|
410
436
|
if (resolved.oauth === void 0) return;
|
|
411
437
|
const oauth = Object.fromEntries(Object.entries(resolved.oauth).map(([provider, config]) => {
|
|
412
438
|
if (typeof config !== "object" || config === null) return [
|
|
@@ -560,6 +586,14 @@ function assertIntegralScryptParameter(name, value) {
|
|
|
560
586
|
throw new Error(`[BymaxAuthModule] password.${name} must be an integer (current: ${value}). Node's crypto.scrypt rejects a non-integral cost parameter, and it does so on the first derivation \u2014 which is the first login after deploy, not at startup.`);
|
|
561
587
|
}
|
|
562
588
|
__name(assertIntegralScryptParameter, "assertIntegralScryptParameter");
|
|
589
|
+
function validatePasswordMinLength(password) {
|
|
590
|
+
const minLength = password?.minLength;
|
|
591
|
+
if (minLength === void 0) return;
|
|
592
|
+
if (!Number.isInteger(minLength) || minLength < 8 || minLength > 128) {
|
|
593
|
+
throw new Error(`[BymaxAuthModule] password.minLength must be an integer between 8 and 128 (current: ${String(minLength)}). NIST SP 800-63B-4 \xA73.1.1.1 allows 8 only for a password used as part of multi-factor authentication and requires 15 for one used as a single factor; 128 is the maximum the password DTOs accept, so a higher policy would reject every password that reaches this service.`);
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
__name(validatePasswordMinLength, "validatePasswordMinLength");
|
|
563
597
|
function validatePasswordCostFactor(password) {
|
|
564
598
|
const costFactor = password?.costFactor;
|
|
565
599
|
if (costFactor === void 0) return;
|
|
@@ -623,7 +657,7 @@ var REQUIRED_OAUTH_FIELDS = [
|
|
|
623
657
|
"clientSecret",
|
|
624
658
|
"callbackUrl"
|
|
625
659
|
];
|
|
626
|
-
function validateOAuthProviders(oauth) {
|
|
660
|
+
function validateOAuthProviders(oauth, isProduction) {
|
|
627
661
|
if (!oauth) return;
|
|
628
662
|
for (const [providerOrField, rawConfig] of Object.entries(oauth)) {
|
|
629
663
|
if (providerOrField === "successRedirectUrl" || providerOrField === "mfaRedirectUrl" || providerOrField === "errorRedirectUrl") continue;
|
|
@@ -635,7 +669,7 @@ function validateOAuthProviders(oauth) {
|
|
|
635
669
|
}
|
|
636
670
|
}
|
|
637
671
|
const callbackUrl = config["callbackUrl"];
|
|
638
|
-
if (typeof callbackUrl === "string" && !callbackUrl.startsWith("https://") &&
|
|
672
|
+
if (typeof callbackUrl === "string" && !callbackUrl.startsWith("https://") && isProduction) {
|
|
639
673
|
throw new Error(`[BymaxAuthModule] oauth.${provider}.callbackUrl must use HTTPS in production (got: '${callbackUrl}'). Use an HTTPS URL to prevent authorization code interception.`);
|
|
640
674
|
}
|
|
641
675
|
}
|
|
@@ -647,7 +681,7 @@ function validateOAuthSuccessRedirectUrl(userOptions) {
|
|
|
647
681
|
if (typeof url !== "string" || url.length === 0) {
|
|
648
682
|
throw new Error(`[BymaxAuthModule] oauth.successRedirectUrl must be a non-empty string when set.`);
|
|
649
683
|
}
|
|
650
|
-
const isProduction =
|
|
684
|
+
const isProduction = isProductionDeployment(userOptions);
|
|
651
685
|
const isSafe = url.startsWith("/") || url.startsWith("https://");
|
|
652
686
|
if (isProduction && !isSafe) {
|
|
653
687
|
throw new Error(`[BymaxAuthModule] oauth.successRedirectUrl must use HTTPS or be a same-origin path (starts with '/') in production (got: '${url}').`);
|
|
@@ -663,7 +697,7 @@ function validateOAuthMfaRedirectUrl(userOptions) {
|
|
|
663
697
|
if (typeof url !== "string" || url.length === 0) {
|
|
664
698
|
throw new Error(`[BymaxAuthModule] oauth.mfaRedirectUrl must be a non-empty string when set.`);
|
|
665
699
|
}
|
|
666
|
-
const isProduction =
|
|
700
|
+
const isProduction = isProductionDeployment(userOptions);
|
|
667
701
|
const isSafe = url.startsWith("/") || url.startsWith("https://");
|
|
668
702
|
if (isProduction && !isSafe) {
|
|
669
703
|
throw new Error(`[BymaxAuthModule] oauth.mfaRedirectUrl must use HTTPS or be a same-origin path (starts with '/') in production (got: '${url}').`);
|
|
@@ -676,7 +710,7 @@ function validateOAuthErrorRedirectUrl(userOptions) {
|
|
|
676
710
|
if (typeof url !== "string" || url.length === 0) {
|
|
677
711
|
throw new Error(`[BymaxAuthModule] oauth.errorRedirectUrl must be a non-empty string when set.`);
|
|
678
712
|
}
|
|
679
|
-
const isProduction =
|
|
713
|
+
const isProduction = isProductionDeployment(userOptions);
|
|
680
714
|
const isSafe = url.startsWith("/") || url.startsWith("https://");
|
|
681
715
|
if (isProduction && !isSafe) {
|
|
682
716
|
throw new Error(`[BymaxAuthModule] oauth.errorRedirectUrl must use HTTPS or be a same-origin path (starts with '/') in production (got: '${url}').`);
|
|
@@ -690,10 +724,47 @@ function validateRefreshCookiePath(routePrefix, cookies) {
|
|
|
690
724
|
}
|
|
691
725
|
}
|
|
692
726
|
__name(validateRefreshCookiePath, "validateRefreshCookiePath");
|
|
727
|
+
function validateCookiePrefixes(userOptions) {
|
|
728
|
+
const cookies = userOptions.cookies;
|
|
729
|
+
if (cookies === void 0) return;
|
|
730
|
+
const secure = userOptions.secureCookies ?? isProductionDeployment(userOptions);
|
|
731
|
+
const hasDomain = cookies.resolveDomains !== void 0;
|
|
732
|
+
const refreshPath = cookies.refreshCookiePath ?? DEFAULT_OPTIONS.cookies.refreshCookiePath;
|
|
733
|
+
const named = [
|
|
734
|
+
{
|
|
735
|
+
option: "accessTokenName",
|
|
736
|
+
name: cookies.accessTokenName,
|
|
737
|
+
path: "/"
|
|
738
|
+
},
|
|
739
|
+
{
|
|
740
|
+
option: "refreshTokenName",
|
|
741
|
+
name: cookies.refreshTokenName,
|
|
742
|
+
path: refreshPath
|
|
743
|
+
},
|
|
744
|
+
{
|
|
745
|
+
option: "sessionSignalName",
|
|
746
|
+
name: cookies.sessionSignalName,
|
|
747
|
+
path: "/"
|
|
748
|
+
}
|
|
749
|
+
];
|
|
750
|
+
for (const { option, name, path } of named) {
|
|
751
|
+
if (name === void 0) continue;
|
|
752
|
+
if (name.startsWith("__Host-")) {
|
|
753
|
+
if (!secure || path !== "/" || hasDomain) {
|
|
754
|
+
throw new Error(`[BymaxAuthModule] cookies.${option} is '${name}' but the __Host- prefix requires secureCookies: true, Path=/ (this cookie uses '${path}'), and no cookies.resolveDomains. Browsers silently drop a Set-Cookie that violates the prefix, so the cookie would never be stored. Fix the attributes or drop the prefix.`);
|
|
755
|
+
}
|
|
756
|
+
continue;
|
|
757
|
+
}
|
|
758
|
+
if (name.startsWith("__Secure-") && !secure) {
|
|
759
|
+
throw new Error(`[BymaxAuthModule] cookies.${option} is '${name}' but the __Secure- prefix requires secureCookies: true. Browsers silently drop a Set-Cookie that violates the prefix, so the cookie would never be stored. Set secureCookies: true (and serve over HTTPS) or drop the prefix.`);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
__name(validateCookiePrefixes, "validateCookiePrefixes");
|
|
693
764
|
function validateSameSiteNoneRequiresSecure(userOptions) {
|
|
694
765
|
const sameSite = userOptions.cookies?.sameSite;
|
|
695
766
|
if (sameSite !== "none") return;
|
|
696
|
-
const secureCookies = userOptions.secureCookies ??
|
|
767
|
+
const secureCookies = userOptions.secureCookies ?? isProductionDeployment(userOptions);
|
|
697
768
|
if (!secureCookies) {
|
|
698
769
|
throw new Error(`[BymaxAuthModule] cookies.sameSite is 'none' but secureCookies is false. Browsers reject SameSite=None cookies without the Secure attribute, so the auth cookies would never be stored. Set secureCookies: true (and serve over HTTPS) or use cookies.sameSite: 'lax' / 'strict'.`);
|
|
699
770
|
}
|
|
@@ -1151,7 +1222,14 @@ var RegisterDto = class {
|
|
|
1151
1222
|
* Plaintext password supplied by the user.
|
|
1152
1223
|
*
|
|
1153
1224
|
* @remarks
|
|
1154
|
-
*
|
|
1225
|
+
* The 8-character floor here is STRUCTURAL, not the deployment's policy: it is the lowest
|
|
1226
|
+
* NIST SP 800-63B-4 §3.1.1.1 permits under any circumstance, and it is what a decorator
|
|
1227
|
+
* can express — decorators are evaluated when the class is defined, before any
|
|
1228
|
+
* configuration exists. The policy floor is `password.minLength` (default 15, as the
|
|
1229
|
+
* standard requires of a single-factor password), enforced by `PasswordService` and
|
|
1230
|
+
* answering this same `auth.validation` code and details shape.
|
|
1231
|
+
*
|
|
1232
|
+
* Maximum 128 characters as a practical
|
|
1155
1233
|
* input bound. The service layer hashes this value immediately after receipt —
|
|
1156
1234
|
* it is never logged or persisted in plaintext.
|
|
1157
1235
|
*/
|
|
@@ -1617,6 +1695,18 @@ if ARGV[3] ~= '' then
|
|
|
1617
1695
|
end
|
|
1618
1696
|
return 1
|
|
1619
1697
|
`;
|
|
1698
|
+
var CREATE_SESSION_LUA = `
|
|
1699
|
+
redis.call('SET', KEYS[1], ARGV[1], 'EX', ARGV[2])
|
|
1700
|
+
redis.call('SADD', KEYS[2], ARGV[4] .. ':' .. ARGV[5])
|
|
1701
|
+
redis.call('EXPIRE', KEYS[2], ARGV[2])
|
|
1702
|
+
-- The family index holds bare hashes: it only ever tracks live sessions, so the prefix is
|
|
1703
|
+
-- implied. A session with no lineage skips it rather than writing an unkeyed member.
|
|
1704
|
+
if ARGV[3] ~= '' then
|
|
1705
|
+
redis.call('SADD', KEYS[3], ARGV[5])
|
|
1706
|
+
redis.call('EXPIRE', KEYS[3], ARGV[2])
|
|
1707
|
+
end
|
|
1708
|
+
return 1
|
|
1709
|
+
`;
|
|
1620
1710
|
var ROTATE_LUA = `
|
|
1621
1711
|
local old = redis.call('GET', KEYS[1])
|
|
1622
1712
|
if old then
|
|
@@ -1951,6 +2041,30 @@ var AuthRedisService = class {
|
|
|
1951
2041
|
};
|
|
1952
2042
|
}
|
|
1953
2043
|
/**
|
|
2044
|
+
* Writes a freshly-issued refresh session atomically — record, session-index member and
|
|
2045
|
+
* family membership, each carrying the refresh TTL.
|
|
2046
|
+
*
|
|
2047
|
+
* See {@link CREATE_SESSION_LUA} for the two windows the loose form left open.
|
|
2048
|
+
*
|
|
2049
|
+
* @param params - The session to store and the keys it belongs under.
|
|
2050
|
+
*/
|
|
2051
|
+
async writeNewSession(params) {
|
|
2052
|
+
const p = prefixesFor(params.kind);
|
|
2053
|
+
await this.eval(CREATE_SESSION_LUA, [
|
|
2054
|
+
`${p.live}:${params.tokenHash}`,
|
|
2055
|
+
`${p.index}:${params.userId}`,
|
|
2056
|
+
// Always passed, even with no family: a Lua script's key list is fixed at the call
|
|
2057
|
+
// site, and the script skips the key rather than the caller skipping the argument.
|
|
2058
|
+
`${p.family}:${params.familyId}`
|
|
2059
|
+
], [
|
|
2060
|
+
params.sessionJson,
|
|
2061
|
+
String(params.refreshTtl),
|
|
2062
|
+
params.familyId,
|
|
2063
|
+
p.live,
|
|
2064
|
+
params.tokenHash
|
|
2065
|
+
]);
|
|
2066
|
+
}
|
|
2067
|
+
/**
|
|
1954
2068
|
* Writes the session a grace recovery produced, atomically with the check that the account
|
|
1955
2069
|
* has not been swept out from under it.
|
|
1956
2070
|
*
|
|
@@ -2107,6 +2221,101 @@ var AuthRedisService = class {
|
|
|
2107
2221
|
return result === "OK";
|
|
2108
2222
|
}
|
|
2109
2223
|
/**
|
|
2224
|
+
* Drops the grace-pointer members whose keys have already expired.
|
|
2225
|
+
*
|
|
2226
|
+
* A rotation removes `rt:{old}` from the index and adds two members: `rt:{new}` and
|
|
2227
|
+
* `rp:{old}`. The `rp:` KEY dies with the grace window — 30 seconds by default — but the
|
|
2228
|
+
* MEMBER was only ever removed by a full revoke-all, so the index gained one permanent
|
|
2229
|
+
* ~68-byte entry per rotation, and the rotation re-arms the set's own TTL each time. The set
|
|
2230
|
+
* never aged out while the account was in use.
|
|
2231
|
+
*
|
|
2232
|
+
* That is not merely untidy. Every reader of the index is linear in its size:
|
|
2233
|
+
* `listSessions` ships the whole set over the wire, `revokeAllExceptCurrent` issues two
|
|
2234
|
+
* sequential round trips per grace member, and `invalidateUserSessions` iterates it inside a
|
|
2235
|
+
* Lua script, which blocks the whole single-threaded store. An attacker holding one stolen
|
|
2236
|
+
* refresh token and rotating at the route limit adds ~14k members a day to their own index,
|
|
2237
|
+
* with no ceiling; a merely active user accrues thousands a year.
|
|
2238
|
+
*
|
|
2239
|
+
* Called from the two paths that already walk the index — a login enforcing the session cap
|
|
2240
|
+
* and a session listing — so the growth is bounded by how long an account can go between
|
|
2241
|
+
* them, and any legitimate interaction heals it. The rotation path deliberately does NOT
|
|
2242
|
+
* call this: it is the hot path, and an O(n) sweep there would trade a slow leak for a slow
|
|
2243
|
+
* refresh.
|
|
2244
|
+
*
|
|
2245
|
+
* Grace members whose key is still live are left alone. They are what lets a revoke-all also
|
|
2246
|
+
* kill a token that was rotated away moments earlier but can still be recovered.
|
|
2247
|
+
*
|
|
2248
|
+
* @param setKey - The un-namespaced index key (`sess:{id}` or `psess:{id}`).
|
|
2249
|
+
* @param gracePrefix - Member prefix for rotation grace pointers (`rp:` or `prp:`).
|
|
2250
|
+
* @returns How many dead members were dropped.
|
|
2251
|
+
*/
|
|
2252
|
+
async pruneExpiredGraceMembers(setKey, gracePrefix) {
|
|
2253
|
+
const removed = await this.eval(`local members = redis.call('SMEMBERS', KEYS[1])
|
|
2254
|
+
local ns, grace = ARGV[1], ARGV[2]
|
|
2255
|
+
local removed = 0
|
|
2256
|
+
for _, member in ipairs(members) do
|
|
2257
|
+
if string.sub(member, 1, string.len(grace)) == grace then
|
|
2258
|
+
-- The member IS the key suffix, so its own liveness is one EXISTS away. A pointer
|
|
2259
|
+
-- still inside its window is left in place; only the expired ones go.
|
|
2260
|
+
if redis.call('EXISTS', ns .. ':' .. member) == 0 then
|
|
2261
|
+
redis.call('SREM', KEYS[1], member)
|
|
2262
|
+
removed = removed + 1
|
|
2263
|
+
end
|
|
2264
|
+
end
|
|
2265
|
+
end
|
|
2266
|
+
return removed`, [
|
|
2267
|
+
setKey
|
|
2268
|
+
], [
|
|
2269
|
+
this.namespace,
|
|
2270
|
+
gracePrefix
|
|
2271
|
+
]);
|
|
2272
|
+
if (typeof removed === "number") return removed;
|
|
2273
|
+
return typeof removed === "string" ? Number(removed) : 0;
|
|
2274
|
+
}
|
|
2275
|
+
/**
|
|
2276
|
+
* Drops index members whose own key is gone, and leaves every other member in place.
|
|
2277
|
+
*
|
|
2278
|
+
* A reader that walks `sess:{userId}` learns a session is stale from something *about* the
|
|
2279
|
+
* session — a detail record that is missing, unreadable or malformed. None of those facts is
|
|
2280
|
+
* the session. The credential is the `rt:{hash}` key, and only its absence means the member
|
|
2281
|
+
* names nothing: a live `rt:` with no `sd:` is a session that still opens the account.
|
|
2282
|
+
*
|
|
2283
|
+
* Removing such a member is not a tidy-up, it is a revocation bypass. `invalidateUserSessions`
|
|
2284
|
+
* revokes what the index names, so a member dropped while its `rt:` key lives produces a
|
|
2285
|
+
* session that survives "sign out everywhere" and keeps rotating, while the user is told every
|
|
2286
|
+
* device was signed out — and the un-indexing is triggered by the user's own session listing.
|
|
2287
|
+
*
|
|
2288
|
+
* So the caller supplies candidates and this decides, with `EXISTS` as the only evidence
|
|
2289
|
+
* admitted. The check and the `SREM` share one script because they must: a candidate whose
|
|
2290
|
+
* `rt:` key is written between the two would otherwise be dropped anyway. A Redis fault makes
|
|
2291
|
+
* the whole script fail rather than prune, which is the safe direction — an index that keeps a
|
|
2292
|
+
* dead member costs a wasted read, an index that loses a live one costs the revocation.
|
|
2293
|
+
*
|
|
2294
|
+
* @param setKey - The un-namespaced index key (`sess:{id}` or `psess:{id}`).
|
|
2295
|
+
* @param members - Candidate members, each a full key suffix (`rt:{hash}`).
|
|
2296
|
+
* @returns How many candidates were actually dropped.
|
|
2297
|
+
*/
|
|
2298
|
+
async pruneDeadMembers(setKey, members) {
|
|
2299
|
+
if (members.length === 0) return 0;
|
|
2300
|
+
const removed = await this.eval(`local ns = ARGV[1]
|
|
2301
|
+
local removed = 0
|
|
2302
|
+
for i = 2, #ARGV do
|
|
2303
|
+
-- The member IS the key suffix, so its own liveness is one EXISTS away.
|
|
2304
|
+
if redis.call('EXISTS', ns .. ':' .. ARGV[i]) == 0 then
|
|
2305
|
+
redis.call('SREM', KEYS[1], ARGV[i])
|
|
2306
|
+
removed = removed + 1
|
|
2307
|
+
end
|
|
2308
|
+
end
|
|
2309
|
+
return removed`, [
|
|
2310
|
+
setKey
|
|
2311
|
+
], [
|
|
2312
|
+
this.namespace,
|
|
2313
|
+
...members
|
|
2314
|
+
]);
|
|
2315
|
+
if (typeof removed === "number") return removed;
|
|
2316
|
+
return typeof removed === "string" ? Number(removed) : 0;
|
|
2317
|
+
}
|
|
2318
|
+
/**
|
|
2110
2319
|
* Atomically deletes every refresh session belonging to one identity plane.
|
|
2111
2320
|
*
|
|
2112
2321
|
* The set members are full key suffixes — `rt:{hash}`/`rp:{hash}` on the dashboard plane,
|
|
@@ -2330,6 +2539,53 @@ function isWsTicketSnapshot(value) {
|
|
|
2330
2539
|
return typeof record["sub"] === "string" && typeof record["role"] === "string" && typeof record["status"] === "string" && typeof record["mfaEnabled"] === "boolean" && typeof record["mfaVerified"] === "boolean" && (record["tenantId"] === void 0 || typeof record["tenantId"] === "string");
|
|
2331
2540
|
}
|
|
2332
2541
|
__name(isWsTicketSnapshot, "isWsTicketSnapshot");
|
|
2542
|
+
var IPV6_GROUPS = 8;
|
|
2543
|
+
var IPV6_PREFIX_GROUPS = 4;
|
|
2544
|
+
function rateLimitBucket(address) {
|
|
2545
|
+
const zoneIndex = address.indexOf("%");
|
|
2546
|
+
const zoneless = zoneIndex === -1 ? address : address.slice(0, zoneIndex);
|
|
2547
|
+
if (!isIPv6(zoneless)) return address;
|
|
2548
|
+
const groups = expandIPv6(zoneless);
|
|
2549
|
+
const mapped = toMappedIPv4(groups);
|
|
2550
|
+
if (mapped !== null) return mapped;
|
|
2551
|
+
return groups.slice(0, IPV6_PREFIX_GROUPS).concat(Array(IPV6_GROUPS - IPV6_PREFIX_GROUPS).fill(0)).map((group) => group.toString(16)).join(":");
|
|
2552
|
+
}
|
|
2553
|
+
__name(rateLimitBucket, "rateLimitBucket");
|
|
2554
|
+
function expandIPv6(address) {
|
|
2555
|
+
let text = address;
|
|
2556
|
+
const lastColon = text.lastIndexOf(":");
|
|
2557
|
+
const tail = text.slice(lastColon + 1);
|
|
2558
|
+
if (tail.includes(".")) {
|
|
2559
|
+
const packed = tail.split(".").reduce((acc, octet) => acc << 8 | Number(octet), 0);
|
|
2560
|
+
const high = packed >>> 16 & 65535;
|
|
2561
|
+
const low = packed & 65535;
|
|
2562
|
+
text = `${text.slice(0, lastColon + 1)}${high.toString(16)}:${low.toString(16)}`;
|
|
2563
|
+
}
|
|
2564
|
+
const [head, compressed] = text.split("::");
|
|
2565
|
+
const parse = /* @__PURE__ */ __name((part) => part === "" ? [] : part.split(":").map((group) => parseInt(group, 16)), "parse");
|
|
2566
|
+
const left = parse(head);
|
|
2567
|
+
if (compressed === void 0) return left;
|
|
2568
|
+
const right = parse(compressed);
|
|
2569
|
+
const missing = IPV6_GROUPS - left.length - right.length;
|
|
2570
|
+
return [
|
|
2571
|
+
...left,
|
|
2572
|
+
...Array(missing).fill(0),
|
|
2573
|
+
...right
|
|
2574
|
+
];
|
|
2575
|
+
}
|
|
2576
|
+
__name(expandIPv6, "expandIPv6");
|
|
2577
|
+
function toMappedIPv4(groups) {
|
|
2578
|
+
const isMapped = groups.slice(0, 5).every((group) => group === 0) && groups[5] === 65535;
|
|
2579
|
+
if (!isMapped) return null;
|
|
2580
|
+
const [high, low] = groups.slice(6);
|
|
2581
|
+
return [
|
|
2582
|
+
high >> 8,
|
|
2583
|
+
high & 255,
|
|
2584
|
+
low >> 8,
|
|
2585
|
+
low & 255
|
|
2586
|
+
].join(".");
|
|
2587
|
+
}
|
|
2588
|
+
__name(toMappedIPv4, "toMappedIPv4");
|
|
2333
2589
|
|
|
2334
2590
|
// src/server/guards/auth-rate-limit.guard.ts
|
|
2335
2591
|
function _ts_decorate6(decorators, target, key, desc) {
|
|
@@ -2387,7 +2643,8 @@ var AuthRateLimitGuard = class {
|
|
|
2387
2643
|
*/
|
|
2388
2644
|
counterKey(request, context) {
|
|
2389
2645
|
const route = `${context.getClass().name}.${context.getHandler().name}`;
|
|
2390
|
-
|
|
2646
|
+
const bucket = rateLimitBucket(this.clientIp(request));
|
|
2647
|
+
return `rl:${route}:${hmacSha256(bucket, this.options.hmacKey)}`;
|
|
2391
2648
|
}
|
|
2392
2649
|
/**
|
|
2393
2650
|
* The address this request is counted against.
|
|
@@ -2415,7 +2672,9 @@ var AuthRateLimitGuard = class {
|
|
|
2415
2672
|
};
|
|
2416
2673
|
AuthRateLimitGuard = _ts_decorate6([
|
|
2417
2674
|
Injectable(),
|
|
2675
|
+
_ts_param2(0, Inject(Reflector)),
|
|
2418
2676
|
_ts_param2(1, Inject(BYMAX_AUTH_OPTIONS)),
|
|
2677
|
+
_ts_param2(2, Inject(AuthRedisService)),
|
|
2419
2678
|
_ts_metadata6("design:type", Function),
|
|
2420
2679
|
_ts_metadata6("design:paramtypes", [
|
|
2421
2680
|
typeof Reflector === "undefined" ? Object : Reflector,
|
|
@@ -2949,6 +3208,10 @@ var JwtAuthGuard = class {
|
|
|
2949
3208
|
};
|
|
2950
3209
|
JwtAuthGuard = _ts_decorate8([
|
|
2951
3210
|
Injectable(),
|
|
3211
|
+
_ts_param4(0, Inject(JwtService)),
|
|
3212
|
+
_ts_param4(1, Inject(TokenDeliveryService)),
|
|
3213
|
+
_ts_param4(2, Inject(AuthRedisService)),
|
|
3214
|
+
_ts_param4(3, Inject(Reflector)),
|
|
2952
3215
|
_ts_param4(4, Inject(BYMAX_AUTH_OPTIONS)),
|
|
2953
3216
|
_ts_metadata8("design:type", Function),
|
|
2954
3217
|
_ts_metadata8("design:paramtypes", [
|
|
@@ -3066,13 +3329,13 @@ var UserStatusGuard = class {
|
|
|
3066
3329
|
status = userRecord.status;
|
|
3067
3330
|
await this.redis.set(cacheKey, status, cacheTtl);
|
|
3068
3331
|
}
|
|
3069
|
-
|
|
3070
|
-
assertNotBlocked(normalizedStatus, this.options.blockedStatuses);
|
|
3332
|
+
assertNotBlocked(status, this.options.blockedStatuses);
|
|
3071
3333
|
return true;
|
|
3072
3334
|
}
|
|
3073
3335
|
};
|
|
3074
3336
|
UserStatusGuard = _ts_decorate10([
|
|
3075
3337
|
Injectable(),
|
|
3338
|
+
_ts_param6(0, Inject(AuthRedisService)),
|
|
3076
3339
|
_ts_param6(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
|
|
3077
3340
|
_ts_param6(2, Inject(BYMAX_AUTH_OPTIONS)),
|
|
3078
3341
|
_ts_metadata10("design:type", Function),
|
|
@@ -3116,7 +3379,7 @@ function flattenValidationErrors(errors, parentPath = "") {
|
|
|
3116
3379
|
message
|
|
3117
3380
|
});
|
|
3118
3381
|
}
|
|
3119
|
-
if (error.children !== void 0
|
|
3382
|
+
if (error.children !== void 0) {
|
|
3120
3383
|
flattened.push(...flattenValidationErrors(error.children, path));
|
|
3121
3384
|
}
|
|
3122
3385
|
}
|
|
@@ -3240,6 +3503,7 @@ var BruteForceService = class _BruteForceService {
|
|
|
3240
3503
|
};
|
|
3241
3504
|
BruteForceService = _ts_decorate12([
|
|
3242
3505
|
Injectable(),
|
|
3506
|
+
_ts_param7(0, Inject(AuthRedisService)),
|
|
3243
3507
|
_ts_param7(1, Inject(BYMAX_AUTH_OPTIONS)),
|
|
3244
3508
|
_ts_metadata11("design:type", Function),
|
|
3245
3509
|
_ts_metadata11("design:paramtypes", [
|
|
@@ -3258,6 +3522,12 @@ function _ts_metadata12(k, v) {
|
|
|
3258
3522
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
3259
3523
|
}
|
|
3260
3524
|
__name(_ts_metadata12, "_ts_metadata");
|
|
3525
|
+
function _ts_param8(paramIndex, decorator) {
|
|
3526
|
+
return function(target, key) {
|
|
3527
|
+
decorator(target, key, paramIndex);
|
|
3528
|
+
};
|
|
3529
|
+
}
|
|
3530
|
+
__name(_ts_param8, "_ts_param");
|
|
3261
3531
|
var MAX_ATTEMPTS = 5;
|
|
3262
3532
|
var MIN_VERIFY_MS = 100;
|
|
3263
3533
|
var OTP_STORE_LUA = `
|
|
@@ -3282,21 +3552,32 @@ end
|
|
|
3282
3552
|
return { 'PRESENT', code }
|
|
3283
3553
|
`;
|
|
3284
3554
|
function parseOtpVerifyReply(raw) {
|
|
3285
|
-
if (!Array.isArray(raw)
|
|
3286
|
-
|
|
3287
|
-
""
|
|
3288
|
-
];
|
|
3555
|
+
if (!Array.isArray(raw)) return expired();
|
|
3556
|
+
if (raw.length < 2) return expired();
|
|
3289
3557
|
const [tag, storedCode] = raw;
|
|
3290
|
-
if (tag
|
|
3558
|
+
if (tag === "MAX") return maxed();
|
|
3559
|
+
if (tag !== "PRESENT") return expired();
|
|
3560
|
+
if (typeof storedCode !== "string" || storedCode === "") return expired();
|
|
3561
|
+
return [
|
|
3562
|
+
"PRESENT",
|
|
3563
|
+
storedCode
|
|
3564
|
+
];
|
|
3565
|
+
}
|
|
3566
|
+
__name(parseOtpVerifyReply, "parseOtpVerifyReply");
|
|
3567
|
+
function expired() {
|
|
3568
|
+
return [
|
|
3291
3569
|
"EXPIRED",
|
|
3292
3570
|
""
|
|
3293
3571
|
];
|
|
3572
|
+
}
|
|
3573
|
+
__name(expired, "expired");
|
|
3574
|
+
function maxed() {
|
|
3294
3575
|
return [
|
|
3295
|
-
|
|
3296
|
-
|
|
3576
|
+
"MAX",
|
|
3577
|
+
""
|
|
3297
3578
|
];
|
|
3298
3579
|
}
|
|
3299
|
-
__name(
|
|
3580
|
+
__name(maxed, "maxed");
|
|
3300
3581
|
var OtpService = class {
|
|
3301
3582
|
static {
|
|
3302
3583
|
__name(this, "OtpService");
|
|
@@ -3385,6 +3666,7 @@ var OtpService = class {
|
|
|
3385
3666
|
};
|
|
3386
3667
|
OtpService = _ts_decorate13([
|
|
3387
3668
|
Injectable(),
|
|
3669
|
+
_ts_param8(0, Inject(AuthRedisService)),
|
|
3388
3670
|
_ts_metadata12("design:type", Function),
|
|
3389
3671
|
_ts_metadata12("design:paramtypes", [
|
|
3390
3672
|
typeof AuthRedisService === "undefined" ? Object : AuthRedisService
|
|
@@ -3401,41 +3683,80 @@ function _ts_metadata13(k, v) {
|
|
|
3401
3683
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
3402
3684
|
}
|
|
3403
3685
|
__name(_ts_metadata13, "_ts_metadata");
|
|
3404
|
-
function
|
|
3686
|
+
function _ts_param9(paramIndex, decorator) {
|
|
3405
3687
|
return function(target, key) {
|
|
3406
3688
|
decorator(target, key, paramIndex);
|
|
3407
3689
|
};
|
|
3408
3690
|
}
|
|
3409
|
-
__name(
|
|
3691
|
+
__name(_ts_param9, "_ts_param");
|
|
3410
3692
|
var scrypt = promisify(scrypt$1);
|
|
3411
3693
|
var SCRYPT_KEY_LEN = 64;
|
|
3412
3694
|
var SALT_BYTES = 16;
|
|
3413
3695
|
var DUMMY_SALT = Buffer.from("d6732149f98b3938274691d8c2f3ee63", "hex");
|
|
3414
3696
|
var DUMMY_EXPECTED = Buffer.alloc(SCRYPT_KEY_LEN, 90);
|
|
3415
|
-
|
|
3416
|
-
|
|
3417
|
-
|
|
3418
|
-
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
if (
|
|
3424
|
-
const
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3697
|
+
var MAX_SCRYPT_PARAMETER = 255;
|
|
3698
|
+
var MIN_KEY_LEN = 10;
|
|
3699
|
+
var MAX_KEY_LEN = 64;
|
|
3700
|
+
function toPhcB64(value) {
|
|
3701
|
+
return value.toString("base64").replace(/=+$/, "");
|
|
3702
|
+
}
|
|
3703
|
+
__name(toPhcB64, "toPhcB64");
|
|
3704
|
+
function fromPhcB64(value) {
|
|
3705
|
+
if (value === "") return null;
|
|
3706
|
+
const decoded = Buffer.from(value, "base64");
|
|
3707
|
+
return toPhcB64(decoded) === value ? decoded : null;
|
|
3708
|
+
}
|
|
3709
|
+
__name(fromPhcB64, "fromPhcB64");
|
|
3710
|
+
function parsePhcParams(text) {
|
|
3711
|
+
const found = /* @__PURE__ */ new Map();
|
|
3712
|
+
for (const pair of text.split(",")) {
|
|
3713
|
+
const eq = pair.indexOf("=");
|
|
3714
|
+
if (eq <= 0) return null;
|
|
3715
|
+
const key = pair.slice(0, eq);
|
|
3716
|
+
const raw = pair.slice(eq + 1);
|
|
3717
|
+
if (found.has(key)) return null;
|
|
3718
|
+
if (!/^(0|[1-9][0-9]*)$/.test(raw)) return null;
|
|
3719
|
+
found.set(key, Number(raw));
|
|
3720
|
+
}
|
|
3721
|
+
const [ln, r, p] = [
|
|
3722
|
+
found.get("ln"),
|
|
3723
|
+
found.get("r"),
|
|
3724
|
+
found.get("p")
|
|
3428
3725
|
];
|
|
3429
|
-
if (
|
|
3430
|
-
if (
|
|
3726
|
+
if (ln === void 0 || r === void 0 || p === void 0) return null;
|
|
3727
|
+
if (ln < 1) return null;
|
|
3728
|
+
if (r < 1 || r > MAX_SCRYPT_PARAMETER || p < 1 || p > MAX_SCRYPT_PARAMETER) return null;
|
|
3729
|
+
if (128 * 2 ** ln * r > MAX_KDF_BYTES_PER_DERIVATION) return null;
|
|
3431
3730
|
return {
|
|
3432
|
-
|
|
3731
|
+
ln,
|
|
3433
3732
|
r,
|
|
3434
|
-
p
|
|
3435
|
-
|
|
3733
|
+
p
|
|
3734
|
+
};
|
|
3735
|
+
}
|
|
3736
|
+
__name(parsePhcParams, "parsePhcParams");
|
|
3737
|
+
function parsePhcHash(hash) {
|
|
3738
|
+
const [leading, algorithm, paramText, saltText, hashText, extra] = hash.split("$");
|
|
3739
|
+
if (extra !== void 0) return null;
|
|
3740
|
+
if (leading !== "" || algorithm !== "scrypt") return null;
|
|
3741
|
+
if (paramText === void 0 || saltText === void 0 || hashText === void 0) return null;
|
|
3742
|
+
const params = parsePhcParams(paramText);
|
|
3743
|
+
if (params === null) return null;
|
|
3744
|
+
const salt = fromPhcB64(saltText);
|
|
3745
|
+
const derived = fromPhcB64(hashText);
|
|
3746
|
+
if (salt === null || derived === null) return null;
|
|
3747
|
+
if (derived.length < MIN_KEY_LEN || derived.length > MAX_KEY_LEN) return null;
|
|
3748
|
+
return {
|
|
3749
|
+
N: 2 ** params.ln,
|
|
3750
|
+
r: params.r,
|
|
3751
|
+
p: params.p,
|
|
3752
|
+
salt,
|
|
3436
3753
|
derived
|
|
3437
3754
|
};
|
|
3438
3755
|
}
|
|
3756
|
+
__name(parsePhcHash, "parsePhcHash");
|
|
3757
|
+
function parseStoredHash(hash) {
|
|
3758
|
+
return parsePhcHash(hash);
|
|
3759
|
+
}
|
|
3439
3760
|
__name(parseStoredHash, "parseStoredHash");
|
|
3440
3761
|
var PasswordService = class _PasswordService {
|
|
3441
3762
|
static {
|
|
@@ -3444,11 +3765,13 @@ var PasswordService = class _PasswordService {
|
|
|
3444
3765
|
breachChecker;
|
|
3445
3766
|
logger = new Logger(_PasswordService.name);
|
|
3446
3767
|
N;
|
|
3768
|
+
minLength;
|
|
3447
3769
|
r;
|
|
3448
3770
|
p;
|
|
3449
3771
|
maxmem;
|
|
3450
3772
|
constructor(options, breachChecker) {
|
|
3451
3773
|
this.breachChecker = breachChecker;
|
|
3774
|
+
this.minLength = options.password.minLength;
|
|
3452
3775
|
this.N = options.password.costFactor;
|
|
3453
3776
|
this.r = options.password.blockSize;
|
|
3454
3777
|
this.p = options.password.parallelization;
|
|
@@ -3458,15 +3781,63 @@ var PasswordService = class _PasswordService {
|
|
|
3458
3781
|
* Hashes a plaintext password using scrypt with a random salt.
|
|
3459
3782
|
*
|
|
3460
3783
|
* @param plain - Plaintext password (UTF-8 string).
|
|
3461
|
-
* @returns Hashed password
|
|
3784
|
+
* @returns Hashed password as a PHC string.
|
|
3462
3785
|
*
|
|
3463
3786
|
* @example
|
|
3464
3787
|
* ```typescript
|
|
3465
3788
|
* const hash = await passwordService.hash('my-password')
|
|
3466
|
-
* // 'scrypt
|
|
3789
|
+
* // '$scrypt$ln=17,r=8,p=1$YmFzZTY0c2FsdA$…'
|
|
3467
3790
|
* ```
|
|
3468
3791
|
*/
|
|
3469
3792
|
/**
|
|
3793
|
+
* The whole password policy, applied wherever a password is being *set*.
|
|
3794
|
+
*
|
|
3795
|
+
* One entry point so the four call sites — registration, reset, authenticated change and
|
|
3796
|
+
* invitation acceptance — cannot drift into applying different halves of it.
|
|
3797
|
+
*
|
|
3798
|
+
* Order matters: length first, because it is decided locally and for free, and the breach
|
|
3799
|
+
* check may reach a network corpus. A password refused for being short should not cost a
|
|
3800
|
+
* round trip, and should not be sent anywhere first.
|
|
3801
|
+
*
|
|
3802
|
+
* @param plain - The plaintext password the user is trying to set.
|
|
3803
|
+
* @param field - The request field to name in a length failure's `details`.
|
|
3804
|
+
* @throws {@link AuthException} with `VALIDATION` when it is too short, or
|
|
3805
|
+
* `PASSWORD_COMPROMISED` when the corpus knows it.
|
|
3806
|
+
*/
|
|
3807
|
+
async assertAcceptable(plain, field) {
|
|
3808
|
+
this.assertLongEnough(plain, field);
|
|
3809
|
+
await this.assertNotCompromised(plain);
|
|
3810
|
+
}
|
|
3811
|
+
/**
|
|
3812
|
+
* Rejects a password shorter than the configured minimum.
|
|
3813
|
+
*
|
|
3814
|
+
* The DTOs carry a structural `@MinLength(8)` — the lowest NIST SP 800-63B-4 permits under any
|
|
3815
|
+
* circumstance — and this is the deployment's policy on top of it, which is configurable and
|
|
3816
|
+
* defaults to 15 because that is what §3.1.1.1 requires of a single-factor password. The check
|
|
3817
|
+
* lives here rather than in a decorator because a decorator is evaluated when the class is
|
|
3818
|
+
* defined, before any configuration exists.
|
|
3819
|
+
*
|
|
3820
|
+
* It answers the same `auth.validation` code and the same `{ field, message }[]` details the
|
|
3821
|
+
* validation pipe produces for a length failure, so a client already handling a short password
|
|
3822
|
+
* sees no new shape and the shared error catalog gains no entry. The breach and
|
|
3823
|
+
* common-password screens run after: they remove passwords that are already *known*, which is
|
|
3824
|
+
* a different question from how many guesses the password is worth.
|
|
3825
|
+
*
|
|
3826
|
+
* @param plain - The plaintext password the user is trying to set.
|
|
3827
|
+
* @param field - The request field to name in `details`, so the message points at the input
|
|
3828
|
+
* the caller actually sent (`password` on registration, `newPassword` on a reset).
|
|
3829
|
+
* @throws {@link AuthException} with `VALIDATION` when the password is too short.
|
|
3830
|
+
*/
|
|
3831
|
+
assertLongEnough(plain, field) {
|
|
3832
|
+
if (plain.length >= this.minLength) return;
|
|
3833
|
+
throw new AuthException(AUTH_ERROR_CODES.VALIDATION, HttpStatus.BAD_REQUEST, [
|
|
3834
|
+
{
|
|
3835
|
+
field,
|
|
3836
|
+
message: `${field} must be at least ${String(this.minLength)} characters`
|
|
3837
|
+
}
|
|
3838
|
+
]);
|
|
3839
|
+
}
|
|
3840
|
+
/**
|
|
3470
3841
|
* Rejects a password that appears in a known-breach corpus.
|
|
3471
3842
|
*
|
|
3472
3843
|
* Called wherever a password is being *set* — registration, reset, invitation acceptance —
|
|
@@ -3510,7 +3881,8 @@ var PasswordService = class _PasswordService {
|
|
|
3510
3881
|
p: this.p,
|
|
3511
3882
|
maxmem: this.maxmem
|
|
3512
3883
|
});
|
|
3513
|
-
|
|
3884
|
+
const ln = Math.log2(this.N);
|
|
3885
|
+
return `$scrypt$ln=${ln},r=${this.r},p=${this.p}$${toPhcB64(salt)}$${toPhcB64(derived)}`;
|
|
3514
3886
|
}
|
|
3515
3887
|
/**
|
|
3516
3888
|
* Whether a stored hash was written under weaker parameters than the ones configured now.
|
|
@@ -3531,7 +3903,7 @@ var PasswordService = class _PasswordService {
|
|
|
3531
3903
|
* Verifies a plaintext password against a stored scrypt hash.
|
|
3532
3904
|
*
|
|
3533
3905
|
* @param plain - Plaintext password supplied by the user.
|
|
3534
|
-
* @param hash - Stored hash
|
|
3906
|
+
* @param hash - Stored hash, as a PHC string.
|
|
3535
3907
|
* @returns `true` if the password matches, `false` otherwise.
|
|
3536
3908
|
*
|
|
3537
3909
|
* @remarks
|
|
@@ -3544,12 +3916,31 @@ var PasswordService = class _PasswordService {
|
|
|
3544
3916
|
const parsed = parseStoredHash(hash);
|
|
3545
3917
|
if (parsed === null) return false;
|
|
3546
3918
|
const { N, r, p } = parsed;
|
|
3547
|
-
const candidate = await scrypt(plain, parsed.salt,
|
|
3919
|
+
const candidate = await scrypt(plain, parsed.salt, parsed.derived.length, {
|
|
3548
3920
|
N,
|
|
3549
3921
|
r,
|
|
3550
3922
|
p,
|
|
3551
|
-
//
|
|
3552
|
-
|
|
3923
|
+
// A FIXED ceiling, deliberately not derived from the record.
|
|
3924
|
+
//
|
|
3925
|
+
// This used to be `Math.max(N * r * 128 * 2, this.maxmem)` — sized to the parameters
|
|
3926
|
+
// actually being used, on the reasoning that `parsePhcParams` had already refused any
|
|
3927
|
+
// record above `MAX_KDF_BYTES_PER_DERIVATION` so it could never widen far. That is true,
|
|
3928
|
+
// and it made this line the second half of a single point of failure: the parser's ceiling
|
|
3929
|
+
// was the ONLY thing between a crafted record and a `128 * N * r` allocation, because a
|
|
3930
|
+
// ceiling computed FROM the record grows to fit whatever the record claims. Remove that one
|
|
3931
|
+
// check and `ln = 31, r = 8` asks for 2 TiB, which does not fail the request — it OOM-kills
|
|
3932
|
+
// the process and every in-flight connection with it.
|
|
3933
|
+
//
|
|
3934
|
+
// A constant cannot be widened by input. Nothing legitimate notices: the parser admits only
|
|
3935
|
+
// records needing at most `MAX_KDF_BYTES_PER_DERIVATION`, and `this.maxmem` cannot exceed
|
|
3936
|
+
// twice that ceiling either (startup holds the configured cost to the same limit), so this
|
|
3937
|
+
// is at or above every value the old expression could produce for a reachable input.
|
|
3938
|
+
// Above it, scrypt throws instead of allocating — a failed verification rather than a dead
|
|
3939
|
+
// host.
|
|
3940
|
+
// Stryker disable next-line ArithmeticOperator: `maxmem` is a CEILING and only its being too
|
|
3941
|
+
// LOW is observable (scrypt throws). Halving it leaves it above what any hash these tests
|
|
3942
|
+
// verify actually needs, so the derivation and its result are identical
|
|
3943
|
+
maxmem: MAX_KDF_BYTES_PER_DERIVATION * 2
|
|
3553
3944
|
});
|
|
3554
3945
|
return timingSafeEqual(candidate, parsed.derived);
|
|
3555
3946
|
}
|
|
@@ -3583,8 +3974,8 @@ var PasswordService = class _PasswordService {
|
|
|
3583
3974
|
};
|
|
3584
3975
|
PasswordService = _ts_decorate14([
|
|
3585
3976
|
Injectable(),
|
|
3586
|
-
|
|
3587
|
-
|
|
3977
|
+
_ts_param9(0, Inject(BYMAX_AUTH_OPTIONS)),
|
|
3978
|
+
_ts_param9(1, Inject(BYMAX_AUTH_BREACH_CHECKER)),
|
|
3588
3979
|
_ts_metadata13("design:type", Function),
|
|
3589
3980
|
_ts_metadata13("design:paramtypes", [
|
|
3590
3981
|
typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions,
|
|
@@ -3602,12 +3993,12 @@ function _ts_metadata14(k, v) {
|
|
|
3602
3993
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
3603
3994
|
}
|
|
3604
3995
|
__name(_ts_metadata14, "_ts_metadata");
|
|
3605
|
-
function
|
|
3996
|
+
function _ts_param10(paramIndex, decorator) {
|
|
3606
3997
|
return function(target, key) {
|
|
3607
3998
|
decorator(target, key, paramIndex);
|
|
3608
3999
|
};
|
|
3609
4000
|
}
|
|
3610
|
-
__name(
|
|
4001
|
+
__name(_ts_param10, "_ts_param");
|
|
3611
4002
|
var MAX_IP_LENGTH = 45;
|
|
3612
4003
|
var SESSION_HASH_RE = /^[a-f0-9]{64}$/;
|
|
3613
4004
|
var REVOKE_SESSION_LUA = `
|
|
@@ -3740,9 +4131,11 @@ var SessionService = class _SessionService {
|
|
|
3740
4131
|
*
|
|
3741
4132
|
* Reads all `rt:`-prefixed members from `sess:{userId}`, fetches the
|
|
3742
4133
|
* corresponding `sd:{hash}` detail records, and marks the caller's own
|
|
3743
|
-
* session via `isCurrent`.
|
|
3744
|
-
*
|
|
3745
|
-
* and
|
|
4134
|
+
* session via `isCurrent`. A member whose detail record is missing, unreadable
|
|
4135
|
+
* or malformed is excluded from the result, and removed from the SET
|
|
4136
|
+
* asynchronously (fire-and-forget) only if its `rt:` key is also gone — see
|
|
4137
|
+
* {@link AuthRedisService.pruneDeadMembers} for why the detail record alone
|
|
4138
|
+
* does not settle it.
|
|
3746
4139
|
*
|
|
3747
4140
|
* Results are sorted by `createdAt` descending (newest session first).
|
|
3748
4141
|
*
|
|
@@ -3752,6 +4145,9 @@ var SessionService = class _SessionService {
|
|
|
3752
4145
|
* @returns Array of {@link SessionInfo} sorted newest-first.
|
|
3753
4146
|
*/
|
|
3754
4147
|
async listSessions(userId, currentSessionHash) {
|
|
4148
|
+
void this.redis.pruneExpiredGraceMembers(`sess:${userId}`, "rp:").catch((err) => {
|
|
4149
|
+
this.logger.warn("listSessions: grace-pointer prune failed", err);
|
|
4150
|
+
});
|
|
3755
4151
|
const members = await this.redis.smembers(`sess:${userId}`);
|
|
3756
4152
|
const rtMembers = members.filter((m) => m.startsWith("rt:"));
|
|
3757
4153
|
const results = [];
|
|
@@ -3802,11 +4198,9 @@ var SessionService = class _SessionService {
|
|
|
3802
4198
|
lastActivityAt: detail.lastActivityAt
|
|
3803
4199
|
});
|
|
3804
4200
|
}));
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
});
|
|
3809
|
-
}
|
|
4201
|
+
void this.redis.pruneDeadMembers(`sess:${userId}`, staleKeys).catch((err) => {
|
|
4202
|
+
this.logger.error(`listSessions: failed to prune ${staleKeys.length} dead member(s)`, err);
|
|
4203
|
+
});
|
|
3810
4204
|
results.sort((a, b) => b.createdAt - a.createdAt);
|
|
3811
4205
|
return results;
|
|
3812
4206
|
}
|
|
@@ -4020,6 +4414,7 @@ var SessionService = class _SessionService {
|
|
|
4020
4414
|
* @param userAgent - User-Agent string (forwarded to the `onSessionEvicted` hook context).
|
|
4021
4415
|
*/
|
|
4022
4416
|
async enforceSessionLimit(userId, newHash, ip, userAgent) {
|
|
4417
|
+
await this.redis.pruneExpiredGraceMembers(`sess:${userId}`, "rp:");
|
|
4023
4418
|
const members = await this.redis.smembers(`sess:${userId}`);
|
|
4024
4419
|
const rtMembers = members.filter((m) => m.startsWith("rt:"));
|
|
4025
4420
|
const limit = await this.resolveSessionLimit(userId);
|
|
@@ -4111,10 +4506,11 @@ var SessionService = class _SessionService {
|
|
|
4111
4506
|
};
|
|
4112
4507
|
SessionService = _ts_decorate15([
|
|
4113
4508
|
Injectable(),
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4509
|
+
_ts_param10(0, Inject(BYMAX_AUTH_OPTIONS)),
|
|
4510
|
+
_ts_param10(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
|
|
4511
|
+
_ts_param10(2, Inject(BYMAX_AUTH_HOOKS)),
|
|
4512
|
+
_ts_param10(2, Optional()),
|
|
4513
|
+
_ts_param10(3, Inject(AuthRedisService)),
|
|
4118
4514
|
_ts_metadata14("design:type", Function),
|
|
4119
4515
|
_ts_metadata14("design:paramtypes", [
|
|
4120
4516
|
typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions,
|
|
@@ -4131,6 +4527,13 @@ function recentAuthKey(plane, userId, hmacKey) {
|
|
|
4131
4527
|
}
|
|
4132
4528
|
__name(recentAuthKey, "recentAuthKey");
|
|
4133
4529
|
|
|
4530
|
+
// src/server/utils/log-safe.ts
|
|
4531
|
+
var CONTROL_CHARACTERS = /[\u0000-\u001F\u007F-\u009F]/;
|
|
4532
|
+
function logSafe(value) {
|
|
4533
|
+
return CONTROL_CHARACTERS.test(value) ? "<malformed>" : value;
|
|
4534
|
+
}
|
|
4535
|
+
__name(logSafe, "logSafe");
|
|
4536
|
+
|
|
4134
4537
|
// src/server/services/token-manager.service.ts
|
|
4135
4538
|
function _ts_decorate16(decorators, target, key, desc) {
|
|
4136
4539
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
@@ -4143,12 +4546,12 @@ function _ts_metadata15(k, v) {
|
|
|
4143
4546
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
4144
4547
|
}
|
|
4145
4548
|
__name(_ts_metadata15, "_ts_metadata");
|
|
4146
|
-
function
|
|
4549
|
+
function _ts_param11(paramIndex, decorator) {
|
|
4147
4550
|
return function(target, key) {
|
|
4148
4551
|
decorator(target, key, paramIndex);
|
|
4149
4552
|
};
|
|
4150
4553
|
}
|
|
4151
|
-
__name(
|
|
4554
|
+
__name(_ts_param11, "_ts_param");
|
|
4152
4555
|
var MFA_TEMP_TOKEN_TTL_SECONDS = 300;
|
|
4153
4556
|
var MAX_SESSION_FIELD_LENGTH = 45;
|
|
4154
4557
|
var TokenManagerService = class _TokenManagerService {
|
|
@@ -4266,15 +4669,17 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
4266
4669
|
});
|
|
4267
4670
|
const rawRefreshToken = generateSecureToken();
|
|
4268
4671
|
const tokenHash = sha256(rawRefreshToken);
|
|
4269
|
-
const sessionKey = `rt:${tokenHash}`;
|
|
4270
4672
|
const familyId = randomUUID();
|
|
4271
4673
|
const session = this.buildSession(user.id, user.tenantId, user.role, ip, userAgent, user.mfaEnabled, familyId);
|
|
4272
4674
|
const ttl = this.options.jwt.refreshExpiresInDays * 86400;
|
|
4273
|
-
await this.redis.
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
|
|
4277
|
-
|
|
4675
|
+
await this.redis.writeNewSession({
|
|
4676
|
+
kind: "dashboard",
|
|
4677
|
+
tokenHash,
|
|
4678
|
+
sessionJson: this.serializeSession(session),
|
|
4679
|
+
familyId,
|
|
4680
|
+
userId: user.id,
|
|
4681
|
+
refreshTtl: ttl
|
|
4682
|
+
});
|
|
4278
4683
|
await this.redis.set(recentAuthKey("dashboard", user.id, this.options.hmacKey), "1", RECENT_AUTH_TTL_SECONDS);
|
|
4279
4684
|
return {
|
|
4280
4685
|
user,
|
|
@@ -4309,15 +4714,17 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
4309
4714
|
});
|
|
4310
4715
|
const rawRefreshToken = generateSecureToken();
|
|
4311
4716
|
const tokenHash = sha256(rawRefreshToken);
|
|
4312
|
-
const sessionKey = `prt:${tokenHash}`;
|
|
4313
4717
|
const familyId = randomUUID();
|
|
4314
4718
|
const session = this.buildSession(admin.id, "", admin.role, ip, userAgent, admin.mfaEnabled, familyId);
|
|
4315
4719
|
const ttl = this.options.jwt.refreshExpiresInDays * 86400;
|
|
4316
|
-
await this.redis.
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4720
|
+
await this.redis.writeNewSession({
|
|
4721
|
+
kind: "platform",
|
|
4722
|
+
tokenHash,
|
|
4723
|
+
sessionJson: this.serializeSession(session),
|
|
4724
|
+
familyId,
|
|
4725
|
+
userId: admin.id,
|
|
4726
|
+
refreshTtl: ttl
|
|
4727
|
+
});
|
|
4321
4728
|
await this.writePlatformSessionDetail(tokenHash, ip, userAgent, ttl);
|
|
4322
4729
|
return {
|
|
4323
4730
|
admin,
|
|
@@ -4408,8 +4815,9 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
4408
4815
|
return this.rotateFromGrace(outcome.sessionJson, ip, userAgent, refreshTtl);
|
|
4409
4816
|
}
|
|
4410
4817
|
if (outcome.kind === "reused") {
|
|
4411
|
-
this.logger.warn(
|
|
4818
|
+
this.logger.warn(`reissueTokens: reuse of a consumed refresh token detected \u2014 revoking the token family familyId=${logSafe(outcome.familyId)}`);
|
|
4412
4819
|
const { ownerId } = await this.redis.revokeFamily(outcome.familyId);
|
|
4820
|
+
this.logger.warn(`reissueTokens: token family revoked after reuse detection userId=${logSafe(ownerId)} familyId=${logSafe(outcome.familyId)}`);
|
|
4413
4821
|
this.emitReuseDetected(ownerId, outcome.familyId);
|
|
4414
4822
|
throw new AuthException(AUTH_ERROR_CODES.REFRESH_TOKEN_INVALID);
|
|
4415
4823
|
}
|
|
@@ -4417,23 +4825,6 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
4417
4825
|
throw new AuthException(AUTH_ERROR_CODES.REFRESH_TOKEN_INVALID);
|
|
4418
4826
|
}
|
|
4419
4827
|
/**
|
|
4420
|
-
* Refuses a rotation once the login it descends from has outlived the absolute cap.
|
|
4421
|
-
*
|
|
4422
|
-
* `refreshExpiresInDays` bounds a single refresh token, not a session: a client rotating
|
|
4423
|
-
* every fifteen minutes renews that lifetime forever, so without this a session established
|
|
4424
|
-
* once never has to be established again. The cap measures from the **family's** birth, which
|
|
4425
|
-
* is carried unchanged through the lineage.
|
|
4426
|
-
*
|
|
4427
|
-
* A session with no birth time predates the field and is not capped — it ages out under the
|
|
4428
|
-
* refresh lifetime like any other. A cap of `0` disables the check entirely.
|
|
4429
|
-
*
|
|
4430
|
-
* @param session - The presented session, or the placeholder when the token is not live.
|
|
4431
|
-
* @throws {@link AuthException} with `REFRESH_TOKEN_INVALID` once the cap is passed. The
|
|
4432
|
-
* caller cannot distinguish this from any other invalid refresh, which is deliberate: the
|
|
4433
|
-
* remedy is the same (sign in again) and the difference would only tell a holder of a
|
|
4434
|
-
* stolen token how old the account's session is.
|
|
4435
|
-
*/
|
|
4436
|
-
/**
|
|
4437
4828
|
* Emits {@link IAuthHooks.onRefreshTokenReuseDetected}, fire-and-forget.
|
|
4438
4829
|
*
|
|
4439
4830
|
* The owner is read from the stored session where it can be — a replay of a token whose live
|
|
@@ -4453,6 +4844,23 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
4453
4844
|
this.logger.error("onRefreshTokenReuseDetected hook threw synchronously", err);
|
|
4454
4845
|
}
|
|
4455
4846
|
}
|
|
4847
|
+
/**
|
|
4848
|
+
* Refuses a rotation once the login it descends from has outlived the absolute cap.
|
|
4849
|
+
*
|
|
4850
|
+
* `refreshExpiresInDays` bounds a single refresh token, not a session: a client rotating
|
|
4851
|
+
* every fifteen minutes renews that lifetime forever, so without this a session established
|
|
4852
|
+
* once never has to be established again. The cap measures from the **family's** birth, which
|
|
4853
|
+
* is carried unchanged through the lineage.
|
|
4854
|
+
*
|
|
4855
|
+
* A session with no birth time predates the field and is not capped — it ages out under the
|
|
4856
|
+
* refresh lifetime like any other. A cap of `0` disables the check entirely.
|
|
4857
|
+
*
|
|
4858
|
+
* @param session - The presented session, or the placeholder when the token is not live.
|
|
4859
|
+
* @throws {@link AuthException} with `REFRESH_TOKEN_INVALID` once the cap is passed. The
|
|
4860
|
+
* caller cannot distinguish this from any other invalid refresh, which is deliberate: the
|
|
4861
|
+
* remedy is the same (sign in again) and the difference would only tell a holder of a
|
|
4862
|
+
* stolen token how old the account's session is.
|
|
4863
|
+
*/
|
|
4456
4864
|
assertWithinAbsoluteLifetime(session) {
|
|
4457
4865
|
const capDays = this.options.jwt.absoluteSessionLifetimeDays;
|
|
4458
4866
|
if (capDays <= 0) return;
|
|
@@ -4685,8 +5093,9 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
4685
5093
|
return this.rotatePlatformFromGrace(outcome.sessionJson, oldHash, ip, userAgent, refreshTtl);
|
|
4686
5094
|
}
|
|
4687
5095
|
if (outcome.kind === "reused") {
|
|
4688
|
-
this.logger.warn(
|
|
5096
|
+
this.logger.warn(`reissuePlatformTokens: reuse of a consumed refresh token detected \u2014 revoking the token family familyId=${logSafe(outcome.familyId)}`);
|
|
4689
5097
|
const { ownerId } = await this.redis.revokeFamily(outcome.familyId, "platform");
|
|
5098
|
+
this.logger.warn(`reissuePlatformTokens: token family revoked after reuse detection userId=${logSafe(ownerId)} familyId=${logSafe(outcome.familyId)}`);
|
|
4690
5099
|
this.emitReuseDetected(ownerId, outcome.familyId);
|
|
4691
5100
|
throw new AuthException(AUTH_ERROR_CODES.REFRESH_TOKEN_INVALID);
|
|
4692
5101
|
}
|
|
@@ -4795,23 +5204,9 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
4795
5204
|
});
|
|
4796
5205
|
}
|
|
4797
5206
|
// ---------------------------------------------------------------------------
|
|
4798
|
-
//
|
|
5207
|
+
// Verification that ignores expiry (logout only)
|
|
4799
5208
|
// ---------------------------------------------------------------------------
|
|
4800
5209
|
/**
|
|
4801
|
-
* Decodes a JWT without validating its expiration or signature.
|
|
4802
|
-
*
|
|
4803
|
-
* @internal
|
|
4804
|
-
* **WARNING:** This method does NOT verify the token signature or expiry.
|
|
4805
|
-
* It must only be used for internal diagnostic purposes (e.g. reading the
|
|
4806
|
-
* `sub` claim from an expired token to look up a session for revocation).
|
|
4807
|
-
* Never use it to authorize requests — use `JwtService.verify()` in guards.
|
|
4808
|
-
*
|
|
4809
|
-
* @param token - Raw JWT string.
|
|
4810
|
-
* @returns Decoded payload.
|
|
4811
|
-
* @throws {@link AuthException} with `TOKEN_INVALID` if the payload is not an
|
|
4812
|
-
* object or lacks required `jti` (string) and `sub` (string) claims.
|
|
4813
|
-
*/
|
|
4814
|
-
/**
|
|
4815
5210
|
* Verifies an access token's signature under the pinned algorithm while **ignoring its
|
|
4816
5211
|
* expiry**, returning the payload.
|
|
4817
5212
|
*
|
|
@@ -4847,16 +5242,6 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
4847
5242
|
ignoreExpiration: true
|
|
4848
5243
|
});
|
|
4849
5244
|
}
|
|
4850
|
-
decodeToken(token) {
|
|
4851
|
-
const raw = this.jwtService.decode(token);
|
|
4852
|
-
if (
|
|
4853
|
-
// Stryker disable next-line ConditionalExpression: the object-type clause is redundant: every reachable non-object value also fails the sibling field checks, so dropping it changes nothing
|
|
4854
|
-
typeof raw !== "object" || raw === null || typeof raw["jti"] !== "string" || typeof raw["sub"] !== "string"
|
|
4855
|
-
) {
|
|
4856
|
-
throw new AuthException(AUTH_ERROR_CODES.TOKEN_INVALID);
|
|
4857
|
-
}
|
|
4858
|
-
return raw;
|
|
4859
|
-
}
|
|
4860
5245
|
// ---------------------------------------------------------------------------
|
|
4861
5246
|
// MFA temp tokens
|
|
4862
5247
|
// ---------------------------------------------------------------------------
|
|
@@ -4964,9 +5349,11 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
4964
5349
|
};
|
|
4965
5350
|
TokenManagerService = _ts_decorate16([
|
|
4966
5351
|
Injectable(),
|
|
4967
|
-
|
|
4968
|
-
|
|
4969
|
-
|
|
5352
|
+
_ts_param11(0, Inject(JwtService)),
|
|
5353
|
+
_ts_param11(1, Inject(BYMAX_AUTH_OPTIONS)),
|
|
5354
|
+
_ts_param11(2, Inject(AuthRedisService)),
|
|
5355
|
+
_ts_param11(3, Inject(BYMAX_AUTH_HOOKS)),
|
|
5356
|
+
_ts_param11(3, Optional()),
|
|
4970
5357
|
_ts_metadata15("design:type", Function),
|
|
4971
5358
|
_ts_metadata15("design:paramtypes", [
|
|
4972
5359
|
typeof JwtService === "undefined" ? Object : JwtService,
|
|
@@ -4976,13 +5363,6 @@ TokenManagerService = _ts_decorate16([
|
|
|
4976
5363
|
])
|
|
4977
5364
|
], TokenManagerService);
|
|
4978
5365
|
|
|
4979
|
-
// src/server/utils/log-safe.ts
|
|
4980
|
-
var CONTROL_CHARACTERS = /[\u0000-\u001F\u007F-\u009F]/;
|
|
4981
|
-
function logSafe(value) {
|
|
4982
|
-
return CONTROL_CHARACTERS.test(value) ? "<malformed>" : value;
|
|
4983
|
-
}
|
|
4984
|
-
__name(logSafe, "logSafe");
|
|
4985
|
-
|
|
4986
5366
|
// src/server/utils/mask-email.ts
|
|
4987
5367
|
function maskEmail(email) {
|
|
4988
5368
|
const atIndex = email.indexOf("@");
|
|
@@ -5025,12 +5405,12 @@ function _ts_metadata16(k, v) {
|
|
|
5025
5405
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
5026
5406
|
}
|
|
5027
5407
|
__name(_ts_metadata16, "_ts_metadata");
|
|
5028
|
-
function
|
|
5408
|
+
function _ts_param12(paramIndex, decorator) {
|
|
5029
5409
|
return function(target, key) {
|
|
5030
5410
|
decorator(target, key, paramIndex);
|
|
5031
5411
|
};
|
|
5032
5412
|
}
|
|
5033
|
-
__name(
|
|
5413
|
+
__name(_ts_param12, "_ts_param");
|
|
5034
5414
|
var ANTI_ENUM_MIN_MS = 300;
|
|
5035
5415
|
var AuthService = class _AuthService {
|
|
5036
5416
|
static {
|
|
@@ -5159,7 +5539,7 @@ var AuthService = class _AuthService {
|
|
|
5159
5539
|
await this.passwordService.compareDummy(dto.password);
|
|
5160
5540
|
throw new AuthException(AUTH_ERROR_CODES.EMAIL_ALREADY_EXISTS);
|
|
5161
5541
|
}
|
|
5162
|
-
await this.passwordService.
|
|
5542
|
+
await this.passwordService.assertAcceptable(dto.password, "password");
|
|
5163
5543
|
const passwordHash = await this.passwordService.hash(dto.password);
|
|
5164
5544
|
const newUser = await this.userRepo.create({
|
|
5165
5545
|
email: dto.email,
|
|
@@ -5645,6 +6025,24 @@ var AuthService = class _AuthService {
|
|
|
5645
6025
|
// Private helpers
|
|
5646
6026
|
// ---------------------------------------------------------------------------
|
|
5647
6027
|
/**
|
|
6028
|
+
* Derives the OTP-record identifier for a `tenantId + email` pair.
|
|
6029
|
+
*
|
|
6030
|
+
* HMAC rather than a bare digest because an address is low-entropy: a bare SHA-256 of one is
|
|
6031
|
+
* reversible by dictionary, and these identifiers are the Redis key an operator can read.
|
|
6032
|
+
* The preimage is pinned by `conformance/wire-contract.json` and shared byte-for-byte with
|
|
6033
|
+
* rust-auth, which keys the same records in the same Redis.
|
|
6034
|
+
*
|
|
6035
|
+
* Deliberately distinct from {@link lockoutIdentifier}: that one namespaces the login
|
|
6036
|
+
* keyspace with a `dashboard:` prefix, and the two must never collide.
|
|
6037
|
+
*
|
|
6038
|
+
* @param tenantId - Tenant scope.
|
|
6039
|
+
* @param email - The canonicalized address.
|
|
6040
|
+
* @returns Hex HMAC-SHA-256 identifier.
|
|
6041
|
+
*/
|
|
6042
|
+
otpIdentifier(tenantId, email) {
|
|
6043
|
+
return hmacSha256(`${tenantId}:${email}`, this.options.hmacKey);
|
|
6044
|
+
}
|
|
6045
|
+
/**
|
|
5648
6046
|
* The brute-force counter key for a dashboard account.
|
|
5649
6047
|
*
|
|
5650
6048
|
* The identity PLANE is part of the preimage, not just the tenant. Without it a tenant whose
|
|
@@ -5664,24 +6062,6 @@ var AuthService = class _AuthService {
|
|
|
5664
6062
|
* @param email - The address, already normalized by the caller.
|
|
5665
6063
|
* @returns The HMAC identifier, opaque and non-reversible.
|
|
5666
6064
|
*/
|
|
5667
|
-
/**
|
|
5668
|
-
* Derives the OTP-record identifier for a `tenantId + email` pair.
|
|
5669
|
-
*
|
|
5670
|
-
* HMAC rather than a bare digest because an address is low-entropy: a bare SHA-256 of one is
|
|
5671
|
-
* reversible by dictionary, and these identifiers are the Redis key an operator can read.
|
|
5672
|
-
* The preimage is pinned by `conformance/wire-contract.json` and shared byte-for-byte with
|
|
5673
|
-
* rust-auth, which keys the same records in the same Redis.
|
|
5674
|
-
*
|
|
5675
|
-
* Deliberately distinct from {@link lockoutIdentifier}: that one namespaces the login
|
|
5676
|
-
* keyspace with a `dashboard:` prefix, and the two must never collide.
|
|
5677
|
-
*
|
|
5678
|
-
* @param tenantId - Tenant scope.
|
|
5679
|
-
* @param email - The canonicalized address.
|
|
5680
|
-
* @returns Hex HMAC-SHA-256 identifier.
|
|
5681
|
-
*/
|
|
5682
|
-
otpIdentifier(tenantId, email) {
|
|
5683
|
-
return hmacSha256(`${tenantId}:${email}`, this.options.hmacKey);
|
|
5684
|
-
}
|
|
5685
6065
|
lockoutIdentifier(tenantId, email) {
|
|
5686
6066
|
return hmacSha256(`dashboard:${tenantId}:${email}`, this.options.hmacKey);
|
|
5687
6067
|
}
|
|
@@ -5766,12 +6146,18 @@ var AuthService = class _AuthService {
|
|
|
5766
6146
|
};
|
|
5767
6147
|
AuthService = _ts_decorate17([
|
|
5768
6148
|
Injectable(),
|
|
5769
|
-
|
|
5770
|
-
|
|
5771
|
-
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
6149
|
+
_ts_param12(0, Inject(BYMAX_AUTH_OPTIONS)),
|
|
6150
|
+
_ts_param12(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
|
|
6151
|
+
_ts_param12(2, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
|
|
6152
|
+
_ts_param12(2, Optional()),
|
|
6153
|
+
_ts_param12(3, Inject(BYMAX_AUTH_HOOKS)),
|
|
6154
|
+
_ts_param12(3, Optional()),
|
|
6155
|
+
_ts_param12(4, Inject(PasswordService)),
|
|
6156
|
+
_ts_param12(5, Inject(TokenManagerService)),
|
|
6157
|
+
_ts_param12(6, Inject(BruteForceService)),
|
|
6158
|
+
_ts_param12(7, Inject(AuthRedisService)),
|
|
6159
|
+
_ts_param12(8, Inject(OtpService)),
|
|
6160
|
+
_ts_param12(9, Inject(SessionService)),
|
|
5775
6161
|
_ts_metadata16("design:type", Function),
|
|
5776
6162
|
_ts_metadata16("design:paramtypes", [
|
|
5777
6163
|
typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions,
|
|
@@ -5807,12 +6193,12 @@ function _ts_metadata17(k, v) {
|
|
|
5807
6193
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
5808
6194
|
}
|
|
5809
6195
|
__name(_ts_metadata17, "_ts_metadata");
|
|
5810
|
-
function
|
|
6196
|
+
function _ts_param13(paramIndex, decorator) {
|
|
5811
6197
|
return function(target, key) {
|
|
5812
6198
|
decorator(target, key, paramIndex);
|
|
5813
6199
|
};
|
|
5814
6200
|
}
|
|
5815
|
-
__name(
|
|
6201
|
+
__name(_ts_param13, "_ts_param");
|
|
5816
6202
|
var WsTicketService = class _WsTicketService {
|
|
5817
6203
|
static {
|
|
5818
6204
|
__name(this, "WsTicketService");
|
|
@@ -5882,8 +6268,9 @@ var WsTicketService = class _WsTicketService {
|
|
|
5882
6268
|
};
|
|
5883
6269
|
WsTicketService = _ts_decorate18([
|
|
5884
6270
|
Injectable(),
|
|
5885
|
-
|
|
5886
|
-
|
|
6271
|
+
_ts_param13(0, Inject(AuthRedisService)),
|
|
6272
|
+
_ts_param13(1, Inject(BYMAX_AUTH_OPTIONS)),
|
|
6273
|
+
_ts_param13(2, Inject(BYMAX_AUTH_USER_REPOSITORY)),
|
|
5887
6274
|
_ts_metadata17("design:type", Function),
|
|
5888
6275
|
_ts_metadata17("design:paramtypes", [
|
|
5889
6276
|
typeof AuthRedisService === "undefined" ? Object : AuthRedisService,
|
|
@@ -5904,12 +6291,12 @@ function _ts_metadata18(k, v) {
|
|
|
5904
6291
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
5905
6292
|
}
|
|
5906
6293
|
__name(_ts_metadata18, "_ts_metadata");
|
|
5907
|
-
function
|
|
6294
|
+
function _ts_param14(paramIndex, decorator) {
|
|
5908
6295
|
return function(target, key) {
|
|
5909
6296
|
decorator(target, key, paramIndex);
|
|
5910
6297
|
};
|
|
5911
6298
|
}
|
|
5912
|
-
__name(
|
|
6299
|
+
__name(_ts_param14, "_ts_param");
|
|
5913
6300
|
function isMfaChallenge(result) {
|
|
5914
6301
|
return "mfaRequired" in result && result.mfaRequired === true;
|
|
5915
6302
|
}
|
|
@@ -6056,9 +6443,9 @@ _ts_decorate19([
|
|
|
6056
6443
|
Throttle(AUTH_THROTTLE_CONFIGS.register),
|
|
6057
6444
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.register),
|
|
6058
6445
|
Post("register"),
|
|
6059
|
-
|
|
6060
|
-
|
|
6061
|
-
|
|
6446
|
+
_ts_param14(0, Body()),
|
|
6447
|
+
_ts_param14(1, Req()),
|
|
6448
|
+
_ts_param14(2, Res({
|
|
6062
6449
|
passthrough: true
|
|
6063
6450
|
})),
|
|
6064
6451
|
_ts_metadata18("design:type", Function),
|
|
@@ -6075,9 +6462,9 @@ _ts_decorate19([
|
|
|
6075
6462
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.login),
|
|
6076
6463
|
HttpCode(HttpStatus.OK),
|
|
6077
6464
|
Post("login"),
|
|
6078
|
-
|
|
6079
|
-
|
|
6080
|
-
|
|
6465
|
+
_ts_param14(0, Body()),
|
|
6466
|
+
_ts_param14(1, Req()),
|
|
6467
|
+
_ts_param14(2, Res({
|
|
6081
6468
|
passthrough: true
|
|
6082
6469
|
})),
|
|
6083
6470
|
_ts_metadata18("design:type", Function),
|
|
@@ -6094,8 +6481,8 @@ _ts_decorate19([
|
|
|
6094
6481
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.logout),
|
|
6095
6482
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
6096
6483
|
Post("logout"),
|
|
6097
|
-
|
|
6098
|
-
|
|
6484
|
+
_ts_param14(0, Req()),
|
|
6485
|
+
_ts_param14(1, Res({
|
|
6099
6486
|
passthrough: true
|
|
6100
6487
|
})),
|
|
6101
6488
|
_ts_metadata18("design:type", Function),
|
|
@@ -6111,8 +6498,8 @@ _ts_decorate19([
|
|
|
6111
6498
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.refresh),
|
|
6112
6499
|
HttpCode(HttpStatus.OK),
|
|
6113
6500
|
Post("refresh"),
|
|
6114
|
-
|
|
6115
|
-
|
|
6501
|
+
_ts_param14(0, Req()),
|
|
6502
|
+
_ts_param14(1, Res({
|
|
6116
6503
|
passthrough: true
|
|
6117
6504
|
})),
|
|
6118
6505
|
_ts_metadata18("design:type", Function),
|
|
@@ -6125,7 +6512,7 @@ _ts_decorate19([
|
|
|
6125
6512
|
_ts_decorate19([
|
|
6126
6513
|
UseGuards(JwtAuthGuard),
|
|
6127
6514
|
Get("me"),
|
|
6128
|
-
|
|
6515
|
+
_ts_param14(0, CurrentUser()),
|
|
6129
6516
|
_ts_metadata18("design:type", Function),
|
|
6130
6517
|
_ts_metadata18("design:paramtypes", [
|
|
6131
6518
|
typeof DashboardJwtPayload === "undefined" ? Object : DashboardJwtPayload
|
|
@@ -6138,7 +6525,7 @@ _ts_decorate19([
|
|
|
6138
6525
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.wsTicket),
|
|
6139
6526
|
Post("ws-ticket"),
|
|
6140
6527
|
HttpCode(HttpStatus.OK),
|
|
6141
|
-
|
|
6528
|
+
_ts_param14(0, CurrentUser()),
|
|
6142
6529
|
_ts_metadata18("design:type", Function),
|
|
6143
6530
|
_ts_metadata18("design:paramtypes", [
|
|
6144
6531
|
typeof DashboardJwtPayload === "undefined" ? Object : DashboardJwtPayload
|
|
@@ -6151,8 +6538,8 @@ _ts_decorate19([
|
|
|
6151
6538
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.verifyEmail),
|
|
6152
6539
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
6153
6540
|
Post("verify-email"),
|
|
6154
|
-
|
|
6155
|
-
|
|
6541
|
+
_ts_param14(0, Body()),
|
|
6542
|
+
_ts_param14(1, Req()),
|
|
6156
6543
|
_ts_metadata18("design:type", Function),
|
|
6157
6544
|
_ts_metadata18("design:paramtypes", [
|
|
6158
6545
|
typeof VerifyEmailDto === "undefined" ? Object : VerifyEmailDto,
|
|
@@ -6166,8 +6553,8 @@ _ts_decorate19([
|
|
|
6166
6553
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.resendVerification),
|
|
6167
6554
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
6168
6555
|
Post("resend-verification"),
|
|
6169
|
-
|
|
6170
|
-
|
|
6556
|
+
_ts_param14(0, Body()),
|
|
6557
|
+
_ts_param14(1, Req()),
|
|
6171
6558
|
_ts_metadata18("design:type", Function),
|
|
6172
6559
|
_ts_metadata18("design:paramtypes", [
|
|
6173
6560
|
typeof ResendVerificationDto === "undefined" ? Object : ResendVerificationDto,
|
|
@@ -6180,6 +6567,9 @@ AuthController = _ts_decorate19([
|
|
|
6180
6567
|
Controller(),
|
|
6181
6568
|
UseGuards(TrustedOriginGuard, AuthRateLimitGuard),
|
|
6182
6569
|
UsePipes(createAuthValidationPipe()),
|
|
6570
|
+
_ts_param14(0, Inject(AuthService)),
|
|
6571
|
+
_ts_param14(1, Inject(TokenDeliveryService)),
|
|
6572
|
+
_ts_param14(2, Inject(WsTicketService)),
|
|
6183
6573
|
_ts_metadata18("design:type", Function),
|
|
6184
6574
|
_ts_metadata18("design:paramtypes", [
|
|
6185
6575
|
typeof AuthService === "undefined" ? Object : AuthService,
|
|
@@ -6270,12 +6660,12 @@ function _ts_metadata21(k, v) {
|
|
|
6270
6660
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
6271
6661
|
}
|
|
6272
6662
|
__name(_ts_metadata21, "_ts_metadata");
|
|
6273
|
-
function
|
|
6663
|
+
function _ts_param15(paramIndex, decorator) {
|
|
6274
6664
|
return function(target, key) {
|
|
6275
6665
|
decorator(target, key, paramIndex);
|
|
6276
6666
|
};
|
|
6277
6667
|
}
|
|
6278
|
-
__name(
|
|
6668
|
+
__name(_ts_param15, "_ts_param");
|
|
6279
6669
|
var EMAIL_CHANGE_TOKEN_BYTES = 32;
|
|
6280
6670
|
function isEmailChangeContext(value) {
|
|
6281
6671
|
if (typeof value !== "object" || value === null) return false;
|
|
@@ -6490,9 +6880,12 @@ var EmailChangeService = class _EmailChangeService {
|
|
|
6490
6880
|
};
|
|
6491
6881
|
EmailChangeService = _ts_decorate22([
|
|
6492
6882
|
Injectable(),
|
|
6493
|
-
|
|
6494
|
-
|
|
6495
|
-
|
|
6883
|
+
_ts_param15(0, Inject(BYMAX_AUTH_OPTIONS)),
|
|
6884
|
+
_ts_param15(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
|
|
6885
|
+
_ts_param15(2, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
|
|
6886
|
+
_ts_param15(3, Inject(PasswordService)),
|
|
6887
|
+
_ts_param15(4, Inject(AuthRedisService)),
|
|
6888
|
+
_ts_param15(5, Inject(BruteForceService)),
|
|
6496
6889
|
_ts_metadata21("design:type", Function),
|
|
6497
6890
|
_ts_metadata21("design:paramtypes", [
|
|
6498
6891
|
typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions,
|
|
@@ -6516,12 +6909,12 @@ function _ts_metadata22(k, v) {
|
|
|
6516
6909
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
6517
6910
|
}
|
|
6518
6911
|
__name(_ts_metadata22, "_ts_metadata");
|
|
6519
|
-
function
|
|
6912
|
+
function _ts_param16(paramIndex, decorator) {
|
|
6520
6913
|
return function(target, key) {
|
|
6521
6914
|
decorator(target, key, paramIndex);
|
|
6522
6915
|
};
|
|
6523
6916
|
}
|
|
6524
|
-
__name(
|
|
6917
|
+
__name(_ts_param16, "_ts_param");
|
|
6525
6918
|
var EmailChangeController = class {
|
|
6526
6919
|
static {
|
|
6527
6920
|
__name(this, "EmailChangeController");
|
|
@@ -6574,8 +6967,8 @@ _ts_decorate23([
|
|
|
6574
6967
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.emailChangeRequest),
|
|
6575
6968
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
6576
6969
|
Post("change"),
|
|
6577
|
-
|
|
6578
|
-
|
|
6970
|
+
_ts_param16(0, Body()),
|
|
6971
|
+
_ts_param16(1, CurrentUser()),
|
|
6579
6972
|
_ts_metadata22("design:type", Function),
|
|
6580
6973
|
_ts_metadata22("design:paramtypes", [
|
|
6581
6974
|
typeof ChangeEmailDto === "undefined" ? Object : ChangeEmailDto,
|
|
@@ -6589,7 +6982,7 @@ _ts_decorate23([
|
|
|
6589
6982
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.emailChangeConfirm),
|
|
6590
6983
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
6591
6984
|
Post("change/confirm"),
|
|
6592
|
-
|
|
6985
|
+
_ts_param16(0, Body()),
|
|
6593
6986
|
_ts_metadata22("design:type", Function),
|
|
6594
6987
|
_ts_metadata22("design:paramtypes", [
|
|
6595
6988
|
typeof ConfirmEmailChangeDto === "undefined" ? Object : ConfirmEmailChangeDto
|
|
@@ -6601,6 +6994,7 @@ EmailChangeController = _ts_decorate23([
|
|
|
6601
6994
|
Controller("email"),
|
|
6602
6995
|
UseGuards(TrustedOriginGuard, AuthRateLimitGuard),
|
|
6603
6996
|
UsePipes(createAuthValidationPipe()),
|
|
6997
|
+
_ts_param16(0, Inject(EmailChangeService)),
|
|
6604
6998
|
_ts_metadata22("design:type", Function),
|
|
6605
6999
|
_ts_metadata22("design:paramtypes", [
|
|
6606
7000
|
typeof EmailChangeService === "undefined" ? Object : EmailChangeService
|
|
@@ -6640,7 +7034,14 @@ var AcceptInvitationDto = class {
|
|
|
6640
7034
|
* Plaintext password for the new account.
|
|
6641
7035
|
*
|
|
6642
7036
|
* @remarks
|
|
6643
|
-
*
|
|
7037
|
+
* The 8-character floor here is STRUCTURAL, not the deployment's policy: it is the lowest
|
|
7038
|
+
* NIST SP 800-63B-4 §3.1.1.1 permits under any circumstance, and it is what a decorator
|
|
7039
|
+
* can express — decorators are evaluated when the class is defined, before any
|
|
7040
|
+
* configuration exists. The policy floor is `password.minLength` (default 15, as the
|
|
7041
|
+
* standard requires of a single-factor password), enforced by `PasswordService` and
|
|
7042
|
+
* answering this same `auth.validation` code and details shape.
|
|
7043
|
+
*
|
|
7044
|
+
* Maximum 128 characters as a practical
|
|
6644
7045
|
* input bound to prevent DoS via pathological scrypt inputs.
|
|
6645
7046
|
* The service layer hashes this value immediately — it is never logged or
|
|
6646
7047
|
* persisted in plaintext.
|
|
@@ -6765,12 +7166,12 @@ function _ts_metadata26(k, v) {
|
|
|
6765
7166
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
6766
7167
|
}
|
|
6767
7168
|
__name(_ts_metadata26, "_ts_metadata");
|
|
6768
|
-
function
|
|
7169
|
+
function _ts_param17(paramIndex, decorator) {
|
|
6769
7170
|
return function(target, key) {
|
|
6770
7171
|
decorator(target, key, paramIndex);
|
|
6771
7172
|
};
|
|
6772
7173
|
}
|
|
6773
|
-
__name(
|
|
7174
|
+
__name(_ts_param17, "_ts_param");
|
|
6774
7175
|
function isStoredInvitation(value) {
|
|
6775
7176
|
if (typeof value !== "object" || value === null) return false;
|
|
6776
7177
|
const v = value;
|
|
@@ -7144,7 +7545,7 @@ var InvitationService = class _InvitationService {
|
|
|
7144
7545
|
}
|
|
7145
7546
|
async acceptInvitation(dto, ip, userAgent, headers) {
|
|
7146
7547
|
const tokenKey = `inv:${sha256(dto.token)}`;
|
|
7147
|
-
await this.passwordService.
|
|
7548
|
+
await this.passwordService.assertAcceptable(dto.password, "password");
|
|
7148
7549
|
const raw = await this.redis.getdel(tokenKey);
|
|
7149
7550
|
if (!raw) {
|
|
7150
7551
|
throw new AuthException(AUTH_ERROR_CODES.INVALID_INVITATION_TOKEN);
|
|
@@ -7199,10 +7600,14 @@ var InvitationService = class _InvitationService {
|
|
|
7199
7600
|
};
|
|
7200
7601
|
InvitationService = _ts_decorate27([
|
|
7201
7602
|
Injectable(),
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
|
|
7603
|
+
_ts_param17(0, Inject(BYMAX_AUTH_USER_REPOSITORY)),
|
|
7604
|
+
_ts_param17(1, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
|
|
7605
|
+
_ts_param17(2, Inject(BYMAX_AUTH_HOOKS)),
|
|
7606
|
+
_ts_param17(3, Inject(AuthRedisService)),
|
|
7607
|
+
_ts_param17(4, Inject(PasswordService)),
|
|
7608
|
+
_ts_param17(5, Inject(SessionService)),
|
|
7609
|
+
_ts_param17(6, Inject(TokenManagerService)),
|
|
7610
|
+
_ts_param17(7, Inject(BYMAX_AUTH_OPTIONS)),
|
|
7206
7611
|
_ts_metadata26("design:type", Function),
|
|
7207
7612
|
_ts_metadata26("design:paramtypes", [
|
|
7208
7613
|
typeof IUserRepository === "undefined" ? Object : IUserRepository,
|
|
@@ -7228,12 +7633,12 @@ function _ts_metadata27(k, v) {
|
|
|
7228
7633
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
7229
7634
|
}
|
|
7230
7635
|
__name(_ts_metadata27, "_ts_metadata");
|
|
7231
|
-
function
|
|
7636
|
+
function _ts_param18(paramIndex, decorator) {
|
|
7232
7637
|
return function(target, key) {
|
|
7233
7638
|
decorator(target, key, paramIndex);
|
|
7234
7639
|
};
|
|
7235
7640
|
}
|
|
7236
|
-
__name(
|
|
7641
|
+
__name(_ts_param18, "_ts_param");
|
|
7237
7642
|
var InvitationController = class {
|
|
7238
7643
|
static {
|
|
7239
7644
|
__name(this, "InvitationController");
|
|
@@ -7315,8 +7720,8 @@ _ts_decorate28([
|
|
|
7315
7720
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.invitationCreate),
|
|
7316
7721
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
7317
7722
|
Post(),
|
|
7318
|
-
|
|
7319
|
-
|
|
7723
|
+
_ts_param18(0, Body()),
|
|
7724
|
+
_ts_param18(1, CurrentUser()),
|
|
7320
7725
|
_ts_metadata27("design:type", Function),
|
|
7321
7726
|
_ts_metadata27("design:paramtypes", [
|
|
7322
7727
|
typeof CreateInvitationDto === "undefined" ? Object : CreateInvitationDto,
|
|
@@ -7330,8 +7735,8 @@ _ts_decorate28([
|
|
|
7330
7735
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.invitationRevoke),
|
|
7331
7736
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
7332
7737
|
Post("revoke"),
|
|
7333
|
-
|
|
7334
|
-
|
|
7738
|
+
_ts_param18(0, Body()),
|
|
7739
|
+
_ts_param18(1, CurrentUser()),
|
|
7335
7740
|
_ts_metadata27("design:type", Function),
|
|
7336
7741
|
_ts_metadata27("design:paramtypes", [
|
|
7337
7742
|
typeof RevokeInvitationDto === "undefined" ? Object : RevokeInvitationDto,
|
|
@@ -7345,9 +7750,9 @@ _ts_decorate28([
|
|
|
7345
7750
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.invitationAccept),
|
|
7346
7751
|
HttpCode(HttpStatus.CREATED),
|
|
7347
7752
|
Post("accept"),
|
|
7348
|
-
|
|
7349
|
-
|
|
7350
|
-
|
|
7753
|
+
_ts_param18(0, Body()),
|
|
7754
|
+
_ts_param18(1, Req()),
|
|
7755
|
+
_ts_param18(2, Res({
|
|
7351
7756
|
passthrough: true
|
|
7352
7757
|
})),
|
|
7353
7758
|
_ts_metadata27("design:type", Function),
|
|
@@ -7363,6 +7768,8 @@ InvitationController = _ts_decorate28([
|
|
|
7363
7768
|
Controller("invitations"),
|
|
7364
7769
|
UseGuards(TrustedOriginGuard, AuthRateLimitGuard),
|
|
7365
7770
|
UsePipes(createAuthValidationPipe()),
|
|
7771
|
+
_ts_param18(0, Inject(InvitationService)),
|
|
7772
|
+
_ts_param18(1, Inject(TokenDeliveryService)),
|
|
7366
7773
|
_ts_metadata27("design:type", Function),
|
|
7367
7774
|
_ts_metadata27("design:paramtypes", [
|
|
7368
7775
|
typeof InvitationService === "undefined" ? Object : InvitationService,
|
|
@@ -7637,12 +8044,12 @@ function _ts_metadata33(k, v) {
|
|
|
7637
8044
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
7638
8045
|
}
|
|
7639
8046
|
__name(_ts_metadata33, "_ts_metadata");
|
|
7640
|
-
function
|
|
8047
|
+
function _ts_param19(paramIndex, decorator) {
|
|
7641
8048
|
return function(target, key) {
|
|
7642
8049
|
decorator(target, key, paramIndex);
|
|
7643
8050
|
};
|
|
7644
8051
|
}
|
|
7645
|
-
__name(
|
|
8052
|
+
__name(_ts_param19, "_ts_param");
|
|
7646
8053
|
var MFA_SETUP_TTL_SECONDS = 600;
|
|
7647
8054
|
var RECOVERY_CODE_CLAIM_TTL_SECONDS = 300;
|
|
7648
8055
|
function totpAntiReplayTtlSeconds(window) {
|
|
@@ -7657,7 +8064,8 @@ end
|
|
|
7657
8064
|
return 0`;
|
|
7658
8065
|
var DEFAULT_RECOVERY_CODE_COUNT = 8;
|
|
7659
8066
|
function isMfaSetupData(value) {
|
|
7660
|
-
if (
|
|
8067
|
+
if (value === null) return false;
|
|
8068
|
+
if (typeof value !== "object") return false;
|
|
7661
8069
|
const v = value;
|
|
7662
8070
|
return typeof v["encryptedSecret"] === "string" && typeof v["encryptedPlainCodes"] === "string" && Array.isArray(v["hashedCodes"]) && v["hashedCodes"].every((code) => typeof code === "string");
|
|
7663
8071
|
}
|
|
@@ -7855,11 +8263,12 @@ var MfaService = class _MfaService {
|
|
|
7855
8263
|
* with Redis write access from distinguishing "no setup pending" from
|
|
7856
8264
|
* "setup payload corrupted".
|
|
7857
8265
|
*/
|
|
7858
|
-
parseSetupData(raw) {
|
|
8266
|
+
parseSetupData(raw, userId) {
|
|
7859
8267
|
let parsed;
|
|
7860
8268
|
try {
|
|
7861
8269
|
parsed = JSON.parse(raw);
|
|
7862
8270
|
} catch {
|
|
8271
|
+
this.logger.warn(`parseSetupData: pending-setup payload is not valid JSON userId=${userId}`);
|
|
7863
8272
|
throw new AuthException(AUTH_ERROR_CODES.MFA_SETUP_REQUIRED);
|
|
7864
8273
|
}
|
|
7865
8274
|
if (!isMfaSetupData(parsed)) {
|
|
@@ -7876,11 +8285,12 @@ var MfaService = class _MfaService {
|
|
|
7876
8285
|
* `MFA_SETUP_REQUIRED` so callers do not learn structural details of the
|
|
7877
8286
|
* encrypted payload.
|
|
7878
8287
|
*/
|
|
7879
|
-
parsePlainRecoveryCodes(raw) {
|
|
8288
|
+
parsePlainRecoveryCodes(raw, userId) {
|
|
7880
8289
|
let parsed;
|
|
7881
8290
|
try {
|
|
7882
8291
|
parsed = JSON.parse(raw);
|
|
7883
8292
|
} catch {
|
|
8293
|
+
this.logger.warn(`parsePlainRecoveryCodes: decrypted payload is not valid JSON userId=${userId}`);
|
|
7884
8294
|
throw new AuthException(AUTH_ERROR_CODES.MFA_SETUP_REQUIRED);
|
|
7885
8295
|
}
|
|
7886
8296
|
if (!Array.isArray(parsed) || parsed.some((code) => typeof code !== "string")) {
|
|
@@ -8051,10 +8461,10 @@ var MfaService = class _MfaService {
|
|
|
8051
8461
|
const setupKey = `mfa_setup:${hmacSha256(`${context}:${userId}`, this.options.hmacKey)}`;
|
|
8052
8462
|
const existingFast = await this.redis.get(setupKey);
|
|
8053
8463
|
if (existingFast !== null) {
|
|
8054
|
-
const data = this.parseSetupData(existingFast);
|
|
8464
|
+
const data = this.parseSetupData(existingFast, userId);
|
|
8055
8465
|
const existingSecret = this.decryptSecret(data.encryptedSecret);
|
|
8056
8466
|
const decryptedCodesJson = this.decryptSecret(data.encryptedPlainCodes);
|
|
8057
|
-
const existingCodes = this.parsePlainRecoveryCodes(decryptedCodesJson);
|
|
8467
|
+
const existingCodes = this.parsePlainRecoveryCodes(decryptedCodesJson, userId);
|
|
8058
8468
|
const qrCodeUri2 = buildTotpUri(existingSecret, user.email, this.mfaOptions.issuer);
|
|
8059
8469
|
return {
|
|
8060
8470
|
secret: existingSecret,
|
|
@@ -8077,10 +8487,10 @@ var MfaService = class _MfaService {
|
|
|
8077
8487
|
if (!wasSet) {
|
|
8078
8488
|
const existing = await this.redis.get(setupKey);
|
|
8079
8489
|
if (existing !== null) {
|
|
8080
|
-
const data = this.parseSetupData(existing);
|
|
8490
|
+
const data = this.parseSetupData(existing, userId);
|
|
8081
8491
|
const existingSecret = this.decryptSecret(data.encryptedSecret);
|
|
8082
8492
|
const decryptedCodesJson = this.decryptSecret(data.encryptedPlainCodes);
|
|
8083
|
-
const existingCodes = this.parsePlainRecoveryCodes(decryptedCodesJson);
|
|
8493
|
+
const existingCodes = this.parsePlainRecoveryCodes(decryptedCodesJson, userId);
|
|
8084
8494
|
const qrCodeUri2 = buildTotpUri(existingSecret, user.email, this.mfaOptions.issuer);
|
|
8085
8495
|
return {
|
|
8086
8496
|
secret: existingSecret,
|
|
@@ -8130,7 +8540,7 @@ var MfaService = class _MfaService {
|
|
|
8130
8540
|
const setupKey = `mfa_setup:${hmacSha256(`${context}:${userId}`, this.options.hmacKey)}`;
|
|
8131
8541
|
const raw = await this.redis.get(setupKey);
|
|
8132
8542
|
if (raw === null) throw new AuthException(AUTH_ERROR_CODES.MFA_SETUP_REQUIRED);
|
|
8133
|
-
const data = this.parseSetupData(raw);
|
|
8543
|
+
const data = this.parseSetupData(raw, userId);
|
|
8134
8544
|
const secretBase32 = this.decryptSecret(data.encryptedSecret);
|
|
8135
8545
|
const totpWindow = this.mfaOptions.totpWindow;
|
|
8136
8546
|
const codeValid = await this.verifyTotpWithAntiReplay(context, userId, secretBase32, code, totpWindow);
|
|
@@ -8340,6 +8750,74 @@ var MfaService = class _MfaService {
|
|
|
8340
8750
|
}
|
|
8341
8751
|
}
|
|
8342
8752
|
// ---------------------------------------------------------------------------
|
|
8753
|
+
// resetMfa() — administrative removal of a second factor
|
|
8754
|
+
// ---------------------------------------------------------------------------
|
|
8755
|
+
/**
|
|
8756
|
+
* Removes a user's second factor without their TOTP code, for a support desk facing a user
|
|
8757
|
+
* who has lost their authenticator AND their recovery codes.
|
|
8758
|
+
*
|
|
8759
|
+
* Every self-service exit from MFA needs the factor itself: {@link disable} wants a valid
|
|
8760
|
+
* TOTP code, and the recovery codes want the codes. A user who has lost both is locked out
|
|
8761
|
+
* permanently, by the control that exists to protect them — ASVS v5 §6.1.1 asks for an
|
|
8762
|
+
* administrative path out for exactly that reason.
|
|
8763
|
+
*
|
|
8764
|
+
* **Authorising the caller is the consumer's job.** The library deliberately ships no route
|
|
8765
|
+
* for this, the same decision and for the same reason as {@link AuthService.unlockAccount}:
|
|
8766
|
+
* who may reset whom is a question only the host application can answer, and all 39 routes
|
|
8767
|
+
* this library does ship are scoped to the caller's own account.
|
|
8768
|
+
*
|
|
8769
|
+
* Idempotent: resetting an account that has no second factor is a no-op, so a support desk
|
|
8770
|
+
* retrying does not get an error for a job already done.
|
|
8771
|
+
*
|
|
8772
|
+
* Three things happen beyond clearing the record, and none of them are optional:
|
|
8773
|
+
*
|
|
8774
|
+
* - **Sessions are invalidated and the token epoch is bumped**, so access tokens carrying
|
|
8775
|
+
* `mfaVerified: true` die with the factor rather than outliving it.
|
|
8776
|
+
* - **The user is notified**, through the same channel {@link disable} uses. An
|
|
8777
|
+
* administrative reset that the account holder cannot see is an account-takeover path:
|
|
8778
|
+
* an attacker who reaches the support desk removes the second factor silently. The
|
|
8779
|
+
* notification is what makes it an event the owner can detect and dispute.
|
|
8780
|
+
* - **It is logged** under its own prefix, so an administrative removal is distinguishable
|
|
8781
|
+
* from a user-initiated one in the library's own log.
|
|
8782
|
+
*
|
|
8783
|
+
* The `afterMfaDisabled` hook fires too, so consumer-side alerting keeps working. It is not
|
|
8784
|
+
* given a separate hook: the consumer is the one calling this method, so they already know
|
|
8785
|
+
* an administrative reset happened — the hook exists to tell them about the paths they do
|
|
8786
|
+
* not initiate.
|
|
8787
|
+
*
|
|
8788
|
+
* @param userId - Internal ID of the user whose second factor is being removed.
|
|
8789
|
+
* @param context - Which identity plane the user belongs to: `'dashboard'` (default) or
|
|
8790
|
+
* `'platform'`. Must match the plane the account lives in, or the lookup misses.
|
|
8791
|
+
* @throws `TOKEN_INVALID` if no user with that ID exists in the given plane.
|
|
8792
|
+
*/
|
|
8793
|
+
async resetMfa(userId, context = "dashboard") {
|
|
8794
|
+
const user = await this.fetchUserForContext(context, userId);
|
|
8795
|
+
if (!user.mfaEnabled) {
|
|
8796
|
+
this.logger.log(`resetMfa: no second factor to remove userId=${userId} context=${context}`);
|
|
8797
|
+
return;
|
|
8798
|
+
}
|
|
8799
|
+
await this.transitionMfaRecord(context, userId, () => ({
|
|
8800
|
+
mfaEnabled: false,
|
|
8801
|
+
mfaSecret: null,
|
|
8802
|
+
mfaRecoveryCodes: null
|
|
8803
|
+
}));
|
|
8804
|
+
await this.redis.invalidateUserSessions(userId, context);
|
|
8805
|
+
await this.redis.bumpUserTokenEpoch(userId, context);
|
|
8806
|
+
this.logger.warn(`resetMfa: MFA removed administratively userId=${userId} context=${context}`);
|
|
8807
|
+
await this.emailProvider.sendMfaDisabledNotification(user.email);
|
|
8808
|
+
const safeUser = context === "platform" ? this.platformUserAsSafeUser(user) : this.toSafeUser(user);
|
|
8809
|
+
if (this.hooks.afterMfaDisabled) {
|
|
8810
|
+
void Promise.resolve(this.hooks.afterMfaDisabled(safeUser, {
|
|
8811
|
+
userId,
|
|
8812
|
+
// No request context: this call does not come from one. Empty rather than invented,
|
|
8813
|
+
// so a consumer logging the hook cannot mistake a placeholder for a real address.
|
|
8814
|
+
ip: "",
|
|
8815
|
+
userAgent: "",
|
|
8816
|
+
sanitizedHeaders: {}
|
|
8817
|
+
})).catch(() => void 0);
|
|
8818
|
+
}
|
|
8819
|
+
}
|
|
8820
|
+
// ---------------------------------------------------------------------------
|
|
8343
8821
|
// regenerateRecoveryCodes — rotate the recovery code set for an MFA-enabled user
|
|
8344
8822
|
// ---------------------------------------------------------------------------
|
|
8345
8823
|
/**
|
|
@@ -8537,12 +9015,17 @@ var MfaService = class _MfaService {
|
|
|
8537
9015
|
};
|
|
8538
9016
|
MfaService = _ts_decorate34([
|
|
8539
9017
|
Injectable(),
|
|
8540
|
-
|
|
8541
|
-
|
|
8542
|
-
|
|
8543
|
-
|
|
8544
|
-
|
|
8545
|
-
|
|
9018
|
+
_ts_param19(0, Inject(BYMAX_AUTH_OPTIONS)),
|
|
9019
|
+
_ts_param19(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
|
|
9020
|
+
_ts_param19(2, Optional()),
|
|
9021
|
+
_ts_param19(2, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
|
|
9022
|
+
_ts_param19(3, Inject(AuthRedisService)),
|
|
9023
|
+
_ts_param19(4, Inject(TokenManagerService)),
|
|
9024
|
+
_ts_param19(5, Inject(BruteForceService)),
|
|
9025
|
+
_ts_param19(6, Inject(PasswordService)),
|
|
9026
|
+
_ts_param19(7, Inject(SessionService)),
|
|
9027
|
+
_ts_param19(8, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
|
|
9028
|
+
_ts_param19(9, Inject(BYMAX_AUTH_HOOKS)),
|
|
8546
9029
|
_ts_metadata33("design:type", Function),
|
|
8547
9030
|
_ts_metadata33("design:paramtypes", [
|
|
8548
9031
|
typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions,
|
|
@@ -8570,12 +9053,12 @@ function _ts_metadata34(k, v) {
|
|
|
8570
9053
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
8571
9054
|
}
|
|
8572
9055
|
__name(_ts_metadata34, "_ts_metadata");
|
|
8573
|
-
function
|
|
9056
|
+
function _ts_param20(paramIndex, decorator) {
|
|
8574
9057
|
return function(target, key) {
|
|
8575
9058
|
decorator(target, key, paramIndex);
|
|
8576
9059
|
};
|
|
8577
9060
|
}
|
|
8578
|
-
__name(
|
|
9061
|
+
__name(_ts_param20, "_ts_param");
|
|
8579
9062
|
function isPlatformResult(result) {
|
|
8580
9063
|
return "admin" in result;
|
|
8581
9064
|
}
|
|
@@ -8769,8 +9252,8 @@ _ts_decorate35([
|
|
|
8769
9252
|
Throttle(AUTH_THROTTLE_CONFIGS.mfaSetup),
|
|
8770
9253
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.mfaSetup),
|
|
8771
9254
|
Post("setup"),
|
|
8772
|
-
|
|
8773
|
-
|
|
9255
|
+
_ts_param20(0, CurrentUser()),
|
|
9256
|
+
_ts_param20(1, Body()),
|
|
8774
9257
|
_ts_metadata34("design:type", Function),
|
|
8775
9258
|
_ts_metadata34("design:paramtypes", [
|
|
8776
9259
|
typeof DashboardJwtPayload === "undefined" ? Object : DashboardJwtPayload,
|
|
@@ -8784,9 +9267,9 @@ _ts_decorate35([
|
|
|
8784
9267
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.mfaVerifyEnable),
|
|
8785
9268
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
8786
9269
|
Post("verify-enable"),
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
9270
|
+
_ts_param20(0, CurrentUser()),
|
|
9271
|
+
_ts_param20(1, Body()),
|
|
9272
|
+
_ts_param20(2, Req()),
|
|
8790
9273
|
_ts_metadata34("design:type", Function),
|
|
8791
9274
|
_ts_metadata34("design:paramtypes", [
|
|
8792
9275
|
typeof DashboardJwtPayload === "undefined" ? Object : DashboardJwtPayload,
|
|
@@ -8802,9 +9285,9 @@ _ts_decorate35([
|
|
|
8802
9285
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.mfaChallenge),
|
|
8803
9286
|
HttpCode(HttpStatus.OK),
|
|
8804
9287
|
Post("challenge"),
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
9288
|
+
_ts_param20(0, Body()),
|
|
9289
|
+
_ts_param20(1, Req()),
|
|
9290
|
+
_ts_param20(2, Res({
|
|
8808
9291
|
passthrough: true
|
|
8809
9292
|
})),
|
|
8810
9293
|
_ts_metadata34("design:type", Function),
|
|
@@ -8821,9 +9304,9 @@ _ts_decorate35([
|
|
|
8821
9304
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.mfaDisable),
|
|
8822
9305
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
8823
9306
|
Post("disable"),
|
|
8824
|
-
|
|
8825
|
-
|
|
8826
|
-
|
|
9307
|
+
_ts_param20(0, CurrentUser()),
|
|
9308
|
+
_ts_param20(1, Body()),
|
|
9309
|
+
_ts_param20(2, Req()),
|
|
8827
9310
|
_ts_metadata34("design:type", Function),
|
|
8828
9311
|
_ts_metadata34("design:paramtypes", [
|
|
8829
9312
|
typeof DashboardJwtPayload === "undefined" ? Object : DashboardJwtPayload,
|
|
@@ -8838,9 +9321,9 @@ _ts_decorate35([
|
|
|
8838
9321
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.mfaDisable),
|
|
8839
9322
|
HttpCode(HttpStatus.OK),
|
|
8840
9323
|
Post("recovery-codes"),
|
|
8841
|
-
|
|
8842
|
-
|
|
8843
|
-
|
|
9324
|
+
_ts_param20(0, CurrentUser()),
|
|
9325
|
+
_ts_param20(1, Body()),
|
|
9326
|
+
_ts_param20(2, Req()),
|
|
8844
9327
|
_ts_metadata34("design:type", Function),
|
|
8845
9328
|
_ts_metadata34("design:paramtypes", [
|
|
8846
9329
|
typeof DashboardJwtPayload === "undefined" ? Object : DashboardJwtPayload,
|
|
@@ -8856,7 +9339,9 @@ MfaController = _ts_decorate35([
|
|
|
8856
9339
|
UsePipes(createAuthValidationPipe({
|
|
8857
9340
|
forbidUnknownValues: true
|
|
8858
9341
|
})),
|
|
8859
|
-
|
|
9342
|
+
_ts_param20(0, Inject(MfaService)),
|
|
9343
|
+
_ts_param20(1, Inject(TokenDeliveryService)),
|
|
9344
|
+
_ts_param20(2, Inject(BYMAX_AUTH_OPTIONS)),
|
|
8860
9345
|
_ts_metadata34("design:type", Function),
|
|
8861
9346
|
_ts_metadata34("design:paramtypes", [
|
|
8862
9347
|
typeof MfaService === "undefined" ? Object : MfaService,
|
|
@@ -8896,7 +9381,14 @@ var ChangePasswordDto = class {
|
|
|
8896
9381
|
currentPassword;
|
|
8897
9382
|
/**
|
|
8898
9383
|
* New plaintext password chosen by the user.
|
|
8899
|
-
*
|
|
9384
|
+
* The 8-character floor here is STRUCTURAL, not the deployment's policy: it is the lowest
|
|
9385
|
+
* NIST SP 800-63B-4 §3.1.1.1 permits under any circumstance, and it is what a decorator
|
|
9386
|
+
* can express — decorators are evaluated when the class is defined, before any
|
|
9387
|
+
* configuration exists. The policy floor is `password.minLength` (default 15, as the
|
|
9388
|
+
* standard requires of a single-factor password), enforced by `PasswordService` and
|
|
9389
|
+
* answering this same `auth.validation` code and details shape.
|
|
9390
|
+
*
|
|
9391
|
+
* Maximum 128 characters as a practical bound.
|
|
8900
9392
|
* Hashed immediately by the service layer — never persisted in plaintext.
|
|
8901
9393
|
*/
|
|
8902
9394
|
newPassword;
|
|
@@ -9016,7 +9508,14 @@ var ResetPasswordDto = class {
|
|
|
9016
9508
|
email;
|
|
9017
9509
|
/**
|
|
9018
9510
|
* New plaintext password chosen by the user.
|
|
9019
|
-
*
|
|
9511
|
+
* The 8-character floor here is STRUCTURAL, not the deployment's policy: it is the lowest
|
|
9512
|
+
* NIST SP 800-63B-4 §3.1.1.1 permits under any circumstance, and it is what a decorator
|
|
9513
|
+
* can express — decorators are evaluated when the class is defined, before any
|
|
9514
|
+
* configuration exists. The policy floor is `password.minLength` (default 15, as the
|
|
9515
|
+
* standard requires of a single-factor password), enforced by `PasswordService` and
|
|
9516
|
+
* answering this same `auth.validation` code and details shape.
|
|
9517
|
+
*
|
|
9518
|
+
* Maximum 128 characters as a practical bound.
|
|
9020
9519
|
* Hashed immediately by the service layer — never persisted in plaintext.
|
|
9021
9520
|
*/
|
|
9022
9521
|
newPassword;
|
|
@@ -9147,12 +9646,12 @@ function _ts_metadata40(k, v) {
|
|
|
9147
9646
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9148
9647
|
}
|
|
9149
9648
|
__name(_ts_metadata40, "_ts_metadata");
|
|
9150
|
-
function
|
|
9649
|
+
function _ts_param21(paramIndex, decorator) {
|
|
9151
9650
|
return function(target, key) {
|
|
9152
9651
|
decorator(target, key, paramIndex);
|
|
9153
9652
|
};
|
|
9154
9653
|
}
|
|
9155
|
-
__name(
|
|
9654
|
+
__name(_ts_param21, "_ts_param");
|
|
9156
9655
|
var ANTI_ENUM_MIN_MS2 = 300;
|
|
9157
9656
|
var VERIFIED_TOKEN_TTL_SECONDS = 300;
|
|
9158
9657
|
var PASSWORD_RESET_PURPOSE = "password_reset";
|
|
@@ -9271,7 +9770,7 @@ var PasswordResetService = class _PasswordResetService {
|
|
|
9271
9770
|
if (proofCount > 1) {
|
|
9272
9771
|
throw new AuthException(AUTH_ERROR_CODES.PASSWORD_RESET_TOKEN_INVALID);
|
|
9273
9772
|
}
|
|
9274
|
-
await this.passwordService.
|
|
9773
|
+
await this.passwordService.assertAcceptable(dto.newPassword, "newPassword");
|
|
9275
9774
|
if (method === "token") {
|
|
9276
9775
|
if (!dto.token) {
|
|
9277
9776
|
throw new AuthException(AUTH_ERROR_CODES.PASSWORD_RESET_TOKEN_INVALID);
|
|
@@ -9489,7 +9988,7 @@ var PasswordResetService = class _PasswordResetService {
|
|
|
9489
9988
|
throw new AuthException(AUTH_ERROR_CODES.INVALID_CREDENTIALS);
|
|
9490
9989
|
}
|
|
9491
9990
|
await this.bruteForce.resetFailures(bfIdentifier);
|
|
9492
|
-
await this.passwordService.
|
|
9991
|
+
await this.passwordService.assertAcceptable(dto.newPassword, "newPassword");
|
|
9493
9992
|
const passwordHash = await this.passwordService.hash(dto.newPassword);
|
|
9494
9993
|
await this.userRepo.updatePassword(userId, passwordHash);
|
|
9495
9994
|
if (currentRefreshToken !== void 0 && currentRefreshToken.length > 0) {
|
|
@@ -9667,12 +10166,17 @@ var PasswordResetService = class _PasswordResetService {
|
|
|
9667
10166
|
};
|
|
9668
10167
|
PasswordResetService = _ts_decorate41([
|
|
9669
10168
|
Injectable(),
|
|
9670
|
-
|
|
9671
|
-
|
|
9672
|
-
|
|
9673
|
-
|
|
9674
|
-
|
|
9675
|
-
|
|
10169
|
+
_ts_param21(0, Inject(BYMAX_AUTH_OPTIONS)),
|
|
10170
|
+
_ts_param21(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
|
|
10171
|
+
_ts_param21(2, Inject(BYMAX_AUTH_EMAIL_PROVIDER)),
|
|
10172
|
+
_ts_param21(2, Optional()),
|
|
10173
|
+
_ts_param21(3, Inject(BYMAX_AUTH_HOOKS)),
|
|
10174
|
+
_ts_param21(3, Optional()),
|
|
10175
|
+
_ts_param21(4, Inject(OtpService)),
|
|
10176
|
+
_ts_param21(5, Inject(PasswordService)),
|
|
10177
|
+
_ts_param21(6, Inject(AuthRedisService)),
|
|
10178
|
+
_ts_param21(7, Inject(SessionService)),
|
|
10179
|
+
_ts_param21(8, Inject(BruteForceService)),
|
|
9676
10180
|
_ts_metadata40("design:type", Function),
|
|
9677
10181
|
_ts_metadata40("design:paramtypes", [
|
|
9678
10182
|
typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions,
|
|
@@ -9704,12 +10208,12 @@ function _ts_metadata41(k, v) {
|
|
|
9704
10208
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9705
10209
|
}
|
|
9706
10210
|
__name(_ts_metadata41, "_ts_metadata");
|
|
9707
|
-
function
|
|
10211
|
+
function _ts_param22(paramIndex, decorator) {
|
|
9708
10212
|
return function(target, key) {
|
|
9709
10213
|
decorator(target, key, paramIndex);
|
|
9710
10214
|
};
|
|
9711
10215
|
}
|
|
9712
|
-
__name(
|
|
10216
|
+
__name(_ts_param22, "_ts_param");
|
|
9713
10217
|
var PasswordResetController = class {
|
|
9714
10218
|
static {
|
|
9715
10219
|
__name(this, "PasswordResetController");
|
|
@@ -9825,8 +10329,8 @@ _ts_decorate42([
|
|
|
9825
10329
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.forgotPassword),
|
|
9826
10330
|
HttpCode(HttpStatus.OK),
|
|
9827
10331
|
Post("forgot-password"),
|
|
9828
|
-
|
|
9829
|
-
|
|
10332
|
+
_ts_param22(0, Body()),
|
|
10333
|
+
_ts_param22(1, Req()),
|
|
9830
10334
|
_ts_metadata41("design:type", Function),
|
|
9831
10335
|
_ts_metadata41("design:paramtypes", [
|
|
9832
10336
|
typeof ForgotPasswordDto === "undefined" ? Object : ForgotPasswordDto,
|
|
@@ -9839,8 +10343,8 @@ _ts_decorate42([
|
|
|
9839
10343
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.resetPassword),
|
|
9840
10344
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
9841
10345
|
Post("reset-password"),
|
|
9842
|
-
|
|
9843
|
-
|
|
10346
|
+
_ts_param22(0, Body()),
|
|
10347
|
+
_ts_param22(1, Req()),
|
|
9844
10348
|
_ts_metadata41("design:type", Function),
|
|
9845
10349
|
_ts_metadata41("design:paramtypes", [
|
|
9846
10350
|
typeof ResetPasswordDto === "undefined" ? Object : ResetPasswordDto,
|
|
@@ -9855,9 +10359,9 @@ _ts_decorate42([
|
|
|
9855
10359
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.changePassword),
|
|
9856
10360
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
9857
10361
|
Post("change"),
|
|
9858
|
-
|
|
9859
|
-
|
|
9860
|
-
|
|
10362
|
+
_ts_param22(0, CurrentUser()),
|
|
10363
|
+
_ts_param22(1, Body()),
|
|
10364
|
+
_ts_param22(2, Req()),
|
|
9861
10365
|
_ts_metadata41("design:type", Function),
|
|
9862
10366
|
_ts_metadata41("design:paramtypes", [
|
|
9863
10367
|
typeof DashboardJwtPayload === "undefined" ? Object : DashboardJwtPayload,
|
|
@@ -9871,8 +10375,8 @@ _ts_decorate42([
|
|
|
9871
10375
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.verifyOtp),
|
|
9872
10376
|
HttpCode(HttpStatus.OK),
|
|
9873
10377
|
Post("verify-otp"),
|
|
9874
|
-
|
|
9875
|
-
|
|
10378
|
+
_ts_param22(0, Body()),
|
|
10379
|
+
_ts_param22(1, Req()),
|
|
9876
10380
|
_ts_metadata41("design:type", Function),
|
|
9877
10381
|
_ts_metadata41("design:paramtypes", [
|
|
9878
10382
|
typeof VerifyOtpDto === "undefined" ? Object : VerifyOtpDto,
|
|
@@ -9885,8 +10389,8 @@ _ts_decorate42([
|
|
|
9885
10389
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.resendPasswordOtp),
|
|
9886
10390
|
HttpCode(HttpStatus.OK),
|
|
9887
10391
|
Post("resend-otp"),
|
|
9888
|
-
|
|
9889
|
-
|
|
10392
|
+
_ts_param22(0, Body()),
|
|
10393
|
+
_ts_param22(1, Req()),
|
|
9890
10394
|
_ts_metadata41("design:type", Function),
|
|
9891
10395
|
_ts_metadata41("design:paramtypes", [
|
|
9892
10396
|
typeof ResendOtpDto === "undefined" ? Object : ResendOtpDto,
|
|
@@ -9900,6 +10404,8 @@ PasswordResetController = _ts_decorate42([
|
|
|
9900
10404
|
Controller("password"),
|
|
9901
10405
|
UseGuards(TrustedOriginGuard, AuthRateLimitGuard),
|
|
9902
10406
|
UsePipes(createAuthValidationPipe()),
|
|
10407
|
+
_ts_param22(0, Inject(PasswordResetService)),
|
|
10408
|
+
_ts_param22(1, Inject(TokenDeliveryService)),
|
|
9903
10409
|
_ts_metadata41("design:type", Function),
|
|
9904
10410
|
_ts_metadata41("design:paramtypes", [
|
|
9905
10411
|
typeof PasswordResetService === "undefined" ? Object : PasswordResetService,
|
|
@@ -9972,12 +10478,12 @@ function _ts_metadata43(k, v) {
|
|
|
9972
10478
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9973
10479
|
}
|
|
9974
10480
|
__name(_ts_metadata43, "_ts_metadata");
|
|
9975
|
-
function
|
|
10481
|
+
function _ts_param23(paramIndex, decorator) {
|
|
9976
10482
|
return function(target, key) {
|
|
9977
10483
|
decorator(target, key, paramIndex);
|
|
9978
10484
|
};
|
|
9979
10485
|
}
|
|
9980
|
-
__name(
|
|
10486
|
+
__name(_ts_param23, "_ts_param");
|
|
9981
10487
|
var JwtPlatformGuard = class {
|
|
9982
10488
|
static {
|
|
9983
10489
|
__name(this, "JwtPlatformGuard");
|
|
@@ -10030,7 +10536,11 @@ var JwtPlatformGuard = class {
|
|
|
10030
10536
|
};
|
|
10031
10537
|
JwtPlatformGuard = _ts_decorate44([
|
|
10032
10538
|
Injectable(),
|
|
10033
|
-
|
|
10539
|
+
_ts_param23(0, Inject(JwtService)),
|
|
10540
|
+
_ts_param23(1, Inject(TokenDeliveryService)),
|
|
10541
|
+
_ts_param23(2, Inject(AuthRedisService)),
|
|
10542
|
+
_ts_param23(3, Inject(Reflector)),
|
|
10543
|
+
_ts_param23(4, Inject(BYMAX_AUTH_OPTIONS)),
|
|
10034
10544
|
_ts_metadata43("design:type", Function),
|
|
10035
10545
|
_ts_metadata43("design:paramtypes", [
|
|
10036
10546
|
typeof JwtService === "undefined" ? Object : JwtService,
|
|
@@ -10051,12 +10561,12 @@ function _ts_metadata44(k, v) {
|
|
|
10051
10561
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10052
10562
|
}
|
|
10053
10563
|
__name(_ts_metadata44, "_ts_metadata");
|
|
10054
|
-
function
|
|
10564
|
+
function _ts_param24(paramIndex, decorator) {
|
|
10055
10565
|
return function(target, key) {
|
|
10056
10566
|
decorator(target, key, paramIndex);
|
|
10057
10567
|
};
|
|
10058
10568
|
}
|
|
10059
|
-
__name(
|
|
10569
|
+
__name(_ts_param24, "_ts_param");
|
|
10060
10570
|
var PlatformAuthService = class _PlatformAuthService {
|
|
10061
10571
|
static {
|
|
10062
10572
|
__name(this, "PlatformAuthService");
|
|
@@ -10236,23 +10746,6 @@ var PlatformAuthService = class _PlatformAuthService {
|
|
|
10236
10746
|
// Session revocation
|
|
10237
10747
|
// ---------------------------------------------------------------------------
|
|
10238
10748
|
/**
|
|
10239
|
-
* Revokes all active platform sessions for the given admin.
|
|
10240
|
-
*
|
|
10241
|
-
* Delegates to {@link AuthRedisService.invalidateUserSessions} which uses an atomic
|
|
10242
|
-
* Lua script to read the `psess:{userId}` SET, delete all session and grace-pointer
|
|
10243
|
-
* keys, and remove the SET itself in a single Redis round-trip. This prevents the
|
|
10244
|
-
* TOCTOU race that would arise from a non-atomic SMEMBERS + loop + DEL approach.
|
|
10245
|
-
*
|
|
10246
|
-
* The token epoch is then advanced, so outstanding platform **access** tokens die with
|
|
10247
|
-
* the refresh sessions rather than working on to expiry — "log out everywhere" that
|
|
10248
|
-
* leaves every access token alive is not what those words promise. Bumped after the
|
|
10249
|
-
* sweep for the same reason the dashboard flow bumps last: a failure in the sweep
|
|
10250
|
-
* leaves the epoch untouched and the operation visibly incomplete, instead of the
|
|
10251
|
-
* reverse, which would read as done while the sessions live on.
|
|
10252
|
-
*
|
|
10253
|
-
* @param userId - The platform admin's internal ID.
|
|
10254
|
-
*/
|
|
10255
|
-
/**
|
|
10256
10749
|
* Derives the brute-force identifier for a platform login: `hmac('platform:{email}')`.
|
|
10257
10750
|
*
|
|
10258
10751
|
* HMAC rather than a bare digest keeps PII out of the Redis key and blocks dictionary
|
|
@@ -10273,6 +10766,23 @@ var PlatformAuthService = class _PlatformAuthService {
|
|
|
10273
10766
|
lockoutIdentifier(email) {
|
|
10274
10767
|
return hmacSha256(`platform:${email}`, this.options.hmacKey);
|
|
10275
10768
|
}
|
|
10769
|
+
/**
|
|
10770
|
+
* Revokes all active platform sessions for the given admin.
|
|
10771
|
+
*
|
|
10772
|
+
* Delegates to {@link AuthRedisService.invalidateUserSessions} which uses an atomic
|
|
10773
|
+
* Lua script to read the `psess:{userId}` SET, delete all session and grace-pointer
|
|
10774
|
+
* keys, and remove the SET itself in a single Redis round-trip. This prevents the
|
|
10775
|
+
* TOCTOU race that would arise from a non-atomic SMEMBERS + loop + DEL approach.
|
|
10776
|
+
*
|
|
10777
|
+
* The token epoch is then advanced, so outstanding platform **access** tokens die with
|
|
10778
|
+
* the refresh sessions rather than working on to expiry — "log out everywhere" that
|
|
10779
|
+
* leaves every access token alive is not what those words promise. Bumped after the
|
|
10780
|
+
* sweep for the same reason the dashboard flow bumps last: a failure in the sweep
|
|
10781
|
+
* leaves the epoch untouched and the operation visibly incomplete, instead of the
|
|
10782
|
+
* reverse, which would read as done while the sessions live on.
|
|
10783
|
+
*
|
|
10784
|
+
* @param userId - The platform admin's internal ID.
|
|
10785
|
+
*/
|
|
10276
10786
|
async revokeAllPlatformSessions(userId) {
|
|
10277
10787
|
await this.redis.invalidateUserSessions(userId, "platform");
|
|
10278
10788
|
await this.redis.bumpUserTokenEpoch(userId, "platform");
|
|
@@ -10280,8 +10790,12 @@ var PlatformAuthService = class _PlatformAuthService {
|
|
|
10280
10790
|
};
|
|
10281
10791
|
PlatformAuthService = _ts_decorate45([
|
|
10282
10792
|
Injectable(),
|
|
10283
|
-
|
|
10284
|
-
|
|
10793
|
+
_ts_param24(0, Inject(BYMAX_AUTH_PLATFORM_USER_REPOSITORY)),
|
|
10794
|
+
_ts_param24(1, Inject(PasswordService)),
|
|
10795
|
+
_ts_param24(2, Inject(TokenManagerService)),
|
|
10796
|
+
_ts_param24(3, Inject(BruteForceService)),
|
|
10797
|
+
_ts_param24(4, Inject(AuthRedisService)),
|
|
10798
|
+
_ts_param24(5, Inject(BYMAX_AUTH_OPTIONS)),
|
|
10285
10799
|
_ts_metadata44("design:type", Function),
|
|
10286
10800
|
_ts_metadata44("design:paramtypes", [
|
|
10287
10801
|
typeof IPlatformUserRepository === "undefined" ? Object : IPlatformUserRepository,
|
|
@@ -10305,12 +10819,12 @@ function _ts_metadata45(k, v) {
|
|
|
10305
10819
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10306
10820
|
}
|
|
10307
10821
|
__name(_ts_metadata45, "_ts_metadata");
|
|
10308
|
-
function
|
|
10822
|
+
function _ts_param25(paramIndex, decorator) {
|
|
10309
10823
|
return function(target, key) {
|
|
10310
10824
|
decorator(target, key, paramIndex);
|
|
10311
10825
|
};
|
|
10312
10826
|
}
|
|
10313
|
-
__name(
|
|
10827
|
+
__name(_ts_param25, "_ts_param");
|
|
10314
10828
|
function isPlatformResult2(result) {
|
|
10315
10829
|
return "admin" in result;
|
|
10316
10830
|
}
|
|
@@ -10476,8 +10990,8 @@ _ts_decorate46([
|
|
|
10476
10990
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.platformLogin),
|
|
10477
10991
|
HttpCode(HttpStatus.OK),
|
|
10478
10992
|
Post("login"),
|
|
10479
|
-
|
|
10480
|
-
|
|
10993
|
+
_ts_param25(0, Body()),
|
|
10994
|
+
_ts_param25(1, Req()),
|
|
10481
10995
|
_ts_metadata45("design:type", Function),
|
|
10482
10996
|
_ts_metadata45("design:paramtypes", [
|
|
10483
10997
|
typeof PlatformLoginDto === "undefined" ? Object : PlatformLoginDto,
|
|
@@ -10491,8 +11005,8 @@ _ts_decorate46([
|
|
|
10491
11005
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.mfaChallenge),
|
|
10492
11006
|
HttpCode(HttpStatus.OK),
|
|
10493
11007
|
Post("mfa/challenge"),
|
|
10494
|
-
|
|
10495
|
-
|
|
11008
|
+
_ts_param25(0, Body()),
|
|
11009
|
+
_ts_param25(1, Req()),
|
|
10496
11010
|
_ts_metadata45("design:type", Function),
|
|
10497
11011
|
_ts_metadata45("design:paramtypes", [
|
|
10498
11012
|
typeof MfaChallengeDto === "undefined" ? Object : MfaChallengeDto,
|
|
@@ -10503,7 +11017,7 @@ _ts_decorate46([
|
|
|
10503
11017
|
_ts_decorate46([
|
|
10504
11018
|
UseGuards(JwtPlatformGuard),
|
|
10505
11019
|
Get("me"),
|
|
10506
|
-
|
|
11020
|
+
_ts_param25(0, CurrentUser()),
|
|
10507
11021
|
_ts_metadata45("design:type", Function),
|
|
10508
11022
|
_ts_metadata45("design:paramtypes", [
|
|
10509
11023
|
typeof PlatformJwtPayload === "undefined" ? Object : PlatformJwtPayload
|
|
@@ -10516,7 +11030,7 @@ _ts_decorate46([
|
|
|
10516
11030
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.logout),
|
|
10517
11031
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
10518
11032
|
Post("logout"),
|
|
10519
|
-
|
|
11033
|
+
_ts_param25(0, Req()),
|
|
10520
11034
|
_ts_metadata45("design:type", Function),
|
|
10521
11035
|
_ts_metadata45("design:paramtypes", [
|
|
10522
11036
|
typeof Request === "undefined" ? Object : Request
|
|
@@ -10529,7 +11043,7 @@ _ts_decorate46([
|
|
|
10529
11043
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.refresh),
|
|
10530
11044
|
HttpCode(HttpStatus.OK),
|
|
10531
11045
|
Post("refresh"),
|
|
10532
|
-
|
|
11046
|
+
_ts_param25(0, Req()),
|
|
10533
11047
|
_ts_metadata45("design:type", Function),
|
|
10534
11048
|
_ts_metadata45("design:paramtypes", [
|
|
10535
11049
|
typeof Request === "undefined" ? Object : Request
|
|
@@ -10542,7 +11056,7 @@ _ts_decorate46([
|
|
|
10542
11056
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.revokeAllSessions),
|
|
10543
11057
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
10544
11058
|
Delete("sessions"),
|
|
10545
|
-
|
|
11059
|
+
_ts_param25(0, CurrentUser()),
|
|
10546
11060
|
_ts_metadata45("design:type", Function),
|
|
10547
11061
|
_ts_metadata45("design:paramtypes", [
|
|
10548
11062
|
typeof PlatformJwtPayload === "undefined" ? Object : PlatformJwtPayload
|
|
@@ -10554,6 +11068,9 @@ PlatformAuthController = _ts_decorate46([
|
|
|
10554
11068
|
Controller("platform"),
|
|
10555
11069
|
UseGuards(TrustedOriginGuard, AuthRateLimitGuard),
|
|
10556
11070
|
UsePipes(createAuthValidationPipe()),
|
|
11071
|
+
_ts_param25(0, Inject(PlatformAuthService)),
|
|
11072
|
+
_ts_param25(1, Inject(MfaService)),
|
|
11073
|
+
_ts_param25(2, Inject(TokenDeliveryService)),
|
|
10557
11074
|
_ts_metadata45("design:type", Function),
|
|
10558
11075
|
_ts_metadata45("design:paramtypes", [
|
|
10559
11076
|
typeof PlatformAuthService === "undefined" ? Object : PlatformAuthService,
|
|
@@ -10572,12 +11089,12 @@ function _ts_metadata46(k, v) {
|
|
|
10572
11089
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10573
11090
|
}
|
|
10574
11091
|
__name(_ts_metadata46, "_ts_metadata");
|
|
10575
|
-
function
|
|
11092
|
+
function _ts_param26(paramIndex, decorator) {
|
|
10576
11093
|
return function(target, key) {
|
|
10577
11094
|
decorator(target, key, paramIndex);
|
|
10578
11095
|
};
|
|
10579
11096
|
}
|
|
10580
|
-
__name(
|
|
11097
|
+
__name(_ts_param26, "_ts_param");
|
|
10581
11098
|
var PlatformMfaController = class {
|
|
10582
11099
|
static {
|
|
10583
11100
|
__name(this, "PlatformMfaController");
|
|
@@ -10661,8 +11178,8 @@ _ts_decorate47([
|
|
|
10661
11178
|
Throttle(AUTH_THROTTLE_CONFIGS.mfaSetup),
|
|
10662
11179
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.mfaSetup),
|
|
10663
11180
|
Post("setup"),
|
|
10664
|
-
|
|
10665
|
-
|
|
11181
|
+
_ts_param26(0, CurrentUser()),
|
|
11182
|
+
_ts_param26(1, Body()),
|
|
10666
11183
|
_ts_metadata46("design:type", Function),
|
|
10667
11184
|
_ts_metadata46("design:paramtypes", [
|
|
10668
11185
|
typeof PlatformJwtPayload === "undefined" ? Object : PlatformJwtPayload,
|
|
@@ -10676,9 +11193,9 @@ _ts_decorate47([
|
|
|
10676
11193
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.mfaVerifyEnable),
|
|
10677
11194
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
10678
11195
|
Post("verify-enable"),
|
|
10679
|
-
|
|
10680
|
-
|
|
10681
|
-
|
|
11196
|
+
_ts_param26(0, CurrentUser()),
|
|
11197
|
+
_ts_param26(1, Body()),
|
|
11198
|
+
_ts_param26(2, Req()),
|
|
10682
11199
|
_ts_metadata46("design:type", Function),
|
|
10683
11200
|
_ts_metadata46("design:paramtypes", [
|
|
10684
11201
|
typeof PlatformJwtPayload === "undefined" ? Object : PlatformJwtPayload,
|
|
@@ -10693,9 +11210,9 @@ _ts_decorate47([
|
|
|
10693
11210
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.mfaDisable),
|
|
10694
11211
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
10695
11212
|
Post("disable"),
|
|
10696
|
-
|
|
10697
|
-
|
|
10698
|
-
|
|
11213
|
+
_ts_param26(0, CurrentUser()),
|
|
11214
|
+
_ts_param26(1, Body()),
|
|
11215
|
+
_ts_param26(2, Req()),
|
|
10699
11216
|
_ts_metadata46("design:type", Function),
|
|
10700
11217
|
_ts_metadata46("design:paramtypes", [
|
|
10701
11218
|
typeof PlatformJwtPayload === "undefined" ? Object : PlatformJwtPayload,
|
|
@@ -10710,9 +11227,9 @@ _ts_decorate47([
|
|
|
10710
11227
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.mfaDisable),
|
|
10711
11228
|
HttpCode(HttpStatus.OK),
|
|
10712
11229
|
Post("recovery-codes"),
|
|
10713
|
-
|
|
10714
|
-
|
|
10715
|
-
|
|
11230
|
+
_ts_param26(0, CurrentUser()),
|
|
11231
|
+
_ts_param26(1, Body()),
|
|
11232
|
+
_ts_param26(2, Req()),
|
|
10716
11233
|
_ts_metadata46("design:type", Function),
|
|
10717
11234
|
_ts_metadata46("design:paramtypes", [
|
|
10718
11235
|
typeof PlatformJwtPayload === "undefined" ? Object : PlatformJwtPayload,
|
|
@@ -10728,6 +11245,7 @@ PlatformMfaController = _ts_decorate47([
|
|
|
10728
11245
|
UsePipes(createAuthValidationPipe({
|
|
10729
11246
|
forbidUnknownValues: true
|
|
10730
11247
|
})),
|
|
11248
|
+
_ts_param26(0, Inject(MfaService)),
|
|
10731
11249
|
_ts_metadata46("design:type", Function),
|
|
10732
11250
|
_ts_metadata46("design:paramtypes", [
|
|
10733
11251
|
typeof MfaService === "undefined" ? Object : MfaService
|
|
@@ -10744,12 +11262,12 @@ function _ts_metadata47(k, v) {
|
|
|
10744
11262
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10745
11263
|
}
|
|
10746
11264
|
__name(_ts_metadata47, "_ts_metadata");
|
|
10747
|
-
function
|
|
11265
|
+
function _ts_param27(paramIndex, decorator) {
|
|
10748
11266
|
return function(target, key) {
|
|
10749
11267
|
decorator(target, key, paramIndex);
|
|
10750
11268
|
};
|
|
10751
11269
|
}
|
|
10752
|
-
__name(
|
|
11270
|
+
__name(_ts_param27, "_ts_param");
|
|
10753
11271
|
var SessionController = class {
|
|
10754
11272
|
static {
|
|
10755
11273
|
__name(this, "SessionController");
|
|
@@ -10829,8 +11347,8 @@ _ts_decorate48([
|
|
|
10829
11347
|
Throttle(AUTH_THROTTLE_CONFIGS.listSessions),
|
|
10830
11348
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.listSessions),
|
|
10831
11349
|
Get(),
|
|
10832
|
-
|
|
10833
|
-
|
|
11350
|
+
_ts_param27(0, CurrentUser()),
|
|
11351
|
+
_ts_param27(1, Req()),
|
|
10834
11352
|
_ts_metadata47("design:type", Function),
|
|
10835
11353
|
_ts_metadata47("design:paramtypes", [
|
|
10836
11354
|
typeof DashboardJwtPayload === "undefined" ? Object : DashboardJwtPayload,
|
|
@@ -10843,8 +11361,8 @@ _ts_decorate48([
|
|
|
10843
11361
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.revokeAllSessions),
|
|
10844
11362
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
10845
11363
|
Delete("all"),
|
|
10846
|
-
|
|
10847
|
-
|
|
11364
|
+
_ts_param27(0, CurrentUser()),
|
|
11365
|
+
_ts_param27(1, Req()),
|
|
10848
11366
|
_ts_metadata47("design:type", Function),
|
|
10849
11367
|
_ts_metadata47("design:paramtypes", [
|
|
10850
11368
|
typeof DashboardJwtPayload === "undefined" ? Object : DashboardJwtPayload,
|
|
@@ -10857,8 +11375,8 @@ _ts_decorate48([
|
|
|
10857
11375
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.revokeSession),
|
|
10858
11376
|
HttpCode(HttpStatus.NO_CONTENT),
|
|
10859
11377
|
Delete(":id"),
|
|
10860
|
-
|
|
10861
|
-
|
|
11378
|
+
_ts_param27(0, CurrentUser()),
|
|
11379
|
+
_ts_param27(1, Param("id")),
|
|
10862
11380
|
_ts_metadata47("design:type", Function),
|
|
10863
11381
|
_ts_metadata47("design:paramtypes", [
|
|
10864
11382
|
typeof DashboardJwtPayload === "undefined" ? Object : DashboardJwtPayload,
|
|
@@ -10871,6 +11389,8 @@ SessionController = _ts_decorate48([
|
|
|
10871
11389
|
Controller("sessions"),
|
|
10872
11390
|
UseGuards(TrustedOriginGuard, AuthRateLimitGuard, JwtAuthGuard, UserStatusGuard),
|
|
10873
11391
|
UsePipes(createAuthValidationPipe()),
|
|
11392
|
+
_ts_param27(0, Inject(SessionService)),
|
|
11393
|
+
_ts_param27(1, Inject(TokenDeliveryService)),
|
|
10874
11394
|
_ts_metadata47("design:type", Function),
|
|
10875
11395
|
_ts_metadata47("design:paramtypes", [
|
|
10876
11396
|
typeof SessionService === "undefined" ? Object : SessionService,
|
|
@@ -10888,6 +11408,12 @@ function _ts_metadata48(k, v) {
|
|
|
10888
11408
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10889
11409
|
}
|
|
10890
11410
|
__name(_ts_metadata48, "_ts_metadata");
|
|
11411
|
+
function _ts_param28(paramIndex, decorator) {
|
|
11412
|
+
return function(target, key) {
|
|
11413
|
+
decorator(target, key, paramIndex);
|
|
11414
|
+
};
|
|
11415
|
+
}
|
|
11416
|
+
__name(_ts_param28, "_ts_param");
|
|
10891
11417
|
var MfaRequiredGuard = class {
|
|
10892
11418
|
static {
|
|
10893
11419
|
__name(this, "MfaRequiredGuard");
|
|
@@ -10916,6 +11442,7 @@ var MfaRequiredGuard = class {
|
|
|
10916
11442
|
};
|
|
10917
11443
|
MfaRequiredGuard = _ts_decorate49([
|
|
10918
11444
|
Injectable(),
|
|
11445
|
+
_ts_param28(0, Inject(Reflector)),
|
|
10919
11446
|
_ts_metadata48("design:type", Function),
|
|
10920
11447
|
_ts_metadata48("design:paramtypes", [
|
|
10921
11448
|
typeof Reflector === "undefined" ? Object : Reflector
|
|
@@ -10936,12 +11463,12 @@ function _ts_metadata49(k, v) {
|
|
|
10936
11463
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10937
11464
|
}
|
|
10938
11465
|
__name(_ts_metadata49, "_ts_metadata");
|
|
10939
|
-
function
|
|
11466
|
+
function _ts_param29(paramIndex, decorator) {
|
|
10940
11467
|
return function(target, key) {
|
|
10941
11468
|
decorator(target, key, paramIndex);
|
|
10942
11469
|
};
|
|
10943
11470
|
}
|
|
10944
|
-
__name(
|
|
11471
|
+
__name(_ts_param29, "_ts_param");
|
|
10945
11472
|
var PlatformRolesGuard = class {
|
|
10946
11473
|
static {
|
|
10947
11474
|
__name(this, "PlatformRolesGuard");
|
|
@@ -10977,7 +11504,8 @@ var PlatformRolesGuard = class {
|
|
|
10977
11504
|
};
|
|
10978
11505
|
PlatformRolesGuard = _ts_decorate50([
|
|
10979
11506
|
Injectable(),
|
|
10980
|
-
|
|
11507
|
+
_ts_param29(0, Inject(Reflector)),
|
|
11508
|
+
_ts_param29(1, Inject(BYMAX_AUTH_OPTIONS)),
|
|
10981
11509
|
_ts_metadata49("design:type", Function),
|
|
10982
11510
|
_ts_metadata49("design:paramtypes", [
|
|
10983
11511
|
typeof Reflector === "undefined" ? Object : Reflector,
|
|
@@ -10999,12 +11527,12 @@ function _ts_metadata50(k, v) {
|
|
|
10999
11527
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
11000
11528
|
}
|
|
11001
11529
|
__name(_ts_metadata50, "_ts_metadata");
|
|
11002
|
-
function
|
|
11530
|
+
function _ts_param30(paramIndex, decorator) {
|
|
11003
11531
|
return function(target, key) {
|
|
11004
11532
|
decorator(target, key, paramIndex);
|
|
11005
11533
|
};
|
|
11006
11534
|
}
|
|
11007
|
-
__name(
|
|
11535
|
+
__name(_ts_param30, "_ts_param");
|
|
11008
11536
|
var RolesGuard = class {
|
|
11009
11537
|
static {
|
|
11010
11538
|
__name(this, "RolesGuard");
|
|
@@ -11036,7 +11564,8 @@ var RolesGuard = class {
|
|
|
11036
11564
|
};
|
|
11037
11565
|
RolesGuard = _ts_decorate51([
|
|
11038
11566
|
Injectable(),
|
|
11039
|
-
|
|
11567
|
+
_ts_param30(0, Inject(Reflector)),
|
|
11568
|
+
_ts_param30(1, Inject(BYMAX_AUTH_OPTIONS)),
|
|
11040
11569
|
_ts_metadata50("design:type", Function),
|
|
11041
11570
|
_ts_metadata50("design:paramtypes", [
|
|
11042
11571
|
typeof Reflector === "undefined" ? Object : Reflector,
|
|
@@ -11116,16 +11645,17 @@ function _ts_metadata51(k, v) {
|
|
|
11116
11645
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
11117
11646
|
}
|
|
11118
11647
|
__name(_ts_metadata51, "_ts_metadata");
|
|
11119
|
-
function
|
|
11648
|
+
function _ts_param31(paramIndex, decorator) {
|
|
11120
11649
|
return function(target, key) {
|
|
11121
11650
|
decorator(target, key, paramIndex);
|
|
11122
11651
|
};
|
|
11123
11652
|
}
|
|
11124
|
-
__name(
|
|
11653
|
+
__name(_ts_param31, "_ts_param");
|
|
11125
11654
|
var OAUTH_STATE_TTL_SECONDS = 600;
|
|
11126
11655
|
function isStoredOAuthState(value) {
|
|
11127
11656
|
if (typeof value !== "object" || value === null) return false;
|
|
11128
11657
|
const v = value;
|
|
11658
|
+
if (typeof v["provider"] !== "string") return false;
|
|
11129
11659
|
if (typeof v["tenantId"] !== "string") return false;
|
|
11130
11660
|
if (typeof v["codeVerifier"] !== "string") return false;
|
|
11131
11661
|
return true;
|
|
@@ -11170,7 +11700,9 @@ var OAuthService = class _OAuthService {
|
|
|
11170
11700
|
* Sequence:
|
|
11171
11701
|
* 1. Validates the `provider` format and resolves the named plugin.
|
|
11172
11702
|
* 2. Generates a 32-byte (64 hex char) cryptographically random state nonce.
|
|
11173
|
-
* 3. Stores `os:{sha256(state)} → { tenantId }` in Redis with a
|
|
11703
|
+
* 3. Stores `os:{sha256(state)} → { provider, tenantId, codeVerifier }` in Redis with a
|
|
11704
|
+
* 10-minute TTL. `provider` is what the callback checks itself against (RFC 9700
|
|
11705
|
+
* mix-up defence).
|
|
11174
11706
|
* 4. Constructs the provider's authorization URL via `plugin.authorizeUrl(state)`.
|
|
11175
11707
|
* 5. Issues a 302 redirect via the Express `res` object.
|
|
11176
11708
|
*
|
|
@@ -11191,6 +11723,7 @@ var OAuthService = class _OAuthService {
|
|
|
11191
11723
|
const codeVerifier = generateSecureToken(32);
|
|
11192
11724
|
const codeChallenge = base64url(createHash("sha256").update(codeVerifier, "utf8").digest());
|
|
11193
11725
|
const stored = {
|
|
11726
|
+
provider,
|
|
11194
11727
|
tenantId,
|
|
11195
11728
|
codeVerifier
|
|
11196
11729
|
};
|
|
@@ -11266,6 +11799,10 @@ var OAuthService = class _OAuthService {
|
|
|
11266
11799
|
if (!isStoredOAuthState(parsedState)) {
|
|
11267
11800
|
throw new AuthException(AUTH_ERROR_CODES.OAUTH_FAILED);
|
|
11268
11801
|
}
|
|
11802
|
+
if (parsedState.provider !== provider) {
|
|
11803
|
+
this.logger.warn(`handleCallback: OAuth state provider mismatch provider=${provider}`);
|
|
11804
|
+
throw new AuthException(AUTH_ERROR_CODES.OAUTH_FAILED);
|
|
11805
|
+
}
|
|
11269
11806
|
const { tenantId, codeVerifier } = parsedState;
|
|
11270
11807
|
let profile;
|
|
11271
11808
|
try {
|
|
@@ -11375,11 +11912,14 @@ var OAuthService = class _OAuthService {
|
|
|
11375
11912
|
};
|
|
11376
11913
|
OAuthService = _ts_decorate53([
|
|
11377
11914
|
Injectable(),
|
|
11378
|
-
|
|
11379
|
-
|
|
11380
|
-
|
|
11381
|
-
|
|
11382
|
-
|
|
11915
|
+
_ts_param31(0, Inject(OAUTH_PLUGINS)),
|
|
11916
|
+
_ts_param31(1, Inject(BYMAX_AUTH_USER_REPOSITORY)),
|
|
11917
|
+
_ts_param31(2, Inject(BYMAX_AUTH_HOOKS)),
|
|
11918
|
+
_ts_param31(2, Optional()),
|
|
11919
|
+
_ts_param31(3, Inject(AuthRedisService)),
|
|
11920
|
+
_ts_param31(4, Inject(TokenManagerService)),
|
|
11921
|
+
_ts_param31(5, Inject(SessionService)),
|
|
11922
|
+
_ts_param31(6, Inject(BYMAX_AUTH_OPTIONS)),
|
|
11383
11923
|
_ts_metadata51("design:type", Function),
|
|
11384
11924
|
_ts_metadata51("design:paramtypes", [
|
|
11385
11925
|
Array,
|
|
@@ -11591,12 +12131,12 @@ function _ts_metadata54(k, v) {
|
|
|
11591
12131
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
11592
12132
|
}
|
|
11593
12133
|
__name(_ts_metadata54, "_ts_metadata");
|
|
11594
|
-
function
|
|
12134
|
+
function _ts_param32(paramIndex, decorator) {
|
|
11595
12135
|
return function(target, key) {
|
|
11596
12136
|
decorator(target, key, paramIndex);
|
|
11597
12137
|
};
|
|
11598
12138
|
}
|
|
11599
|
-
__name(
|
|
12139
|
+
__name(_ts_param32, "_ts_param");
|
|
11600
12140
|
function isOAuthMfaChallenge(result) {
|
|
11601
12141
|
return "mfaRequired" in result && result.mfaRequired === true;
|
|
11602
12142
|
}
|
|
@@ -11818,10 +12358,10 @@ _ts_decorate56([
|
|
|
11818
12358
|
Throttle(AUTH_THROTTLE_CONFIGS.oauthInitiate),
|
|
11819
12359
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.oauthInitiate),
|
|
11820
12360
|
Get(":provider"),
|
|
11821
|
-
|
|
11822
|
-
|
|
11823
|
-
|
|
11824
|
-
|
|
12361
|
+
_ts_param32(0, Param("provider")),
|
|
12362
|
+
_ts_param32(1, Query()),
|
|
12363
|
+
_ts_param32(2, Req()),
|
|
12364
|
+
_ts_param32(3, Res({
|
|
11825
12365
|
passthrough: true
|
|
11826
12366
|
})),
|
|
11827
12367
|
_ts_metadata54("design:type", Function),
|
|
@@ -11838,10 +12378,10 @@ _ts_decorate56([
|
|
|
11838
12378
|
AuthRateLimit(AUTH_THROTTLE_CONFIGS.oauthCallback),
|
|
11839
12379
|
HttpCode(HttpStatus.OK),
|
|
11840
12380
|
Get(":provider/callback"),
|
|
11841
|
-
|
|
11842
|
-
|
|
11843
|
-
|
|
11844
|
-
|
|
12381
|
+
_ts_param32(0, Param("provider")),
|
|
12382
|
+
_ts_param32(1, Query()),
|
|
12383
|
+
_ts_param32(2, Req()),
|
|
12384
|
+
_ts_param32(3, Res({
|
|
11845
12385
|
passthrough: true
|
|
11846
12386
|
})),
|
|
11847
12387
|
_ts_metadata54("design:type", Function),
|
|
@@ -11862,7 +12402,9 @@ OAuthController = _ts_decorate56([
|
|
|
11862
12402
|
UsePipes(createAuthValidationPipe({
|
|
11863
12403
|
forbidUnknownValues: true
|
|
11864
12404
|
})),
|
|
11865
|
-
|
|
12405
|
+
_ts_param32(0, Inject(OAuthService)),
|
|
12406
|
+
_ts_param32(1, Inject(TokenDeliveryService)),
|
|
12407
|
+
_ts_param32(2, Inject(BYMAX_AUTH_OPTIONS)),
|
|
11866
12408
|
_ts_metadata54("design:type", Function),
|
|
11867
12409
|
_ts_metadata54("design:paramtypes", [
|
|
11868
12410
|
typeof OAuthService === "undefined" ? Object : OAuthService,
|
|
@@ -12093,12 +12635,12 @@ function _ts_metadata55(k, v) {
|
|
|
12093
12635
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
12094
12636
|
}
|
|
12095
12637
|
__name(_ts_metadata55, "_ts_metadata");
|
|
12096
|
-
function
|
|
12638
|
+
function _ts_param33(paramIndex, decorator) {
|
|
12097
12639
|
return function(target, key) {
|
|
12098
12640
|
decorator(target, key, paramIndex);
|
|
12099
12641
|
};
|
|
12100
12642
|
}
|
|
12101
|
-
__name(
|
|
12643
|
+
__name(_ts_param33, "_ts_param");
|
|
12102
12644
|
var COMMON_BASE_WORDS = [
|
|
12103
12645
|
// The perennial top of every published list.
|
|
12104
12646
|
"password",
|
|
@@ -12347,7 +12889,7 @@ var LEET_MAP = /* @__PURE__ */ new Map([
|
|
|
12347
12889
|
]
|
|
12348
12890
|
]);
|
|
12349
12891
|
function isDecoration(char) {
|
|
12350
|
-
return
|
|
12892
|
+
return !new RegExp("\\p{L}", "u").test(char);
|
|
12351
12893
|
}
|
|
12352
12894
|
__name(isDecoration, "isDecoration");
|
|
12353
12895
|
function stripTrailingDecoration(value) {
|
|
@@ -12361,7 +12903,7 @@ function reduceToBaseWord(password) {
|
|
|
12361
12903
|
let reduced = "";
|
|
12362
12904
|
for (const char of undecorated) {
|
|
12363
12905
|
const mapped = LEET_MAP.get(char) ?? char;
|
|
12364
|
-
if (/[
|
|
12906
|
+
if (/[\p{L}\p{N}]/u.test(mapped)) reduced += mapped;
|
|
12365
12907
|
}
|
|
12366
12908
|
return reduced;
|
|
12367
12909
|
}
|
|
@@ -12395,7 +12937,9 @@ var CommonPasswordChecker = class {
|
|
|
12395
12937
|
/** @inheritdoc */
|
|
12396
12938
|
async isBreached(password) {
|
|
12397
12939
|
const base = reduceToBaseWord(password);
|
|
12398
|
-
if (
|
|
12940
|
+
if ([
|
|
12941
|
+
...base
|
|
12942
|
+
].length < 4) return true;
|
|
12399
12943
|
if (this.blocked.has(base)) return true;
|
|
12400
12944
|
if (isSequential(base)) return true;
|
|
12401
12945
|
if (/^(.{1,4}?)\1{2,}$/.test(base)) return true;
|
|
@@ -12404,8 +12948,8 @@ var CommonPasswordChecker = class {
|
|
|
12404
12948
|
};
|
|
12405
12949
|
CommonPasswordChecker = _ts_decorate58([
|
|
12406
12950
|
Injectable(),
|
|
12407
|
-
|
|
12408
|
-
|
|
12951
|
+
_ts_param33(0, Inject(BYMAX_AUTH_OPTIONS)),
|
|
12952
|
+
_ts_param33(0, Optional()),
|
|
12409
12953
|
_ts_metadata55("design:type", Function),
|
|
12410
12954
|
_ts_metadata55("design:paramtypes", [
|
|
12411
12955
|
typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
|
|
@@ -12734,6 +13278,23 @@ var BymaxAuthModule = class _BymaxAuthModule {
|
|
|
12734
13278
|
// NestJS auto-registers @UseGuards() guards as local providers in the controller's
|
|
12735
13279
|
// module; all constructor deps must be resolvable from that module's context.
|
|
12736
13280
|
AuthRedisService,
|
|
13281
|
+
// Same reason, for the two exported guards whose remaining constructor deps are not
|
|
13282
|
+
// covered by the entries above. Exporting the guard class is necessary but not
|
|
13283
|
+
// sufficient: because @UseGuards() re-instantiates the guard in the *consumer's*
|
|
13284
|
+
// injector, a dep missing here fails the consumer's boot with
|
|
13285
|
+
// UnknownDependenciesException even though the guard itself is exported.
|
|
13286
|
+
//
|
|
13287
|
+
// UserStatusGuard -> BYMAX_AUTH_USER_REPOSITORY
|
|
13288
|
+
// WsJwtGuard -> WsTicketService
|
|
13289
|
+
//
|
|
13290
|
+
// Re-exporting the token (rather than asking the consumer to register the repository
|
|
13291
|
+
// again) is what keeps the guard bound to the SAME instance the auth module uses; a
|
|
13292
|
+
// second registration would resolve the guard against a different object.
|
|
13293
|
+
BYMAX_AUTH_USER_REPOSITORY,
|
|
13294
|
+
// WsTicketService also stands on its own as public surface: single-use ticket
|
|
13295
|
+
// handshakes are the credential a realtime transport is meant to use, and a consumer
|
|
13296
|
+
// cannot mint one without injecting this service.
|
|
13297
|
+
WsTicketService,
|
|
12737
13298
|
// Export JwtModule so host-app modules that apply JWT-dependent guards via
|
|
12738
13299
|
// @UseGuards() have JwtService in scope.
|
|
12739
13300
|
JwtModule
|
|
@@ -12865,12 +13426,12 @@ function _ts_metadata57(k, v) {
|
|
|
12865
13426
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
12866
13427
|
}
|
|
12867
13428
|
__name(_ts_metadata57, "_ts_metadata");
|
|
12868
|
-
function
|
|
13429
|
+
function _ts_param34(paramIndex, decorator) {
|
|
12869
13430
|
return function(target, key) {
|
|
12870
13431
|
decorator(target, key, paramIndex);
|
|
12871
13432
|
};
|
|
12872
13433
|
}
|
|
12873
|
-
__name(
|
|
13434
|
+
__name(_ts_param34, "_ts_param");
|
|
12874
13435
|
var SelfOrAdminGuard = class {
|
|
12875
13436
|
static {
|
|
12876
13437
|
__name(this, "SelfOrAdminGuard");
|
|
@@ -12902,7 +13463,7 @@ var SelfOrAdminGuard = class {
|
|
|
12902
13463
|
};
|
|
12903
13464
|
SelfOrAdminGuard = _ts_decorate63([
|
|
12904
13465
|
Injectable(),
|
|
12905
|
-
|
|
13466
|
+
_ts_param34(0, Inject(BYMAX_AUTH_OPTIONS)),
|
|
12906
13467
|
_ts_metadata57("design:type", Function),
|
|
12907
13468
|
_ts_metadata57("design:paramtypes", [
|
|
12908
13469
|
typeof ResolvedOptions === "undefined" ? Object : ResolvedOptions
|
|
@@ -12928,12 +13489,12 @@ function _ts_metadata58(k, v) {
|
|
|
12928
13489
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
12929
13490
|
}
|
|
12930
13491
|
__name(_ts_metadata58, "_ts_metadata");
|
|
12931
|
-
function
|
|
13492
|
+
function _ts_param35(paramIndex, decorator) {
|
|
12932
13493
|
return function(target, key) {
|
|
12933
13494
|
decorator(target, key, paramIndex);
|
|
12934
13495
|
};
|
|
12935
13496
|
}
|
|
12936
|
-
__name(
|
|
13497
|
+
__name(_ts_param35, "_ts_param");
|
|
12937
13498
|
var WsJwtGuard = class {
|
|
12938
13499
|
static {
|
|
12939
13500
|
__name(this, "WsJwtGuard");
|
|
@@ -12998,7 +13559,10 @@ var WsJwtGuard = class {
|
|
|
12998
13559
|
};
|
|
12999
13560
|
WsJwtGuard = _ts_decorate64([
|
|
13000
13561
|
Injectable(),
|
|
13001
|
-
|
|
13562
|
+
_ts_param35(0, Inject(JwtService)),
|
|
13563
|
+
_ts_param35(1, Inject(AuthRedisService)),
|
|
13564
|
+
_ts_param35(2, Inject(WsTicketService)),
|
|
13565
|
+
_ts_param35(3, Inject(BYMAX_AUTH_OPTIONS)),
|
|
13002
13566
|
_ts_metadata58("design:type", Function),
|
|
13003
13567
|
_ts_metadata58("design:paramtypes", [
|
|
13004
13568
|
typeof JwtService === "undefined" ? Object : JwtService,
|
|
@@ -13021,7 +13585,8 @@ function readUpgradeTicket(client) {
|
|
|
13021
13585
|
if (typeof fromQuery === "string" && fromQuery !== "") return fromQuery;
|
|
13022
13586
|
if (fromQuery !== void 0) return void 0;
|
|
13023
13587
|
const url = client.handshake.url;
|
|
13024
|
-
if (typeof url !== "string"
|
|
13588
|
+
if (typeof url !== "string") return void 0;
|
|
13589
|
+
if (url === "") return void 0;
|
|
13025
13590
|
let params;
|
|
13026
13591
|
try {
|
|
13027
13592
|
params = new URL(url, "http://ws.invalid").searchParams;
|