@bymax-one/nest-auth 1.5.13 → 1.5.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,6 +54,17 @@ function assertArray(label, value) {
54
54
  throw new Error(`[BymaxAuthModule] ${label} must be an array (received ${describeReceived(value)}).`);
55
55
  }
56
56
  __name(assertArray, "assertArray");
57
+ function assertKnownChildren(label, children, declared) {
58
+ children.forEach((child, position) => {
59
+ if (typeof child !== "string") {
60
+ throw new Error(`[BymaxAuthModule] ${label} must name roles as strings (received ${describeReceived(child)} at position ${position}).`);
61
+ }
62
+ if (!declared.has(child)) {
63
+ throw new Error(`[BymaxAuthModule] ${label} references unknown role '${child}'. All roles referenced as children must be declared as keys in the hierarchy.`);
64
+ }
65
+ });
66
+ }
67
+ __name(assertKnownChildren, "assertKnownChildren");
57
68
 
58
69
  // src/server/config/enum-boolean-options.ts
59
70
  var BOOLEAN_OPTIONS = [
@@ -103,8 +114,8 @@ var ENUM_OPTIONS = {
103
114
  "otp"
104
115
  ]
105
116
  };
106
- function readPath(root, path) {
107
- let node = root;
117
+ function readPath(root2, path) {
118
+ let node = root2;
108
119
  for (const step of path.split(".")) {
109
120
  if (typeof node !== "object" || node === null) return void 0;
110
121
  node = Reflect.get(node, step);
@@ -580,6 +591,25 @@ function durationToSeconds(value) {
580
591
  return amount * seconds;
581
592
  }
582
593
  __name(durationToSeconds, "durationToSeconds");
594
+
595
+ // src/server/config/no-inherited-keys.ts
596
+ var MAX_DEPTH = 4;
597
+ function isPlain(value) {
598
+ if (typeof value !== "object" || value === null) return false;
599
+ const prototype = Object.getPrototypeOf(value);
600
+ return prototype === null || Object.getPrototypeOf(prototype) === null;
601
+ }
602
+ __name(isPlain, "isPlain");
603
+ function withoutInheritedKeys(value, depth = 0) {
604
+ if (depth >= MAX_DEPTH || !isPlain(value)) return value;
605
+ const copy = /* @__PURE__ */ Object.create(null);
606
+ for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
607
+ if ("value" in descriptor) descriptor.value = withoutInheritedKeys(descriptor.value, depth + 1);
608
+ Object.defineProperty(copy, key, descriptor);
609
+ }
610
+ return copy;
611
+ }
612
+ __name(withoutInheritedKeys, "withoutInheritedKeys");
583
613
  var TOTP_STEP_SECONDS = 30;
584
614
  var TOTP_DIGITS = 6;
585
615
  var BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
@@ -833,10 +863,14 @@ var OBJECT_GROUPS = [
833
863
  "oauth",
834
864
  "roles",
835
865
  "workspaces",
836
- "workspaces.roles"
866
+ "workspaces.roles",
867
+ "workspaces.permissions",
868
+ "jwt",
869
+ "mfa",
870
+ "apiKeys"
837
871
  ];
838
- function readPath2(root, path) {
839
- let node = root;
872
+ function readPath2(root2, path) {
873
+ let node = root2;
840
874
  for (const step of path.split(".")) {
841
875
  if (Object(node) !== node) return void 0;
842
876
  node = Reflect.get(node, step);
@@ -870,6 +904,16 @@ function validateTextOptions(userOptions) {
870
904
  }
871
905
  __name(validateTextOptions, "validateTextOptions");
872
906
 
907
+ // src/server/utils/own-or-class.ts
908
+ function readOwnOrClass(group, key) {
909
+ for (let holder = group; holder !== null; holder = Object.getPrototypeOf(holder)) {
910
+ if (!Object.hasOwn(holder, key)) continue;
911
+ return holder !== group && Object.getPrototypeOf(holder) === null ? void 0 : Reflect.get(group, key);
912
+ }
913
+ return Reflect.get(group, key);
914
+ }
915
+ __name(readOwnOrClass, "readOwnOrClass");
916
+
873
917
  // src/server/config/unset-options.ts
874
918
  var TOP_KEYS = {
875
919
  identifierKey: true,
@@ -1034,6 +1078,12 @@ var WORKSPACE_SUBGROUP_KEYS = {
1034
1078
  roles: [
1035
1079
  "hierarchy",
1036
1080
  "ownerRole"
1081
+ ],
1082
+ permissions: [
1083
+ "manageWorkspace",
1084
+ "deleteWorkspace",
1085
+ "manageMembers",
1086
+ "viewMembers"
1037
1087
  ]
1038
1088
  };
1039
1089
  function isObjectGroup(value) {
@@ -1041,24 +1091,24 @@ function isObjectGroup(value) {
1041
1091
  }
1042
1092
  __name(isObjectGroup, "isObjectGroup");
1043
1093
  function readSetKeys(group, keys) {
1044
- const out = {};
1094
+ const out = /* @__PURE__ */ Object.create(null);
1045
1095
  for (const key of /* @__PURE__ */ new Set([
1046
1096
  ...keys,
1047
1097
  ...Object.keys(group)
1048
1098
  ])) {
1049
- const entry = Reflect.get(group, key);
1099
+ const entry = readOwnOrClass(group, key);
1050
1100
  if (entry !== void 0 && entry !== null) out[key] = entry;
1051
1101
  }
1052
1102
  return out;
1053
1103
  }
1054
1104
  __name(readSetKeys, "readSetKeys");
1055
1105
  function readKeptKeys(group, keys) {
1056
- const out = {};
1106
+ const out = /* @__PURE__ */ Object.create(null);
1057
1107
  for (const key of /* @__PURE__ */ new Set([
1058
1108
  ...keys,
1059
1109
  ...Object.keys(group)
1060
1110
  ])) {
1061
- const entry = Reflect.get(group, key);
1111
+ const entry = readOwnOrClass(group, key);
1062
1112
  if (entry !== void 0 || Object.hasOwn(group, key)) out[key] = entry;
1063
1113
  }
1064
1114
  return out;
@@ -1083,7 +1133,7 @@ function dropUnset(options) {
1083
1133
  if (name === "workspaces") {
1084
1134
  for (const [sub, subKeys] of Object.entries(WORKSPACE_SUBGROUP_KEYS)) {
1085
1135
  const inner = group[sub];
1086
- if (isObjectGroup(inner)) group[sub] = (sub === "roles" ? readKeptKeys : readSetKeys)(inner, subKeys);
1136
+ if (isObjectGroup(inner)) group[sub] = (sub === "accessDeniedEvents" ? readSetKeys : readKeptKeys)(inner, subKeys);
1087
1137
  }
1088
1138
  }
1089
1139
  copy[name] = group;
@@ -1094,12 +1144,12 @@ function dropUnset(options) {
1094
1144
  }
1095
1145
  const oauth = copy["oauth"];
1096
1146
  if (isObjectGroup(oauth)) {
1097
- const google = Reflect.get(oauth, "google");
1147
+ const google = readOwnOrClass(oauth, "google");
1098
1148
  if (isObjectGroup(google)) {
1099
1149
  Reflect.set(oauth, "google", readKeptKeys(google, Object.keys(OAUTH_GOOGLE_KEYS)));
1100
1150
  }
1101
1151
  }
1102
- return Object.assign({}, copy);
1152
+ return Object.assign(/* @__PURE__ */ Object.create(null), copy);
1103
1153
  }
1104
1154
  __name(dropUnset, "dropUnset");
1105
1155
 
@@ -1107,7 +1157,7 @@ __name(dropUnset, "dropUnset");
1107
1157
  function readOptions(given) {
1108
1158
  const options = dropUnset(given);
1109
1159
  validateTextOptions(options);
1110
- return pinHierarchies(options);
1160
+ return pinCopied(options);
1111
1161
  }
1112
1162
  __name(readOptions, "readOptions");
1113
1163
  function copyHierarchy(held) {
@@ -1120,39 +1170,110 @@ function copyHierarchy(held) {
1120
1170
  ]));
1121
1171
  }
1122
1172
  __name(copyHierarchy, "copyHierarchy");
1123
- function pinIn(group, keys) {
1124
- if (Object(group) !== group) return group;
1125
- const plain = group;
1126
- for (const key of keys) if (plain[key] !== void 0) plain[key] = copyHierarchy(plain[key]);
1127
- return group;
1128
- }
1129
- __name(pinIn, "pinIn");
1130
- function pinHierarchies(options) {
1131
- const { roles, workspaces } = options;
1132
- const { roles: workspaceRoles, ...workspaceRest } = workspaces ?? {};
1133
- return {
1134
- ...options,
1135
- roles: pinIn(roles, [
1173
+ function copyList(held) {
1174
+ return Array.isArray(held) ? [
1175
+ ...held
1176
+ ] : held;
1177
+ }
1178
+ __name(copyList, "copyList");
1179
+ var COPIED = [
1180
+ {
1181
+ path: [
1182
+ "roles"
1183
+ ],
1184
+ keys: [
1136
1185
  "hierarchy",
1137
1186
  "platformHierarchy"
1138
- ]),
1139
- ...workspaceRoles === void 0 ? {} : {
1140
- workspaces: {
1141
- ...workspaceRest,
1142
- roles: pinIn(workspaceRoles, [
1143
- "hierarchy"
1144
- ])
1145
- }
1146
- }
1147
- };
1187
+ ],
1188
+ copy: copyHierarchy
1189
+ },
1190
+ {
1191
+ path: [
1192
+ "workspaces",
1193
+ "roles"
1194
+ ],
1195
+ keys: [
1196
+ "hierarchy"
1197
+ ],
1198
+ copy: copyHierarchy
1199
+ },
1200
+ {
1201
+ path: [
1202
+ "workspaces",
1203
+ "permissions"
1204
+ ],
1205
+ keys: [
1206
+ "manageWorkspace",
1207
+ "deleteWorkspace",
1208
+ "manageMembers",
1209
+ "viewMembers"
1210
+ ],
1211
+ copy: copyList
1212
+ },
1213
+ {
1214
+ path: [
1215
+ "jwt"
1216
+ ],
1217
+ keys: [
1218
+ "previousSecrets"
1219
+ ],
1220
+ copy: copyList
1221
+ },
1222
+ {
1223
+ path: [
1224
+ "mfa"
1225
+ ],
1226
+ keys: [
1227
+ "previousEncryptionKeys"
1228
+ ],
1229
+ copy: copyList
1230
+ },
1231
+ {
1232
+ path: [
1233
+ "apiKeys"
1234
+ ],
1235
+ keys: [
1236
+ "scopes"
1237
+ ],
1238
+ copy: copyList
1239
+ }
1240
+ ];
1241
+ function pinCopied(options) {
1242
+ for (const { path, keys, copy } of COPIED) {
1243
+ let group = options;
1244
+ for (const step of path) group = Object(group) === group ? group[step] : void 0;
1245
+ if (Object(group) !== group) continue;
1246
+ const plain = group;
1247
+ for (const key of keys) if (plain[key] !== void 0) plain[key] = copy(plain[key]);
1248
+ }
1249
+ return options;
1148
1250
  }
1149
- __name(pinHierarchies, "pinHierarchies");
1251
+ __name(pinCopied, "pinCopied");
1150
1252
  function validateOptionValues(userOptions) {
1151
1253
  validateNumericOptions(userOptions);
1152
1254
  validateEnumAndBooleanOptions(userOptions);
1153
1255
  }
1154
1256
  __name(validateOptionValues, "validateOptionValues");
1155
1257
 
1258
+ // src/server/config/platform-options.ts
1259
+ function validatePlatformAdmin(platform, roles) {
1260
+ if (!platform?.enabled) return;
1261
+ const hierarchy = roles.platformHierarchy;
1262
+ if (!hierarchy) {
1263
+ throw new Error(`[BymaxAuthModule] roles.platformHierarchy is required when platform.enabled is true. Define the platform role hierarchy (e.g. { SUPER_ADMIN: ['SUPPORT'], SUPPORT: [] }).`);
1264
+ }
1265
+ assertObject("roles.platformHierarchy", hierarchy);
1266
+ const names = new Set(Object.keys(hierarchy));
1267
+ if (names.size === 0) {
1268
+ throw new Error(`[BymaxAuthModule] roles.platformHierarchy must not be an empty object. Define at least one role (e.g. { SUPER_ADMIN: [] }).`);
1269
+ }
1270
+ for (const [role, children] of Object.entries(hierarchy)) {
1271
+ assertArray(`roles.platformHierarchy['${role}']`, children);
1272
+ assertKnownChildren(`roles.platformHierarchy['${role}']`, children, names);
1273
+ }
1274
+ }
1275
+ __name(validatePlatformAdmin, "validatePlatformAdmin");
1276
+
1156
1277
  // src/server/constants/workspace-roles.ts
1157
1278
  var ANY_WORKSPACE_MEMBER = /* @__PURE__ */ Symbol("ANY_WORKSPACE_MEMBER");
1158
1279
 
@@ -1496,7 +1617,7 @@ function resolveOptions(given) {
1496
1617
  validateTrustedOrigins(userOptions);
1497
1618
  validateAccessLifetimeAgainstEpochRetention(userOptions.jwt);
1498
1619
  const { mfa: _mfa, identifierKey: _identifierKey, workspaces: _workspaces, ...userOptionsWithoutMfa } = userOptions;
1499
- const resolved = {
1620
+ const resolved = withoutInheritedKeys({
1500
1621
  ...userOptionsWithoutMfa,
1501
1622
  jwt: {
1502
1623
  ...DEFAULT_OPTIONS.jwt,
@@ -1590,7 +1711,7 @@ function resolveOptions(given) {
1590
1711
  ...userOptions.mfa
1591
1712
  }
1592
1713
  }
1593
- };
1714
+ });
1594
1715
  withholdSecrets(resolved);
1595
1716
  return resolved;
1596
1717
  }
@@ -1747,20 +1868,10 @@ function validateRolesHierarchy(roles) {
1747
1868
  const allRoles = new Set(Object.keys(roles.hierarchy));
1748
1869
  for (const [role, children] of Object.entries(roles.hierarchy)) {
1749
1870
  assertArray(`roles.hierarchy['${role}']`, children);
1750
- for (const child of children) {
1751
- if (!allRoles.has(child)) {
1752
- throw new Error(`[BymaxAuthModule] roles.hierarchy['${role}'] references unknown role '${child}'. All roles referenced as children must be declared as keys in the hierarchy.`);
1753
- }
1754
- }
1871
+ assertKnownChildren(`roles.hierarchy['${role}']`, children, allRoles);
1755
1872
  }
1756
1873
  }
1757
1874
  __name(validateRolesHierarchy, "validateRolesHierarchy");
1758
- function validatePlatformAdmin(platform, roles) {
1759
- if (platform?.enabled && !roles.platformHierarchy) {
1760
- throw new Error(`[BymaxAuthModule] roles.platformHierarchy is required when platform.enabled is true. Define the platform role hierarchy (e.g. { SUPER_ADMIN: ['SUPPORT'], SUPPORT: [] }).`);
1761
- }
1762
- }
1763
- __name(validatePlatformAdmin, "validatePlatformAdmin");
1764
1875
  function assertIntegralScryptParameter(name, value) {
1765
1876
  if (value === void 0 || Number.isInteger(value)) return;
1766
1877
  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.`);
@@ -5092,6 +5203,142 @@ exports.AuthRevocationService = _ts_decorate7([
5092
5203
  typeof AuthRedisService === "undefined" ? Object : AuthRedisService
5093
5204
  ])
5094
5205
  ], exports.AuthRevocationService);
5206
+
5207
+ // src/server/utils/object-prototype-guard.ts
5208
+ var STANDARD = [
5209
+ "constructor",
5210
+ "__defineGetter__",
5211
+ "__defineSetter__",
5212
+ "hasOwnProperty",
5213
+ "__lookupGetter__",
5214
+ "__lookupSetter__",
5215
+ "isPrototypeOf",
5216
+ "propertyIsEnumerable",
5217
+ "toString",
5218
+ "valueOf",
5219
+ "__proto__",
5220
+ "toLocaleString"
5221
+ ];
5222
+ var ownKeys = Reflect.ownKeys;
5223
+ var hasOwn = Object.hasOwn;
5224
+ var getDescriptor = Object.getOwnPropertyDescriptor;
5225
+ var root = Object.prototype;
5226
+ function describe2(name) {
5227
+ const descriptor = getDescriptor(root, name);
5228
+ if (descriptor === void 0) return void 0;
5229
+ const field = /* @__PURE__ */ __name((key) => hasOwn(descriptor, key) ? descriptor[key] : void 0, "field");
5230
+ return Object.assign(/* @__PURE__ */ Object.create(null), {
5231
+ value: field("value"),
5232
+ get: field("get"),
5233
+ set: field("set"),
5234
+ enumerable: field("enumerable") === true
5235
+ });
5236
+ }
5237
+ __name(describe2, "describe");
5238
+ var BASELINE = new Map(STANDARD.map((name) => [
5239
+ name,
5240
+ describe2(name)
5241
+ ]));
5242
+ function isStandardKind(name, descriptor) {
5243
+ if (name === "__proto__" && descriptor === void 0) return true;
5244
+ if (descriptor === void 0 || descriptor.enumerable) return false;
5245
+ return name === "__proto__" ? typeof descriptor.get === "function" && typeof descriptor.set === "function" : typeof descriptor.value === "function";
5246
+ }
5247
+ __name(isStandardKind, "isStandardKind");
5248
+ var LOADED_STANDARD = STANDARD.every((name) => isStandardKind(name, BASELINE.get(name)));
5249
+ function same(left, right) {
5250
+ return left !== void 0 && right !== void 0 && left.value === right.value && left.get === right.get && left.set === right.set && left.enumerable === right.enumerable;
5251
+ }
5252
+ __name(same, "same");
5253
+ function plantedOnRoot() {
5254
+ let count = LOADED_STANDARD ? 0 : 1;
5255
+ for (const key of ownKeys(root)) if (typeof key === "string" && !same(describe2(key), BASELINE.get(key))) count += 1;
5256
+ for (const name of STANDARD) if (describe2(name) === void 0 && BASELINE.get(name) !== void 0) count += 1;
5257
+ return count;
5258
+ }
5259
+ __name(plantedOnRoot, "plantedOnRoot");
5260
+ function assertRootIsStandard() {
5261
+ const planted = plantedOnRoot();
5262
+ if (planted > 0) throw new AuthException(AUTH_ERROR_CODES.INTERNAL, void 0, {
5263
+ cause: new Error(`Object.prototype holds ${planted} entries that are not the runtime's own`)
5264
+ });
5265
+ }
5266
+ __name(assertRootIsStandard, "assertRootIsStandard");
5267
+ function assertRootIsStandardAtBoot() {
5268
+ const planted = plantedOnRoot();
5269
+ if (planted > 0) throw new Error(`[BymaxAuthModule] Object.prototype holds ${planted} entries that are not the runtime's own; the module does not start while a key is planted there.`);
5270
+ }
5271
+ __name(assertRootIsStandardAtBoot, "assertRootIsStandardAtBoot");
5272
+
5273
+ // src/server/utils/dependency-options.ts
5274
+ var JWT_MODULE_SHADOWS = Object.freeze({
5275
+ secretOrPrivateKey: void 0,
5276
+ secretOrKeyProvider: void 0,
5277
+ publicKey: void 0,
5278
+ privateKey: void 0,
5279
+ verifyOptions: void 0
5280
+ });
5281
+ var JWT_VERIFY_SHADOWS = Object.freeze({
5282
+ complete: false,
5283
+ clockTimestamp: void 0,
5284
+ clockTolerance: void 0,
5285
+ ignoreNotBefore: false,
5286
+ maxAge: void 0,
5287
+ nonce: void 0,
5288
+ subject: void 0,
5289
+ jwtid: void 0,
5290
+ allowInvalidAsymmetricKeyTypes: false
5291
+ });
5292
+ var JWT_SIGN_SHADOWS = Object.freeze({
5293
+ noTimestamp: false,
5294
+ mutatePayload: false,
5295
+ header: Object.freeze({}),
5296
+ // Stryker disable next-line StringLiteral: an empty encoding falls back to utf8 in `jsonwebtoken` and in `jws`, so the emptied value signs the same bytes as the shadow
5297
+ encoding: "utf8",
5298
+ allowInsecureKeySizes: false,
5299
+ allowInvalidAsymmetricKeyTypes: false
5300
+ });
5301
+ var SCRYPT_SHADOWS = Object.freeze({
5302
+ cost: void 0,
5303
+ blockSize: void 0,
5304
+ parallelization: void 0
5305
+ });
5306
+ var COOKIE_SHADOWS = Object.freeze(Object.assign({}, {
5307
+ domain: void 0,
5308
+ expires: void 0,
5309
+ encode: void 0,
5310
+ partitioned: false,
5311
+ priority: void 0,
5312
+ signed: false
5313
+ }));
5314
+ function jwtModuleOptions(secret) {
5315
+ return Object.assign(
5316
+ // Stryker disable next-line ObjectLiteral: jsonwebtoken defaults to HS256 and every sign call names its own algorithm, so the emptied `signOptions` signs identically
5317
+ {
5318
+ secret,
5319
+ signOptions: {
5320
+ algorithm: "HS256"
5321
+ }
5322
+ },
5323
+ JWT_MODULE_SHADOWS
5324
+ );
5325
+ }
5326
+ __name(jwtModuleOptions, "jwtModuleOptions");
5327
+ function jwtSignOptions(chosen) {
5328
+ assertRootIsStandard();
5329
+ return Object.assign({}, JWT_SIGN_SHADOWS, chosen);
5330
+ }
5331
+ __name(jwtSignOptions, "jwtSignOptions");
5332
+ function cookieOptions(chosen = {}) {
5333
+ assertRootIsStandard();
5334
+ return {
5335
+ ...COOKIE_SHADOWS,
5336
+ ...chosen
5337
+ };
5338
+ }
5339
+ __name(cookieOptions, "cookieOptions");
5340
+
5341
+ // src/server/services/token-delivery.service.ts
5095
5342
  function _ts_decorate8(decorators, target, key, desc) {
5096
5343
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5097
5344
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -5409,12 +5656,12 @@ exports.TokenDeliveryService = class TokenDeliveryService {
5409
5656
  }
5410
5657
  /** Returns base Set-Cookie options for auth cookies, optionally scoped to a domain. */
5411
5658
  baseCookieOptions(domain) {
5412
- return {
5659
+ return cookieOptions({
5413
5660
  sameSite: this.options.cookies.sameSite,
5414
5661
  ...domain ? {
5415
5662
  domain
5416
5663
  } : {}
5417
- };
5664
+ });
5418
5665
  }
5419
5666
  /** Reads the value of the cookie identified by `name` from the request. */
5420
5667
  readCookie(req, name) {
@@ -5487,11 +5734,13 @@ function signerOf(options) {
5487
5734
  }
5488
5735
  __name(signerOf, "signerOf");
5489
5736
  function verifyWithRotation(jwtService, options, token, { ignoreExpiration = false } = {}) {
5737
+ assertRootIsStandard();
5490
5738
  const algorithms = [
5491
5739
  options.jwt.algorithm
5492
5740
  ];
5493
5741
  const { issuer, audience, secret } = options.jwt;
5494
5742
  const base = {
5743
+ ...JWT_VERIFY_SHADOWS,
5495
5744
  algorithms,
5496
5745
  ignoreExpiration,
5497
5746
  issuer,
@@ -6702,12 +6951,13 @@ function _ts_param11(paramIndex, decorator) {
6702
6951
  }
6703
6952
  __name(_ts_param11, "_ts_param");
6704
6953
  async function releasingCooldownOnFailure(redis, logger, cooldownKey, work) {
6954
+ const release = /* @__PURE__ */ __name(() => redis.del(cooldownKey).then(() => void 0, (err) => {
6955
+ logStore(logger, "AUTH_STORE_FAILED", "resend_cooldown_release", err);
6956
+ }), "release");
6705
6957
  try {
6706
- return await work();
6958
+ if (await work() === false) await release();
6707
6959
  } catch (error) {
6708
- await redis.del(cooldownKey).catch((err) => {
6709
- logStore(logger, "AUTH_STORE_FAILED", "resend_cooldown_release", err);
6710
- });
6960
+ await release();
6711
6961
  throw error;
6712
6962
  }
6713
6963
  }
@@ -7109,8 +7359,10 @@ var PasswordService = class _PasswordService {
7109
7359
  }
7110
7360
  }
7111
7361
  async hash(plain) {
7362
+ assertRootIsStandard();
7112
7363
  const salt = crypto.randomBytes(SALT_BYTES);
7113
7364
  const derived = await scrypt(plain, salt, SCRYPT_KEY_LEN, {
7365
+ ...SCRYPT_SHADOWS,
7114
7366
  N: this.N,
7115
7367
  r: this.r,
7116
7368
  p: this.p,
@@ -7148,10 +7400,12 @@ var PasswordService = class _PasswordService {
7148
7400
  * without revealing the reason (invalid hash vs. wrong password).
7149
7401
  */
7150
7402
  async compare(plain, hash) {
7403
+ assertRootIsStandard();
7151
7404
  const parsed = parseStoredHash(hash);
7152
7405
  if (parsed === null) return false;
7153
7406
  const { N, r, p } = parsed;
7154
7407
  const candidate = await scrypt(plain, parsed.salt, parsed.derived.length, {
7408
+ ...SCRYPT_SHADOWS,
7155
7409
  N,
7156
7410
  r,
7157
7411
  p,
@@ -7198,7 +7452,9 @@ var PasswordService = class _PasswordService {
7198
7452
  * password request already costs; pair it with route-level rate limiting.
7199
7453
  */
7200
7454
  async compareDummy(plain) {
7455
+ assertRootIsStandard();
7201
7456
  const candidate = await scrypt(plain, DUMMY_SALT, SCRYPT_KEY_LEN, {
7457
+ ...SCRYPT_SHADOWS,
7202
7458
  N: this.N,
7203
7459
  r: this.r,
7204
7460
  p: this.p,
@@ -7222,8 +7478,8 @@ PasswordService = _ts_decorate20([
7222
7478
  var RECORD_CONTRACTS = {
7223
7479
  workspace: {
7224
7480
  fields: {
7225
- id: "~id",
7226
- tenantId: "string",
7481
+ id: "id",
7482
+ tenantId: "tenant",
7227
7483
  name: "~string",
7228
7484
  status: "string",
7229
7485
  createdAt: "~date",
@@ -7233,9 +7489,9 @@ var RECORD_CONTRACTS = {
7233
7489
  },
7234
7490
  membership: {
7235
7491
  fields: {
7236
- tenantId: "string",
7237
- workspaceId: "~id",
7238
- userId: "~id",
7492
+ tenantId: "tenant",
7493
+ workspaceId: "id",
7494
+ userId: "id",
7239
7495
  role: "string",
7240
7496
  status: "string",
7241
7497
  invitedByUserId: "~id",
@@ -7246,13 +7502,13 @@ var RECORD_CONTRACTS = {
7246
7502
  },
7247
7503
  user: {
7248
7504
  fields: {
7249
- id: "~id",
7505
+ id: "id",
7250
7506
  email: "~string",
7251
7507
  name: "~string",
7252
7508
  passwordHash: "string|null",
7253
7509
  role: "string",
7254
7510
  status: "string",
7255
- tenantId: "string",
7511
+ tenantId: "tenant",
7256
7512
  emailVerified: "boolean",
7257
7513
  mfaEnabled: "boolean",
7258
7514
  mfaSecret: "string?",
@@ -7266,7 +7522,7 @@ var RECORD_CONTRACTS = {
7266
7522
  },
7267
7523
  platformUser: {
7268
7524
  fields: {
7269
- id: "~id",
7525
+ id: "id",
7270
7526
  email: "~string",
7271
7527
  name: "~string",
7272
7528
  passwordHash: "string",
@@ -7284,7 +7540,7 @@ var RECORD_CONTRACTS = {
7284
7540
  },
7285
7541
  apiKey: {
7286
7542
  fields: {
7287
- id: "~id",
7543
+ id: "id",
7288
7544
  label: "~string",
7289
7545
  digest: "string",
7290
7546
  scopes: "strings",
@@ -7297,7 +7553,7 @@ var RECORD_CONTRACTS = {
7297
7553
  },
7298
7554
  removedMembership: {
7299
7555
  fields: {
7300
- workspaceId: "~id",
7556
+ workspaceId: "id",
7301
7557
  role: "string"
7302
7558
  },
7303
7559
  nested: {}
@@ -7540,12 +7796,29 @@ function copyStrings(value, read) {
7540
7796
  return copy;
7541
7797
  }
7542
7798
  __name(copyStrings, "copyStrings");
7799
+ var BUILT_IN_VALUES = [
7800
+ Date,
7801
+ RegExp,
7802
+ Error,
7803
+ DataView,
7804
+ URL,
7805
+ Intl.Locale,
7806
+ Object.getPrototypeOf(Uint8Array)
7807
+ ];
7808
+ function isBuiltInValue(value) {
7809
+ return util.types.isDate(value) || util.types.isRegExp(value) || util.types.isNativeError(value) || util.types.isArrayBufferView(value) || BUILT_IN_VALUES.some((kind) => value instanceof kind);
7810
+ }
7811
+ __name(isBuiltInValue, "isBuiltInValue");
7812
+ var NOT_AN_ID_TEXT = /* @__PURE__ */ new Set([
7813
+ "undefined",
7814
+ "null"
7815
+ ]);
7543
7816
  function readId(value) {
7544
- if (typeof value === "string") return accept(value !== "", value);
7545
7817
  if (typeof value === "number") return accept(Number.isSafeInteger(value), String(value));
7546
- if (!isHostInstance(value) || util.types.isDate(value) || util.types.isRegExp(value)) throw new Error(WRONG_KIND);
7547
- const printed = String(value);
7548
- return accept(printed !== "" && !printed.startsWith("[object "), printed);
7818
+ if (typeof value !== "string" && (!isHostInstance(value) || isBuiltInValue(value))) throw new Error(WRONG_KIND);
7819
+ const text = String(value);
7820
+ const printed = typeof value !== "string";
7821
+ return accept(text.trim() !== "" && !NOT_AN_ID_TEXT.has(text) && !(printed && text.startsWith("[object ")), text);
7549
7822
  }
7550
7823
  __name(readId, "readId");
7551
7824
  function readInforming(value) {
@@ -7564,6 +7837,8 @@ __name(readInformingDate, "readInformingDate");
7564
7837
  var READERS = {
7565
7838
  boolean: /* @__PURE__ */ __name((value) => accept(typeof value === "boolean", value), "boolean"),
7566
7839
  string: /* @__PURE__ */ __name((value) => accept(typeof value === "string", value), "string"),
7840
+ tenant: /* @__PURE__ */ __name((value) => accept(typeof value === "string" && value.trim() !== "", value), "tenant"),
7841
+ id: readId,
7567
7842
  number: /* @__PURE__ */ __name((value) => accept(Number.isFinite(value), value), "number"),
7568
7843
  date: copyDate,
7569
7844
  strings: copyStrings,
@@ -7595,7 +7870,7 @@ function readScalar(value, spec, run) {
7595
7870
  }
7596
7871
  __name(readScalar, "readScalar");
7597
7872
  function copyRecord(value, contract, run) {
7598
- const copy = {};
7873
+ const copy = /* @__PURE__ */ Object.create(null);
7599
7874
  rememberUnder(run, value, contract, copy);
7600
7875
  ENTITIES.set(copy, value);
7601
7876
  const source = value;
@@ -7609,7 +7884,7 @@ function copyRecord(value, contract, run) {
7609
7884
  const own = new Set(keys);
7610
7885
  for (const [field, spec] of Object.entries(contract.fields)) {
7611
7886
  const { base, nullable, optional } = parseSpec(spec);
7612
- const held = source[field];
7887
+ const held = readOwnOrClass(source, field);
7613
7888
  if (held === void 0) {
7614
7889
  if (optional) continue;
7615
7890
  throw new Error(ABSENT);
@@ -8648,22 +8923,13 @@ var TokenManagerService = class _TokenManagerService {
8648
8923
  jti
8649
8924
  }, this.accessSignOptions());
8650
8925
  }
8651
- /**
8652
- * Builds JwtSignOptions from resolved configuration.
8653
- *
8654
- * The double-cast through `unknown` is required because:
8655
- * 1. `@nestjs/jwt` types `expiresIn` as the branded `StringValue` from `ms`
8656
- * (not a plain `string`), and
8657
- * 2. `exactOptionalPropertyTypes` rejects `string | undefined` as the value
8658
- * type of an optional property typed as `StringValue`.
8659
- * At runtime the value is always a valid `ms` string — the cast is safe.
8660
- */
8926
+ /** The options of an access-token `sign` call: the resolved configuration, over a neutral value for every option the library does not choose. */
8661
8927
  accessSignOptions() {
8662
- return {
8928
+ return jwtSignOptions({
8663
8929
  expiresIn: this.options.jwt.accessExpiresIn,
8664
8930
  ...signerOf(this.options),
8665
8931
  ...this.issuerAudience()
8666
- };
8932
+ });
8667
8933
  }
8668
8934
  /**
8669
8935
  * The `iss`/`aud` pair to stamp and to require, or nothing when the deployment configured
@@ -9445,14 +9711,14 @@ var TokenManagerService = class _TokenManagerService {
9445
9711
  // the claim's own documentation for what it was surviving.
9446
9712
  epoch: await this.redis.getUserTokenEpoch(userId, tenantId, context)
9447
9713
  };
9448
- const token = this.jwtService.sign(payload, {
9714
+ const token = this.jwtService.sign(payload, jwtSignOptions({
9449
9715
  expiresIn: `${MFA_TEMP_TOKEN_TTL_SECONDS}s`,
9450
9716
  ...signerOf(this.options),
9451
9717
  // The challenge token is stamped and checked like every other: it grants no resource
9452
9718
  // access on its own, but it is still a token this backend minted, and a verifier that
9453
9719
  // exempted one shape would be a verifier an attacker aims at.
9454
9720
  ...this.issuerAudience()
9455
- });
9721
+ }));
9456
9722
  await this.redis.set(`mfa:${sha256(jti)}`, userId, MFA_TEMP_TOKEN_TTL_SECONDS);
9457
9723
  return token;
9458
9724
  }
@@ -10477,7 +10743,7 @@ exports.AuthService = class _AuthService {
10477
10743
  email,
10478
10744
  tenantId
10479
10745
  }), tenantId);
10480
- if (user && !user.emailVerified) await this.sendVerificationOtp(tenantId, email);
10746
+ return user && !user.emailVerified ? this.sendVerificationOtp(tenantId, email) : void 0;
10481
10747
  });
10482
10748
  await sleep(Math.max(0, ANTI_ENUM_MIN_MS - (Date.now() - start)));
10483
10749
  }
@@ -10728,12 +10994,12 @@ exports.AuthService = class _AuthService {
10728
10994
  logEvent(this.logger, "AUTH_PROVIDER_MISSING", {
10729
10995
  flow: "email_verification_otp"
10730
10996
  });
10731
- return;
10997
+ return true;
10732
10998
  }
10733
10999
  const identifier = this.otpIdentifier(tenantId, email);
10734
11000
  const otp = this.otpService.generate(6);
10735
11001
  const { otpTtlSeconds: ttl } = this.options.emailVerification;
10736
- if (!await storeVerificationCode(this.otpService, this.logger, identifier, otp, ttl)) return;
11002
+ if (!await storeVerificationCode(this.otpService, this.logger, identifier, otp, ttl)) return false;
10737
11003
  const provider = this.emailProvider;
10738
11004
  void (async () => {
10739
11005
  try {
@@ -10742,6 +11008,7 @@ exports.AuthService = class _AuthService {
10742
11008
  logDelivery(this.logger, "email_verification_otp", err);
10743
11009
  }
10744
11010
  })();
11011
+ return true;
10745
11012
  }
10746
11013
  };
10747
11014
  exports.AuthService = _ts_decorate23([
@@ -14812,6 +15079,7 @@ var MfaController = class {
14812
15079
  */
14813
15080
  clearMfaTempCookie(res) {
14814
15081
  res.clearCookie(MFA_TEMP_COOKIE_NAME, {
15082
+ ...cookieOptions(),
14815
15083
  path: this.options.cookies.mfaTempCookiePath,
14816
15084
  httpOnly: true,
14817
15085
  secure: this.options.secureCookies,
@@ -18109,7 +18377,7 @@ exports.WorkspaceAccessService = class _WorkspaceAccessService {
18109
18377
  if (membership?.status !== "active" || workspace === null) return {
18110
18378
  kind: "denied"
18111
18379
  };
18112
- if (workspace.tenantId !== ref.tenantId || membership.tenantId !== ref.tenantId) return {
18380
+ if (workspace.tenantId !== ref.tenantId || membership.tenantId !== ref.tenantId || workspace.id !== ref.workspaceId || membership.workspaceId !== ref.workspaceId || membership.userId !== ref.userId) return {
18113
18381
  kind: "denied"
18114
18382
  };
18115
18383
  const member = {
@@ -22930,6 +23198,7 @@ exports.OAuthService = class _OAuthService {
22930
23198
  */
22931
23199
  bindToBrowser(res, state) {
22932
23200
  res.cookie(OAUTH_STATE_COOKIE_NAME, state, {
23201
+ ...cookieOptions(),
22933
23202
  httpOnly: true,
22934
23203
  secure: this.options.secureCookies,
22935
23204
  sameSite: OAUTH_STATE_COOKIE_SAME_SITE,
@@ -23809,6 +24078,7 @@ var OAuthController = class _OAuthController {
23809
24078
  */
23810
24079
  clearOAuthStateCookie(res) {
23811
24080
  res.clearCookie(OAUTH_STATE_COOKIE_NAME, {
24081
+ ...cookieOptions(),
23812
24082
  httpOnly: true,
23813
24083
  secure: this.options.secureCookies,
23814
24084
  sameSite: OAUTH_STATE_COOKIE_SAME_SITE,
@@ -23833,6 +24103,7 @@ var OAuthController = class _OAuthController {
23833
24103
  */
23834
24104
  setMfaTempCookie(res, mfaTempToken) {
23835
24105
  res.cookie(MFA_TEMP_COOKIE_NAME, mfaTempToken, {
24106
+ ...cookieOptions(),
23836
24107
  httpOnly: true,
23837
24108
  secure: this.options.secureCookies,
23838
24109
  sameSite: this.options.cookies.sameSite,
@@ -25233,7 +25504,7 @@ function buildAuthOpenApiFragment(options, registered) {
25233
25504
  for (const [controller, handlers] of Object.entries(OPERATIONS)) {
25234
25505
  if (!registered[controller]) continue;
25235
25506
  for (const [handler, credential] of Object.entries(handlers)) {
25236
- const described = describe2(credential, cookieDelivery, bearerDelivery);
25507
+ const described = describe3(credential, cookieDelivery, bearerDelivery);
25237
25508
  const note = OPERATION_DESCRIPTIONS.get(handler);
25238
25509
  operations[handler] = note === void 0 ? described : {
25239
25510
  ...described,
@@ -25251,7 +25522,7 @@ function buildAuthOpenApiFragment(options, registered) {
25251
25522
  };
25252
25523
  }
25253
25524
  __name(buildAuthOpenApiFragment, "buildAuthOpenApiFragment");
25254
- function describe2(credential, cookieDelivery, bearerDelivery) {
25525
+ function describe3(credential, cookieDelivery, bearerDelivery) {
25255
25526
  switch (credential) {
25256
25527
  case "none":
25257
25528
  return {
@@ -25321,7 +25592,7 @@ function describe2(credential, cookieDelivery, bearerDelivery) {
25321
25592
  };
25322
25593
  }
25323
25594
  }
25324
- __name(describe2, "describe");
25595
+ __name(describe3, "describe");
25325
25596
  function describeTwoCredentials(credential, cookieDelivery, bearerDelivery) {
25326
25597
  const required = {
25327
25598
  access: credential !== "optionalAccessAndRefresh",
@@ -26710,6 +26981,7 @@ exports.BymaxAuthModule = class _BymaxAuthModule {
26710
26981
  if (hostHasKey(userOptions, "controllers")) {
26711
26982
  throw new Error("[BymaxAuthModule] `controllers` must be passed to registerAsync() itself, not returned from useFactory \u2014 the module is assembled before the factory runs, so flags returned here are ignored and the endpoints are never registered.");
26712
26983
  }
26984
+ assertRootIsStandardAtBoot();
26713
26985
  const resolved = readHostOptions(() => resolveOptions(userOptions));
26714
26986
  if (includeMfa && resolved.mfa === void 0) {
26715
26987
  throw new Error("[BymaxAuthModule] controllers.mfa: true requires the mfa group (encryptionKey and issuer) to be configured in the useFactory return value.");
@@ -26868,13 +27140,7 @@ exports.BymaxAuthModule = class _BymaxAuthModule {
26868
27140
  imports: options.imports ?? [],
26869
27141
  useFactory: /* @__PURE__ */ __name(async (...args) => {
26870
27142
  const { value: userOptions } = await callFactory(options.useFactory, args);
26871
- return {
26872
- secret: readHostOptions(() => userOptions.jwt.secret),
26873
- // Stryker disable next-line ObjectLiteral: jsonwebtoken defaults to HS256 and TokenManagerService overrides signOptions per call, so the emptied `signOptions` produces identical signing
26874
- signOptions: {
26875
- algorithm: "HS256"
26876
- }
26877
- };
27143
+ return jwtModuleOptions(readHostOptions(() => userOptions.jwt.secret));
26878
27144
  }, "useFactory"),
26879
27145
  inject: options.inject ?? []
26880
27146
  })