@bymax-one/nest-auth 1.5.14 → 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.
package/CHANGELOG.md CHANGED
@@ -18,6 +18,19 @@ what moves, and that note is the compatibility contract until strict SemVer begi
18
18
 
19
19
  ## [Unreleased]
20
20
 
21
+ ## [1.5.15] - 2026-11-22
22
+
23
+ A patch release.
24
+
25
+ ### Fixed
26
+
27
+ - **A key planted on `Object.prototype` is not an option.** The options a host did not write were read by property from objects that inherit from `Object.prototype`, so a key planted there by a library with a prototype-pollution flaw (`sessions`, `invitations`, `emailChange`, `workspaces`, `apiKeys`, `mfa`, `blockedStatuses`, `environment`, `tokenDelivery`, `redisNamespace` and the rest) reached every option the host left unwritten: it switched a feature on, turned `emailVerification.required` off or emptied the blocked statuses. The options are read from the object itself or from the class it is an instance of, never from the runtime's root object, and the resolved options and their groups hold no prototype to fall through to.
28
+ - **A key planted on `Object.prototype` is not a field of a record a repository answers.** A field the record lacks was read from the root object of the runtime, so with a strict field removed from the row and its name planted, `mfaEnabled` false, `emailVerified` true, `status`, `role`, `tenantId` and `id` were accepted instead of refused as absent, and a planted `mfaSecret` or `mfaRecoveryCodes` appeared on the copy of a record that never held one. A field is read from the record itself or from the class it is an instance of, and the copy holds no prototype. The copies handed to host hooks hold no prototype either, so `toString` and `hasOwnProperty` are absent on them (use `Object.hasOwn` and `String(…)`). A record whose fields are served by an ancestor with no prototype of its own is not read from that ancestor, because it cannot be told from the root object of a realm; a strict field held only there is refused as absent.
29
+ - **A child in a role hierarchy is a role name.** A child of `roles.hierarchy` or `roles.platformHierarchy` that is not a string is refused naming its position and what it is (`must name roles as strings (received … at position N)`), and the value is no longer printed, so a `toString` the host wrote does not run and a symbol does not throw from the message.
30
+ - **The tenant of a record is not blank.** A `tenantId` that is empty or only whitespace is refused as `auth.internal`, with the other tenants that are no string. **Apply to a derived backend:** a host that stores an empty string as the tenant of its single-tenant rows must serve a real tenant id, because that record is now refused.
31
+ - **A lookalike of an error, a date, a regular expression, a view of bytes, a link or a locale is no id.** A Proxy of one, an object made from the prototype of one and an instance of a subclass are refused as an id, as the real ones already were.
32
+ - **A key planted on `Object.prototype` is not read by the libraries the options are handed to.** `@nestjs/jwt`, `jsonwebtoken` and `express` copy the options they are given into a new object and read names the library never set, so a key planted on the root object was read as one. A planted `secretOrPrivateKey` made a token forged under any secret verify; a planted `clockTolerance`, `clockTimestamp` or `verifyOptions` made an expired token verify; `noTimestamp`, `header` and `keyid` changed what the backend signed; a planted `cost`, `blockSize` or `parallelization` made every login and password change throw; a planted `domain` scoped the auth cookies. Every call now carries an own key with a neutral value for each option the dependency reads and the library does not choose, and the module options of `@nestjs/jwt` shadow the options that pick another key. The names that have no neutral value (`keyid`, `notBefore`, `jwtid`, `subject`, `issuer`, `audience`) refuse the signature with `auth.internal` while the process carries one of them on `Object.prototype`. A test reads the sources of the pinned dependencies and fails when one reads an option name the library neither sets nor shadows. Beside the own keys, the library refuses while `Object.prototype` holds an entry that is not the runtime's own: it does not start, and it refuses every signature, verification, password hash and verification and cookie write with `auth.internal`. The standard entries are listed by name and compared, by value, accessors and enumerability, with what they were at load, so an overwritten `hasOwnProperty`, `toString` or `constructor` counts like a new key, and the error reports a count and no name. A runtime started with `--disable-proto=delete`, which has no `__proto__`, has a standard root. One limit remains: `express` removes `maxAge` from its copy in `clearCookie`, so a planted `maxAge` lengthens the life of the empty cookie that ends a session.
33
+
21
34
  ## [1.5.14] - 2026-11-22
22
35
 
23
36
  A patch release.
@@ -5595,7 +5608,8 @@ ever installable.
5595
5608
  - Phase 4 password-reset tests cover: both `token` and `otp` flows, mutual exclusivity validation, `verifiedToken` exchange, resend cooldown, anti-enumeration (no error on unknown email), and session invalidation on reset
5596
5609
  - Phase 5 tests cover: platform login with MFA path and brute-force lockout, `JwtPlatformGuard` cross-context rejection, `PlatformRolesGuard` hierarchy enforcement, OAuth CSRF state lifecycle, `onOAuthLogin` hook resolution strategies, and invitation role-authorization + acceptance single-use enforcement
5597
5610
 
