@bymax-one/nest-auth 1.5.8 → 1.5.10
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 +125 -1
- package/README.md +13 -1
- package/dist/server/index.cjs +670 -173
- package/dist/server/index.d.cts +4 -4
- package/dist/server/index.d.ts +4 -4
- package/dist/server/index.mjs +670 -173
- package/package.json +1 -1
package/dist/server/index.mjs
CHANGED
|
@@ -25,6 +25,193 @@ var BYMAX_AUTH_API_KEY_CLOCK = /* @__PURE__ */ Symbol("BYMAX_AUTH_API_KEY_CLOCK"
|
|
|
25
25
|
var BYMAX_AUTH_WORKSPACE_REPOSITORY = /* @__PURE__ */ Symbol("BYMAX_AUTH_WORKSPACE_REPOSITORY");
|
|
26
26
|
var BYMAX_AUTH_MEMBERSHIP_REPOSITORY = /* @__PURE__ */ Symbol("BYMAX_AUTH_MEMBERSHIP_REPOSITORY");
|
|
27
27
|
|
|
28
|
+
// src/server/config/describe-received.ts
|
|
29
|
+
function describeReceived(value) {
|
|
30
|
+
if (typeof value === "number") return String(value);
|
|
31
|
+
if (value === null || value === void 0) return String(value);
|
|
32
|
+
if (Array.isArray(value)) return "an array";
|
|
33
|
+
const kind = typeof value;
|
|
34
|
+
return `${kind === "object" ? "an" : "a"} ${kind}`;
|
|
35
|
+
}
|
|
36
|
+
__name(describeReceived, "describeReceived");
|
|
37
|
+
|
|
38
|
+
// src/server/config/enum-boolean-options.ts
|
|
39
|
+
var BOOLEAN_OPTIONS = [
|
|
40
|
+
"secureCookies",
|
|
41
|
+
"enforceTenantBinding",
|
|
42
|
+
"sessions.enabled",
|
|
43
|
+
"emailVerification.required",
|
|
44
|
+
"platform.enabled",
|
|
45
|
+
"invitations.enabled",
|
|
46
|
+
"rateLimit.enabled",
|
|
47
|
+
"workspaces.enabled",
|
|
48
|
+
"apiKeys.enabled"
|
|
49
|
+
];
|
|
50
|
+
var BOOLEAN_OR_FUNCTION_OPTIONS = [
|
|
51
|
+
"workspaces.allowCreate"
|
|
52
|
+
];
|
|
53
|
+
var CONTROLLER_FLAGS = [
|
|
54
|
+
"auth",
|
|
55
|
+
"mfa",
|
|
56
|
+
"passwordReset",
|
|
57
|
+
"sessions",
|
|
58
|
+
"platform",
|
|
59
|
+
"oauth",
|
|
60
|
+
"invitations",
|
|
61
|
+
"emailChange",
|
|
62
|
+
"workspaces",
|
|
63
|
+
"workspaceInvitations"
|
|
64
|
+
];
|
|
65
|
+
var ENUM_OPTIONS = {
|
|
66
|
+
tokenDelivery: [
|
|
67
|
+
"cookie",
|
|
68
|
+
"bearer",
|
|
69
|
+
"both"
|
|
70
|
+
],
|
|
71
|
+
environment: [
|
|
72
|
+
"production",
|
|
73
|
+
"development",
|
|
74
|
+
"test"
|
|
75
|
+
],
|
|
76
|
+
"cookies.sameSite": [
|
|
77
|
+
"lax",
|
|
78
|
+
"strict",
|
|
79
|
+
"none"
|
|
80
|
+
],
|
|
81
|
+
"passwordReset.method": [
|
|
82
|
+
"token",
|
|
83
|
+
"otp"
|
|
84
|
+
]
|
|
85
|
+
};
|
|
86
|
+
function readPath(root, path) {
|
|
87
|
+
let node = root;
|
|
88
|
+
for (const step of path.split(".")) {
|
|
89
|
+
if (typeof node !== "object" || node === null) return void 0;
|
|
90
|
+
node = Reflect.get(node, step);
|
|
91
|
+
}
|
|
92
|
+
return node;
|
|
93
|
+
}
|
|
94
|
+
__name(readPath, "readPath");
|
|
95
|
+
function assertBoolean(path, value) {
|
|
96
|
+
if (value === void 0 || typeof value === "boolean") return;
|
|
97
|
+
throw new Error(`[BymaxAuthModule] ${path} must be true or false (received ${describeReceived(value)}).`);
|
|
98
|
+
}
|
|
99
|
+
__name(assertBoolean, "assertBoolean");
|
|
100
|
+
function assertOneOf(path, value, allowed) {
|
|
101
|
+
if (value === void 0 || typeof value === "string" && allowed.includes(value)) return;
|
|
102
|
+
throw new Error(`[BymaxAuthModule] ${path} must be one of ${allowed.map((entry) => `'${entry}'`).join(", ")} (received ${describeReceived(value)}).`);
|
|
103
|
+
}
|
|
104
|
+
__name(assertOneOf, "assertOneOf");
|
|
105
|
+
function validateControllerFlags(flags) {
|
|
106
|
+
for (const name of CONTROLLER_FLAGS) {
|
|
107
|
+
const flag = readPath(flags, name);
|
|
108
|
+
if (flag !== null) assertBoolean(`controllers.${name}`, flag);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
__name(validateControllerFlags, "validateControllerFlags");
|
|
112
|
+
function validateEnumAndBooleanOptions(userOptions) {
|
|
113
|
+
for (const path of BOOLEAN_OPTIONS) assertBoolean(path, readPath(userOptions, path));
|
|
114
|
+
for (const path of BOOLEAN_OR_FUNCTION_OPTIONS) {
|
|
115
|
+
const value = readPath(userOptions, path);
|
|
116
|
+
if (typeof value !== "function") assertBoolean(path, value);
|
|
117
|
+
}
|
|
118
|
+
for (const [path, allowed] of Object.entries(ENUM_OPTIONS)) {
|
|
119
|
+
assertOneOf(path, readPath(userOptions, path), allowed);
|
|
120
|
+
}
|
|
121
|
+
validateControllerFlags(userOptions.controllers);
|
|
122
|
+
}
|
|
123
|
+
__name(validateEnumAndBooleanOptions, "validateEnumAndBooleanOptions");
|
|
124
|
+
|
|
125
|
+
// src/server/config/provider-shape.ts
|
|
126
|
+
var REQUIRED_EMAIL_METHODS = [
|
|
127
|
+
"sendPasswordResetToken",
|
|
128
|
+
"sendPasswordResetOtp",
|
|
129
|
+
"sendEmailVerificationOtp",
|
|
130
|
+
"sendMfaEnabledNotification",
|
|
131
|
+
"sendMfaDisabledNotification",
|
|
132
|
+
"sendInvitation"
|
|
133
|
+
];
|
|
134
|
+
function readyMadeValue(providers, token) {
|
|
135
|
+
const entry = providers.find((p) => typeof p !== "function" && "provide" in p && p.provide === token);
|
|
136
|
+
if (entry === void 0 || !("useValue" in entry)) return {
|
|
137
|
+
found: false,
|
|
138
|
+
value: void 0
|
|
139
|
+
};
|
|
140
|
+
return {
|
|
141
|
+
found: true,
|
|
142
|
+
value: entry.useValue
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
__name(readyMadeValue, "readyMadeValue");
|
|
146
|
+
var HOOK_NAMES = Object.keys({
|
|
147
|
+
beforeRegister: true,
|
|
148
|
+
afterRegister: true,
|
|
149
|
+
beforeLogin: true,
|
|
150
|
+
afterLogin: true,
|
|
151
|
+
afterLogout: true,
|
|
152
|
+
afterPlatformLogout: true,
|
|
153
|
+
onLoginFailed: true,
|
|
154
|
+
onLockout: true,
|
|
155
|
+
onRefreshTokenReuseDetected: true,
|
|
156
|
+
afterMfaEnabled: true,
|
|
157
|
+
afterMfaDisabled: true,
|
|
158
|
+
afterMfaRecoveryCodesRegenerated: true,
|
|
159
|
+
onNewSession: true,
|
|
160
|
+
afterEmailVerified: true,
|
|
161
|
+
afterPasswordReset: true,
|
|
162
|
+
onOAuthLogin: true,
|
|
163
|
+
afterInvitationAccepted: true,
|
|
164
|
+
onSessionEvicted: true,
|
|
165
|
+
onApiKeyRequest: true,
|
|
166
|
+
beforeWorkspaceCreate: true,
|
|
167
|
+
onWorkspaceEvent: true
|
|
168
|
+
});
|
|
169
|
+
var EMAIL_METHOD_NAMES = Object.keys({
|
|
170
|
+
sendPasswordResetToken: true,
|
|
171
|
+
sendPasswordResetOtp: true,
|
|
172
|
+
sendEmailVerificationOtp: true,
|
|
173
|
+
sendPasswordChangedNotification: true,
|
|
174
|
+
sendEmailChangeVerification: true,
|
|
175
|
+
sendEmailChangedNotification: true,
|
|
176
|
+
sendMfaEnabledNotification: true,
|
|
177
|
+
sendMfaDisabledNotification: true,
|
|
178
|
+
sendNewSessionAlert: true,
|
|
179
|
+
sendInvitation: true,
|
|
180
|
+
sendWorkspaceInvitation: true
|
|
181
|
+
});
|
|
182
|
+
function assertNamedFunctions(label, value, names) {
|
|
183
|
+
if (typeof value !== "object" || value === null) {
|
|
184
|
+
throw new Error(`[BymaxAuthModule] ${label} must be an object (received ${describeReceived(value)}).`);
|
|
185
|
+
}
|
|
186
|
+
for (const name of names) {
|
|
187
|
+
const member = Reflect.get(value, name);
|
|
188
|
+
if (member !== void 0 && member !== null && typeof member !== "function") {
|
|
189
|
+
throw new Error(`[BymaxAuthModule] ${label}.${name} must be a function (received ${describeReceived(member)}).`);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
__name(assertNamedFunctions, "assertNamedFunctions");
|
|
194
|
+
function assertProviderShapes(providers) {
|
|
195
|
+
const hooks = readyMadeValue(providers, BYMAX_AUTH_HOOKS);
|
|
196
|
+
if (hooks.found && hooks.value !== null && hooks.value !== void 0) {
|
|
197
|
+
assertNamedFunctions("BYMAX_AUTH_HOOKS", hooks.value, HOOK_NAMES);
|
|
198
|
+
}
|
|
199
|
+
const email = readyMadeValue(providers, BYMAX_AUTH_EMAIL_PROVIDER);
|
|
200
|
+
if (!email.found) return;
|
|
201
|
+
assertNamedFunctions("BYMAX_AUTH_EMAIL_PROVIDER", email.value, EMAIL_METHOD_NAMES);
|
|
202
|
+
for (const name of REQUIRED_EMAIL_METHODS) {
|
|
203
|
+
if (typeof Reflect.get(email.value, name) !== "function") {
|
|
204
|
+
throw new Error(`[BymaxAuthModule] BYMAX_AUTH_EMAIL_PROVIDER.${name} is required and must be a function.`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
__name(assertProviderShapes, "assertProviderShapes");
|
|
209
|
+
function validateRegistrationShapes(controllers, providers) {
|
|
210
|
+
validateControllerFlags(controllers);
|
|
211
|
+
assertProviderShapes(providers);
|
|
212
|
+
}
|
|
213
|
+
__name(validateRegistrationShapes, "validateRegistrationShapes");
|
|
214
|
+
|
|
28
215
|
// src/server/config/default-options.ts
|
|
29
216
|
var DEFAULT_OPTIONS = {
|
|
30
217
|
jwt: {
|
|
@@ -362,6 +549,461 @@ function durationToSeconds(value) {
|
|
|
362
549
|
return amount * seconds;
|
|
363
550
|
}
|
|
364
551
|
__name(durationToSeconds, "durationToSeconds");
|
|
552
|
+
var TOTP_STEP_SECONDS = 30;
|
|
553
|
+
var TOTP_DIGITS = 6;
|
|
554
|
+
var BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
555
|
+
var MIN_SECRET_BYTES = 20;
|
|
556
|
+
function toBase32(input) {
|
|
557
|
+
let bits = 0;
|
|
558
|
+
let value = 0;
|
|
559
|
+
let output = "";
|
|
560
|
+
for (let i = 0; i < input.length; i++) {
|
|
561
|
+
value = value << 8 | input.readUInt8(i);
|
|
562
|
+
bits += 8;
|
|
563
|
+
while (bits >= 5) {
|
|
564
|
+
bits -= 5;
|
|
565
|
+
output += BASE32_ALPHABET[value >>> bits & 31];
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
if (bits > 0) {
|
|
569
|
+
output += BASE32_ALPHABET[value << 5 - bits & 31];
|
|
570
|
+
}
|
|
571
|
+
return output;
|
|
572
|
+
}
|
|
573
|
+
__name(toBase32, "toBase32");
|
|
574
|
+
function fromBase32(input) {
|
|
575
|
+
const normalized = input.toUpperCase().replace(/[\s=-]/g, "");
|
|
576
|
+
let bits = 0;
|
|
577
|
+
let value = 0;
|
|
578
|
+
const output = [];
|
|
579
|
+
for (const char of normalized) {
|
|
580
|
+
const idx = BASE32_ALPHABET.indexOf(char);
|
|
581
|
+
if (idx === -1) {
|
|
582
|
+
throw new Error(`[totp] Invalid Base32 character: ${JSON.stringify(char)}`);
|
|
583
|
+
}
|
|
584
|
+
value = value << 5 | idx;
|
|
585
|
+
bits += 5;
|
|
586
|
+
if (bits >= 8) {
|
|
587
|
+
bits -= 8;
|
|
588
|
+
output.push(value >>> bits & 255);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
return Buffer.from(output);
|
|
592
|
+
}
|
|
593
|
+
__name(fromBase32, "fromBase32");
|
|
594
|
+
function generateTotpSecret() {
|
|
595
|
+
const raw = randomBytes(MIN_SECRET_BYTES);
|
|
596
|
+
return {
|
|
597
|
+
raw,
|
|
598
|
+
base32: toBase32(raw)
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
__name(generateTotpSecret, "generateTotpSecret");
|
|
602
|
+
function buildTotpUri(secretBase32, accountEmail, issuer) {
|
|
603
|
+
if (!secretBase32 || secretBase32.length < 32) {
|
|
604
|
+
throw new Error("[totp] secretBase32 must encode at least 20 bytes (minimum 32 base32 characters)");
|
|
605
|
+
}
|
|
606
|
+
if (!issuer) {
|
|
607
|
+
throw new Error("[totp] issuer must not be empty");
|
|
608
|
+
}
|
|
609
|
+
if (!accountEmail) {
|
|
610
|
+
throw new Error("[totp] accountEmail must not be empty");
|
|
611
|
+
}
|
|
612
|
+
const label = `${encodeURIComponent(issuer)}:${encodeURIComponent(accountEmail)}`;
|
|
613
|
+
const qs = [
|
|
614
|
+
`secret=${encodeURIComponent(secretBase32)}`,
|
|
615
|
+
`issuer=${encodeURIComponent(issuer)}`,
|
|
616
|
+
`algorithm=SHA1`,
|
|
617
|
+
`digits=${String(TOTP_DIGITS)}`,
|
|
618
|
+
`period=${String(TOTP_STEP_SECONDS)}`
|
|
619
|
+
].join("&");
|
|
620
|
+
return `otpauth://totp/${label}?${qs}`;
|
|
621
|
+
}
|
|
622
|
+
__name(buildTotpUri, "buildTotpUri");
|
|
623
|
+
function generateHotp(secretBase32, counter) {
|
|
624
|
+
const key = fromBase32(secretBase32);
|
|
625
|
+
if (key.length < MIN_SECRET_BYTES) {
|
|
626
|
+
throw new Error(`[totp] Secret too short: ${key.length} bytes (minimum ${MIN_SECRET_BYTES}). Generate secrets with generateTotpSecret().`);
|
|
627
|
+
}
|
|
628
|
+
if (!Number.isInteger(counter) || counter < 0 || counter > Number.MAX_SAFE_INTEGER) {
|
|
629
|
+
throw new Error(`[totp] Counter must be a non-negative safe integer (got ${counter}).`);
|
|
630
|
+
}
|
|
631
|
+
const counterBuffer = Buffer.allocUnsafe(8);
|
|
632
|
+
const hi = Math.floor(counter / 4294967296);
|
|
633
|
+
const lo = counter >>> 0;
|
|
634
|
+
counterBuffer.writeUInt32BE(hi, 0);
|
|
635
|
+
counterBuffer.writeUInt32BE(lo, 4);
|
|
636
|
+
const hmac = createHmac("sha1", key).update(counterBuffer).digest();
|
|
637
|
+
const offset = hmac.readUInt8(hmac.length - 1) & 15;
|
|
638
|
+
const truncated = (hmac.readUInt8(offset) & 127) << 24 | (hmac.readUInt8(offset + 1) & 255) << 16 | (hmac.readUInt8(offset + 2) & 255) << 8 | hmac.readUInt8(offset + 3);
|
|
639
|
+
const mod = 10 ** TOTP_DIGITS;
|
|
640
|
+
return String(truncated % mod).padStart(TOTP_DIGITS, "0");
|
|
641
|
+
}
|
|
642
|
+
__name(generateHotp, "generateHotp");
|
|
643
|
+
var MAX_VERIFY_WINDOW = 2;
|
|
644
|
+
function verifyTotp(secretBase32, code, window = 1) {
|
|
645
|
+
if (!/^\d{6}$/.test(code)) return false;
|
|
646
|
+
const currentStep = Math.floor(Date.now() / 1e3 / TOTP_STEP_SECONDS);
|
|
647
|
+
const effective = Math.min(Math.max(window, 0), MAX_VERIFY_WINDOW);
|
|
648
|
+
for (let delta = -effective; delta <= effective; delta++) {
|
|
649
|
+
const expected = generateHotp(secretBase32, currentStep + delta);
|
|
650
|
+
const expectedBuf = Buffer.from(expected, "utf8");
|
|
651
|
+
const codeBuf = Buffer.from(code, "utf8");
|
|
652
|
+
if (expectedBuf.length === codeBuf.length && timingSafeEqual(expectedBuf, codeBuf)) {
|
|
653
|
+
return true;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
__name(verifyTotp, "verifyTotp");
|
|
659
|
+
|
|
660
|
+
// src/server/config/numeric-options.ts
|
|
661
|
+
var MAX_USER_STATUS_CACHE_TTL_SECONDS = 3600;
|
|
662
|
+
var MAX_REDIS_TTL_SECONDS = 31536e4;
|
|
663
|
+
var MAX_COOKIE_MAX_AGE_MS = MAX_REDIS_TTL_SECONDS * 1e3;
|
|
664
|
+
var MAX_SESSIONS_PER_USER = 1e3;
|
|
665
|
+
var MAX_LIFETIME_DAYS = 3650;
|
|
666
|
+
var MIN_ABSOLUTE_LIFETIME_DAYS = 1 / 24;
|
|
667
|
+
var MAX_SCRYPT_PARALLELIZATION = 16;
|
|
668
|
+
var MAX_BRUTE_FORCE_WINDOW_SECONDS = 604800;
|
|
669
|
+
function assertWholeNumber(path, value, min, max, why) {
|
|
670
|
+
if (value === void 0) return;
|
|
671
|
+
if (Number.isSafeInteger(value) && value >= min && value <= max) return;
|
|
672
|
+
throw new Error(`[BymaxAuthModule] ${path} must be a whole number between ${min} and ${max} inclusive (received ${describeReceived(value)}). ${why}`);
|
|
673
|
+
}
|
|
674
|
+
__name(assertWholeNumber, "assertWholeNumber");
|
|
675
|
+
function validateWholeNumberOptions(userOptions) {
|
|
676
|
+
assertWholeNumber("jwt.accessCookieMaxAgeMs", userOptions.jwt.accessCookieMaxAgeMs, 1e3, MAX_COOKIE_MAX_AGE_MS, "It is the cookie Max-Age in milliseconds, sent in whole seconds: under 1000 it becomes Max-Age=0, which deletes the cookie, and NaN is ignored by the browser, so the session would end with the tab.");
|
|
677
|
+
assertWholeNumber("sessions.defaultMaxSessions", userOptions.sessions?.defaultMaxSessions, 1, MAX_SESSIONS_PER_USER, "It caps concurrent sessions per user, counted in whole sessions: NaN evicts no session, zero or a negative value evicts them all, a fraction cannot be counted, and a value above 1000 is no cap.");
|
|
678
|
+
assertWholeNumber("bruteForce.windowSeconds", userOptions.bruteForce?.windowSeconds, 1, MAX_BRUTE_FORCE_WINDOW_SECONDS, "It is the Redis expiry of each failure counter: Redis deletes a key on `EXPIRE key 0`, so a zero or negative window destroys each counter as it is created and the lockout never engages, silently; a window past a week locks an account for a month over a few typos.");
|
|
679
|
+
assertWholeNumber("userStatusCacheTtlSeconds", userOptions.userStatusCacheTtlSeconds, 1, MAX_USER_STATUS_CACHE_TTL_SECONDS, "It is how long a suspended account keeps passing the dashboard guards, so it has a ceiling.");
|
|
680
|
+
}
|
|
681
|
+
__name(validateWholeNumberOptions, "validateWholeNumberOptions");
|
|
682
|
+
function validateRedisTtls(userOptions) {
|
|
683
|
+
const ttls = [
|
|
684
|
+
[
|
|
685
|
+
"passwordReset.tokenTtlSeconds",
|
|
686
|
+
userOptions.passwordReset?.tokenTtlSeconds
|
|
687
|
+
],
|
|
688
|
+
[
|
|
689
|
+
"passwordReset.otpTtlSeconds",
|
|
690
|
+
userOptions.passwordReset?.otpTtlSeconds
|
|
691
|
+
],
|
|
692
|
+
[
|
|
693
|
+
"emailVerification.otpTtlSeconds",
|
|
694
|
+
userOptions.emailVerification?.otpTtlSeconds
|
|
695
|
+
],
|
|
696
|
+
[
|
|
697
|
+
"emailChange.tokenTtlSeconds",
|
|
698
|
+
userOptions.emailChange?.tokenTtlSeconds
|
|
699
|
+
],
|
|
700
|
+
[
|
|
701
|
+
"invitations.tokenTtlSeconds",
|
|
702
|
+
userOptions.invitations?.tokenTtlSeconds
|
|
703
|
+
]
|
|
704
|
+
];
|
|
705
|
+
for (const [path, value] of ttls) {
|
|
706
|
+
assertWholeNumber(path, value, 1, MAX_REDIS_TTL_SECONDS, "It is a Redis expiry in seconds: zero or a negative deletes the record as it is written, and NaN, a fraction, Infinity or a value past what Redis can hold is refused by Redis on every request.");
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
__name(validateRedisTtls, "validateRedisTtls");
|
|
710
|
+
function validateAbsoluteSessionLifetime(jwt) {
|
|
711
|
+
const days = jwt.absoluteSessionLifetimeDays;
|
|
712
|
+
if (days === void 0 || days === 0 || Number.isFinite(days) && days >= MIN_ABSOLUTE_LIFETIME_DAYS && days <= MAX_LIFETIME_DAYS) {
|
|
713
|
+
return;
|
|
714
|
+
}
|
|
715
|
+
throw new Error(`[BymaxAuthModule] jwt.absoluteSessionLifetimeDays must be 0 or between ${MIN_ABSOLUTE_LIFETIME_DAYS.toFixed(4)} and ${MAX_LIFETIME_DAYS} days (received ${describeReceived(days)}). Only 0 switches the cap off; NaN, a negative or a value so large that its length in milliseconds overflows would skip it without being asked to, and a value under an hour ends every session at its first rotation after that age, minutes after login. Set 0 to accept unbounded sessions deliberately.`);
|
|
716
|
+
}
|
|
717
|
+
__name(validateAbsoluteSessionLifetime, "validateAbsoluteSessionLifetime");
|
|
718
|
+
function validatePasswordResetOtpLength(passwordReset) {
|
|
719
|
+
const otpLength = passwordReset?.otpLength;
|
|
720
|
+
if (otpLength === void 0) return;
|
|
721
|
+
if (!Number.isInteger(otpLength) || otpLength < 4 || otpLength > 8) {
|
|
722
|
+
throw new Error(`[BymaxAuthModule] passwordReset.otpLength must be between 4 and 8 inclusive (received ${describeReceived(otpLength)}). Values below 4 are too easily guessable; values above 8 are not required for security and degrade user experience. The value must also be a whole number: a comparison with NaN is false both ways, so a bound written as a range alone lets it through.`);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
__name(validatePasswordResetOtpLength, "validatePasswordResetOtpLength");
|
|
726
|
+
function validateMfaVerificationParameters(mfa) {
|
|
727
|
+
const totpWindow = mfa?.totpWindow;
|
|
728
|
+
if (totpWindow !== void 0 && (!Number.isInteger(totpWindow) || totpWindow < 0 || totpWindow > MAX_VERIFY_WINDOW)) {
|
|
729
|
+
throw new Error(`[BymaxAuthModule] mfa.totpWindow must be between 0 and ${MAX_VERIFY_WINDOW} inclusive (received ${describeReceived(totpWindow)}). The window is counted in 30-second steps on either side of the current time, so ${typeof totpWindow === "number" ? 2 * totpWindow + 1 : "2N + 1"} codes would be valid at once. RFC 6238 \xA75.2 recommends at most one step of tolerance; the default of 1 accepts three codes. The bound matches the drift window the verifier actually applies, so a configured value means what it says and is never silently clamped. It must be a whole number.`);
|
|
730
|
+
}
|
|
731
|
+
const recoveryCodeCount = mfa?.recoveryCodeCount;
|
|
732
|
+
if (recoveryCodeCount !== void 0 && (!Number.isInteger(recoveryCodeCount) || recoveryCodeCount < 1 || recoveryCodeCount > 50)) {
|
|
733
|
+
throw new Error(`[BymaxAuthModule] mfa.recoveryCodeCount must be between 1 and 50 inclusive (received ${describeReceived(recoveryCodeCount)}). Zero enrols an account with no way back if the authenticator is lost. The count must be a whole number.`);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
__name(validateMfaVerificationParameters, "validateMfaVerificationParameters");
|
|
737
|
+
var MAX_REFRESH_GRACE_WINDOW_SECONDS = 300;
|
|
738
|
+
function validateRefreshGraceWindow(jwt) {
|
|
739
|
+
const graceSeconds = jwt.refreshGraceWindowSeconds ?? DEFAULT_OPTIONS.jwt.refreshGraceWindowSeconds;
|
|
740
|
+
const refreshExpiresInDays = jwt.refreshExpiresInDays ?? DEFAULT_OPTIONS.jwt.refreshExpiresInDays;
|
|
741
|
+
const refreshLifetimeSeconds = typeof refreshExpiresInDays === "number" ? refreshExpiresInDays * 86400 : Number.NaN;
|
|
742
|
+
const isGraceNumber = typeof graceSeconds === "number";
|
|
743
|
+
if (!Number.isFinite(refreshExpiresInDays) || refreshExpiresInDays <= 0 || refreshExpiresInDays > MAX_LIFETIME_DAYS || !Number.isInteger(refreshLifetimeSeconds)) {
|
|
744
|
+
throw new Error(`[BymaxAuthModule] jwt.refreshExpiresInDays must be a positive finite number. It received ${describeReceived(refreshExpiresInDays)}. Zero, negative, NaN, and Infinity are all rejected \u2014 any of these would produce an invalid Redis TTL and cause all token rotations to fail at runtime. It is at most ${MAX_LIFETIME_DAYS} days, and days \xD7 86400 must be a whole number of seconds, because Redis takes an integer expiry: 1.5 and 0.25 are, 1.1 is not.`);
|
|
745
|
+
}
|
|
746
|
+
if (isGraceNumber && graceSeconds >= refreshLifetimeSeconds) {
|
|
747
|
+
throw new Error(`[BymaxAuthModule] jwt.refreshGraceWindowSeconds (${graceSeconds} s) must be less than the refresh token lifetime jwt.refreshExpiresInDays * 86400 (${refreshLifetimeSeconds} s). A grace window equal to or longer than the token lifetime would allow grace pointers to outlive the refresh session they protect.`);
|
|
748
|
+
}
|
|
749
|
+
if (!isGraceNumber || !Number.isInteger(graceSeconds) || graceSeconds < 0 || graceSeconds > MAX_REFRESH_GRACE_WINDOW_SECONDS) {
|
|
750
|
+
throw new Error(`[BymaxAuthModule] jwt.refreshGraceWindowSeconds must be between 0 and ${MAX_REFRESH_GRACE_WINDOW_SECONDS} inclusive (received ${describeReceived(graceSeconds)}). The window is how long an already-consumed refresh token recovers a session, so it is exactly the replay window for a stolen one. It covers a client that rotated but never received the response \u2014 a retry, not a policy. 0 disables grace recovery entirely. The value must be a whole number: Redis takes an integer expiry, so a fraction or NaN would fail every rotation.`);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
__name(validateRefreshGraceWindow, "validateRefreshGraceWindow");
|
|
754
|
+
function validateScryptParallelizationCeiling(password) {
|
|
755
|
+
const parallelization = password?.parallelization;
|
|
756
|
+
if (parallelization === void 0 || !Number.isFinite(parallelization) || parallelization <= MAX_SCRYPT_PARALLELIZATION) {
|
|
757
|
+
return;
|
|
758
|
+
}
|
|
759
|
+
throw new Error(`[BymaxAuthModule] password.parallelization must be at most ${MAX_SCRYPT_PARALLELIZATION} (received ${describeReceived(parallelization)}). scrypt's CPU cost grows linearly with it and an unauthenticated login derives a hash even for an address that does not exist.`);
|
|
760
|
+
}
|
|
761
|
+
__name(validateScryptParallelizationCeiling, "validateScryptParallelizationCeiling");
|
|
762
|
+
function validateNumericOptions(userOptions) {
|
|
763
|
+
validatePasswordResetOtpLength(userOptions.passwordReset);
|
|
764
|
+
validateMfaVerificationParameters(userOptions.mfa);
|
|
765
|
+
validateRefreshGraceWindow(userOptions.jwt);
|
|
766
|
+
validateAbsoluteSessionLifetime(userOptions.jwt);
|
|
767
|
+
validateScryptParallelizationCeiling(userOptions.password);
|
|
768
|
+
validateWholeNumberOptions(userOptions);
|
|
769
|
+
validateRedisTtls(userOptions);
|
|
770
|
+
}
|
|
771
|
+
__name(validateNumericOptions, "validateNumericOptions");
|
|
772
|
+
|
|
773
|
+
// src/server/config/option-values.ts
|
|
774
|
+
function validateOptionValues(userOptions) {
|
|
775
|
+
validateNumericOptions(userOptions);
|
|
776
|
+
validateEnumAndBooleanOptions(userOptions);
|
|
777
|
+
}
|
|
778
|
+
__name(validateOptionValues, "validateOptionValues");
|
|
779
|
+
|
|
780
|
+
// src/server/config/shape-checks.ts
|
|
781
|
+
function assertObject(label, value) {
|
|
782
|
+
if (Object(value) === value) return;
|
|
783
|
+
throw new Error(`[BymaxAuthModule] ${label} must be an object (received ${describeReceived(value)}).`);
|
|
784
|
+
}
|
|
785
|
+
__name(assertObject, "assertObject");
|
|
786
|
+
function assertArray(label, value) {
|
|
787
|
+
if (Array.isArray(value)) return;
|
|
788
|
+
throw new Error(`[BymaxAuthModule] ${label} must be an array (received ${describeReceived(value)}).`);
|
|
789
|
+
}
|
|
790
|
+
__name(assertArray, "assertArray");
|
|
791
|
+
|
|
792
|
+
// src/server/config/unset-options.ts
|
|
793
|
+
var TOP_KEYS = {
|
|
794
|
+
identifierKey: true,
|
|
795
|
+
jwt: true,
|
|
796
|
+
password: true,
|
|
797
|
+
tokenDelivery: true,
|
|
798
|
+
environment: true,
|
|
799
|
+
secureCookies: true,
|
|
800
|
+
cookies: true,
|
|
801
|
+
rateLimit: true,
|
|
802
|
+
mfa: true,
|
|
803
|
+
sessions: true,
|
|
804
|
+
bruteForce: true,
|
|
805
|
+
passwordReset: true,
|
|
806
|
+
emailVerification: true,
|
|
807
|
+
platform: true,
|
|
808
|
+
emailChange: true,
|
|
809
|
+
invitations: true,
|
|
810
|
+
apiKeys: true,
|
|
811
|
+
roles: true,
|
|
812
|
+
blockedStatuses: true,
|
|
813
|
+
redisNamespace: true,
|
|
814
|
+
oauth: true,
|
|
815
|
+
workspaces: true,
|
|
816
|
+
registration: true,
|
|
817
|
+
routePrefix: true,
|
|
818
|
+
tenantIdResolver: true,
|
|
819
|
+
enforceTenantBinding: true,
|
|
820
|
+
isTrustedProxy: true,
|
|
821
|
+
controllers: true,
|
|
822
|
+
userStatusCacheTtlSeconds: true
|
|
823
|
+
};
|
|
824
|
+
var GROUP_KEYS = {
|
|
825
|
+
jwt: {
|
|
826
|
+
secret: true,
|
|
827
|
+
previousSecrets: true,
|
|
828
|
+
accessExpiresIn: true,
|
|
829
|
+
accessCookieMaxAgeMs: true,
|
|
830
|
+
refreshExpiresInDays: true,
|
|
831
|
+
absoluteSessionLifetimeDays: true,
|
|
832
|
+
algorithm: true,
|
|
833
|
+
issuer: true,
|
|
834
|
+
audience: true,
|
|
835
|
+
refreshGraceWindowSeconds: true
|
|
836
|
+
},
|
|
837
|
+
password: {
|
|
838
|
+
costFactor: true,
|
|
839
|
+
minLength: true,
|
|
840
|
+
blockSize: true,
|
|
841
|
+
parallelization: true,
|
|
842
|
+
blocklist: true
|
|
843
|
+
},
|
|
844
|
+
cookies: {
|
|
845
|
+
accessTokenName: true,
|
|
846
|
+
refreshTokenName: true,
|
|
847
|
+
sessionSignalName: true,
|
|
848
|
+
refreshCookiePath: true,
|
|
849
|
+
mfaTempCookiePath: true,
|
|
850
|
+
resolveDomains: true,
|
|
851
|
+
sameSite: true,
|
|
852
|
+
trustedOrigins: true
|
|
853
|
+
},
|
|
854
|
+
sessions: {
|
|
855
|
+
enabled: true,
|
|
856
|
+
defaultMaxSessions: true,
|
|
857
|
+
maxSessionsResolver: true
|
|
858
|
+
},
|
|
859
|
+
bruteForce: {
|
|
860
|
+
maxAttempts: true,
|
|
861
|
+
windowSeconds: true
|
|
862
|
+
},
|
|
863
|
+
passwordReset: {
|
|
864
|
+
method: true,
|
|
865
|
+
tokenTtlSeconds: true,
|
|
866
|
+
otpTtlSeconds: true,
|
|
867
|
+
otpLength: true
|
|
868
|
+
},
|
|
869
|
+
emailVerification: {
|
|
870
|
+
required: true,
|
|
871
|
+
otpTtlSeconds: true
|
|
872
|
+
},
|
|
873
|
+
platform: {
|
|
874
|
+
enabled: true
|
|
875
|
+
},
|
|
876
|
+
invitations: {
|
|
877
|
+
enabled: true,
|
|
878
|
+
tokenTtlSeconds: true
|
|
879
|
+
},
|
|
880
|
+
emailChange: {
|
|
881
|
+
tokenTtlSeconds: true
|
|
882
|
+
},
|
|
883
|
+
controllers: {
|
|
884
|
+
auth: true,
|
|
885
|
+
mfa: true,
|
|
886
|
+
passwordReset: true,
|
|
887
|
+
sessions: true,
|
|
888
|
+
platform: true,
|
|
889
|
+
oauth: true,
|
|
890
|
+
invitations: true,
|
|
891
|
+
emailChange: true,
|
|
892
|
+
workspaces: true,
|
|
893
|
+
workspaceInvitations: true
|
|
894
|
+
},
|
|
895
|
+
rateLimit: {
|
|
896
|
+
enabled: true,
|
|
897
|
+
clientIpSource: true
|
|
898
|
+
},
|
|
899
|
+
mfa: {
|
|
900
|
+
encryptionKey: true,
|
|
901
|
+
previousEncryptionKeys: true,
|
|
902
|
+
issuer: true,
|
|
903
|
+
recoveryCodeCount: true,
|
|
904
|
+
totpWindow: true
|
|
905
|
+
},
|
|
906
|
+
apiKeys: {
|
|
907
|
+
enabled: true,
|
|
908
|
+
pepper: true,
|
|
909
|
+
scopes: true,
|
|
910
|
+
header: true,
|
|
911
|
+
prefix: true,
|
|
912
|
+
lastUsedFlushSeconds: true,
|
|
913
|
+
auditMode: true
|
|
914
|
+
},
|
|
915
|
+
workspaces: {
|
|
916
|
+
enabled: true,
|
|
917
|
+
roles: true,
|
|
918
|
+
permissions: true,
|
|
919
|
+
allowCreate: true,
|
|
920
|
+
maxWorkspacesPerUser: true,
|
|
921
|
+
invitationTtlSeconds: true,
|
|
922
|
+
maxPendingInvitationsPerWorkspace: true,
|
|
923
|
+
membershipCacheTtlSeconds: true,
|
|
924
|
+
deletionGraceDays: true,
|
|
925
|
+
accessDeniedEvents: true,
|
|
926
|
+
resolveRequestWorkspace: true,
|
|
927
|
+
resolveWsWorkspace: true
|
|
928
|
+
}
|
|
929
|
+
};
|
|
930
|
+
var KEPT_GROUP_KEYS = {
|
|
931
|
+
oauth: {
|
|
932
|
+
successRedirectUrl: true,
|
|
933
|
+
mfaRedirectUrl: true,
|
|
934
|
+
errorRedirectUrl: true,
|
|
935
|
+
google: true
|
|
936
|
+
},
|
|
937
|
+
roles: {
|
|
938
|
+
hierarchy: true,
|
|
939
|
+
platformHierarchy: true
|
|
940
|
+
}
|
|
941
|
+
};
|
|
942
|
+
var WORKSPACE_SUBGROUP_KEYS = {
|
|
943
|
+
accessDeniedEvents: [
|
|
944
|
+
"max",
|
|
945
|
+
"windowSeconds"
|
|
946
|
+
]
|
|
947
|
+
};
|
|
948
|
+
function isObjectGroup(value) {
|
|
949
|
+
return Object(value) === value && typeof value !== "function" && !Array.isArray(value);
|
|
950
|
+
}
|
|
951
|
+
__name(isObjectGroup, "isObjectGroup");
|
|
952
|
+
function readSetKeys(group, keys) {
|
|
953
|
+
const out = {};
|
|
954
|
+
for (const key of /* @__PURE__ */ new Set([
|
|
955
|
+
...keys,
|
|
956
|
+
...Object.keys(group)
|
|
957
|
+
])) {
|
|
958
|
+
const entry = Reflect.get(group, key);
|
|
959
|
+
if (entry !== void 0 && entry !== null) out[key] = entry;
|
|
960
|
+
}
|
|
961
|
+
return out;
|
|
962
|
+
}
|
|
963
|
+
__name(readSetKeys, "readSetKeys");
|
|
964
|
+
function readKeptKeys(group, keys) {
|
|
965
|
+
const out = {};
|
|
966
|
+
for (const key of /* @__PURE__ */ new Set([
|
|
967
|
+
...keys,
|
|
968
|
+
...Object.keys(group)
|
|
969
|
+
])) {
|
|
970
|
+
const entry = Reflect.get(group, key);
|
|
971
|
+
if (entry !== void 0 || Object.hasOwn(group, key)) out[key] = entry;
|
|
972
|
+
}
|
|
973
|
+
return out;
|
|
974
|
+
}
|
|
975
|
+
__name(readKeptKeys, "readKeptKeys");
|
|
976
|
+
function dropUnsetKeys(value) {
|
|
977
|
+
const copy = {
|
|
978
|
+
...value
|
|
979
|
+
};
|
|
980
|
+
for (const [key, entry] of Object.entries(copy)) {
|
|
981
|
+
if (entry === void 0 || entry === null) Reflect.deleteProperty(copy, key);
|
|
982
|
+
}
|
|
983
|
+
return copy;
|
|
984
|
+
}
|
|
985
|
+
__name(dropUnsetKeys, "dropUnsetKeys");
|
|
986
|
+
function dropUnset(options) {
|
|
987
|
+
const copy = readSetKeys(options, Object.keys(TOP_KEYS));
|
|
988
|
+
for (const [name, keys] of Object.entries(GROUP_KEYS)) {
|
|
989
|
+
const entry = copy[name];
|
|
990
|
+
if (!isObjectGroup(entry)) continue;
|
|
991
|
+
const group = readSetKeys(entry, Object.keys(keys));
|
|
992
|
+
if (name === "workspaces") {
|
|
993
|
+
for (const [sub, subKeys] of Object.entries(WORKSPACE_SUBGROUP_KEYS)) {
|
|
994
|
+
const inner = group[sub];
|
|
995
|
+
if (isObjectGroup(inner)) group[sub] = readSetKeys(inner, subKeys);
|
|
996
|
+
}
|
|
997
|
+
}
|
|
998
|
+
copy[name] = group;
|
|
999
|
+
}
|
|
1000
|
+
for (const [name, keys] of Object.entries(KEPT_GROUP_KEYS)) {
|
|
1001
|
+
const entry = copy[name];
|
|
1002
|
+
if (isObjectGroup(entry)) copy[name] = readKeptKeys(entry, Object.keys(keys));
|
|
1003
|
+
}
|
|
1004
|
+
return Object.assign({}, copy);
|
|
1005
|
+
}
|
|
1006
|
+
__name(dropUnset, "dropUnset");
|
|
365
1007
|
|
|
366
1008
|
// src/server/constants/workspace-roles.ts
|
|
367
1009
|
var ANY_WORKSPACE_MEMBER = /* @__PURE__ */ Symbol("ANY_WORKSPACE_MEMBER");
|
|
@@ -516,6 +1158,7 @@ __name(validateWorkspaceRoles, "validateWorkspaceRoles");
|
|
|
516
1158
|
function validateWorkspacePermissions(permissions, roles) {
|
|
517
1159
|
for (const [action, list] of Object.entries(permissions ?? {})) {
|
|
518
1160
|
if (list === void 0) continue;
|
|
1161
|
+
assertArray(`workspaces.permissions.${action}`, list);
|
|
519
1162
|
for (const role of list) {
|
|
520
1163
|
const known = roles.has(role);
|
|
521
1164
|
if (!known && !(action === "viewMembers" && role === ANY_WORKSPACE_MEMBER)) {
|
|
@@ -666,113 +1309,6 @@ __name(assertWorkspaceProviders, "assertWorkspaceProviders");
|
|
|
666
1309
|
|
|
667
1310
|
// src/server/constants/token-epoch.ts
|
|
668
1311
|
var TOKEN_EPOCH_RETENTION_SECONDS = 30 * 24 * 60 * 60;
|
|
669
|
-
var TOTP_STEP_SECONDS = 30;
|
|
670
|
-
var TOTP_DIGITS = 6;
|
|
671
|
-
var BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
672
|
-
var MIN_SECRET_BYTES = 20;
|
|
673
|
-
function toBase32(input) {
|
|
674
|
-
let bits = 0;
|
|
675
|
-
let value = 0;
|
|
676
|
-
let output = "";
|
|
677
|
-
for (let i = 0; i < input.length; i++) {
|
|
678
|
-
value = value << 8 | input.readUInt8(i);
|
|
679
|
-
bits += 8;
|
|
680
|
-
while (bits >= 5) {
|
|
681
|
-
bits -= 5;
|
|
682
|
-
output += BASE32_ALPHABET[value >>> bits & 31];
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
if (bits > 0) {
|
|
686
|
-
output += BASE32_ALPHABET[value << 5 - bits & 31];
|
|
687
|
-
}
|
|
688
|
-
return output;
|
|
689
|
-
}
|
|
690
|
-
__name(toBase32, "toBase32");
|
|
691
|
-
function fromBase32(input) {
|
|
692
|
-
const normalized = input.toUpperCase().replace(/[\s=-]/g, "");
|
|
693
|
-
let bits = 0;
|
|
694
|
-
let value = 0;
|
|
695
|
-
const output = [];
|
|
696
|
-
for (const char of normalized) {
|
|
697
|
-
const idx = BASE32_ALPHABET.indexOf(char);
|
|
698
|
-
if (idx === -1) {
|
|
699
|
-
throw new Error(`[totp] Invalid Base32 character: ${JSON.stringify(char)}`);
|
|
700
|
-
}
|
|
701
|
-
value = value << 5 | idx;
|
|
702
|
-
bits += 5;
|
|
703
|
-
if (bits >= 8) {
|
|
704
|
-
bits -= 8;
|
|
705
|
-
output.push(value >>> bits & 255);
|
|
706
|
-
}
|
|
707
|
-
}
|
|
708
|
-
return Buffer.from(output);
|
|
709
|
-
}
|
|
710
|
-
__name(fromBase32, "fromBase32");
|
|
711
|
-
function generateTotpSecret() {
|
|
712
|
-
const raw = randomBytes(MIN_SECRET_BYTES);
|
|
713
|
-
return {
|
|
714
|
-
raw,
|
|
715
|
-
base32: toBase32(raw)
|
|
716
|
-
};
|
|
717
|
-
}
|
|
718
|
-
__name(generateTotpSecret, "generateTotpSecret");
|
|
719
|
-
function buildTotpUri(secretBase32, accountEmail, issuer) {
|
|
720
|
-
if (!secretBase32 || secretBase32.length < 32) {
|
|
721
|
-
throw new Error("[totp] secretBase32 must encode at least 20 bytes (minimum 32 base32 characters)");
|
|
722
|
-
}
|
|
723
|
-
if (!issuer) {
|
|
724
|
-
throw new Error("[totp] issuer must not be empty");
|
|
725
|
-
}
|
|
726
|
-
if (!accountEmail) {
|
|
727
|
-
throw new Error("[totp] accountEmail must not be empty");
|
|
728
|
-
}
|
|
729
|
-
const label = `${encodeURIComponent(issuer)}:${encodeURIComponent(accountEmail)}`;
|
|
730
|
-
const qs = [
|
|
731
|
-
`secret=${encodeURIComponent(secretBase32)}`,
|
|
732
|
-
`issuer=${encodeURIComponent(issuer)}`,
|
|
733
|
-
`algorithm=SHA1`,
|
|
734
|
-
`digits=${String(TOTP_DIGITS)}`,
|
|
735
|
-
`period=${String(TOTP_STEP_SECONDS)}`
|
|
736
|
-
].join("&");
|
|
737
|
-
return `otpauth://totp/${label}?${qs}`;
|
|
738
|
-
}
|
|
739
|
-
__name(buildTotpUri, "buildTotpUri");
|
|
740
|
-
function generateHotp(secretBase32, counter) {
|
|
741
|
-
const key = fromBase32(secretBase32);
|
|
742
|
-
if (key.length < MIN_SECRET_BYTES) {
|
|
743
|
-
throw new Error(`[totp] Secret too short: ${key.length} bytes (minimum ${MIN_SECRET_BYTES}). Generate secrets with generateTotpSecret().`);
|
|
744
|
-
}
|
|
745
|
-
if (!Number.isInteger(counter) || counter < 0 || counter > Number.MAX_SAFE_INTEGER) {
|
|
746
|
-
throw new Error(`[totp] Counter must be a non-negative safe integer (got ${counter}).`);
|
|
747
|
-
}
|
|
748
|
-
const counterBuffer = Buffer.allocUnsafe(8);
|
|
749
|
-
const hi = Math.floor(counter / 4294967296);
|
|
750
|
-
const lo = counter >>> 0;
|
|
751
|
-
counterBuffer.writeUInt32BE(hi, 0);
|
|
752
|
-
counterBuffer.writeUInt32BE(lo, 4);
|
|
753
|
-
const hmac = createHmac("sha1", key).update(counterBuffer).digest();
|
|
754
|
-
const offset = hmac.readUInt8(hmac.length - 1) & 15;
|
|
755
|
-
const truncated = (hmac.readUInt8(offset) & 127) << 24 | (hmac.readUInt8(offset + 1) & 255) << 16 | (hmac.readUInt8(offset + 2) & 255) << 8 | hmac.readUInt8(offset + 3);
|
|
756
|
-
const mod = 10 ** TOTP_DIGITS;
|
|
757
|
-
return String(truncated % mod).padStart(TOTP_DIGITS, "0");
|
|
758
|
-
}
|
|
759
|
-
__name(generateHotp, "generateHotp");
|
|
760
|
-
var MAX_VERIFY_WINDOW = 2;
|
|
761
|
-
function verifyTotp(secretBase32, code, window = 1) {
|
|
762
|
-
if (!/^\d{6}$/.test(code)) return false;
|
|
763
|
-
const currentStep = Math.floor(Date.now() / 1e3 / TOTP_STEP_SECONDS);
|
|
764
|
-
const effective = Math.min(Math.max(window, 0), MAX_VERIFY_WINDOW);
|
|
765
|
-
for (let delta = -effective; delta <= effective; delta++) {
|
|
766
|
-
const expected = generateHotp(secretBase32, currentStep + delta);
|
|
767
|
-
const expectedBuf = Buffer.from(expected, "utf8");
|
|
768
|
-
const codeBuf = Buffer.from(code, "utf8");
|
|
769
|
-
if (expectedBuf.length === codeBuf.length && timingSafeEqual(expectedBuf, codeBuf)) {
|
|
770
|
-
return true;
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
return false;
|
|
774
|
-
}
|
|
775
|
-
__name(verifyTotp, "verifyTotp");
|
|
776
1312
|
|
|
777
1313
|
// src/server/config/resolved-options.ts
|
|
778
1314
|
var HMAC_KEY_DERIVATION_LABEL = "bymax-auth:hmac-key:v1";
|
|
@@ -784,17 +1320,17 @@ function isProductionDeployment(userOptions) {
|
|
|
784
1320
|
return (userOptions.environment ?? "production") === "production";
|
|
785
1321
|
}
|
|
786
1322
|
__name(isProductionDeployment, "isProductionDeployment");
|
|
787
|
-
function resolveOptions(
|
|
1323
|
+
function resolveOptions(given) {
|
|
1324
|
+
const userOptions = dropUnset(given);
|
|
788
1325
|
validateJwt(userOptions.jwt);
|
|
789
1326
|
validateIdentifierKey(userOptions.identifierKey);
|
|
790
1327
|
validateMfaEncryptionKey(userOptions.mfa);
|
|
791
1328
|
validateRolesHierarchy(userOptions.roles);
|
|
792
1329
|
validatePlatformAdmin(userOptions.platform, userOptions.roles);
|
|
793
|
-
|
|
1330
|
+
validateOptionValues(userOptions);
|
|
794
1331
|
validatePasswordMinLength(userOptions.password);
|
|
795
1332
|
validatePasswordCostFactor(userOptions.password);
|
|
796
1333
|
validatePasswordMemoryParameters(userOptions.password);
|
|
797
|
-
validateMfaVerificationParameters(userOptions.mfa);
|
|
798
1334
|
validateBruteForce(userOptions.bruteForce);
|
|
799
1335
|
validateOAuthProviders(userOptions.oauth, isProductionDeployment(userOptions));
|
|
800
1336
|
validateClientIpSource(userOptions.rateLimit);
|
|
@@ -810,7 +1346,6 @@ function resolveOptions(userOptions) {
|
|
|
810
1346
|
validateProductionCookiesAreSecure(userOptions);
|
|
811
1347
|
validateCookiePrefixes(userOptions);
|
|
812
1348
|
validateTrustedOrigins(userOptions);
|
|
813
|
-
validateRefreshGraceWindow(userOptions.jwt);
|
|
814
1349
|
validateAccessLifetimeAgainstEpochRetention(userOptions.jwt);
|
|
815
1350
|
const { mfa: _mfa, identifierKey: _identifierKey, workspaces: _workspaces, ...userOptionsWithoutMfa } = userOptions;
|
|
816
1351
|
const resolved = {
|
|
@@ -884,16 +1419,14 @@ function resolveOptions(userOptions) {
|
|
|
884
1419
|
userStatusCacheTtlSeconds: userOptions.userStatusCacheTtlSeconds ?? DEFAULT_OPTIONS.userStatusCacheTtlSeconds,
|
|
885
1420
|
// Evaluated once at startup — not re-evaluated per request.
|
|
886
1421
|
//
|
|
887
|
-
// `clientIpSource` has no default and `validateClientIpSource`
|
|
888
|
-
//
|
|
889
|
-
//
|
|
890
|
-
// consults no request header at all.
|
|
1422
|
+
// `clientIpSource` has no default and `validateClientIpSource` refused a deployment that left it
|
|
1423
|
+
// unset with limiting on. The fallback is reached only when limiting is OFF, where the value is
|
|
1424
|
+
// never read; `'peer'` is the inert choice because it consults no request header at all.
|
|
891
1425
|
rateLimit: {
|
|
892
1426
|
...DEFAULT_OPTIONS.rateLimit,
|
|
893
1427
|
...userOptions.rateLimit,
|
|
894
|
-
// Stryker disable next-line OptionalChaining: unreachable — `validateClientIpSource` has
|
|
895
|
-
//
|
|
896
|
-
// naming a source or disabling limiting), so `rateLimit` is never undefined here
|
|
1428
|
+
// Stryker disable next-line OptionalChaining: unreachable — `validateClientIpSource` has run, and
|
|
1429
|
+
// it returns only when `rateLimit` is an object (naming a source or disabling limiting)
|
|
897
1430
|
clientIpSource: userOptions.rateLimit?.clientIpSource ?? "peer"
|
|
898
1431
|
},
|
|
899
1432
|
environment: userOptions.environment ?? "production",
|
|
@@ -958,7 +1491,7 @@ function validateClientIpSource(rateLimit) {
|
|
|
958
1491
|
if (rateLimit?.clientIpSource === "peer" || rateLimit?.clientIpSource === "trusted-proxy") {
|
|
959
1492
|
return;
|
|
960
1493
|
}
|
|
961
|
-
throw new Error(`[BymaxAuthModule] rateLimit.clientIpSource must be 'peer' or 'trusted-proxy' when rate limiting is enabled (
|
|
1494
|
+
throw new Error(`[BymaxAuthModule] rateLimit.clientIpSource must be 'peer' or 'trusted-proxy' when rate limiting is enabled (received ${describeReceived(rateLimit?.clientIpSource)}). Set 'peer' when the application is directly exposed (the limit keys on the socket address), or 'trusted-proxy' when it runs behind a proxy and 'trust proxy' is configured for the real hop count (the limit keys on the forwarded client address). There is no default: 'peer' behind a proxy puts every client in ONE bucket, so one caller can rate-limit your whole user base, and 'trusted-proxy' without a proxy lets the caller choose their own key. Both look like a working limiter. Pass rateLimit.enabled: false if the limits are enforced at the edge instead.`);
|
|
962
1495
|
}
|
|
963
1496
|
__name(validateClientIpSource, "validateClientIpSource");
|
|
964
1497
|
function validateTenantBinding(userOptions) {
|
|
@@ -1065,6 +1598,7 @@ function validateRolesHierarchy(roles) {
|
|
|
1065
1598
|
}
|
|
1066
1599
|
const allRoles = new Set(Object.keys(roles.hierarchy));
|
|
1067
1600
|
for (const [role, children] of Object.entries(roles.hierarchy)) {
|
|
1601
|
+
assertArray(`roles.hierarchy['${role}']`, children);
|
|
1068
1602
|
for (const child of children) {
|
|
1069
1603
|
if (!allRoles.has(child)) {
|
|
1070
1604
|
throw new Error(`[BymaxAuthModule] roles.hierarchy['${role}'] references unknown role '${child}'. All roles referenced as children must be declared as keys in the hierarchy.`);
|
|
@@ -1079,24 +1613,16 @@ function validatePlatformAdmin(platform, roles) {
|
|
|
1079
1613
|
}
|
|
1080
1614
|
}
|
|
1081
1615
|
__name(validatePlatformAdmin, "validatePlatformAdmin");
|
|
1082
|
-
function validatePasswordResetOtpLength(passwordReset) {
|
|
1083
|
-
const otpLength = passwordReset?.otpLength;
|
|
1084
|
-
if (otpLength === void 0) return;
|
|
1085
|
-
if (otpLength < 4 || otpLength > 8) {
|
|
1086
|
-
throw new Error(`[BymaxAuthModule] passwordReset.otpLength must be between 4 and 8 inclusive (current: ${otpLength}). Values below 4 are too easily guessable; values above 8 are not required for security and degrade user experience.`);
|
|
1087
|
-
}
|
|
1088
|
-
}
|
|
1089
|
-
__name(validatePasswordResetOtpLength, "validatePasswordResetOtpLength");
|
|
1090
1616
|
function assertIntegralScryptParameter(name, value) {
|
|
1091
1617
|
if (value === void 0 || Number.isInteger(value)) return;
|
|
1092
|
-
throw new Error(`[BymaxAuthModule] password.${name} must be an integer (
|
|
1618
|
+
throw new Error(`[BymaxAuthModule] password.${name} must be an integer (received ${describeReceived(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.`);
|
|
1093
1619
|
}
|
|
1094
1620
|
__name(assertIntegralScryptParameter, "assertIntegralScryptParameter");
|
|
1095
1621
|
function validatePasswordMinLength(password) {
|
|
1096
1622
|
const minLength = password?.minLength;
|
|
1097
1623
|
if (minLength === void 0) return;
|
|
1098
1624
|
if (!Number.isInteger(minLength) || minLength < 8 || minLength > 128) {
|
|
1099
|
-
throw new Error(`[BymaxAuthModule] password.minLength must be an integer between 8 and 128 (
|
|
1625
|
+
throw new Error(`[BymaxAuthModule] password.minLength must be an integer between 8 and 128 (received ${describeReceived(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.`);
|
|
1100
1626
|
}
|
|
1101
1627
|
}
|
|
1102
1628
|
__name(validatePasswordMinLength, "validatePasswordMinLength");
|
|
@@ -1105,24 +1631,20 @@ function validatePasswordCostFactor(password) {
|
|
|
1105
1631
|
if (costFactor === void 0) return;
|
|
1106
1632
|
assertIntegralScryptParameter("costFactor", costFactor);
|
|
1107
1633
|
if (costFactor < 16384) {
|
|
1108
|
-
throw new Error(`[BymaxAuthModule] password.costFactor must be at least 16384 (2^14) (
|
|
1634
|
+
throw new Error(`[BymaxAuthModule] password.costFactor must be at least 16384 (2^14) (received ${describeReceived(costFactor)}). Lower values produce hashes vulnerable to brute-force attacks. The recommended minimum for production is 32768 (2^15).`);
|
|
1109
1635
|
}
|
|
1110
1636
|
if ((costFactor & costFactor - 1) !== 0) {
|
|
1111
|
-
throw new Error(`[BymaxAuthModule] password.costFactor must be a power of 2 (
|
|
1637
|
+
throw new Error(`[BymaxAuthModule] password.costFactor must be a power of 2 (received ${describeReceived(costFactor)}).`);
|
|
1112
1638
|
}
|
|
1113
1639
|
}
|
|
1114
1640
|
__name(validatePasswordCostFactor, "validatePasswordCostFactor");
|
|
1115
1641
|
function validateBruteForce(bruteForce) {
|
|
1116
|
-
const windowSeconds = bruteForce?.windowSeconds;
|
|
1117
|
-
if (windowSeconds !== void 0 && (!Number.isInteger(windowSeconds) || windowSeconds < 1)) {
|
|
1118
|
-
throw new Error(`[BymaxAuthModule] bruteForce.windowSeconds must be a whole number of at least 1 (current: ${windowSeconds}). Redis deletes a key on \`EXPIRE key 0\`, so a zero or negative window destroys each failure counter as it is created and the account lockout never engages \u2014 silently, with the configuration still reading as enabled.`);
|
|
1119
|
-
}
|
|
1120
1642
|
const maxAttempts = bruteForce?.maxAttempts;
|
|
1121
1643
|
if (maxAttempts !== void 0 && (!Number.isInteger(maxAttempts) || maxAttempts < 1)) {
|
|
1122
|
-
throw new Error(`[BymaxAuthModule] bruteForce.maxAttempts must be a whole number of at least 1 (
|
|
1644
|
+
throw new Error(`[BymaxAuthModule] bruteForce.maxAttempts must be a whole number of at least 1 (received ${describeReceived(maxAttempts)}). Zero locks out every account permanently, because a freshly created counter already satisfies "attempts >= 0".`);
|
|
1123
1645
|
}
|
|
1124
1646
|
if (maxAttempts !== void 0 && maxAttempts > MAX_BRUTE_FORCE_ATTEMPTS) {
|
|
1125
|
-
throw new Error(`[BymaxAuthModule] bruteForce.maxAttempts must not exceed ${MAX_BRUTE_FORCE_ATTEMPTS} (
|
|
1647
|
+
throw new Error(`[BymaxAuthModule] bruteForce.maxAttempts must not exceed ${MAX_BRUTE_FORCE_ATTEMPTS} (received ${describeReceived(maxAttempts)}). A threshold this high disables the lockout as effectively as switching it off, while the configuration still reads as enabled.`);
|
|
1126
1648
|
}
|
|
1127
1649
|
}
|
|
1128
1650
|
__name(validateBruteForce, "validateBruteForce");
|
|
@@ -1132,12 +1654,12 @@ function validatePasswordMemoryParameters(password) {
|
|
|
1132
1654
|
const blockSize = password?.blockSize;
|
|
1133
1655
|
assertIntegralScryptParameter("blockSize", blockSize);
|
|
1134
1656
|
if (blockSize !== void 0 && blockSize < 8) {
|
|
1135
|
-
throw new Error(`[BymaxAuthModule] password.blockSize must be at least 8 (
|
|
1657
|
+
throw new Error(`[BymaxAuthModule] password.blockSize must be at least 8 (received ${describeReceived(blockSize)}). scrypt's memory cost is 128 * N * r, so a smaller block size divides the memory hardness that password.costFactor's floor exists to guarantee.`);
|
|
1136
1658
|
}
|
|
1137
1659
|
const parallelization = password?.parallelization;
|
|
1138
1660
|
assertIntegralScryptParameter("parallelization", parallelization);
|
|
1139
1661
|
if (parallelization !== void 0 && parallelization < 1) {
|
|
1140
|
-
throw new Error(`[BymaxAuthModule] password.parallelization must be at least 1 (
|
|
1662
|
+
throw new Error(`[BymaxAuthModule] password.parallelization must be at least 1 (received ${describeReceived(parallelization)}).`);
|
|
1141
1663
|
}
|
|
1142
1664
|
const effectiveN = password?.costFactor ?? DEFAULT_OPTIONS.password.costFactor;
|
|
1143
1665
|
const effectiveR = password?.blockSize ?? DEFAULT_OPTIONS.password.blockSize;
|
|
@@ -1147,17 +1669,6 @@ function validatePasswordMemoryParameters(password) {
|
|
|
1147
1669
|
}
|
|
1148
1670
|
}
|
|
1149
1671
|
__name(validatePasswordMemoryParameters, "validatePasswordMemoryParameters");
|
|
1150
|
-
function validateMfaVerificationParameters(mfa) {
|
|
1151
|
-
const totpWindow = mfa?.totpWindow;
|
|
1152
|
-
if (totpWindow !== void 0 && (totpWindow < 0 || totpWindow > MAX_VERIFY_WINDOW)) {
|
|
1153
|
-
throw new Error(`[BymaxAuthModule] mfa.totpWindow must be between 0 and ${MAX_VERIFY_WINDOW} inclusive (current: ${totpWindow}). The window is counted in 30-second steps on either side of now, so ${2 * totpWindow + 1} codes would be valid at once. RFC 6238 \xA75.2 recommends at most one step of tolerance; the default of 1 accepts three codes. The bound matches the drift window the verifier actually applies, so a configured value always means what it says instead of being silently clamped.`);
|
|
1154
|
-
}
|
|
1155
|
-
const recoveryCodeCount = mfa?.recoveryCodeCount;
|
|
1156
|
-
if (recoveryCodeCount !== void 0 && (recoveryCodeCount < 1 || recoveryCodeCount > 50)) {
|
|
1157
|
-
throw new Error(`[BymaxAuthModule] mfa.recoveryCodeCount must be between 1 and 50 inclusive (current: ${recoveryCodeCount}). Zero enrols an account with no way back if the authenticator is lost.`);
|
|
1158
|
-
}
|
|
1159
|
-
}
|
|
1160
|
-
__name(validateMfaVerificationParameters, "validateMfaVerificationParameters");
|
|
1161
1672
|
var REQUIRED_OAUTH_FIELDS = [
|
|
1162
1673
|
"clientId",
|
|
1163
1674
|
"clientSecret",
|
|
@@ -1168,6 +1679,7 @@ function validateOAuthProviders(oauth, isProduction) {
|
|
|
1168
1679
|
for (const [providerOrField, rawConfig] of Object.entries(oauth)) {
|
|
1169
1680
|
if (providerOrField === "successRedirectUrl" || providerOrField === "mfaRedirectUrl" || providerOrField === "errorRedirectUrl") continue;
|
|
1170
1681
|
const provider = providerOrField;
|
|
1682
|
+
assertObject(`oauth.${provider}`, rawConfig);
|
|
1171
1683
|
const config = rawConfig;
|
|
1172
1684
|
for (const field of REQUIRED_OAUTH_FIELDS) {
|
|
1173
1685
|
if (!config[field]) {
|
|
@@ -1176,7 +1688,7 @@ function validateOAuthProviders(oauth, isProduction) {
|
|
|
1176
1688
|
}
|
|
1177
1689
|
const callbackUrl = config["callbackUrl"];
|
|
1178
1690
|
if (typeof callbackUrl === "string" && !callbackUrl.startsWith("https://") && isProduction) {
|
|
1179
|
-
throw new Error(`[BymaxAuthModule] oauth.${provider}.callbackUrl must use HTTPS in production (
|
|
1691
|
+
throw new Error(`[BymaxAuthModule] oauth.${provider}.callbackUrl must use HTTPS in production (received a string). Use an HTTPS URL to prevent authorization code interception.`);
|
|
1180
1692
|
}
|
|
1181
1693
|
}
|
|
1182
1694
|
}
|
|
@@ -1190,7 +1702,7 @@ function validateOAuthSuccessRedirectUrl(userOptions) {
|
|
|
1190
1702
|
const isProduction = isProductionDeployment(userOptions);
|
|
1191
1703
|
const isSafe = url.startsWith("/") || url.startsWith("https://");
|
|
1192
1704
|
if (isProduction && !isSafe) {
|
|
1193
|
-
throw new Error(`[BymaxAuthModule] oauth.successRedirectUrl must use HTTPS or be a same-origin path (starts with '/') in production (
|
|
1705
|
+
throw new Error(`[BymaxAuthModule] oauth.successRedirectUrl must use HTTPS or be a same-origin path (starts with '/') in production (received a string).`);
|
|
1194
1706
|
}
|
|
1195
1707
|
if (userOptions.tokenDelivery === "bearer") {
|
|
1196
1708
|
throw new Error(`[BymaxAuthModule] oauth.successRedirectUrl is set but tokenDelivery is 'bearer'. A redirect discards the JSON response body, so the access token would never reach the client. Use tokenDelivery: 'cookie' or 'both' when configuring a successRedirectUrl.`);
|
|
@@ -1206,7 +1718,7 @@ function validateOAuthMfaRedirectUrl(userOptions) {
|
|
|
1206
1718
|
const isProduction = isProductionDeployment(userOptions);
|
|
1207
1719
|
const isSafe = url.startsWith("/") || url.startsWith("https://");
|
|
1208
1720
|
if (isProduction && !isSafe) {
|
|
1209
|
-
throw new Error(`[BymaxAuthModule] oauth.mfaRedirectUrl must use HTTPS or be a same-origin path (starts with '/') in production (
|
|
1721
|
+
throw new Error(`[BymaxAuthModule] oauth.mfaRedirectUrl must use HTTPS or be a same-origin path (starts with '/') in production (received a string).`);
|
|
1210
1722
|
}
|
|
1211
1723
|
}
|
|
1212
1724
|
__name(validateOAuthMfaRedirectUrl, "validateOAuthMfaRedirectUrl");
|
|
@@ -1219,7 +1731,7 @@ function validateOAuthErrorRedirectUrl(userOptions) {
|
|
|
1219
1731
|
const isProduction = isProductionDeployment(userOptions);
|
|
1220
1732
|
const isSafe = url.startsWith("/") || url.startsWith("https://");
|
|
1221
1733
|
if (isProduction && !isSafe) {
|
|
1222
|
-
throw new Error(`[BymaxAuthModule] oauth.errorRedirectUrl must use HTTPS or be a same-origin path (starts with '/') in production (
|
|
1734
|
+
throw new Error(`[BymaxAuthModule] oauth.errorRedirectUrl must use HTTPS or be a same-origin path (starts with '/') in production (received a string).`);
|
|
1223
1735
|
}
|
|
1224
1736
|
}
|
|
1225
1737
|
__name(validateOAuthErrorRedirectUrl, "validateOAuthErrorRedirectUrl");
|
|
@@ -1301,30 +1813,14 @@ function isAbsoluteOrigin(value) {
|
|
|
1301
1813
|
}
|
|
1302
1814
|
}
|
|
1303
1815
|
__name(isAbsoluteOrigin, "isAbsoluteOrigin");
|
|
1304
|
-
var MAX_REFRESH_GRACE_WINDOW_SECONDS = 300;
|
|
1305
|
-
function validateRefreshGraceWindow(jwt) {
|
|
1306
|
-
const graceSeconds = jwt.refreshGraceWindowSeconds ?? DEFAULT_OPTIONS.jwt.refreshGraceWindowSeconds;
|
|
1307
|
-
const refreshExpiresInDays = jwt.refreshExpiresInDays ?? DEFAULT_OPTIONS.jwt.refreshExpiresInDays;
|
|
1308
|
-
const refreshLifetimeSeconds = refreshExpiresInDays * 86400;
|
|
1309
|
-
if (!Number.isFinite(refreshExpiresInDays) || refreshExpiresInDays <= 0) {
|
|
1310
|
-
throw new Error(`[BymaxAuthModule] jwt.refreshExpiresInDays must be a positive finite number. Got: ${refreshExpiresInDays}. Zero, negative, NaN, and Infinity are all rejected \u2014 any of these would produce an invalid Redis TTL and cause all token rotations to fail at runtime.`);
|
|
1311
|
-
}
|
|
1312
|
-
if (graceSeconds >= refreshLifetimeSeconds) {
|
|
1313
|
-
throw new Error(`[BymaxAuthModule] jwt.refreshGraceWindowSeconds (${graceSeconds} s) must be less than the refresh token lifetime jwt.refreshExpiresInDays * 86400 (${refreshLifetimeSeconds} s). A grace window equal to or longer than the token lifetime would allow grace pointers to outlive the refresh session they protect.`);
|
|
1314
|
-
}
|
|
1315
|
-
if (graceSeconds < 0 || graceSeconds > MAX_REFRESH_GRACE_WINDOW_SECONDS) {
|
|
1316
|
-
throw new Error(`[BymaxAuthModule] jwt.refreshGraceWindowSeconds must be between 0 and ${MAX_REFRESH_GRACE_WINDOW_SECONDS} inclusive (current: ${graceSeconds}). The window is how long an already-consumed refresh token still recovers a session, so it is exactly the replay window for a stolen one. It covers a client that rotated but never received the response \u2014 a retry, not a policy. 0 disables grace recovery entirely.`);
|
|
1317
|
-
}
|
|
1318
|
-
}
|
|
1319
|
-
__name(validateRefreshGraceWindow, "validateRefreshGraceWindow");
|
|
1320
1816
|
function validateAccessLifetimeAgainstEpochRetention(jwt) {
|
|
1321
1817
|
const configured = jwt.accessExpiresIn ?? DEFAULT_OPTIONS.jwt.accessExpiresIn;
|
|
1322
1818
|
const seconds = durationToSeconds(configured);
|
|
1323
1819
|
if (seconds === void 0) {
|
|
1324
|
-
throw new Error(`[BymaxAuthModule] jwt.accessExpiresIn must be a time span such as '15m', '1h' or '900s'.
|
|
1820
|
+
throw new Error(`[BymaxAuthModule] jwt.accessExpiresIn must be a time span such as '15m', '1h' or '900s'. Received ${describeReceived(configured)}. A value the signer cannot read would fail at the first token issued, and leaves the token-epoch retention bound unverifiable at startup.`);
|
|
1325
1821
|
}
|
|
1326
1822
|
if (seconds > TOKEN_EPOCH_RETENTION_SECONDS) {
|
|
1327
|
-
throw new Error(`[BymaxAuthModule] jwt.accessExpiresIn (
|
|
1823
|
+
throw new Error(`[BymaxAuthModule] jwt.accessExpiresIn (${seconds} s) must not exceed the token-epoch retention window (${TOKEN_EPOCH_RETENTION_SECONDS} s). An access token that outlives the stored epoch would survive the password reset that revoked it: the epoch lookup falls back to 0 once the record expires, and the staleness check stops firing.`);
|
|
1328
1824
|
}
|
|
1329
1825
|
}
|
|
1330
1826
|
__name(validateAccessLifetimeAgainstEpochRetention, "validateAccessLifetimeAgainstEpochRetention");
|
|
@@ -24270,6 +24766,7 @@ var BymaxAuthModule = class _BymaxAuthModule {
|
|
|
24270
24766
|
*/
|
|
24271
24767
|
static registerAsync(options) {
|
|
24272
24768
|
const extraProviders = options.extraProviders ?? [];
|
|
24769
|
+
validateRegistrationShapes(options.controllers, extraProviders);
|
|
24273
24770
|
if (!hasProviderToken(extraProviders, BYMAX_AUTH_USER_REPOSITORY)) {
|
|
24274
24771
|
throw new Error("[BymaxAuthModule] BYMAX_AUTH_USER_REPOSITORY is required in extraProviders. Provide your IUserRepository implementation: { provide: BYMAX_AUTH_USER_REPOSITORY, useClass: YourUserRepository }.");
|
|
24275
24772
|
}
|
|
@@ -24882,7 +25379,7 @@ var DefaultAuthEmailProvider = class _DefaultAuthEmailProvider {
|
|
|
24882
25379
|
this.sink = sink;
|
|
24883
25380
|
this.messages = {
|
|
24884
25381
|
...DEFAULT_MESSAGES,
|
|
24885
|
-
...options?.messages
|
|
25382
|
+
...dropUnsetKeys(options?.messages ?? {})
|
|
24886
25383
|
};
|
|
24887
25384
|
const configured = options?.onDeliveryError;
|
|
24888
25385
|
this.deliveryErrorPolicy = new Map(typeof configured === "string" ? AUTH_EMAIL_KINDS.map((kind) => [
|