@bymax-one/nest-auth 1.5.12 → 1.5.13
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 +50 -1
- package/README.md +4 -4
- package/dist/server/index.cjs +135 -52
- package/dist/server/index.mjs +135 -52
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -18,6 +18,54 @@ what moves, and that note is the compatibility contract until strict SemVer begi
|
|
|
18
18
|
|
|
19
19
|
## [Unreleased]
|
|
20
20
|
|
|
21
|
+
## [1.5.13] - 2026-11-21
|
|
22
|
+
|
|
23
|
+
A patch release.
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- **A tenant is read as a string and as nothing else.** The `tenantId` of a user, a workspace and a membership was
|
|
28
|
+
accepted as a string or as any instance of a class of the host: a `Date`, a `Map`, an object that inherits from a
|
|
29
|
+
plain object, a class that only has `toString`. Comparisons with the tenant of a request already failed closed, but
|
|
30
|
+
the value is written into the claims of a token, where two tenants whose ids are objects both serialize to `{}`. Any
|
|
31
|
+
value that is not a string now ends as `auth.internal`. **Apply to a derived backend:** a repository that serves the
|
|
32
|
+
tenant as an object (an id type of a driver) has to serve it as a string.
|
|
33
|
+
- **The time of a real date is the time it holds.** A subclass of `Date` that overrides `getTime` was asked for its
|
|
34
|
+
time, so a host could name a deadline other than the one the date carries. A real date is read through
|
|
35
|
+
`Date.prototype.getTime`; a Proxy of a date, which has no slot, is still read through its own `getTime`.
|
|
36
|
+
- **A read follows a bounded number of nodes in all.** The cap of 100 000 elements or keys applied to each array and
|
|
37
|
+
each object, so a list of records that each stayed under it could still make a copy walk as many nodes as the host
|
|
38
|
+
served. A read now follows at most 1 000 000 nodes (the elements of lists, the own keys of records and the strings of
|
|
39
|
+
lists of strings); an answer that holds more ends as `auth.internal`.
|
|
40
|
+
- **Access to a workspace is refused when the repository answers with a row of another tenant.** The workspace and the
|
|
41
|
+
membership read for a tenant, a workspace and a user are now checked to carry the tenant that was asked about; the
|
|
42
|
+
key given to a repository is not a proof of the row it returned.
|
|
43
|
+
- **An id names one row, and the library keeps it as a string.** The ids of users, workspaces and memberships were
|
|
44
|
+
accepted as a string, a finite number or any instance of a class of the host, so a `Map` or a `Date` was an id, and
|
|
45
|
+
two of them printed the same in a claim, a key or the scope of a query. An id is now a non-empty string, a safe
|
|
46
|
+
integer, or an object of the host that prints as a non-empty text of its own, and what the library keeps is the text
|
|
47
|
+
it prints as, read once. A `Date`, a `RegExp`, a `Map`, a `Set`, a `Promise`, an array, a plain object, a function, a
|
|
48
|
+
boolean, a fraction, an integer past the safe range and an object that prints as nothing or as `[object ...]` end as
|
|
49
|
+
`auth.internal`. An account whose id is a number now works after the login: the token's subject was the number, which
|
|
50
|
+
the verifier refuses, so `/me`, a refresh and a password change answered 401 for an account that had just logged in.
|
|
51
|
+
**Apply to a derived backend:** the library hands the repository the id as a string (it always did, from the token),
|
|
52
|
+
so a repository keyed by a number has to accept the string; a repository that serves a numeric id as a fraction or
|
|
53
|
+
past 2^53 has to serve it as a string. A hook that receives a user now sees the id as its string form (a host
|
|
54
|
+
callback that receives the host's own entity, such as `maxSessionsResolver`, still gets the object as it was).
|
|
55
|
+
- **The secret that signs is the secret that was checked, and the role hierarchies are read once.** The signer is
|
|
56
|
+
configured by a second call of the host's options factory, and what that call answered was the secret that signed
|
|
57
|
+
and verified: a factory that answered a weak secret the second time passed the strength check on the first answer and
|
|
58
|
+
signed with the weak one. Every sign and every verify now names the secret the options resolved to. The role
|
|
59
|
+
hierarchies (`roles.hierarchy`, `roles.platformHierarchy` and `workspaces.roles.hierarchy`) were kept as the host's
|
|
60
|
+
own objects and read through its getters at every check; each is read once, as plain data, so a getter that answers
|
|
61
|
+
differently later cannot grant a role that was never validated. `roles`, `workspaces` and `workspaces.roles` must be objects: a
|
|
62
|
+
function, an array or a primitive given for one is refused with `[BymaxAuthModule] <option> must be an object
|
|
63
|
+
(received …)`, as the other option groups already were.
|
|
64
|
+
- **A resend of the verification code that fails gives the cooldown back.** The request took the one-minute cooldown
|
|
65
|
+
before it looked the account up, so a request that failed there (a repository that throws, or answers with a record the
|
|
66
|
+
copy refuses) left the retry it invites refused for the rest of the minute. A request that took the cooldown and failed
|
|
67
|
+
releases it, as the password reset request already did; a request that sent, or found the cooldown taken, keeps it.
|
|
68
|
+
|
|
21
69
|
## [1.5.12] - 2026-11-21
|
|
22
70
|
|
|
23
71
|
A patch release.
|
|
@@ -5512,7 +5560,8 @@ ever installable.
|
|
|
5512
5560
|
- 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
|
|
5513
5561
|
- 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
|
|
5514
5562
|
|
|
5515
|
-
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.
|
|
5563
|
+
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.13...HEAD
|
|
5564
|
+
[1.5.13]: https://github.com/bymaxone/nest-auth/compare/v1.5.12...v1.5.13
|
|
5516
5565
|
[1.5.12]: https://github.com/bymaxone/nest-auth/compare/v1.5.11...v1.5.12
|
|
5517
5566
|
[1.5.11]: https://github.com/bymaxone/nest-auth/compare/v1.5.10...v1.5.11
|
|
5518
5567
|
[1.5.10]: https://github.com/bymaxone/nest-auth/compare/v1.5.9...v1.5.10
|
package/README.md
CHANGED
|
@@ -1408,9 +1408,9 @@ With `@opentelemetry/api` installed and an SDK registered, each of these routes
|
|
|
1408
1408
|
|
|
1409
1409
|
| Span | Routes |
|
|
1410
1410
|
| --------------------- | ----------------------------------------------------------------- |
|
|
1411
|
-
| `auth.login` | `POST /login`, `POST /platform/
|
|
1412
|
-
| `auth.refresh` | `POST /refresh`, `POST /platform/
|
|
1413
|
-
| `auth.mfa.verify` | `POST /mfa/challenge`, `POST /platform/
|
|
1411
|
+
| `auth.login` | `POST /login`, `POST /platform/login` |
|
|
1412
|
+
| `auth.refresh` | `POST /refresh`, `POST /platform/refresh` |
|
|
1413
|
+
| `auth.mfa.verify` | `POST /mfa/challenge`, `POST /platform/mfa/challenge` |
|
|
1414
1414
|
| `auth.password_reset` | `POST /password/forgot-password`, `POST /password/reset-password` |
|
|
1415
1415
|
|
|
1416
1416
|
### Readiness
|
|
@@ -1494,7 +1494,7 @@ A Nest `Logger` calls the host logger and discards what it returns, so a host lo
|
|
|
1494
1494
|
The fields that name a step come from sets the library owns, typed in the code and listed here; none is ever text a host or a store wrote.
|
|
1495
1495
|
|
|
1496
1496
|
- **`hook`** of `AUTH_HOOK_FAILED`: `beforeRegister`, `afterRegister`, `beforeLogin`, `afterLogin`, `afterLogout`, `afterPlatformLogout`, `onLoginFailed`, `onLockout`, `onRefreshTokenReuseDetected`, `afterMfaEnabled`, `afterMfaDisabled`, `afterMfaRecoveryCodesRegenerated`, `onNewSession`, `afterEmailVerified`, `afterPasswordReset`, `onOAuthLogin`, `afterInvitationAccepted`, `onSessionEvicted`, `onApiKeyRequest`, `beforeWorkspaceCreate`, `onWorkspaceEvent`, `updateLastLogin`, `accessDenied`, `maxSessionsResolver`.
|
|
1497
|
-
- **`operation`** of `AUTH_STORE_FAILED` and `AUTH_STORE_DEGRADED`: `account_status_cache_write`, `api_key_last_used_flush`, `api_key_lookup`, `cache_invalidation`, `dead_member_prune`, `grace_pointer_prune`, `invitation_withdraw`, `logout_marker_clear`, `logout_owner_keep`, `mfa_lock_release`, `mfa_reencryption`, `new_session_user_lookup`, `rehash_on_verify`, `reset_account_lookup`, `reset_cooldown_release`, `reset_cooldown_store`, `reset_issue`, `session_cleanup`, `session_detail_read`, `session_detail_rotation`, `workspace_cache_read`, `workspace_cache_write`.
|
|
1497
|
+
- **`operation`** of `AUTH_STORE_FAILED` and `AUTH_STORE_DEGRADED`: `account_status_cache_write`, `api_key_last_used_flush`, `api_key_lookup`, `cache_invalidation`, `dead_member_prune`, `grace_pointer_prune`, `invitation_withdraw`, `logout_marker_clear`, `logout_owner_keep`, `mfa_lock_release`, `mfa_reencryption`, `new_session_user_lookup`, `rehash_on_verify`, `resend_cooldown_release`, `reset_account_lookup`, `reset_cooldown_release`, `reset_cooldown_store`, `reset_issue`, `session_cleanup`, `session_detail_read`, `session_detail_rotation`, `workspace_cache_read`, `workspace_cache_write`.
|
|
1498
1498
|
- **`kind`** of `AUTH_DELIVERY_FAILED`: `passwordResetToken`, `passwordResetOtp`, `emailVerificationOtp`, `passwordChanged`, `emailChangeVerification`, `emailChanged`, `mfaEnabled`, `mfaDisabled`, `newSessionAlert`, `invitation`, `workspaceInvitation`, `email_verification_otp`, `password_changed_notice`, `password_reset_token`, `password_reset_otp`, `mfa_enabled_notice`, `mfa_disabled_notice`, `mfa_reset_notice`, `email_change_notice`.
|
|
1499
1499
|
|
|
1500
1500
|
---
|
package/dist/server/index.cjs
CHANGED
|
@@ -830,7 +830,10 @@ var OBJECT_GROUPS = [
|
|
|
830
830
|
"platform",
|
|
831
831
|
"invitations",
|
|
832
832
|
"emailChange",
|
|
833
|
-
"oauth"
|
|
833
|
+
"oauth",
|
|
834
|
+
"roles",
|
|
835
|
+
"workspaces",
|
|
836
|
+
"workspaces.roles"
|
|
834
837
|
];
|
|
835
838
|
function readPath2(root, path) {
|
|
836
839
|
let node = root;
|
|
@@ -1027,6 +1030,10 @@ var WORKSPACE_SUBGROUP_KEYS = {
|
|
|
1027
1030
|
accessDeniedEvents: [
|
|
1028
1031
|
"max",
|
|
1029
1032
|
"windowSeconds"
|
|
1033
|
+
],
|
|
1034
|
+
roles: [
|
|
1035
|
+
"hierarchy",
|
|
1036
|
+
"ownerRole"
|
|
1030
1037
|
]
|
|
1031
1038
|
};
|
|
1032
1039
|
function isObjectGroup(value) {
|
|
@@ -1076,7 +1083,7 @@ function dropUnset(options) {
|
|
|
1076
1083
|
if (name === "workspaces") {
|
|
1077
1084
|
for (const [sub, subKeys] of Object.entries(WORKSPACE_SUBGROUP_KEYS)) {
|
|
1078
1085
|
const inner = group[sub];
|
|
1079
|
-
if (isObjectGroup(inner)) group[sub] = readSetKeys(inner, subKeys);
|
|
1086
|
+
if (isObjectGroup(inner)) group[sub] = (sub === "roles" ? readKeptKeys : readSetKeys)(inner, subKeys);
|
|
1080
1087
|
}
|
|
1081
1088
|
}
|
|
1082
1089
|
copy[name] = group;
|
|
@@ -1100,9 +1107,46 @@ __name(dropUnset, "dropUnset");
|
|
|
1100
1107
|
function readOptions(given) {
|
|
1101
1108
|
const options = dropUnset(given);
|
|
1102
1109
|
validateTextOptions(options);
|
|
1103
|
-
return options;
|
|
1110
|
+
return pinHierarchies(options);
|
|
1104
1111
|
}
|
|
1105
1112
|
__name(readOptions, "readOptions");
|
|
1113
|
+
function copyHierarchy(held) {
|
|
1114
|
+
if (Object(held) !== held) return held;
|
|
1115
|
+
return Object.fromEntries(Object.entries(held).map(([role, children]) => [
|
|
1116
|
+
role,
|
|
1117
|
+
Array.isArray(children) ? [
|
|
1118
|
+
...children
|
|
1119
|
+
] : children
|
|
1120
|
+
]));
|
|
1121
|
+
}
|
|
1122
|
+
__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, [
|
|
1136
|
+
"hierarchy",
|
|
1137
|
+
"platformHierarchy"
|
|
1138
|
+
]),
|
|
1139
|
+
...workspaceRoles === void 0 ? {} : {
|
|
1140
|
+
workspaces: {
|
|
1141
|
+
...workspaceRest,
|
|
1142
|
+
roles: pinIn(workspaceRoles, [
|
|
1143
|
+
"hierarchy"
|
|
1144
|
+
])
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
};
|
|
1148
|
+
}
|
|
1149
|
+
__name(pinHierarchies, "pinHierarchies");
|
|
1106
1150
|
function validateOptionValues(userOptions) {
|
|
1107
1151
|
validateNumericOptions(userOptions);
|
|
1108
1152
|
validateEnumAndBooleanOptions(userOptions);
|
|
@@ -5435,26 +5479,34 @@ function malformedRefreshToken() {
|
|
|
5435
5479
|
__name(malformedRefreshToken, "malformedRefreshToken");
|
|
5436
5480
|
|
|
5437
5481
|
// src/server/utils/verify-with-rotation.ts
|
|
5482
|
+
function signerOf(options) {
|
|
5483
|
+
return {
|
|
5484
|
+
secret: options.jwt.secret,
|
|
5485
|
+
algorithm: options.jwt.algorithm
|
|
5486
|
+
};
|
|
5487
|
+
}
|
|
5488
|
+
__name(signerOf, "signerOf");
|
|
5438
5489
|
function verifyWithRotation(jwtService, options, token, { ignoreExpiration = false } = {}) {
|
|
5439
5490
|
const algorithms = [
|
|
5440
5491
|
options.jwt.algorithm
|
|
5441
5492
|
];
|
|
5442
|
-
const { issuer, audience } = options.jwt;
|
|
5493
|
+
const { issuer, audience, secret } = options.jwt;
|
|
5443
5494
|
const base = {
|
|
5444
5495
|
algorithms,
|
|
5445
5496
|
ignoreExpiration,
|
|
5446
5497
|
issuer,
|
|
5447
|
-
audience
|
|
5498
|
+
audience,
|
|
5499
|
+
secret
|
|
5448
5500
|
};
|
|
5449
5501
|
try {
|
|
5450
5502
|
return jwtService.verify(token, base);
|
|
5451
5503
|
} catch (currentFailure) {
|
|
5452
5504
|
const previous = options.jwt.previousSecrets ?? [];
|
|
5453
|
-
for (const
|
|
5505
|
+
for (const secret2 of previous) {
|
|
5454
5506
|
try {
|
|
5455
5507
|
return jwtService.verify(token, {
|
|
5456
5508
|
...base,
|
|
5457
|
-
secret
|
|
5509
|
+
secret: secret2
|
|
5458
5510
|
});
|
|
5459
5511
|
} catch {
|
|
5460
5512
|
}
|
|
@@ -6649,6 +6701,17 @@ function _ts_param11(paramIndex, decorator) {
|
|
|
6649
6701
|
};
|
|
6650
6702
|
}
|
|
6651
6703
|
__name(_ts_param11, "_ts_param");
|
|
6704
|
+
async function releasingCooldownOnFailure(redis, logger, cooldownKey, work) {
|
|
6705
|
+
try {
|
|
6706
|
+
return await work();
|
|
6707
|
+
} catch (error) {
|
|
6708
|
+
await redis.del(cooldownKey).catch((err) => {
|
|
6709
|
+
logStore(logger, "AUTH_STORE_FAILED", "resend_cooldown_release", err);
|
|
6710
|
+
});
|
|
6711
|
+
throw error;
|
|
6712
|
+
}
|
|
6713
|
+
}
|
|
6714
|
+
__name(releasingCooldownOnFailure, "releasingCooldownOnFailure");
|
|
6652
6715
|
var MAX_ATTEMPTS = 5;
|
|
6653
6716
|
var MIN_VERIFY_MS = 100;
|
|
6654
6717
|
var OTP_STORE_LUA = `
|
|
@@ -7160,7 +7223,7 @@ var RECORD_CONTRACTS = {
|
|
|
7160
7223
|
workspace: {
|
|
7161
7224
|
fields: {
|
|
7162
7225
|
id: "~id",
|
|
7163
|
-
tenantId: "
|
|
7226
|
+
tenantId: "string",
|
|
7164
7227
|
name: "~string",
|
|
7165
7228
|
status: "string",
|
|
7166
7229
|
createdAt: "~date",
|
|
@@ -7170,7 +7233,7 @@ var RECORD_CONTRACTS = {
|
|
|
7170
7233
|
},
|
|
7171
7234
|
membership: {
|
|
7172
7235
|
fields: {
|
|
7173
|
-
tenantId: "
|
|
7236
|
+
tenantId: "string",
|
|
7174
7237
|
workspaceId: "~id",
|
|
7175
7238
|
userId: "~id",
|
|
7176
7239
|
role: "string",
|
|
@@ -7189,7 +7252,7 @@ var RECORD_CONTRACTS = {
|
|
|
7189
7252
|
passwordHash: "string|null",
|
|
7190
7253
|
role: "string",
|
|
7191
7254
|
status: "string",
|
|
7192
|
-
tenantId: "
|
|
7255
|
+
tenantId: "string",
|
|
7193
7256
|
emailVerified: "boolean",
|
|
7194
7257
|
mfaEnabled: "boolean",
|
|
7195
7258
|
mfaSecret: "string?",
|
|
@@ -7373,14 +7436,15 @@ var CREDENTIAL_FIELDS = /* @__PURE__ */ new Set([
|
|
|
7373
7436
|
|
|
7374
7437
|
// src/server/utils/host-read.ts
|
|
7375
7438
|
var MAX_BREADTH = 1e5;
|
|
7376
|
-
|
|
7377
|
-
|
|
7439
|
+
var MAX_NODES = 1e6;
|
|
7440
|
+
function copiedUnder(read, value, contract) {
|
|
7441
|
+
return read.copies.get(value)?.get(contract);
|
|
7378
7442
|
}
|
|
7379
7443
|
__name(copiedUnder, "copiedUnder");
|
|
7380
|
-
function rememberUnder(
|
|
7381
|
-
const copies =
|
|
7444
|
+
function rememberUnder(read, value, contract, copy) {
|
|
7445
|
+
const copies = read.copies.get(value) ?? /* @__PURE__ */ new Map();
|
|
7382
7446
|
copies.set(contract, copy);
|
|
7383
|
-
|
|
7447
|
+
read.copies.set(value, copies);
|
|
7384
7448
|
}
|
|
7385
7449
|
__name(rememberUnder, "rememberUnder");
|
|
7386
7450
|
function readHostOptions(read) {
|
|
@@ -7426,10 +7490,11 @@ function define(copy, key, value, enumerable) {
|
|
|
7426
7490
|
}
|
|
7427
7491
|
__name(define, "define");
|
|
7428
7492
|
var ENTITIES = /* @__PURE__ */ new WeakMap();
|
|
7429
|
-
function
|
|
7430
|
-
|
|
7493
|
+
function follow(read, size) {
|
|
7494
|
+
read.nodes -= size;
|
|
7495
|
+
if (size > MAX_BREADTH || read.nodes < 0) throw new Error("the answer holds more than the library follows");
|
|
7431
7496
|
}
|
|
7432
|
-
__name(
|
|
7497
|
+
__name(follow, "follow");
|
|
7433
7498
|
function isDateLike(value) {
|
|
7434
7499
|
return util.types.isDate(value) || util.types.isProxy(value) && value instanceof Date;
|
|
7435
7500
|
}
|
|
@@ -7451,17 +7516,22 @@ function isHostInstance(value) {
|
|
|
7451
7516
|
return typeof value === "object" && value !== null && !Array.isArray(value) && !util.types.isBoxedPrimitive(value) && !isPlainObject(value);
|
|
7452
7517
|
}
|
|
7453
7518
|
__name(isHostInstance, "isHostInstance");
|
|
7519
|
+
function timeOf(date) {
|
|
7520
|
+
const real = util.types.isDate(date);
|
|
7521
|
+
return real ? Date.prototype.getTime.call(date) : date.getTime();
|
|
7522
|
+
}
|
|
7523
|
+
__name(timeOf, "timeOf");
|
|
7454
7524
|
function copyDate(value) {
|
|
7455
7525
|
if (typeof value !== "object" || value === null || !isDateLike(value)) throw new Error(WRONG_KIND);
|
|
7456
|
-
const time = value
|
|
7526
|
+
const time = timeOf(value);
|
|
7457
7527
|
const copy = new Date(typeof time === "number" ? time : Number.NaN);
|
|
7458
7528
|
if (Number.isNaN(copy.getTime())) throw new Error(NOT_A_TIME);
|
|
7459
7529
|
return copy;
|
|
7460
7530
|
}
|
|
7461
7531
|
__name(copyDate, "copyDate");
|
|
7462
|
-
function copyStrings(value) {
|
|
7532
|
+
function copyStrings(value, read) {
|
|
7463
7533
|
if (!Array.isArray(value)) throw new Error(WRONG_KIND);
|
|
7464
|
-
|
|
7534
|
+
follow(read, value.length);
|
|
7465
7535
|
const copy = [];
|
|
7466
7536
|
for (let index = 0; index < value.length; index += 1) {
|
|
7467
7537
|
const element = value[index];
|
|
@@ -7470,6 +7540,14 @@ function copyStrings(value) {
|
|
|
7470
7540
|
return copy;
|
|
7471
7541
|
}
|
|
7472
7542
|
__name(copyStrings, "copyStrings");
|
|
7543
|
+
function readId(value) {
|
|
7544
|
+
if (typeof value === "string") return accept(value !== "", value);
|
|
7545
|
+
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);
|
|
7549
|
+
}
|
|
7550
|
+
__name(readId, "readId");
|
|
7473
7551
|
function readInforming(value) {
|
|
7474
7552
|
return accept(typeof value === "string" || Number.isFinite(value) || isHostInstance(value), value);
|
|
7475
7553
|
}
|
|
@@ -7478,7 +7556,7 @@ function readInformingDate(value) {
|
|
|
7478
7556
|
if (typeof value === "string" || Number.isFinite(value)) return value;
|
|
7479
7557
|
if (!isHostInstance(value)) throw new Error(WRONG_KIND);
|
|
7480
7558
|
if (!isDateLike(value)) return value;
|
|
7481
|
-
const time = value
|
|
7559
|
+
const time = timeOf(value);
|
|
7482
7560
|
const copy = new Date(typeof time === "number" ? time : Number.NaN);
|
|
7483
7561
|
return Number.isNaN(copy.getTime()) ? value : copy;
|
|
7484
7562
|
}
|
|
@@ -7487,10 +7565,9 @@ var READERS = {
|
|
|
7487
7565
|
boolean: /* @__PURE__ */ __name((value) => accept(typeof value === "boolean", value), "boolean"),
|
|
7488
7566
|
string: /* @__PURE__ */ __name((value) => accept(typeof value === "string", value), "string"),
|
|
7489
7567
|
number: /* @__PURE__ */ __name((value) => accept(Number.isFinite(value), value), "number"),
|
|
7490
|
-
id: /* @__PURE__ */ __name((value) => accept(typeof value === "string" || isHostInstance(value), value), "id"),
|
|
7491
7568
|
date: copyDate,
|
|
7492
7569
|
strings: copyStrings,
|
|
7493
|
-
"~id":
|
|
7570
|
+
"~id": readId,
|
|
7494
7571
|
"~string": readInforming,
|
|
7495
7572
|
"~date": readInformingDate
|
|
7496
7573
|
};
|
|
@@ -7511,19 +7588,19 @@ function readNull(nullable) {
|
|
|
7511
7588
|
return null;
|
|
7512
7589
|
}
|
|
7513
7590
|
__name(readNull, "readNull");
|
|
7514
|
-
function readScalar(value, spec) {
|
|
7591
|
+
function readScalar(value, spec, run) {
|
|
7515
7592
|
const { base, nullable } = parseSpec(spec);
|
|
7516
7593
|
if (base === "void") return void 0;
|
|
7517
|
-
return value === null ? readNull(nullable) : READERS[base](value);
|
|
7594
|
+
return value === null ? readNull(nullable) : READERS[base](value, run);
|
|
7518
7595
|
}
|
|
7519
7596
|
__name(readScalar, "readScalar");
|
|
7520
|
-
function copyRecord(value, contract,
|
|
7597
|
+
function copyRecord(value, contract, run) {
|
|
7521
7598
|
const copy = {};
|
|
7522
|
-
rememberUnder(
|
|
7599
|
+
rememberUnder(run, value, contract, copy);
|
|
7523
7600
|
ENTITIES.set(copy, value);
|
|
7524
7601
|
const source = value;
|
|
7525
7602
|
const keys = Object.keys(value);
|
|
7526
|
-
|
|
7603
|
+
follow(run, keys.length);
|
|
7527
7604
|
for (const key of keys) {
|
|
7528
7605
|
if (Object.hasOwn(contract.fields, key)) continue;
|
|
7529
7606
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
@@ -7532,38 +7609,42 @@ function copyRecord(value, contract, seen) {
|
|
|
7532
7609
|
const own = new Set(keys);
|
|
7533
7610
|
for (const [field, spec] of Object.entries(contract.fields)) {
|
|
7534
7611
|
const { base, nullable, optional } = parseSpec(spec);
|
|
7535
|
-
const
|
|
7536
|
-
if (
|
|
7612
|
+
const held = source[field];
|
|
7613
|
+
if (held === void 0) {
|
|
7537
7614
|
if (optional) continue;
|
|
7538
7615
|
throw new Error(ABSENT);
|
|
7539
7616
|
}
|
|
7540
|
-
const copied =
|
|
7617
|
+
const copied = held === null ? readNull(nullable || optional) : base === "nested" ? applyContract(held, contract.nested[field], run) : READERS[base](held, run);
|
|
7541
7618
|
define(copy, field, copied, own.has(field) || !CREDENTIAL_FIELDS.has(field));
|
|
7542
7619
|
}
|
|
7543
7620
|
return copy;
|
|
7544
7621
|
}
|
|
7545
7622
|
__name(copyRecord, "copyRecord");
|
|
7546
|
-
function applyContract(value, contract,
|
|
7623
|
+
function applyContract(value, contract, run) {
|
|
7547
7624
|
if (typeof value !== "object" || value === null) throw new Error(WRONG_KIND);
|
|
7548
|
-
const known = copiedUnder(
|
|
7625
|
+
const known = copiedUnder(run, value, contract);
|
|
7549
7626
|
if (known !== void 0) return known;
|
|
7550
7627
|
if ("list" in contract) {
|
|
7551
7628
|
if (!Array.isArray(value)) throw new Error("the answer is not the list its method promises");
|
|
7552
|
-
|
|
7629
|
+
follow(run, value.length);
|
|
7553
7630
|
const copy = [];
|
|
7554
|
-
rememberUnder(
|
|
7555
|
-
for (let index = 0; index < value.length; index += 1) copy.push(applyContract(value[index], contract.list,
|
|
7631
|
+
rememberUnder(run, value, contract, copy);
|
|
7632
|
+
for (let index = 0; index < value.length; index += 1) copy.push(applyContract(value[index], contract.list, run));
|
|
7556
7633
|
return copy;
|
|
7557
7634
|
}
|
|
7558
7635
|
if (Array.isArray(value)) throw new Error("the answer is not the record its method promises");
|
|
7559
|
-
return copyRecord(value, contract,
|
|
7636
|
+
return copyRecord(value, contract, run);
|
|
7560
7637
|
}
|
|
7561
7638
|
__name(applyContract, "applyContract");
|
|
7562
7639
|
function copyHostRecord(record, contract) {
|
|
7563
7640
|
try {
|
|
7564
|
-
|
|
7641
|
+
const run = {
|
|
7642
|
+
copies: /* @__PURE__ */ new WeakMap(),
|
|
7643
|
+
nodes: MAX_NODES
|
|
7644
|
+
};
|
|
7645
|
+
if (typeof contract === "string") return readScalar(record, contract, run);
|
|
7565
7646
|
if ((record === null || record === void 0) && contract.nullable === true) return record;
|
|
7566
|
-
return applyContract(record, contract,
|
|
7647
|
+
return applyContract(record, contract, run);
|
|
7567
7648
|
} catch (error) {
|
|
7568
7649
|
throw new AuthException(AUTH_ERROR_CODES.INTERNAL, void 0, {
|
|
7569
7650
|
cause: error
|
|
@@ -8580,7 +8661,7 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
8580
8661
|
accessSignOptions() {
|
|
8581
8662
|
return {
|
|
8582
8663
|
expiresIn: this.options.jwt.accessExpiresIn,
|
|
8583
|
-
|
|
8664
|
+
...signerOf(this.options),
|
|
8584
8665
|
...this.issuerAudience()
|
|
8585
8666
|
};
|
|
8586
8667
|
}
|
|
@@ -9366,7 +9447,7 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
9366
9447
|
};
|
|
9367
9448
|
const token = this.jwtService.sign(payload, {
|
|
9368
9449
|
expiresIn: `${MFA_TEMP_TOKEN_TTL_SECONDS}s`,
|
|
9369
|
-
|
|
9450
|
+
...signerOf(this.options),
|
|
9370
9451
|
// The challenge token is stamped and checked like every other: it grants no resource
|
|
9371
9452
|
// access on its own, but it is still a token this backend minted, and a verifier that
|
|
9372
9453
|
// exempted one shape would be a verifier an attacker aims at.
|
|
@@ -10391,13 +10472,13 @@ exports.AuthService = class _AuthService {
|
|
|
10391
10472
|
await sleep(Math.max(0, ANTI_ENUM_MIN_MS - (Date.now() - start)));
|
|
10392
10473
|
return;
|
|
10393
10474
|
}
|
|
10394
|
-
|
|
10395
|
-
|
|
10396
|
-
|
|
10397
|
-
|
|
10398
|
-
|
|
10399
|
-
await this.sendVerificationOtp(tenantId, email);
|
|
10400
|
-
}
|
|
10475
|
+
await releasingCooldownOnFailure(this.redis, this.logger, cooldownKey, async () => {
|
|
10476
|
+
const user = tenantScoped(await this.userRepo.findByEmail({
|
|
10477
|
+
email,
|
|
10478
|
+
tenantId
|
|
10479
|
+
}), tenantId);
|
|
10480
|
+
if (user && !user.emailVerified) await this.sendVerificationOtp(tenantId, email);
|
|
10481
|
+
});
|
|
10401
10482
|
await sleep(Math.max(0, ANTI_ENUM_MIN_MS - (Date.now() - start)));
|
|
10402
10483
|
}
|
|
10403
10484
|
// ---------------------------------------------------------------------------
|
|
@@ -18028,6 +18109,9 @@ exports.WorkspaceAccessService = class _WorkspaceAccessService {
|
|
|
18028
18109
|
if (membership?.status !== "active" || workspace === null) return {
|
|
18029
18110
|
kind: "denied"
|
|
18030
18111
|
};
|
|
18112
|
+
if (workspace.tenantId !== ref.tenantId || membership.tenantId !== ref.tenantId) return {
|
|
18113
|
+
kind: "denied"
|
|
18114
|
+
};
|
|
18031
18115
|
const member = {
|
|
18032
18116
|
...ref,
|
|
18033
18117
|
role: membership.role
|
|
@@ -26776,9 +26860,8 @@ exports.BymaxAuthModule = class _BymaxAuthModule {
|
|
|
26776
26860
|
...includeApiKeys ? [
|
|
26777
26861
|
core.DiscoveryModule
|
|
26778
26862
|
] : [],
|
|
26779
|
-
//
|
|
26780
|
-
//
|
|
26781
|
-
// in the BYMAX_AUTH_OPTIONS provider above.
|
|
26863
|
+
// A second call of the consumer factory, not resolveOptions: what it answers is not what the
|
|
26864
|
+
// BYMAX_AUTH_OPTIONS provider validated, so every sign and verify names the resolved secret.
|
|
26782
26865
|
// expiresIn is omitted — TokenManagerService sets it per-call via accessSignOptions().
|
|
26783
26866
|
jwt.JwtModule.registerAsync({
|
|
26784
26867
|
// The factory runs here too, so it needs the modules the consumer's `inject` tokens come from.
|
package/dist/server/index.mjs
CHANGED
|
@@ -828,7 +828,10 @@ var OBJECT_GROUPS = [
|
|
|
828
828
|
"platform",
|
|
829
829
|
"invitations",
|
|
830
830
|
"emailChange",
|
|
831
|
-
"oauth"
|
|
831
|
+
"oauth",
|
|
832
|
+
"roles",
|
|
833
|
+
"workspaces",
|
|
834
|
+
"workspaces.roles"
|
|
832
835
|
];
|
|
833
836
|
function readPath2(root, path) {
|
|
834
837
|
let node = root;
|
|
@@ -1025,6 +1028,10 @@ var WORKSPACE_SUBGROUP_KEYS = {
|
|
|
1025
1028
|
accessDeniedEvents: [
|
|
1026
1029
|
"max",
|
|
1027
1030
|
"windowSeconds"
|
|
1031
|
+
],
|
|
1032
|
+
roles: [
|
|
1033
|
+
"hierarchy",
|
|
1034
|
+
"ownerRole"
|
|
1028
1035
|
]
|
|
1029
1036
|
};
|
|
1030
1037
|
function isObjectGroup(value) {
|
|
@@ -1074,7 +1081,7 @@ function dropUnset(options) {
|
|
|
1074
1081
|
if (name === "workspaces") {
|
|
1075
1082
|
for (const [sub, subKeys] of Object.entries(WORKSPACE_SUBGROUP_KEYS)) {
|
|
1076
1083
|
const inner = group[sub];
|
|
1077
|
-
if (isObjectGroup(inner)) group[sub] = readSetKeys(inner, subKeys);
|
|
1084
|
+
if (isObjectGroup(inner)) group[sub] = (sub === "roles" ? readKeptKeys : readSetKeys)(inner, subKeys);
|
|
1078
1085
|
}
|
|
1079
1086
|
}
|
|
1080
1087
|
copy[name] = group;
|
|
@@ -1098,9 +1105,46 @@ __name(dropUnset, "dropUnset");
|
|
|
1098
1105
|
function readOptions(given) {
|
|
1099
1106
|
const options = dropUnset(given);
|
|
1100
1107
|
validateTextOptions(options);
|
|
1101
|
-
return options;
|
|
1108
|
+
return pinHierarchies(options);
|
|
1102
1109
|
}
|
|
1103
1110
|
__name(readOptions, "readOptions");
|
|
1111
|
+
function copyHierarchy(held) {
|
|
1112
|
+
if (Object(held) !== held) return held;
|
|
1113
|
+
return Object.fromEntries(Object.entries(held).map(([role, children]) => [
|
|
1114
|
+
role,
|
|
1115
|
+
Array.isArray(children) ? [
|
|
1116
|
+
...children
|
|
1117
|
+
] : children
|
|
1118
|
+
]));
|
|
1119
|
+
}
|
|
1120
|
+
__name(copyHierarchy, "copyHierarchy");
|
|
1121
|
+
function pinIn(group, keys) {
|
|
1122
|
+
if (Object(group) !== group) return group;
|
|
1123
|
+
const plain = group;
|
|
1124
|
+
for (const key of keys) if (plain[key] !== void 0) plain[key] = copyHierarchy(plain[key]);
|
|
1125
|
+
return group;
|
|
1126
|
+
}
|
|
1127
|
+
__name(pinIn, "pinIn");
|
|
1128
|
+
function pinHierarchies(options) {
|
|
1129
|
+
const { roles, workspaces } = options;
|
|
1130
|
+
const { roles: workspaceRoles, ...workspaceRest } = workspaces ?? {};
|
|
1131
|
+
return {
|
|
1132
|
+
...options,
|
|
1133
|
+
roles: pinIn(roles, [
|
|
1134
|
+
"hierarchy",
|
|
1135
|
+
"platformHierarchy"
|
|
1136
|
+
]),
|
|
1137
|
+
...workspaceRoles === void 0 ? {} : {
|
|
1138
|
+
workspaces: {
|
|
1139
|
+
...workspaceRest,
|
|
1140
|
+
roles: pinIn(workspaceRoles, [
|
|
1141
|
+
"hierarchy"
|
|
1142
|
+
])
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
__name(pinHierarchies, "pinHierarchies");
|
|
1104
1148
|
function validateOptionValues(userOptions) {
|
|
1105
1149
|
validateNumericOptions(userOptions);
|
|
1106
1150
|
validateEnumAndBooleanOptions(userOptions);
|
|
@@ -5433,26 +5477,34 @@ function malformedRefreshToken() {
|
|
|
5433
5477
|
__name(malformedRefreshToken, "malformedRefreshToken");
|
|
5434
5478
|
|
|
5435
5479
|
// src/server/utils/verify-with-rotation.ts
|
|
5480
|
+
function signerOf(options) {
|
|
5481
|
+
return {
|
|
5482
|
+
secret: options.jwt.secret,
|
|
5483
|
+
algorithm: options.jwt.algorithm
|
|
5484
|
+
};
|
|
5485
|
+
}
|
|
5486
|
+
__name(signerOf, "signerOf");
|
|
5436
5487
|
function verifyWithRotation(jwtService, options, token, { ignoreExpiration = false } = {}) {
|
|
5437
5488
|
const algorithms = [
|
|
5438
5489
|
options.jwt.algorithm
|
|
5439
5490
|
];
|
|
5440
|
-
const { issuer, audience } = options.jwt;
|
|
5491
|
+
const { issuer, audience, secret } = options.jwt;
|
|
5441
5492
|
const base = {
|
|
5442
5493
|
algorithms,
|
|
5443
5494
|
ignoreExpiration,
|
|
5444
5495
|
issuer,
|
|
5445
|
-
audience
|
|
5496
|
+
audience,
|
|
5497
|
+
secret
|
|
5446
5498
|
};
|
|
5447
5499
|
try {
|
|
5448
5500
|
return jwtService.verify(token, base);
|
|
5449
5501
|
} catch (currentFailure) {
|
|
5450
5502
|
const previous = options.jwt.previousSecrets ?? [];
|
|
5451
|
-
for (const
|
|
5503
|
+
for (const secret2 of previous) {
|
|
5452
5504
|
try {
|
|
5453
5505
|
return jwtService.verify(token, {
|
|
5454
5506
|
...base,
|
|
5455
|
-
secret
|
|
5507
|
+
secret: secret2
|
|
5456
5508
|
});
|
|
5457
5509
|
} catch {
|
|
5458
5510
|
}
|
|
@@ -6647,6 +6699,17 @@ function _ts_param11(paramIndex, decorator) {
|
|
|
6647
6699
|
};
|
|
6648
6700
|
}
|
|
6649
6701
|
__name(_ts_param11, "_ts_param");
|
|
6702
|
+
async function releasingCooldownOnFailure(redis, logger, cooldownKey, work) {
|
|
6703
|
+
try {
|
|
6704
|
+
return await work();
|
|
6705
|
+
} catch (error) {
|
|
6706
|
+
await redis.del(cooldownKey).catch((err) => {
|
|
6707
|
+
logStore(logger, "AUTH_STORE_FAILED", "resend_cooldown_release", err);
|
|
6708
|
+
});
|
|
6709
|
+
throw error;
|
|
6710
|
+
}
|
|
6711
|
+
}
|
|
6712
|
+
__name(releasingCooldownOnFailure, "releasingCooldownOnFailure");
|
|
6650
6713
|
var MAX_ATTEMPTS = 5;
|
|
6651
6714
|
var MIN_VERIFY_MS = 100;
|
|
6652
6715
|
var OTP_STORE_LUA = `
|
|
@@ -7158,7 +7221,7 @@ var RECORD_CONTRACTS = {
|
|
|
7158
7221
|
workspace: {
|
|
7159
7222
|
fields: {
|
|
7160
7223
|
id: "~id",
|
|
7161
|
-
tenantId: "
|
|
7224
|
+
tenantId: "string",
|
|
7162
7225
|
name: "~string",
|
|
7163
7226
|
status: "string",
|
|
7164
7227
|
createdAt: "~date",
|
|
@@ -7168,7 +7231,7 @@ var RECORD_CONTRACTS = {
|
|
|
7168
7231
|
},
|
|
7169
7232
|
membership: {
|
|
7170
7233
|
fields: {
|
|
7171
|
-
tenantId: "
|
|
7234
|
+
tenantId: "string",
|
|
7172
7235
|
workspaceId: "~id",
|
|
7173
7236
|
userId: "~id",
|
|
7174
7237
|
role: "string",
|
|
@@ -7187,7 +7250,7 @@ var RECORD_CONTRACTS = {
|
|
|
7187
7250
|
passwordHash: "string|null",
|
|
7188
7251
|
role: "string",
|
|
7189
7252
|
status: "string",
|
|
7190
|
-
tenantId: "
|
|
7253
|
+
tenantId: "string",
|
|
7191
7254
|
emailVerified: "boolean",
|
|
7192
7255
|
mfaEnabled: "boolean",
|
|
7193
7256
|
mfaSecret: "string?",
|
|
@@ -7371,14 +7434,15 @@ var CREDENTIAL_FIELDS = /* @__PURE__ */ new Set([
|
|
|
7371
7434
|
|
|
7372
7435
|
// src/server/utils/host-read.ts
|
|
7373
7436
|
var MAX_BREADTH = 1e5;
|
|
7374
|
-
|
|
7375
|
-
|
|
7437
|
+
var MAX_NODES = 1e6;
|
|
7438
|
+
function copiedUnder(read, value, contract) {
|
|
7439
|
+
return read.copies.get(value)?.get(contract);
|
|
7376
7440
|
}
|
|
7377
7441
|
__name(copiedUnder, "copiedUnder");
|
|
7378
|
-
function rememberUnder(
|
|
7379
|
-
const copies =
|
|
7442
|
+
function rememberUnder(read, value, contract, copy) {
|
|
7443
|
+
const copies = read.copies.get(value) ?? /* @__PURE__ */ new Map();
|
|
7380
7444
|
copies.set(contract, copy);
|
|
7381
|
-
|
|
7445
|
+
read.copies.set(value, copies);
|
|
7382
7446
|
}
|
|
7383
7447
|
__name(rememberUnder, "rememberUnder");
|
|
7384
7448
|
function readHostOptions(read) {
|
|
@@ -7424,10 +7488,11 @@ function define(copy, key, value, enumerable) {
|
|
|
7424
7488
|
}
|
|
7425
7489
|
__name(define, "define");
|
|
7426
7490
|
var ENTITIES = /* @__PURE__ */ new WeakMap();
|
|
7427
|
-
function
|
|
7428
|
-
|
|
7491
|
+
function follow(read, size) {
|
|
7492
|
+
read.nodes -= size;
|
|
7493
|
+
if (size > MAX_BREADTH || read.nodes < 0) throw new Error("the answer holds more than the library follows");
|
|
7429
7494
|
}
|
|
7430
|
-
__name(
|
|
7495
|
+
__name(follow, "follow");
|
|
7431
7496
|
function isDateLike(value) {
|
|
7432
7497
|
return types.isDate(value) || types.isProxy(value) && value instanceof Date;
|
|
7433
7498
|
}
|
|
@@ -7449,17 +7514,22 @@ function isHostInstance(value) {
|
|
|
7449
7514
|
return typeof value === "object" && value !== null && !Array.isArray(value) && !types.isBoxedPrimitive(value) && !isPlainObject(value);
|
|
7450
7515
|
}
|
|
7451
7516
|
__name(isHostInstance, "isHostInstance");
|
|
7517
|
+
function timeOf(date) {
|
|
7518
|
+
const real = types.isDate(date);
|
|
7519
|
+
return real ? Date.prototype.getTime.call(date) : date.getTime();
|
|
7520
|
+
}
|
|
7521
|
+
__name(timeOf, "timeOf");
|
|
7452
7522
|
function copyDate(value) {
|
|
7453
7523
|
if (typeof value !== "object" || value === null || !isDateLike(value)) throw new Error(WRONG_KIND);
|
|
7454
|
-
const time = value
|
|
7524
|
+
const time = timeOf(value);
|
|
7455
7525
|
const copy = new Date(typeof time === "number" ? time : Number.NaN);
|
|
7456
7526
|
if (Number.isNaN(copy.getTime())) throw new Error(NOT_A_TIME);
|
|
7457
7527
|
return copy;
|
|
7458
7528
|
}
|
|
7459
7529
|
__name(copyDate, "copyDate");
|
|
7460
|
-
function copyStrings(value) {
|
|
7530
|
+
function copyStrings(value, read) {
|
|
7461
7531
|
if (!Array.isArray(value)) throw new Error(WRONG_KIND);
|
|
7462
|
-
|
|
7532
|
+
follow(read, value.length);
|
|
7463
7533
|
const copy = [];
|
|
7464
7534
|
for (let index = 0; index < value.length; index += 1) {
|
|
7465
7535
|
const element = value[index];
|
|
@@ -7468,6 +7538,14 @@ function copyStrings(value) {
|
|
|
7468
7538
|
return copy;
|
|
7469
7539
|
}
|
|
7470
7540
|
__name(copyStrings, "copyStrings");
|
|
7541
|
+
function readId(value) {
|
|
7542
|
+
if (typeof value === "string") return accept(value !== "", value);
|
|
7543
|
+
if (typeof value === "number") return accept(Number.isSafeInteger(value), String(value));
|
|
7544
|
+
if (!isHostInstance(value) || types.isDate(value) || types.isRegExp(value)) throw new Error(WRONG_KIND);
|
|
7545
|
+
const printed = String(value);
|
|
7546
|
+
return accept(printed !== "" && !printed.startsWith("[object "), printed);
|
|
7547
|
+
}
|
|
7548
|
+
__name(readId, "readId");
|
|
7471
7549
|
function readInforming(value) {
|
|
7472
7550
|
return accept(typeof value === "string" || Number.isFinite(value) || isHostInstance(value), value);
|
|
7473
7551
|
}
|
|
@@ -7476,7 +7554,7 @@ function readInformingDate(value) {
|
|
|
7476
7554
|
if (typeof value === "string" || Number.isFinite(value)) return value;
|
|
7477
7555
|
if (!isHostInstance(value)) throw new Error(WRONG_KIND);
|
|
7478
7556
|
if (!isDateLike(value)) return value;
|
|
7479
|
-
const time = value
|
|
7557
|
+
const time = timeOf(value);
|
|
7480
7558
|
const copy = new Date(typeof time === "number" ? time : Number.NaN);
|
|
7481
7559
|
return Number.isNaN(copy.getTime()) ? value : copy;
|
|
7482
7560
|
}
|
|
@@ -7485,10 +7563,9 @@ var READERS = {
|
|
|
7485
7563
|
boolean: /* @__PURE__ */ __name((value) => accept(typeof value === "boolean", value), "boolean"),
|
|
7486
7564
|
string: /* @__PURE__ */ __name((value) => accept(typeof value === "string", value), "string"),
|
|
7487
7565
|
number: /* @__PURE__ */ __name((value) => accept(Number.isFinite(value), value), "number"),
|
|
7488
|
-
id: /* @__PURE__ */ __name((value) => accept(typeof value === "string" || isHostInstance(value), value), "id"),
|
|
7489
7566
|
date: copyDate,
|
|
7490
7567
|
strings: copyStrings,
|
|
7491
|
-
"~id":
|
|
7568
|
+
"~id": readId,
|
|
7492
7569
|
"~string": readInforming,
|
|
7493
7570
|
"~date": readInformingDate
|
|
7494
7571
|
};
|
|
@@ -7509,19 +7586,19 @@ function readNull(nullable) {
|
|
|
7509
7586
|
return null;
|
|
7510
7587
|
}
|
|
7511
7588
|
__name(readNull, "readNull");
|
|
7512
|
-
function readScalar(value, spec) {
|
|
7589
|
+
function readScalar(value, spec, run) {
|
|
7513
7590
|
const { base, nullable } = parseSpec(spec);
|
|
7514
7591
|
if (base === "void") return void 0;
|
|
7515
|
-
return value === null ? readNull(nullable) : READERS[base](value);
|
|
7592
|
+
return value === null ? readNull(nullable) : READERS[base](value, run);
|
|
7516
7593
|
}
|
|
7517
7594
|
__name(readScalar, "readScalar");
|
|
7518
|
-
function copyRecord(value, contract,
|
|
7595
|
+
function copyRecord(value, contract, run) {
|
|
7519
7596
|
const copy = {};
|
|
7520
|
-
rememberUnder(
|
|
7597
|
+
rememberUnder(run, value, contract, copy);
|
|
7521
7598
|
ENTITIES.set(copy, value);
|
|
7522
7599
|
const source = value;
|
|
7523
7600
|
const keys = Object.keys(value);
|
|
7524
|
-
|
|
7601
|
+
follow(run, keys.length);
|
|
7525
7602
|
for (const key of keys) {
|
|
7526
7603
|
if (Object.hasOwn(contract.fields, key)) continue;
|
|
7527
7604
|
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
@@ -7530,38 +7607,42 @@ function copyRecord(value, contract, seen) {
|
|
|
7530
7607
|
const own = new Set(keys);
|
|
7531
7608
|
for (const [field, spec] of Object.entries(contract.fields)) {
|
|
7532
7609
|
const { base, nullable, optional } = parseSpec(spec);
|
|
7533
|
-
const
|
|
7534
|
-
if (
|
|
7610
|
+
const held = source[field];
|
|
7611
|
+
if (held === void 0) {
|
|
7535
7612
|
if (optional) continue;
|
|
7536
7613
|
throw new Error(ABSENT);
|
|
7537
7614
|
}
|
|
7538
|
-
const copied =
|
|
7615
|
+
const copied = held === null ? readNull(nullable || optional) : base === "nested" ? applyContract(held, contract.nested[field], run) : READERS[base](held, run);
|
|
7539
7616
|
define(copy, field, copied, own.has(field) || !CREDENTIAL_FIELDS.has(field));
|
|
7540
7617
|
}
|
|
7541
7618
|
return copy;
|
|
7542
7619
|
}
|
|
7543
7620
|
__name(copyRecord, "copyRecord");
|
|
7544
|
-
function applyContract(value, contract,
|
|
7621
|
+
function applyContract(value, contract, run) {
|
|
7545
7622
|
if (typeof value !== "object" || value === null) throw new Error(WRONG_KIND);
|
|
7546
|
-
const known = copiedUnder(
|
|
7623
|
+
const known = copiedUnder(run, value, contract);
|
|
7547
7624
|
if (known !== void 0) return known;
|
|
7548
7625
|
if ("list" in contract) {
|
|
7549
7626
|
if (!Array.isArray(value)) throw new Error("the answer is not the list its method promises");
|
|
7550
|
-
|
|
7627
|
+
follow(run, value.length);
|
|
7551
7628
|
const copy = [];
|
|
7552
|
-
rememberUnder(
|
|
7553
|
-
for (let index = 0; index < value.length; index += 1) copy.push(applyContract(value[index], contract.list,
|
|
7629
|
+
rememberUnder(run, value, contract, copy);
|
|
7630
|
+
for (let index = 0; index < value.length; index += 1) copy.push(applyContract(value[index], contract.list, run));
|
|
7554
7631
|
return copy;
|
|
7555
7632
|
}
|
|
7556
7633
|
if (Array.isArray(value)) throw new Error("the answer is not the record its method promises");
|
|
7557
|
-
return copyRecord(value, contract,
|
|
7634
|
+
return copyRecord(value, contract, run);
|
|
7558
7635
|
}
|
|
7559
7636
|
__name(applyContract, "applyContract");
|
|
7560
7637
|
function copyHostRecord(record, contract) {
|
|
7561
7638
|
try {
|
|
7562
|
-
|
|
7639
|
+
const run = {
|
|
7640
|
+
copies: /* @__PURE__ */ new WeakMap(),
|
|
7641
|
+
nodes: MAX_NODES
|
|
7642
|
+
};
|
|
7643
|
+
if (typeof contract === "string") return readScalar(record, contract, run);
|
|
7563
7644
|
if ((record === null || record === void 0) && contract.nullable === true) return record;
|
|
7564
|
-
return applyContract(record, contract,
|
|
7645
|
+
return applyContract(record, contract, run);
|
|
7565
7646
|
} catch (error) {
|
|
7566
7647
|
throw new AuthException(AUTH_ERROR_CODES.INTERNAL, void 0, {
|
|
7567
7648
|
cause: error
|
|
@@ -8578,7 +8659,7 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
8578
8659
|
accessSignOptions() {
|
|
8579
8660
|
return {
|
|
8580
8661
|
expiresIn: this.options.jwt.accessExpiresIn,
|
|
8581
|
-
|
|
8662
|
+
...signerOf(this.options),
|
|
8582
8663
|
...this.issuerAudience()
|
|
8583
8664
|
};
|
|
8584
8665
|
}
|
|
@@ -9364,7 +9445,7 @@ var TokenManagerService = class _TokenManagerService {
|
|
|
9364
9445
|
};
|
|
9365
9446
|
const token = this.jwtService.sign(payload, {
|
|
9366
9447
|
expiresIn: `${MFA_TEMP_TOKEN_TTL_SECONDS}s`,
|
|
9367
|
-
|
|
9448
|
+
...signerOf(this.options),
|
|
9368
9449
|
// The challenge token is stamped and checked like every other: it grants no resource
|
|
9369
9450
|
// access on its own, but it is still a token this backend minted, and a verifier that
|
|
9370
9451
|
// exempted one shape would be a verifier an attacker aims at.
|
|
@@ -10389,13 +10470,13 @@ var AuthService = class _AuthService {
|
|
|
10389
10470
|
await sleep(Math.max(0, ANTI_ENUM_MIN_MS - (Date.now() - start)));
|
|
10390
10471
|
return;
|
|
10391
10472
|
}
|
|
10392
|
-
|
|
10393
|
-
|
|
10394
|
-
|
|
10395
|
-
|
|
10396
|
-
|
|
10397
|
-
await this.sendVerificationOtp(tenantId, email);
|
|
10398
|
-
}
|
|
10473
|
+
await releasingCooldownOnFailure(this.redis, this.logger, cooldownKey, async () => {
|
|
10474
|
+
const user = tenantScoped(await this.userRepo.findByEmail({
|
|
10475
|
+
email,
|
|
10476
|
+
tenantId
|
|
10477
|
+
}), tenantId);
|
|
10478
|
+
if (user && !user.emailVerified) await this.sendVerificationOtp(tenantId, email);
|
|
10479
|
+
});
|
|
10399
10480
|
await sleep(Math.max(0, ANTI_ENUM_MIN_MS - (Date.now() - start)));
|
|
10400
10481
|
}
|
|
10401
10482
|
// ---------------------------------------------------------------------------
|
|
@@ -18026,6 +18107,9 @@ var WorkspaceAccessService = class _WorkspaceAccessService {
|
|
|
18026
18107
|
if (membership?.status !== "active" || workspace === null) return {
|
|
18027
18108
|
kind: "denied"
|
|
18028
18109
|
};
|
|
18110
|
+
if (workspace.tenantId !== ref.tenantId || membership.tenantId !== ref.tenantId) return {
|
|
18111
|
+
kind: "denied"
|
|
18112
|
+
};
|
|
18029
18113
|
const member = {
|
|
18030
18114
|
...ref,
|
|
18031
18115
|
role: membership.role
|
|
@@ -26774,9 +26858,8 @@ var BymaxAuthModule = class _BymaxAuthModule {
|
|
|
26774
26858
|
...includeApiKeys ? [
|
|
26775
26859
|
DiscoveryModule
|
|
26776
26860
|
] : [],
|
|
26777
|
-
//
|
|
26778
|
-
//
|
|
26779
|
-
// in the BYMAX_AUTH_OPTIONS provider above.
|
|
26861
|
+
// A second call of the consumer factory, not resolveOptions: what it answers is not what the
|
|
26862
|
+
// BYMAX_AUTH_OPTIONS provider validated, so every sign and verify names the resolved secret.
|
|
26780
26863
|
// expiresIn is omitted — TokenManagerService sets it per-call via accessSignOptions().
|
|
26781
26864
|
JwtModule.registerAsync({
|
|
26782
26865
|
// The factory runs here too, so it needs the modules the consumer's `inject` tokens come from.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymax-one/nest-auth",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.13",
|
|
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",
|