5598
- [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.14...HEAD
5611
+ [Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.15...HEAD
5612
+ [1.5.15]: https://github.com/bymaxone/nest-auth/compare/v1.5.14...v1.5.15
5599
5613
  [1.5.14]: https://github.com/bymaxone/nest-auth/compare/v1.5.13...v1.5.14
5600
5614
  [1.5.13]: https://github.com/bymaxone/nest-auth/compare/v1.5.12...v1.5.13
5601
5615
  [1.5.12]: https://github.com/bymaxone/nest-auth/compare/v1.5.11...v1.5.12
@@ -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";
@@ -839,8 +869,8 @@ var OBJECT_GROUPS = [
839
869
  "mfa",
840
870
  "apiKeys"
841
871
  ];
842
- function readPath2(root, path) {
843
- let node = root;
872
+ function readPath2(root2, path) {
873
+ let node = root2;
844
874
  for (const step of path.split(".")) {
845
875
  if (Object(node) !== node) return void 0;
846
876
  node = Reflect.get(node, step);
@@ -874,6 +904,16 @@ function validateTextOptions(userOptions) {
874
904
  }
875
905
  __name(validateTextOptions, "validateTextOptions");
876
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
+
877
917
  // src/server/config/unset-options.ts
878
918
  var TOP_KEYS = {
879
919
  identifierKey: true,
@@ -1051,24 +1091,24 @@ function isObjectGroup(value) {
1051
1091
  }
1052
1092
  __name(isObjectGroup, "isObjectGroup");
1053
1093
  function readSetKeys(group, keys) {
1054
- const out = {};
1094
+ const out = /* @__PURE__ */ Object.create(null);
1055
1095
  for (const key of /* @__PURE__ */ new Set([
1056
1096
  ...keys,
1057
1097
  ...Object.keys(group)
1058
1098
  ])) {
1059
- const entry = Reflect.get(group, key);
1099
+ const entry = readOwnOrClass(group, key);
1060
1100
  if (entry !== void 0 && entry !== null) out[key] = entry;
1061
1101
  }
1062
1102
  return out;
1063
1103
  }
1064
1104
  __name(readSetKeys, "readSetKeys");
1065
1105
  function readKeptKeys(group, keys) {
1066
- const out = {};
1106
+ const out = /* @__PURE__ */ Object.create(null);
1067
1107
  for (const key of /* @__PURE__ */ new Set([
1068
1108
  ...keys,
1069
1109
  ...Object.keys(group)
1070
1110
  ])) {
1071
- const entry = Reflect.get(group, key);
1111
+ const entry = readOwnOrClass(group, key);
1072
1112
  if (entry !== void 0 || Object.hasOwn(group, key)) out[key] = entry;
1073
1113
  }
1074
1114
  return out;
@@ -1104,12 +1144,12 @@ function dropUnset(options) {
1104
1144
  }
1105
1145
  const oauth = copy["oauth"];
1106
1146
  if (isObjectGroup(oauth)) {
1107
- const google = Reflect.get(oauth, "google");
1147
+ const google = readOwnOrClass(oauth, "google");
1108
1148
  if (isObjectGroup(google)) {
1109
1149
  Reflect.set(oauth, "google", readKeptKeys(google, Object.keys(OAUTH_GOOGLE_KEYS)));
1110
1150
  }
1111
1151
  }
1112
- return Object.assign({}, copy);
1152
+ return Object.assign(/* @__PURE__ */ Object.create(null), copy);
1113
1153
  }
1114
1154
  __name(dropUnset, "dropUnset");
1115
1155
 
@@ -1229,11 +1269,7 @@ function validatePlatformAdmin(platform, roles) {
1229
1269
  }
1230
1270
  for (const [role, children] of Object.entries(hierarchy)) {
1231
1271
  assertArray(`roles.platformHierarchy['${role}']`, children);
1232
- for (const child of children) {
1233
- if (!names.has(child)) {
1234
- throw new Error(`[BymaxAuthModule] roles.platformHierarchy['${role}'] references unknown role '${child}'. All roles referenced as children must be declared as keys in the hierarchy.`);
1235
- }
1236
- }
1272
+ assertKnownChildren(`roles.platformHierarchy['${role}']`, children, names);
1237
1273
  }
1238
1274
  }
1239
1275
  __name(validatePlatformAdmin, "validatePlatformAdmin");
@@ -1581,7 +1617,7 @@ function resolveOptions(given) {
1581
1617
  validateTrustedOrigins(userOptions);
1582
1618
  validateAccessLifetimeAgainstEpochRetention(userOptions.jwt);
1583
1619
  const { mfa: _mfa, identifierKey: _identifierKey, workspaces: _workspaces, ...userOptionsWithoutMfa } = userOptions;
1584
- const resolved = {
1620
+ const resolved = withoutInheritedKeys({
1585
1621
  ...userOptionsWithoutMfa,
1586
1622
  jwt: {
1587
1623
  ...DEFAULT_OPTIONS.jwt,
@@ -1675,7 +1711,7 @@ function resolveOptions(given) {
1675
1711
  ...userOptions.mfa
1676
1712
  }
1677
1713
  }
1678
- };
1714
+ });
1679
1715
  withholdSecrets(resolved);
1680
1716
  return resolved;
1681
1717
  }
@@ -1832,11 +1868,7 @@ function validateRolesHierarchy(roles) {
1832
1868
  const allRoles = new Set(Object.keys(roles.hierarchy));
1833
1869
  for (const [role, children] of Object.entries(roles.hierarchy)) {
1834
1870
  assertArray(`roles.hierarchy['${role}']`, children);
1835
- for (const child of children) {
1836
- if (!allRoles.has(child)) {
1837
- throw new Error(`[BymaxAuthModule] roles.hierarchy['${role}'] references unknown role '${child}'. All roles referenced as children must be declared as keys in the hierarchy.`);
1838
- }
1839
- }
1871
+ assertKnownChildren(`roles.hierarchy['${role}']`, children, allRoles);
1840
1872
  }
1841
1873
  }
1842
1874
  __name(validateRolesHierarchy, "validateRolesHierarchy");
@@ -5171,6 +5203,142 @@ exports.AuthRevocationService = _ts_decorate7([
5171
5203
  typeof AuthRedisService === "undefined" ? Object : AuthRedisService
5172
5204
  ])
5173
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
5174
5342
  function _ts_decorate8(decorators, target, key, desc) {
5175
5343
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5176
5344
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -5488,12 +5656,12 @@ exports.TokenDeliveryService = class TokenDeliveryService {
5488
5656
  }
5489
5657
  /** Returns base Set-Cookie options for auth cookies, optionally scoped to a domain. */
5490
5658
  baseCookieOptions(domain) {
5491
- return {
5659
+ return cookieOptions({
5492
5660
  sameSite: this.options.cookies.sameSite,
5493
5661
  ...domain ? {
5494
5662
  domain
5495
5663
  } : {}
5496
- };
5664
+ });
5497
5665
  }
5498
5666
  /** Reads the value of the cookie identified by `name` from the request. */
5499
5667
  readCookie(req, name) {
@@ -5566,11 +5734,13 @@ function signerOf(options) {
5566
5734
  }
5567
5735
  __name(signerOf, "signerOf");
5568
5736
  function verifyWithRotation(jwtService, options, token, { ignoreExpiration = false } = {}) {
5737
+ assertRootIsStandard();
5569
5738
  const algorithms = [
5570
5739
  options.jwt.algorithm
5571
5740
  ];
5572
5741
  const { issuer, audience, secret } = options.jwt;
5573
5742
  const base = {
5743
+ ...JWT_VERIFY_SHADOWS,
5574
5744
  algorithms,
5575
5745
  ignoreExpiration,
5576
5746
  issuer,
@@ -7189,8 +7359,10 @@ var PasswordService = class _PasswordService {
7189
7359
  }
7190
7360
  }
7191
7361
  async hash(plain) {
7362
+ assertRootIsStandard();
7192
7363
  const salt = crypto.randomBytes(SALT_BYTES);
7193
7364
  const derived = await scrypt(plain, salt, SCRYPT_KEY_LEN, {
7365
+ ...SCRYPT_SHADOWS,
7194
7366
  N: this.N,
7195
7367
  r: this.r,
7196
7368
  p: this.p,
@@ -7228,10 +7400,12 @@ var PasswordService = class _PasswordService {
7228
7400
  * without revealing the reason (invalid hash vs. wrong password).
7229
7401
  */
7230
7402
  async compare(plain, hash) {
7403
+ assertRootIsStandard();
7231
7404
  const parsed = parseStoredHash(hash);
7232
7405
  if (parsed === null) return false;
7233
7406
  const { N, r, p } = parsed;
7234
7407
  const candidate = await scrypt(plain, parsed.salt, parsed.derived.length, {
7408
+ ...SCRYPT_SHADOWS,
7235
7409
  N,
7236
7410
  r,
7237
7411
  p,
@@ -7278,7 +7452,9 @@ var PasswordService = class _PasswordService {
7278
7452
  * password request already costs; pair it with route-level rate limiting.
7279
7453
  */
7280
7454
  async compareDummy(plain) {
7455
+ assertRootIsStandard();
7281
7456
  const candidate = await scrypt(plain, DUMMY_SALT, SCRYPT_KEY_LEN, {
7457
+ ...SCRYPT_SHADOWS,
7282
7458
  N: this.N,
7283
7459
  r: this.r,
7284
7460
  p: this.p,
@@ -7303,7 +7479,7 @@ var RECORD_CONTRACTS = {
7303
7479
  workspace: {
7304
7480
  fields: {
7305
7481
  id: "id",
7306
- tenantId: "string",
7482
+ tenantId: "tenant",
7307
7483
  name: "~string",
7308
7484
  status: "string",
7309
7485
  createdAt: "~date",
@@ -7313,7 +7489,7 @@ var RECORD_CONTRACTS = {
7313
7489
  },
7314
7490
  membership: {
7315
7491
  fields: {
7316
- tenantId: "string",
7492
+ tenantId: "tenant",
7317
7493
  workspaceId: "id",
7318
7494
  userId: "id",
7319
7495
  role: "string",
@@ -7332,7 +7508,7 @@ var RECORD_CONTRACTS = {
7332
7508
  passwordHash: "string|null",
7333
7509
  role: "string",
7334
7510
  status: "string",
7335
- tenantId: "string",
7511
+ tenantId: "tenant",
7336
7512
  emailVerified: "boolean",
7337
7513
  mfaEnabled: "boolean",
7338
7514
  mfaSecret: "string?",
@@ -7620,13 +7796,26 @@ function copyStrings(value, read) {
7620
7796
  return copy;
7621
7797
  }
7622
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");
7623
7812
  var NOT_AN_ID_TEXT = /* @__PURE__ */ new Set([
7624
7813
  "undefined",
7625
7814
  "null"
7626
7815
  ]);
7627
7816
  function readId(value) {
7628
7817
  if (typeof value === "number") return accept(Number.isSafeInteger(value), String(value));
7629
- if (typeof value !== "string" && (!isHostInstance(value) || util.types.isDate(value) || util.types.isRegExp(value) || util.types.isNativeError(value) || util.types.isArrayBufferView(value))) throw new Error(WRONG_KIND);
7818
+ if (typeof value !== "string" && (!isHostInstance(value) || isBuiltInValue(value))) throw new Error(WRONG_KIND);
7630
7819
  const text = String(value);
7631
7820
  const printed = typeof value !== "string";
7632
7821
  return accept(text.trim() !== "" && !NOT_AN_ID_TEXT.has(text) && !(printed && text.startsWith("[object ")), text);
@@ -7648,6 +7837,7 @@ __name(readInformingDate, "readInformingDate");
7648
7837
  var READERS = {
7649
7838
  boolean: /* @__PURE__ */ __name((value) => accept(typeof value === "boolean", value), "boolean"),
7650
7839
  string: /* @__PURE__ */ __name((value) => accept(typeof value === "string", value), "string"),
7840
+ tenant: /* @__PURE__ */ __name((value) => accept(typeof value === "string" && value.trim() !== "", value), "tenant"),
7651
7841
  id: readId,
7652
7842
  number: /* @__PURE__ */ __name((value) => accept(Number.isFinite(value), value), "number"),
7653
7843
  date: copyDate,
@@ -7680,7 +7870,7 @@ function readScalar(value, spec, run) {
7680
7870
  }
7681
7871
  __name(readScalar, "readScalar");
7682
7872
  function copyRecord(value, contract, run) {
7683
- const copy = {};
7873
+ const copy = /* @__PURE__ */ Object.create(null);
7684
7874
  rememberUnder(run, value, contract, copy);
7685
7875
  ENTITIES.set(copy, value);
7686
7876
  const source = value;
@@ -7694,7 +7884,7 @@ function copyRecord(value, contract, run) {
7694
7884
  const own = new Set(keys);
7695
7885
  for (const [field, spec] of Object.entries(contract.fields)) {
7696
7886
  const { base, nullable, optional } = parseSpec(spec);
7697
- const held = source[field];
7887
+ const held = readOwnOrClass(source, field);
7698
7888
  if (held === void 0) {
7699
7889
  if (optional) continue;
7700
7890
  throw new Error(ABSENT);
@@ -8733,22 +8923,13 @@ var TokenManagerService = class _TokenManagerService {
8733
8923
  jti
8734
8924
  }, this.accessSignOptions());
8735
8925
  }
8736
- /**
8737
- * Builds JwtSignOptions from resolved configuration.
8738
- *
8739
- * The double-cast through `unknown` is required because:
8740
- * 1. `@nestjs/jwt` types `expiresIn` as the branded `StringValue` from `ms`
8741
- * (not a plain `string`), and
8742
- * 2. `exactOptionalPropertyTypes` rejects `string | undefined` as the value
8743
- * type of an optional property typed as `StringValue`.
8744
- * At runtime the value is always a valid `ms` string — the cast is safe.
8745
- */
8926
+ /** The options of an access-token `sign` call: the resolved configuration, over a neutral value for every option the library does not choose. */
8746
8927
  accessSignOptions() {
8747
- return {
8928
+ return jwtSignOptions({
8748
8929
  expiresIn: this.options.jwt.accessExpiresIn,
8749
8930
  ...signerOf(this.options),
8750
8931
  ...this.issuerAudience()
8751
- };
8932
+ });
8752
8933
  }
8753
8934
  /**
8754
8935
  * The `iss`/`aud` pair to stamp and to require, or nothing when the deployment configured
@@ -9530,14 +9711,14 @@ var TokenManagerService = class _TokenManagerService {
9530
9711
  // the claim's own documentation for what it was surviving.
9531
9712
  epoch: await this.redis.getUserTokenEpoch(userId, tenantId, context)
9532
9713
  };
9533
- const token = this.jwtService.sign(payload, {
9714
+ const token = this.jwtService.sign(payload, jwtSignOptions({
9534
9715
  expiresIn: `${MFA_TEMP_TOKEN_TTL_SECONDS}s`,
9535
9716
  ...signerOf(this.options),
9536
9717
  // The challenge token is stamped and checked like every other: it grants no resource
9537
9718
  // access on its own, but it is still a token this backend minted, and a verifier that
9538
9719
  // exempted one shape would be a verifier an attacker aims at.
9539
9720
  ...this.issuerAudience()
9540
- });
9721
+ }));
9541
9722
  await this.redis.set(`mfa:${sha256(jti)}`, userId, MFA_TEMP_TOKEN_TTL_SECONDS);
9542
9723
  return token;
9543
9724
  }
@@ -14898,6 +15079,7 @@ var MfaController = class {
14898
15079
  */
14899
15080
  clearMfaTempCookie(res) {
14900
15081
  res.clearCookie(MFA_TEMP_COOKIE_NAME, {
15082
+ ...cookieOptions(),
14901
15083
  path: this.options.cookies.mfaTempCookiePath,
14902
15084
  httpOnly: true,
14903
15085
  secure: this.options.secureCookies,
@@ -23016,6 +23198,7 @@ exports.OAuthService = class _OAuthService {
23016
23198
  */
23017
23199
  bindToBrowser(res, state) {
23018
23200
  res.cookie(OAUTH_STATE_COOKIE_NAME, state, {
23201
+ ...cookieOptions(),
23019
23202
  httpOnly: true,
23020
23203
  secure: this.options.secureCookies,
23021
23204
  sameSite: OAUTH_STATE_COOKIE_SAME_SITE,
@@ -23895,6 +24078,7 @@ var OAuthController = class _OAuthController {
23895
24078
  */
23896
24079
  clearOAuthStateCookie(res) {
23897
24080
  res.clearCookie(OAUTH_STATE_COOKIE_NAME, {
24081
+ ...cookieOptions(),
23898
24082
  httpOnly: true,
23899
24083
  secure: this.options.secureCookies,
23900
24084
  sameSite: OAUTH_STATE_COOKIE_SAME_SITE,
@@ -23919,6 +24103,7 @@ var OAuthController = class _OAuthController {
23919
24103
  */
23920
24104
  setMfaTempCookie(res, mfaTempToken) {
23921
24105
  res.cookie(MFA_TEMP_COOKIE_NAME, mfaTempToken, {
24106
+ ...cookieOptions(),
23922
24107
  httpOnly: true,
23923
24108
  secure: this.options.secureCookies,
23924
24109
  sameSite: this.options.cookies.sameSite,
@@ -25319,7 +25504,7 @@ function buildAuthOpenApiFragment(options, registered) {
25319
25504
  for (const [controller, handlers] of Object.entries(OPERATIONS)) {
25320
25505
  if (!registered[controller]) continue;
25321
25506
  for (const [handler, credential] of Object.entries(handlers)) {
25322
- const described = describe2(credential, cookieDelivery, bearerDelivery);
25507
+ const described = describe3(credential, cookieDelivery, bearerDelivery);
25323
25508
  const note = OPERATION_DESCRIPTIONS.get(handler);
25324
25509
  operations[handler] = note === void 0 ? described : {
25325
25510
  ...described,
@@ -25337,7 +25522,7 @@ function buildAuthOpenApiFragment(options, registered) {
25337
25522
  };
25338
25523
  }
25339
25524
  __name(buildAuthOpenApiFragment, "buildAuthOpenApiFragment");
25340
- function describe2(credential, cookieDelivery, bearerDelivery) {
25525
+ function describe3(credential, cookieDelivery, bearerDelivery) {
25341
25526
  switch (credential) {
25342
25527
  case "none":
25343
25528
  return {
@@ -25407,7 +25592,7 @@ function describe2(credential, cookieDelivery, bearerDelivery) {
25407
25592
  };
25408
25593
  }
25409
25594
  }
25410
- __name(describe2, "describe");
25595
+ __name(describe3, "describe");
25411
25596
  function describeTwoCredentials(credential, cookieDelivery, bearerDelivery) {
25412
25597
  const required = {
25413
25598
  access: credential !== "optionalAccessAndRefresh",
@@ -26796,6 +26981,7 @@ exports.BymaxAuthModule = class _BymaxAuthModule {
26796
26981
  if (hostHasKey(userOptions, "controllers")) {
26797
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.");
26798
26983
  }
26984
+ assertRootIsStandardAtBoot();
26799
26985
  const resolved = readHostOptions(() => resolveOptions(userOptions));
26800
26986
  if (includeMfa && resolved.mfa === void 0) {
26801
26987
  throw new Error("[BymaxAuthModule] controllers.mfa: true requires the mfa group (encryptionKey and issuer) to be configured in the useFactory return value.");
@@ -26954,13 +27140,7 @@ exports.BymaxAuthModule = class _BymaxAuthModule {
26954
27140
  imports: options.imports ?? [],
26955
27141
  useFactory: /* @__PURE__ */ __name(async (...args) => {
26956
27142
  const { value: userOptions } = await callFactory(options.useFactory, args);
26957
- return {
26958
- secret: readHostOptions(() => userOptions.jwt.secret),
26959
- // Stryker disable next-line ObjectLiteral: jsonwebtoken defaults to HS256 and TokenManagerService overrides signOptions per call, so the emptied `signOptions` produces identical signing
26960
- signOptions: {
26961
- algorithm: "HS256"
26962
- }
26963
- };
27143
+ return jwtModuleOptions(readHostOptions(() => userOptions.jwt.secret));
26964
27144
  }, "useFactory"),
26965
27145
  inject: options.inject ?? []
26966
27146
  })
@@ -9839,16 +9839,7 @@ declare class TokenManagerService {
9839
9839
  * @returns Signed JWT string.
9840
9840
  */
9841
9841
  private issuePlatformAccess;
9842
- /**
9843
- * Builds JwtSignOptions from resolved configuration.
9844
- *
9845
- * The double-cast through `unknown` is required because:
9846
- * 1. `@nestjs/jwt` types `expiresIn` as the branded `StringValue` from `ms`
9847
- * (not a plain `string`), and
9848
- * 2. `exactOptionalPropertyTypes` rejects `string | undefined` as the value
9849
- * type of an optional property typed as `StringValue`.
9850
- * At runtime the value is always a valid `ms` string — the cast is safe.
9851
- */
9842
+ /** The options of an access-token `sign` call: the resolved configuration, over a neutral value for every option the library does not choose. */
9852
9843
  private accessSignOptions;
9853
9844
  /**
9854
9845
  * The `iss`/`aud` pair to stamp and to require, or nothing when the deployment configured
@@ -9839,16 +9839,7 @@ declare class TokenManagerService {
9839
9839
  * @returns Signed JWT string.
9840
9840
  */
9841
9841
  private issuePlatformAccess;
9842
- /**
9843
- * Builds JwtSignOptions from resolved configuration.
9844
- *
9845
- * The double-cast through `unknown` is required because:
9846
- * 1. `@nestjs/jwt` types `expiresIn` as the branded `StringValue` from `ms`
9847
- * (not a plain `string`), and
9848
- * 2. `exactOptionalPropertyTypes` rejects `string | undefined` as the value
9849
- * type of an optional property typed as `StringValue`.
9850
- * At runtime the value is always a valid `ms` string — the cast is safe.
9851
- */
9842
+ /** The options of an access-token `sign` call: the resolved configuration, over a neutral value for every option the library does not choose. */
9852
9843
  private accessSignOptions;
9853
9844
  /**
9854
9845
  * The `iss`/`aud` pair to stamp and to require, or nothing when the deployment configured
@@ -52,6 +52,17 @@ function assertArray(label, value) {
52
52
  throw new Error(`[BymaxAuthModule] ${label} must be an array (received ${describeReceived(value)}).`);
53
53
  }
54
54
  __name(assertArray, "assertArray");
55
+ function assertKnownChildren(label, children, declared) {
56
+ children.forEach((child, position) => {
57
+ if (typeof child !== "string") {
58
+ throw new Error(`[BymaxAuthModule] ${label} must name roles as strings (received ${describeReceived(child)} at position ${position}).`);
59
+ }
60
+ if (!declared.has(child)) {
61
+ throw new Error(`[BymaxAuthModule] ${label} references unknown role '${child}'. All roles referenced as children must be declared as keys in the hierarchy.`);
62
+ }
63
+ });
64
+ }
65
+ __name(assertKnownChildren, "assertKnownChildren");
55
66
 
56
67
  // src/server/config/enum-boolean-options.ts
57
68
  var BOOLEAN_OPTIONS = [
@@ -101,8 +112,8 @@ var ENUM_OPTIONS = {
101
112
  "otp"
102
113
  ]
103
114
  };
104
- function readPath(root, path) {
105
- let node = root;
115
+ function readPath(root2, path) {
116
+ let node = root2;
106
117
  for (const step of path.split(".")) {
107
118
  if (typeof node !== "object" || node === null) return void 0;
108
119
  node = Reflect.get(node, step);
@@ -578,6 +589,25 @@ function durationToSeconds(value) {
578
589
  return amount * seconds;
579
590
  }
580
591
  __name(durationToSeconds, "durationToSeconds");
592
+
593
+ // src/server/config/no-inherited-keys.ts
594
+ var MAX_DEPTH = 4;
595
+ function isPlain(value) {
596
+ if (typeof value !== "object" || value === null) return false;
597
+ const prototype = Object.getPrototypeOf(value);
598
+ return prototype === null || Object.getPrototypeOf(prototype) === null;
599
+ }
600
+ __name(isPlain, "isPlain");
601
+ function withoutInheritedKeys(value, depth = 0) {
602
+ if (depth >= MAX_DEPTH || !isPlain(value)) return value;
603
+ const copy = /* @__PURE__ */ Object.create(null);
604
+ for (const [key, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(value))) {
605
+ if ("value" in descriptor) descriptor.value = withoutInheritedKeys(descriptor.value, depth + 1);
606
+ Object.defineProperty(copy, key, descriptor);
607
+ }
608
+ return copy;
609
+ }
610
+ __name(withoutInheritedKeys, "withoutInheritedKeys");
581
611
  var TOTP_STEP_SECONDS = 30;
582
612
  var TOTP_DIGITS = 6;
583
613
  var BASE32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
@@ -837,8 +867,8 @@ var OBJECT_GROUPS = [
837
867
  "mfa",
838
868
  "apiKeys"
839
869
  ];
840
- function readPath2(root, path) {
841
- let node = root;
870
+ function readPath2(root2, path) {
871
+ let node = root2;
842
872
  for (const step of path.split(".")) {
843
873
  if (Object(node) !== node) return void 0;
844
874
  node = Reflect.get(node, step);
@@ -872,6 +902,16 @@ function validateTextOptions(userOptions) {
872
902
  }
873
903
  __name(validateTextOptions, "validateTextOptions");
874
904
 
905
+ // src/server/utils/own-or-class.ts
906
+ function readOwnOrClass(group, key) {
907
+ for (let holder = group; holder !== null; holder = Object.getPrototypeOf(holder)) {
908
+ if (!Object.hasOwn(holder, key)) continue;
909
+ return holder !== group && Object.getPrototypeOf(holder) === null ? void 0 : Reflect.get(group, key);
910
+ }
911
+ return Reflect.get(group, key);
912
+ }
913
+ __name(readOwnOrClass, "readOwnOrClass");
914
+
875
915
  // src/server/config/unset-options.ts
876
916
  var TOP_KEYS = {
877
917
  identifierKey: true,
@@ -1049,24 +1089,24 @@ function isObjectGroup(value) {
1049
1089
  }
1050
1090
  __name(isObjectGroup, "isObjectGroup");
1051
1091
  function readSetKeys(group, keys) {
1052
- const out = {};
1092
+ const out = /* @__PURE__ */ Object.create(null);
1053
1093
  for (const key of /* @__PURE__ */ new Set([
1054
1094
  ...keys,
1055
1095
  ...Object.keys(group)
1056
1096
  ])) {
1057
- const entry = Reflect.get(group, key);
1097
+ const entry = readOwnOrClass(group, key);
1058
1098
  if (entry !== void 0 && entry !== null) out[key] = entry;
1059
1099
  }
1060
1100
  return out;
1061
1101
  }
1062
1102
  __name(readSetKeys, "readSetKeys");
1063
1103
  function readKeptKeys(group, keys) {
1064
- const out = {};
1104
+ const out = /* @__PURE__ */ Object.create(null);
1065
1105
  for (const key of /* @__PURE__ */ new Set([
1066
1106
  ...keys,
1067
1107
  ...Object.keys(group)
1068
1108
  ])) {
1069
- const entry = Reflect.get(group, key);
1109
+ const entry = readOwnOrClass(group, key);
1070
1110
  if (entry !== void 0 || Object.hasOwn(group, key)) out[key] = entry;
1071
1111
  }
1072
1112
  return out;
@@ -1102,12 +1142,12 @@ function dropUnset(options) {
1102
1142
  }
1103
1143
  const oauth = copy["oauth"];
1104
1144
  if (isObjectGroup(oauth)) {
1105
- const google = Reflect.get(oauth, "google");
1145
+ const google = readOwnOrClass(oauth, "google");
1106
1146
  if (isObjectGroup(google)) {
1107
1147
  Reflect.set(oauth, "google", readKeptKeys(google, Object.keys(OAUTH_GOOGLE_KEYS)));
1108
1148
  }
1109
1149
  }
1110
- return Object.assign({}, copy);
1150
+ return Object.assign(/* @__PURE__ */ Object.create(null), copy);
1111
1151
  }
1112
1152
  __name(dropUnset, "dropUnset");
1113
1153
 
@@ -1227,11 +1267,7 @@ function validatePlatformAdmin(platform, roles) {
1227
1267
  }
1228
1268
  for (const [role, children] of Object.entries(hierarchy)) {
1229
1269
  assertArray(`roles.platformHierarchy['${role}']`, children);
1230
- for (const child of children) {
1231
- if (!names.has(child)) {
1232
- throw new Error(`[BymaxAuthModule] roles.platformHierarchy['${role}'] references unknown role '${child}'. All roles referenced as children must be declared as keys in the hierarchy.`);
1233
- }
1234
- }
1270
+ assertKnownChildren(`roles.platformHierarchy['${role}']`, children, names);
1235
1271
  }
1236
1272
  }
1237
1273
  __name(validatePlatformAdmin, "validatePlatformAdmin");
@@ -1579,7 +1615,7 @@ function resolveOptions(given) {
1579
1615
  validateTrustedOrigins(userOptions);
1580
1616
  validateAccessLifetimeAgainstEpochRetention(userOptions.jwt);
1581
1617
  const { mfa: _mfa, identifierKey: _identifierKey, workspaces: _workspaces, ...userOptionsWithoutMfa } = userOptions;
1582
- const resolved = {
1618
+ const resolved = withoutInheritedKeys({
1583
1619
  ...userOptionsWithoutMfa,
1584
1620
  jwt: {
1585
1621
  ...DEFAULT_OPTIONS.jwt,
@@ -1673,7 +1709,7 @@ function resolveOptions(given) {
1673
1709
  ...userOptions.mfa
1674
1710
  }
1675
1711
  }
1676
- };
1712
+ });
1677
1713
  withholdSecrets(resolved);
1678
1714
  return resolved;
1679
1715
  }
@@ -1830,11 +1866,7 @@ function validateRolesHierarchy(roles) {
1830
1866
  const allRoles = new Set(Object.keys(roles.hierarchy));
1831
1867
  for (const [role, children] of Object.entries(roles.hierarchy)) {
1832
1868
  assertArray(`roles.hierarchy['${role}']`, children);
1833
- for (const child of children) {
1834
- if (!allRoles.has(child)) {
1835
- throw new Error(`[BymaxAuthModule] roles.hierarchy['${role}'] references unknown role '${child}'. All roles referenced as children must be declared as keys in the hierarchy.`);
1836
- }
1837
- }
1869
+ assertKnownChildren(`roles.hierarchy['${role}']`, children, allRoles);
1838
1870
  }
1839
1871
  }
1840
1872
  __name(validateRolesHierarchy, "validateRolesHierarchy");
@@ -5169,6 +5201,142 @@ AuthRevocationService = _ts_decorate7([
5169
5201
  typeof AuthRedisService === "undefined" ? Object : AuthRedisService
5170
5202
  ])
5171
5203
  ], AuthRevocationService);
5204
+
5205
+ // src/server/utils/object-prototype-guard.ts
5206
+ var STANDARD = [
5207
+ "constructor",
5208
+ "__defineGetter__",
5209
+ "__defineSetter__",
5210
+ "hasOwnProperty",
5211
+ "__lookupGetter__",
5212
+ "__lookupSetter__",
5213
+ "isPrototypeOf",
5214
+ "propertyIsEnumerable",
5215
+ "toString",
5216
+ "valueOf",
5217
+ "__proto__",
5218
+ "toLocaleString"
5219
+ ];
5220
+ var ownKeys = Reflect.ownKeys;
5221
+ var hasOwn = Object.hasOwn;
5222
+ var getDescriptor = Object.getOwnPropertyDescriptor;
5223
+ var root = Object.prototype;
5224
+ function describe2(name) {
5225
+ const descriptor = getDescriptor(root, name);
5226
+ if (descriptor === void 0) return void 0;
5227
+ const field = /* @__PURE__ */ __name((key) => hasOwn(descriptor, key) ? descriptor[key] : void 0, "field");
5228
+ return Object.assign(/* @__PURE__ */ Object.create(null), {
5229
+ value: field("value"),
5230
+ get: field("get"),
5231
+ set: field("set"),
5232
+ enumerable: field("enumerable") === true
5233
+ });
5234
+ }
5235
+ __name(describe2, "describe");
5236
+ var BASELINE = new Map(STANDARD.map((name) => [
5237
+ name,
5238
+ describe2(name)
5239
+ ]));
5240
+ function isStandardKind(name, descriptor) {
5241
+ if (name === "__proto__" && descriptor === void 0) return true;
5242
+ if (descriptor === void 0 || descriptor.enumerable) return false;
5243
+ return name === "__proto__" ? typeof descriptor.get === "function" && typeof descriptor.set === "function" : typeof descriptor.value === "function";
5244
+ }
5245
+ __name(isStandardKind, "isStandardKind");
5246
+ var LOADED_STANDARD = STANDARD.every((name) => isStandardKind(name, BASELINE.get(name)));
5247
+ function same(left, right) {
5248
+ return left !== void 0 && right !== void 0 && left.value === right.value && left.get === right.get && left.set === right.set && left.enumerable === right.enumerable;
5249
+ }
5250
+ __name(same, "same");
5251
+ function plantedOnRoot() {
5252
+ let count = LOADED_STANDARD ? 0 : 1;
5253
+ for (const key of ownKeys(root)) if (typeof key === "string" && !same(describe2(key), BASELINE.get(key))) count += 1;
5254
+ for (const name of STANDARD) if (describe2(name) === void 0 && BASELINE.get(name) !== void 0) count += 1;
5255
+ return count;
5256
+ }
5257
+ __name(plantedOnRoot, "plantedOnRoot");
5258
+ function assertRootIsStandard() {
5259
+ const planted = plantedOnRoot();
5260
+ if (planted > 0) throw new AuthException(AUTH_ERROR_CODES.INTERNAL, void 0, {
5261
+ cause: new Error(`Object.prototype holds ${planted} entries that are not the runtime's own`)
5262
+ });
5263
+ }
5264
+ __name(assertRootIsStandard, "assertRootIsStandard");
5265
+ function assertRootIsStandardAtBoot() {
5266
+ const planted = plantedOnRoot();
5267
+ 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.`);
5268
+ }
5269
+ __name(assertRootIsStandardAtBoot, "assertRootIsStandardAtBoot");
5270
+
5271
+ // src/server/utils/dependency-options.ts
5272
+ var JWT_MODULE_SHADOWS = Object.freeze({
5273
+ secretOrPrivateKey: void 0,
5274
+ secretOrKeyProvider: void 0,
5275
+ publicKey: void 0,
5276
+ privateKey: void 0,
5277
+ verifyOptions: void 0
5278
+ });
5279
+ var JWT_VERIFY_SHADOWS = Object.freeze({
5280
+ complete: false,
5281
+ clockTimestamp: void 0,
5282
+ clockTolerance: void 0,
5283
+ ignoreNotBefore: false,
5284
+ maxAge: void 0,
5285
+ nonce: void 0,
5286
+ subject: void 0,
5287
+ jwtid: void 0,
5288
+ allowInvalidAsymmetricKeyTypes: false
5289
+ });
5290
+ var JWT_SIGN_SHADOWS = Object.freeze({
5291
+ noTimestamp: false,
5292
+ mutatePayload: false,
5293
+ header: Object.freeze({}),
5294
+ // 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
5295
+ encoding: "utf8",
5296
+ allowInsecureKeySizes: false,
5297
+ allowInvalidAsymmetricKeyTypes: false
5298
+ });
5299
+ var SCRYPT_SHADOWS = Object.freeze({
5300
+ cost: void 0,
5301
+ blockSize: void 0,
5302
+ parallelization: void 0
5303
+ });
5304
+ var COOKIE_SHADOWS = Object.freeze(Object.assign({}, {
5305
+ domain: void 0,
5306
+ expires: void 0,
5307
+ encode: void 0,
5308
+ partitioned: false,
5309
+ priority: void 0,
5310
+ signed: false
5311
+ }));
5312
+ function jwtModuleOptions(secret) {
5313
+ return Object.assign(
5314
+ // Stryker disable next-line ObjectLiteral: jsonwebtoken defaults to HS256 and every sign call names its own algorithm, so the emptied `signOptions` signs identically
5315
+ {
5316
+ secret,
5317
+ signOptions: {
5318
+ algorithm: "HS256"
5319
+ }
5320
+ },
5321
+ JWT_MODULE_SHADOWS
5322
+ );
5323
+ }
5324
+ __name(jwtModuleOptions, "jwtModuleOptions");
5325
+ function jwtSignOptions(chosen) {
5326
+ assertRootIsStandard();
5327
+ return Object.assign({}, JWT_SIGN_SHADOWS, chosen);
5328
+ }
5329
+ __name(jwtSignOptions, "jwtSignOptions");
5330
+ function cookieOptions(chosen = {}) {
5331
+ assertRootIsStandard();
5332
+ return {
5333
+ ...COOKIE_SHADOWS,
5334
+ ...chosen
5335
+ };
5336
+ }
5337
+ __name(cookieOptions, "cookieOptions");
5338
+
5339
+ // src/server/services/token-delivery.service.ts
5172
5340
  function _ts_decorate8(decorators, target, key, desc) {
5173
5341
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5174
5342
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") {
@@ -5486,12 +5654,12 @@ var TokenDeliveryService = class {
5486
5654
  }
5487
5655
  /** Returns base Set-Cookie options for auth cookies, optionally scoped to a domain. */
5488
5656
  baseCookieOptions(domain) {
5489
- return {
5657
+ return cookieOptions({
5490
5658
  sameSite: this.options.cookies.sameSite,
5491
5659
  ...domain ? {
5492
5660
  domain
5493
5661
  } : {}
5494
- };
5662
+ });
5495
5663
  }
5496
5664
  /** Reads the value of the cookie identified by `name` from the request. */
5497
5665
  readCookie(req, name) {
@@ -5564,11 +5732,13 @@ function signerOf(options) {
5564
5732
  }
5565
5733
  __name(signerOf, "signerOf");
5566
5734
  function verifyWithRotation(jwtService, options, token, { ignoreExpiration = false } = {}) {
5735
+ assertRootIsStandard();
5567
5736
  const algorithms = [
5568
5737
  options.jwt.algorithm
5569
5738
  ];
5570
5739
  const { issuer, audience, secret } = options.jwt;
5571
5740
  const base = {
5741
+ ...JWT_VERIFY_SHADOWS,
5572
5742
  algorithms,
5573
5743
  ignoreExpiration,
5574
5744
  issuer,
@@ -7187,8 +7357,10 @@ var PasswordService = class _PasswordService {
7187
7357
  }
7188
7358
  }
7189
7359
  async hash(plain) {
7360
+ assertRootIsStandard();
7190
7361
  const salt = randomBytes(SALT_BYTES);
7191
7362
  const derived = await scrypt(plain, salt, SCRYPT_KEY_LEN, {
7363
+ ...SCRYPT_SHADOWS,
7192
7364
  N: this.N,
7193
7365
  r: this.r,
7194
7366
  p: this.p,
@@ -7226,10 +7398,12 @@ var PasswordService = class _PasswordService {
7226
7398
  * without revealing the reason (invalid hash vs. wrong password).
7227
7399
  */
7228
7400
  async compare(plain, hash) {
7401
+ assertRootIsStandard();
7229
7402
  const parsed = parseStoredHash(hash);
7230
7403
  if (parsed === null) return false;
7231
7404
  const { N, r, p } = parsed;
7232
7405
  const candidate = await scrypt(plain, parsed.salt, parsed.derived.length, {
7406
+ ...SCRYPT_SHADOWS,
7233
7407
  N,
7234
7408
  r,
7235
7409
  p,
@@ -7276,7 +7450,9 @@ var PasswordService = class _PasswordService {
7276
7450
  * password request already costs; pair it with route-level rate limiting.
7277
7451
  */
7278
7452
  async compareDummy(plain) {
7453
+ assertRootIsStandard();
7279
7454
  const candidate = await scrypt(plain, DUMMY_SALT, SCRYPT_KEY_LEN, {
7455
+ ...SCRYPT_SHADOWS,
7280
7456
  N: this.N,
7281
7457
  r: this.r,
7282
7458
  p: this.p,
@@ -7301,7 +7477,7 @@ var RECORD_CONTRACTS = {
7301
7477
  workspace: {
7302
7478
  fields: {
7303
7479
  id: "id",
7304
- tenantId: "string",
7480
+ tenantId: "tenant",
7305
7481
  name: "~string",
7306
7482
  status: "string",
7307
7483
  createdAt: "~date",
@@ -7311,7 +7487,7 @@ var RECORD_CONTRACTS = {
7311
7487
  },
7312
7488
  membership: {
7313
7489
  fields: {
7314
- tenantId: "string",
7490
+ tenantId: "tenant",
7315
7491
  workspaceId: "id",
7316
7492
  userId: "id",
7317
7493
  role: "string",
@@ -7330,7 +7506,7 @@ var RECORD_CONTRACTS = {
7330
7506
  passwordHash: "string|null",
7331
7507
  role: "string",
7332
7508
  status: "string",
7333
- tenantId: "string",
7509
+ tenantId: "tenant",
7334
7510
  emailVerified: "boolean",
7335
7511
  mfaEnabled: "boolean",
7336
7512
  mfaSecret: "string?",
@@ -7618,13 +7794,26 @@ function copyStrings(value, read) {
7618
7794
  return copy;
7619
7795
  }
7620
7796
  __name(copyStrings, "copyStrings");
7797
+ var BUILT_IN_VALUES = [
7798
+ Date,
7799
+ RegExp,
7800
+ Error,
7801
+ DataView,
7802
+ URL,
7803
+ Intl.Locale,
7804
+ Object.getPrototypeOf(Uint8Array)
7805
+ ];
7806
+ function isBuiltInValue(value) {
7807
+ return types.isDate(value) || types.isRegExp(value) || types.isNativeError(value) || types.isArrayBufferView(value) || BUILT_IN_VALUES.some((kind) => value instanceof kind);
7808
+ }
7809
+ __name(isBuiltInValue, "isBuiltInValue");
7621
7810
  var NOT_AN_ID_TEXT = /* @__PURE__ */ new Set([
7622
7811
  "undefined",
7623
7812
  "null"
7624
7813
  ]);
7625
7814
  function readId(value) {
7626
7815
  if (typeof value === "number") return accept(Number.isSafeInteger(value), String(value));
7627
- if (typeof value !== "string" && (!isHostInstance(value) || types.isDate(value) || types.isRegExp(value) || types.isNativeError(value) || types.isArrayBufferView(value))) throw new Error(WRONG_KIND);
7816
+ if (typeof value !== "string" && (!isHostInstance(value) || isBuiltInValue(value))) throw new Error(WRONG_KIND);
7628
7817
  const text = String(value);
7629
7818
  const printed = typeof value !== "string";
7630
7819
  return accept(text.trim() !== "" && !NOT_AN_ID_TEXT.has(text) && !(printed && text.startsWith("[object ")), text);
@@ -7646,6 +7835,7 @@ __name(readInformingDate, "readInformingDate");
7646
7835
  var READERS = {
7647
7836
  boolean: /* @__PURE__ */ __name((value) => accept(typeof value === "boolean", value), "boolean"),
7648
7837
  string: /* @__PURE__ */ __name((value) => accept(typeof value === "string", value), "string"),
7838
+ tenant: /* @__PURE__ */ __name((value) => accept(typeof value === "string" && value.trim() !== "", value), "tenant"),
7649
7839
  id: readId,
7650
7840
  number: /* @__PURE__ */ __name((value) => accept(Number.isFinite(value), value), "number"),
7651
7841
  date: copyDate,
@@ -7678,7 +7868,7 @@ function readScalar(value, spec, run) {
7678
7868
  }
7679
7869
  __name(readScalar, "readScalar");
7680
7870
  function copyRecord(value, contract, run) {
7681
- const copy = {};
7871
+ const copy = /* @__PURE__ */ Object.create(null);
7682
7872
  rememberUnder(run, value, contract, copy);
7683
7873
  ENTITIES.set(copy, value);
7684
7874
  const source = value;
@@ -7692,7 +7882,7 @@ function copyRecord(value, contract, run) {
7692
7882
  const own = new Set(keys);
7693
7883
  for (const [field, spec] of Object.entries(contract.fields)) {
7694
7884
  const { base, nullable, optional } = parseSpec(spec);
7695
- const held = source[field];
7885
+ const held = readOwnOrClass(source, field);
7696
7886
  if (held === void 0) {
7697
7887
  if (optional) continue;
7698
7888
  throw new Error(ABSENT);
@@ -8731,22 +8921,13 @@ var TokenManagerService = class _TokenManagerService {
8731
8921
  jti
8732
8922
  }, this.accessSignOptions());
8733
8923
  }
8734
- /**
8735
- * Builds JwtSignOptions from resolved configuration.
8736
- *
8737
- * The double-cast through `unknown` is required because:
8738
- * 1. `@nestjs/jwt` types `expiresIn` as the branded `StringValue` from `ms`
8739
- * (not a plain `string`), and
8740
- * 2. `exactOptionalPropertyTypes` rejects `string | undefined` as the value
8741
- * type of an optional property typed as `StringValue`.
8742
- * At runtime the value is always a valid `ms` string — the cast is safe.
8743
- */
8924
+ /** The options of an access-token `sign` call: the resolved configuration, over a neutral value for every option the library does not choose. */
8744
8925
  accessSignOptions() {
8745
- return {
8926
+ return jwtSignOptions({
8746
8927
  expiresIn: this.options.jwt.accessExpiresIn,
8747
8928
  ...signerOf(this.options),
8748
8929
  ...this.issuerAudience()
8749
- };
8930
+ });
8750
8931
  }
8751
8932
  /**
8752
8933
  * The `iss`/`aud` pair to stamp and to require, or nothing when the deployment configured
@@ -9528,14 +9709,14 @@ var TokenManagerService = class _TokenManagerService {
9528
9709
  // the claim's own documentation for what it was surviving.
9529
9710
  epoch: await this.redis.getUserTokenEpoch(userId, tenantId, context)
9530
9711
  };
9531
- const token = this.jwtService.sign(payload, {
9712
+ const token = this.jwtService.sign(payload, jwtSignOptions({
9532
9713
  expiresIn: `${MFA_TEMP_TOKEN_TTL_SECONDS}s`,
9533
9714
  ...signerOf(this.options),
9534
9715
  // The challenge token is stamped and checked like every other: it grants no resource
9535
9716
  // access on its own, but it is still a token this backend minted, and a verifier that
9536
9717
  // exempted one shape would be a verifier an attacker aims at.
9537
9718
  ...this.issuerAudience()
9538
- });
9719
+ }));
9539
9720
  await this.redis.set(`mfa:${sha256(jti)}`, userId, MFA_TEMP_TOKEN_TTL_SECONDS);
9540
9721
  return token;
9541
9722
  }
@@ -14896,6 +15077,7 @@ var MfaController = class {
14896
15077
  */
14897
15078
  clearMfaTempCookie(res) {
14898
15079
  res.clearCookie(MFA_TEMP_COOKIE_NAME, {
15080
+ ...cookieOptions(),
14899
15081
  path: this.options.cookies.mfaTempCookiePath,
14900
15082
  httpOnly: true,
14901
15083
  secure: this.options.secureCookies,
@@ -23014,6 +23196,7 @@ var OAuthService = class _OAuthService {
23014
23196
  */
23015
23197
  bindToBrowser(res, state) {
23016
23198
  res.cookie(OAUTH_STATE_COOKIE_NAME, state, {
23199
+ ...cookieOptions(),
23017
23200
  httpOnly: true,
23018
23201
  secure: this.options.secureCookies,
23019
23202
  sameSite: OAUTH_STATE_COOKIE_SAME_SITE,
@@ -23893,6 +24076,7 @@ var OAuthController = class _OAuthController {
23893
24076
  */
23894
24077
  clearOAuthStateCookie(res) {
23895
24078
  res.clearCookie(OAUTH_STATE_COOKIE_NAME, {
24079
+ ...cookieOptions(),
23896
24080
  httpOnly: true,
23897
24081
  secure: this.options.secureCookies,
23898
24082
  sameSite: OAUTH_STATE_COOKIE_SAME_SITE,
@@ -23917,6 +24101,7 @@ var OAuthController = class _OAuthController {
23917
24101
  */
23918
24102
  setMfaTempCookie(res, mfaTempToken) {
23919
24103
  res.cookie(MFA_TEMP_COOKIE_NAME, mfaTempToken, {
24104
+ ...cookieOptions(),
23920
24105
  httpOnly: true,
23921
24106
  secure: this.options.secureCookies,
23922
24107
  sameSite: this.options.cookies.sameSite,
@@ -25317,7 +25502,7 @@ function buildAuthOpenApiFragment(options, registered) {
25317
25502
  for (const [controller, handlers] of Object.entries(OPERATIONS)) {
25318
25503
  if (!registered[controller]) continue;
25319
25504
  for (const [handler, credential] of Object.entries(handlers)) {
25320
- const described = describe2(credential, cookieDelivery, bearerDelivery);
25505
+ const described = describe3(credential, cookieDelivery, bearerDelivery);
25321
25506
  const note = OPERATION_DESCRIPTIONS.get(handler);
25322
25507
  operations[handler] = note === void 0 ? described : {
25323
25508
  ...described,
@@ -25335,7 +25520,7 @@ function buildAuthOpenApiFragment(options, registered) {
25335
25520
  };
25336
25521
  }
25337
25522
  __name(buildAuthOpenApiFragment, "buildAuthOpenApiFragment");
25338
- function describe2(credential, cookieDelivery, bearerDelivery) {
25523
+ function describe3(credential, cookieDelivery, bearerDelivery) {
25339
25524
  switch (credential) {
25340
25525
  case "none":
25341
25526
  return {
@@ -25405,7 +25590,7 @@ function describe2(credential, cookieDelivery, bearerDelivery) {
25405
25590
  };
25406
25591
  }
25407
25592
  }
25408
- __name(describe2, "describe");
25593
+ __name(describe3, "describe");
25409
25594
  function describeTwoCredentials(credential, cookieDelivery, bearerDelivery) {
25410
25595
  const required = {
25411
25596
  access: credential !== "optionalAccessAndRefresh",
@@ -26794,6 +26979,7 @@ var BymaxAuthModule = class _BymaxAuthModule {
26794
26979
  if (hostHasKey(userOptions, "controllers")) {
26795
26980
  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.");
26796
26981
  }
26982
+ assertRootIsStandardAtBoot();
26797
26983
  const resolved = readHostOptions(() => resolveOptions(userOptions));
26798
26984
  if (includeMfa && resolved.mfa === void 0) {
26799
26985
  throw new Error("[BymaxAuthModule] controllers.mfa: true requires the mfa group (encryptionKey and issuer) to be configured in the useFactory return value.");
@@ -26952,13 +27138,7 @@ var BymaxAuthModule = class _BymaxAuthModule {
26952
27138
  imports: options.imports ?? [],
26953
27139
  useFactory: /* @__PURE__ */ __name(async (...args) => {
26954
27140
  const { value: userOptions } = await callFactory(options.useFactory, args);
26955
- return {
26956
- secret: readHostOptions(() => userOptions.jwt.secret),
26957
- // Stryker disable next-line ObjectLiteral: jsonwebtoken defaults to HS256 and TokenManagerService overrides signOptions per call, so the emptied `signOptions` produces identical signing
26958
- signOptions: {
26959
- algorithm: "HS256"
26960
- }
26961
- };
27141
+ return jwtModuleOptions(readHostOptions(() => userOptions.jwt.secret));
26962
27142
  }, "useFactory"),
26963
27143
  inject: options.inject ?? []
26964
27144
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-auth",
3
- "version": "1.5.14",
3
+ "version": "1.5.15",
4
4
  "description": "Full-stack authentication and authorization package for NestJS, React and Next.js — JWT, MFA, OAuth, sessions, multi-tenant SaaS ready",
5
5
  "author": "Bymax One <support@bymax.one>",
6
6
  "license": "MIT",