@bymax-one/nest-auth 1.5.13 → 1.5.14
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 +37 -1
- package/dist/server/index.cjs +138 -52
- package/dist/server/index.mjs +138 -52
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -18,6 +18,41 @@ what moves, and that note is the compatibility contract until strict SemVer begi
|
|
|
18
18
|
|
|
19
19
|
## [Unreleased]
|
|
20
20
|
|
|
21
|
+
## [1.5.14] - 2026-11-22
|
|
22
|
+
|
|
23
|
+
A patch release.
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- **The lists a host keeps in its options are read once and what is checked is what is kept.** The permissions of the
|
|
28
|
+
workspaces (`manageWorkspace`, `deleteWorkspace`, `manageMembers`, `viewMembers`) were validated through their own
|
|
29
|
+
entries and then read again by property and kept as the host's arrays: a typed configuration class that served them on
|
|
30
|
+
its prototype was never validated, and a change by the host after start reached the authorization table. They are read
|
|
31
|
+
by property like the other groups and kept as copies, and so are `jwt.previousSecrets`,
|
|
32
|
+
`mfa.previousEncryptionKeys` and `apiKeys.scopes`, whose strength and format checks ran once at start.
|
|
33
|
+
`jwt`, `mfa`, `apiKeys` and `workspaces.permissions` must be objects: a function, an array or a primitive given for
|
|
34
|
+
one is refused with `[BymaxAuthModule] <option> must be an object (received …)`.
|
|
35
|
+
- **The id of a row is required.** The ids of a user, a platform user, an API key, a workspace and of a membership (its
|
|
36
|
+
workspace and its user) were accepted when absent or `null`, so a row without an id logged in with a token whose
|
|
37
|
+
subject was nothing. Each is refused as `auth.internal` when it is absent, `undefined` or `null`; an id that
|
|
38
|
+
is optional by design, such as the user that invited a member, is still accepted when absent.
|
|
39
|
+
- **A resend of the verification code gives the cooldown back when the code cannot be stored.** The write of the code
|
|
40
|
+
to the store was the one failure on the path that the response had not left yet and that kept the cooldown. A request
|
|
41
|
+
that finds no account, or an account that is already verified, still keeps it, so the throttle never tells the two
|
|
42
|
+
apart. A mail provider that fails after the response left does not release it: a delete by key from there could remove
|
|
43
|
+
the cooldown of a later request, so the user retries after the minute.
|
|
44
|
+
- **The hierarchy of the platform is judged as the others are.** When the platform is enabled, `roles.platformHierarchy`
|
|
45
|
+
must be an object that names at least one role, whose children are lists of roles it declares (a string, a number, a
|
|
46
|
+
child that is no list or a child nobody declares ends the boot with the option and the role named).
|
|
47
|
+
- **An id is never blank, the text of a missing value, an error or a buffer.** A string or a printed text that is empty
|
|
48
|
+
or only whitespace, `undefined` or `null`, and an `Error`, a `Buffer` or any other view of bytes, are refused as an id
|
|
49
|
+
with `auth.internal`.
|
|
50
|
+
- **The ids of the rows the workspace access reads are compared with the ones asked about.** The id of the workspace, the
|
|
51
|
+
workspace of the membership and the user of the membership are compared exactly, as the tenant already was; a
|
|
52
|
+
repository that answers another row is denied access and nothing is cached. **Apply to a derived backend:** the ids
|
|
53
|
+
are compared as the exact strings the library keeps, so a store that normalises an id when it reads it (a column that
|
|
54
|
+
lowercases a uuid) has to be asked for the id in the form it returns, or it answers a row that is denied.
|
|
55
|
+
|
|
21
56
|
## [1.5.13] - 2026-11-21
|
|
22
57
|
|
|
23
58
|
A patch release.
|
|
@@ -5560,7 +5595,8 @@ ever installable.
|
|
|
5560
5595
|
- 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
|
|
5561
5596
|
- 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
|
|
5562
5597
|
|
|
5563
|
-
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.
|
|
5598
|
+
[Unreleased]: https://github.com/bymaxone/nest-auth/compare/v1.5.14...HEAD
|
|
5599
|
+
[1.5.14]: https://github.com/bymaxone/nest-auth/compare/v1.5.13...v1.5.14
|
|
5564
5600
|
[1.5.13]: https://github.com/bymaxone/nest-auth/compare/v1.5.12...v1.5.13
|
|
5565
5601
|
[1.5.12]: https://github.com/bymaxone/nest-auth/compare/v1.5.11...v1.5.12
|
|
5566
5602
|
[1.5.11]: https://github.com/bymaxone/nest-auth/compare/v1.5.10...v1.5.11
|
package/dist/server/index.cjs
CHANGED
|
@@ -833,7 +833,11 @@ var OBJECT_GROUPS = [
|
|
|
833
833
|
"oauth",
|
|
834
834
|
"roles",
|
|
835
835
|
"workspaces",
|
|
836
|
-
"workspaces.roles"
|
|
836
|
+
"workspaces.roles",
|
|
837
|
+
"workspaces.permissions",
|
|
838
|
+
"jwt",
|
|
839
|
+
"mfa",
|
|
840
|
+
"apiKeys"
|
|
837
841
|
];
|
|
838
842
|
function readPath2(root, path) {
|
|
839
843
|
let node = root;
|
|
@@ -1034,6 +1038,12 @@ var WORKSPACE_SUBGROUP_KEYS = {
|
|
|
1034
1038
|
roles: [
|
|
1035
1039
|
"hierarchy",
|
|
1036
1040
|
"ownerRole"
|
|
1041
|
+
],
|
|
1042
|
+
permissions: [
|
|
1043
|
+
"manageWorkspace",
|
|
1044
|
+
"deleteWorkspace",
|
|
1045
|
+
"manageMembers",
|
|
1046
|
+
"viewMembers"
|
|
1037
1047
|
]
|
|
1038
1048
|
};
|
|
1039
1049
|
function isObjectGroup(value) {
|
|
@@ -1083,7 +1093,7 @@ function dropUnset(options) {
|
|
|
1083
1093
|
if (name === "workspaces") {
|
|
1084
1094
|
for (const [sub, subKeys] of Object.entries(WORKSPACE_SUBGROUP_KEYS)) {
|
|
1085
1095
|
const inner = group[sub];
|
|
1086
|
-
if (isObjectGroup(inner)) group[sub] = (sub === "
|
|
1096
|
+
if (isObjectGroup(inner)) group[sub] = (sub === "accessDeniedEvents" ? readSetKeys : readKeptKeys)(inner, subKeys);
|
|
1087
1097
|
}
|
|
1088
1098
|
}
|
|
1089
1099
|
copy[name] = group;
|
|
@@ -1107,7 +1117,7 @@ __name(dropUnset, "dropUnset");
|
|
|
1107
1117
|
function readOptions(given) {
|
|
1108
1118
|
const options = dropUnset(given);
|
|
1109
1119
|
validateTextOptions(options);
|
|
1110
|
-
return
|
|
1120
|
+
return pinCopied(options);
|
|
1111
1121
|
}
|
|
1112
1122
|
__name(readOptions, "readOptions");
|
|
1113
1123
|
function copyHierarchy(held) {
|
|
@@ -1120,39 +1130,114 @@ function copyHierarchy(held) {
|
|
|
1120
1130
|
]));
|
|
1121
1131
|
}
|
|
1122
1132
|
__name(copyHierarchy, "copyHierarchy");
|
|
1123
|
-
function
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
roles: pinIn(roles, [
|
|
1133
|
+
function copyList(held) {
|
|
1134
|
+
return Array.isArray(held) ? [
|
|
1135
|
+
...held
|
|
1136
|
+
] : held;
|
|
1137
|
+
}
|
|
1138
|
+
__name(copyList, "copyList");
|
|
1139
|
+
var COPIED = [
|
|
1140
|
+
{
|
|
1141
|
+
path: [
|
|
1142
|
+
"roles"
|
|
1143
|
+
],
|
|
1144
|
+
keys: [
|
|
1136
1145
|
"hierarchy",
|
|
1137
1146
|
"platformHierarchy"
|
|
1138
|
-
]
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1147
|
+
],
|
|
1148
|
+
copy: copyHierarchy
|
|
1149
|
+
},
|
|
1150
|
+
{
|
|
1151
|
+
path: [
|
|
1152
|
+
"workspaces",
|
|
1153
|
+
"roles"
|
|
1154
|
+
],
|
|
1155
|
+
keys: [
|
|
1156
|
+
"hierarchy"
|
|
1157
|
+
],
|
|
1158
|
+
copy: copyHierarchy
|
|
1159
|
+
},
|
|
1160
|
+
{
|
|
1161
|
+
path: [
|
|
1162
|
+
"workspaces",
|
|
1163
|
+
"permissions"
|
|
1164
|
+
],
|
|
1165
|
+
keys: [
|
|
1166
|
+
"manageWorkspace",
|
|
1167
|
+
"deleteWorkspace",
|
|
1168
|
+
"manageMembers",
|
|
1169
|
+
"viewMembers"
|
|
1170
|
+
],
|
|
1171
|
+
copy: copyList
|
|
1172
|
+
},
|
|
1173
|
+
{
|
|
1174
|
+
path: [
|
|
1175
|
+
"jwt"
|
|
1176
|
+
],
|
|
1177
|
+
keys: [
|
|
1178
|
+
"previousSecrets"
|
|
1179
|
+
],
|
|
1180
|
+
copy: copyList
|
|
1181
|
+
},
|
|
1182
|
+
{
|
|
1183
|
+
path: [
|
|
1184
|
+
"mfa"
|
|
1185
|
+
],
|
|
1186
|
+
keys: [
|
|
1187
|
+
"previousEncryptionKeys"
|
|
1188
|
+
],
|
|
1189
|
+
copy: copyList
|
|
1190
|
+
},
|
|
1191
|
+
{
|
|
1192
|
+
path: [
|
|
1193
|
+
"apiKeys"
|
|
1194
|
+
],
|
|
1195
|
+
keys: [
|
|
1196
|
+
"scopes"
|
|
1197
|
+
],
|
|
1198
|
+
copy: copyList
|
|
1199
|
+
}
|
|
1200
|
+
];
|
|
1201
|
+
function pinCopied(options) {
|
|
1202
|
+
for (const { path, keys, copy } of COPIED) {
|
|
1203
|
+
let group = options;
|
|
1204
|
+
for (const step of path) group = Object(group) === group ? group[step] : void 0;
|
|
1205
|
+
if (Object(group) !== group) continue;
|
|
1206
|
+
const plain = group;
|
|
1207
|
+
for (const key of keys) if (plain[key] !== void 0) plain[key] = copy(plain[key]);
|
|
1208
|
+
}
|
|
1209
|
+
return options;
|
|
1148
1210
|
}
|
|
1149
|
-
__name(
|
|
1211
|
+
__name(pinCopied, "pinCopied");
|
|
1150
1212
|
function validateOptionValues(userOptions) {
|
|
1151
1213
|
validateNumericOptions(userOptions);
|
|
1152
1214
|
validateEnumAndBooleanOptions(userOptions);
|
|
1153
1215
|
}
|
|
1154
1216
|
__name(validateOptionValues, "validateOptionValues");
|
|
1155
1217
|
|
|
1218
|
+
// src/server/config/platform-options.ts
|
|
1219
|
+
function validatePlatformAdmin(platform, roles) {
|
|
1220
|
+
if (!platform?.enabled) return;
|
|
1221
|
+
const hierarchy = roles.platformHierarchy;
|
|
1222
|
+
if (!hierarchy) {
|
|
1223
|
+
throw new Error(`[BymaxAuthModule] roles.platformHierarchy is required when platform.enabled is true. Define the platform role hierarchy (e.g. { SUPER_ADMIN: ['SUPPORT'], SUPPORT: [] }).`);
|
|
1224
|
+
}
|
|
1225
|
+
assertObject("roles.platformHierarchy", hierarchy);
|
|
1226
|
+
const names = new Set(Object.keys(hierarchy));
|
|
1227
|
+
if (names.size === 0) {
|
|
1228
|
+
throw new Error(`[BymaxAuthModule] roles.platformHierarchy must not be an empty object. Define at least one role (e.g. { SUPER_ADMIN: [] }).`);
|
|
1229
|
+
}
|
|
1230
|
+
for (const [role, children] of Object.entries(hierarchy)) {
|
|
1231
|
+
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
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
__name(validatePlatformAdmin, "validatePlatformAdmin");
|
|
1240
|
+
|
|
1156
1241
|
// src/server/constants/workspace-roles.ts
|
|
1157
1242
|
var ANY_WORKSPACE_MEMBER = /* @__PURE__ */ Symbol("ANY_WORKSPACE_MEMBER");
|
|
1158
1243
|
|
|
@@ -1755,12 +1840,6 @@ function validateRolesHierarchy(roles) {
|
|
|
1755
1840
|
}
|
|
1756
1841
|
}
|
|
1757
1842
|
__name(validateRolesHierarchy, "validateRolesHierarchy");
|
|
1758
|
-
function validatePlatformAdmin(platform, roles) {
|
|
1759
|
-
if (platform?.enabled && !roles.platformHierarchy) {
|
|
1760
|
-
throw new Error(`[BymaxAuthModule] roles.platformHierarchy is required when platform.enabled is true. Define the platform role hierarchy (e.g. { SUPER_ADMIN: ['SUPPORT'], SUPPORT: [] }).`);
|
|
1761
|
-
}
|
|
1762
|
-
}
|
|
1763
|
-
__name(validatePlatformAdmin, "validatePlatformAdmin");
|
|
1764
1843
|
function assertIntegralScryptParameter(name, value) {
|
|
1765
1844
|
if (value === void 0 || Number.isInteger(value)) return;
|
|
1766
1845
|
throw new Error(`[BymaxAuthModule] password.${name} must be an integer (received ${describeReceived(value)}). Node's crypto.scrypt rejects a non-integral cost parameter, and it does so on the first derivation \u2014 which is the first login after deploy, not at startup.`);
|
|
@@ -6702,12 +6781,13 @@ function _ts_param11(paramIndex, decorator) {
|
|
|
6702
6781
|
}
|
|
6703
6782
|
__name(_ts_param11, "_ts_param");
|
|
6704
6783
|
async function releasingCooldownOnFailure(redis, logger, cooldownKey, work) {
|
|
6784
|
+
const release = /* @__PURE__ */ __name(() => redis.del(cooldownKey).then(() => void 0, (err) => {
|
|
6785
|
+
logStore(logger, "AUTH_STORE_FAILED", "resend_cooldown_release", err);
|
|
6786
|
+
}), "release");
|
|
6705
6787
|
try {
|
|
6706
|
-
|
|
6788
|
+
if (await work() === false) await release();
|
|
6707
6789
|
} catch (error) {
|
|
6708
|
-
await
|
|
6709
|
-
logStore(logger, "AUTH_STORE_FAILED", "resend_cooldown_release", err);
|
|
6710
|
-
});
|
|
6790
|
+
await release();
|
|
6711
6791
|
throw error;
|
|
6712
6792
|
}
|
|
6713
6793
|
}
|
|
@@ -7222,7 +7302,7 @@ PasswordService = _ts_decorate20([
|
|
|
7222
7302
|
var RECORD_CONTRACTS = {
|
|
7223
7303
|
workspace: {
|
|
7224
7304
|
fields: {
|
|
7225
|
-
id: "
|
|
7305
|
+
id: "id",
|
|
7226
7306
|
tenantId: "string",
|
|
7227
7307
|
name: "~string",
|
|
7228
7308
|
status: "string",
|
|
@@ -7234,8 +7314,8 @@ var RECORD_CONTRACTS = {
|
|
|
7234
7314
|
membership: {
|
|
7235
7315
|
fields: {
|
|
7236
7316
|
tenantId: "string",
|
|
7237
|
-
workspaceId: "
|
|
7238
|
-
userId: "
|
|
7317
|
+
workspaceId: "id",
|
|
7318
|
+
userId: "id",
|
|
7239
7319
|
role: "string",
|
|
7240
7320
|
status: "string",
|
|
7241
7321
|
invitedByUserId: "~id",
|
|
@@ -7246,7 +7326,7 @@ var RECORD_CONTRACTS = {
|
|
|
7246
7326
|
},
|
|
7247
7327
|
user: {
|
|
7248
7328
|
fields: {
|
|
7249
|
-
id: "
|
|
7329
|
+
id: "id",
|
|
7250
7330
|
email: "~string",
|
|
7251
7331
|
name: "~string",
|
|
7252
7332
|
passwordHash: "string|null",
|
|
@@ -7266,7 +7346,7 @@ var RECORD_CONTRACTS = {
|
|
|
7266
7346
|
},
|
|
7267
7347
|
platformUser: {
|
|
7268
7348
|
fields: {
|
|
7269
|
-
id: "
|
|
7349
|
+
id: "id",
|
|
7270
7350
|
email: "~string",
|
|
7271
7351
|
name: "~string",
|
|
7272
7352
|
passwordHash: "string",
|
|
@@ -7284,7 +7364,7 @@ var RECORD_CONTRACTS = {
|
|
|
7284
7364
|
},
|
|
7285
7365
|
apiKey: {
|
|
7286
7366
|
fields: {
|
|
7287
|
-
id: "
|
|
7367
|
+
id: "id",
|
|
7288
7368
|
label: "~string",
|
|
7289
7369
|
digest: "string",
|
|
7290
7370
|
scopes: "strings",
|
|
@@ -7297,7 +7377,7 @@ var RECORD_CONTRACTS = {
|
|
|
7297
7377
|
},
|
|
7298
7378
|
removedMembership: {
|
|
7299
7379
|
fields: {
|
|
7300
|
-
workspaceId: "
|
|
7380
|
+
workspaceId: "id",
|
|
7301
7381
|
role: "string"
|
|
7302
7382
|
},
|
|
7303
7383
|
nested: {}
|
|
@@ -7540,12 +7620,16 @@ function copyStrings(value, read) {
|
|
|
7540
7620
|
return copy;
|
|
7541
7621
|
}
|
|
7542
7622
|
__name(copyStrings, "copyStrings");
|
|
7623
|
+
var NOT_AN_ID_TEXT = /* @__PURE__ */ new Set([
|
|
7624
|
+
"undefined",
|
|
7625
|
+
"null"
|
|
7626
|
+
]);
|
|
7543
7627
|
function readId(value) {
|
|
7544
|
-
if (typeof value === "string") return accept(value !== "", value);
|
|
7545
7628
|
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
|
|
7548
|
-
|
|
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);
|
|
7630
|
+
const text = String(value);
|
|
7631
|
+
const printed = typeof value !== "string";
|
|
7632
|
+
return accept(text.trim() !== "" && !NOT_AN_ID_TEXT.has(text) && !(printed && text.startsWith("[object ")), text);
|
|
7549
7633
|
}
|
|
7550
7634
|
__name(readId, "readId");
|
|
7551
7635
|
function readInforming(value) {
|
|
@@ -7564,6 +7648,7 @@ __name(readInformingDate, "readInformingDate");
|
|
|
7564
7648
|
var READERS = {
|
|
7565
7649
|
boolean: /* @__PURE__ */ __name((value) => accept(typeof value === "boolean", value), "boolean"),
|
|
7566
7650
|
string: /* @__PURE__ */ __name((value) => accept(typeof value === "string", value), "string"),
|
|
7651
|
+
id: readId,
|
|
7567
7652
|
number: /* @__PURE__ */ __name((value) => accept(Number.isFinite(value), value), "number"),
|
|
7568
7653
|
date: copyDate,
|
|
7569
7654
|
strings: copyStrings,
|
|
@@ -10477,7 +10562,7 @@ exports.AuthService = class _AuthService {
|
|
|
10477
10562
|
email,
|
|
10478
10563
|
tenantId
|
|
10479
10564
|
}), tenantId);
|
|
10480
|
-
|
|
10565
|
+
return user && !user.emailVerified ? this.sendVerificationOtp(tenantId, email) : void 0;
|
|
10481
10566
|
});
|
|
10482
10567
|
await sleep(Math.max(0, ANTI_ENUM_MIN_MS - (Date.now() - start)));
|
|
10483
10568
|
}
|
|
@@ -10728,12 +10813,12 @@ exports.AuthService = class _AuthService {
|
|
|
10728
10813
|
logEvent(this.logger, "AUTH_PROVIDER_MISSING", {
|
|
10729
10814
|
flow: "email_verification_otp"
|
|
10730
10815
|
});
|
|
10731
|
-
return;
|
|
10816
|
+
return true;
|
|
10732
10817
|
}
|
|
10733
10818
|
const identifier = this.otpIdentifier(tenantId, email);
|
|
10734
10819
|
const otp = this.otpService.generate(6);
|
|
10735
10820
|
const { otpTtlSeconds: ttl } = this.options.emailVerification;
|
|
10736
|
-
if (!await storeVerificationCode(this.otpService, this.logger, identifier, otp, ttl)) return;
|
|
10821
|
+
if (!await storeVerificationCode(this.otpService, this.logger, identifier, otp, ttl)) return false;
|
|
10737
10822
|
const provider = this.emailProvider;
|
|
10738
10823
|
void (async () => {
|
|
10739
10824
|
try {
|
|
@@ -10742,6 +10827,7 @@ exports.AuthService = class _AuthService {
|
|
|
10742
10827
|
logDelivery(this.logger, "email_verification_otp", err);
|
|
10743
10828
|
}
|
|
10744
10829
|
})();
|
|
10830
|
+
return true;
|
|
10745
10831
|
}
|
|
10746
10832
|
};
|
|
10747
10833
|
exports.AuthService = _ts_decorate23([
|
|
@@ -18109,7 +18195,7 @@ exports.WorkspaceAccessService = class _WorkspaceAccessService {
|
|
|
18109
18195
|
if (membership?.status !== "active" || workspace === null) return {
|
|
18110
18196
|
kind: "denied"
|
|
18111
18197
|
};
|
|
18112
|
-
if (workspace.tenantId !== ref.tenantId || membership.tenantId !== ref.tenantId) return {
|
|
18198
|
+
if (workspace.tenantId !== ref.tenantId || membership.tenantId !== ref.tenantId || workspace.id !== ref.workspaceId || membership.workspaceId !== ref.workspaceId || membership.userId !== ref.userId) return {
|
|
18113
18199
|
kind: "denied"
|
|
18114
18200
|
};
|
|
18115
18201
|
const member = {
|
package/dist/server/index.mjs
CHANGED
|
@@ -831,7 +831,11 @@ var OBJECT_GROUPS = [
|
|
|
831
831
|
"oauth",
|
|
832
832
|
"roles",
|
|
833
833
|
"workspaces",
|
|
834
|
-
"workspaces.roles"
|
|
834
|
+
"workspaces.roles",
|
|
835
|
+
"workspaces.permissions",
|
|
836
|
+
"jwt",
|
|
837
|
+
"mfa",
|
|
838
|
+
"apiKeys"
|
|
835
839
|
];
|
|
836
840
|
function readPath2(root, path) {
|
|
837
841
|
let node = root;
|
|
@@ -1032,6 +1036,12 @@ var WORKSPACE_SUBGROUP_KEYS = {
|
|
|
1032
1036
|
roles: [
|
|
1033
1037
|
"hierarchy",
|
|
1034
1038
|
"ownerRole"
|
|
1039
|
+
],
|
|
1040
|
+
permissions: [
|
|
1041
|
+
"manageWorkspace",
|
|
1042
|
+
"deleteWorkspace",
|
|
1043
|
+
"manageMembers",
|
|
1044
|
+
"viewMembers"
|
|
1035
1045
|
]
|
|
1036
1046
|
};
|
|
1037
1047
|
function isObjectGroup(value) {
|
|
@@ -1081,7 +1091,7 @@ function dropUnset(options) {
|
|
|
1081
1091
|
if (name === "workspaces") {
|
|
1082
1092
|
for (const [sub, subKeys] of Object.entries(WORKSPACE_SUBGROUP_KEYS)) {
|
|
1083
1093
|
const inner = group[sub];
|
|
1084
|
-
if (isObjectGroup(inner)) group[sub] = (sub === "
|
|
1094
|
+
if (isObjectGroup(inner)) group[sub] = (sub === "accessDeniedEvents" ? readSetKeys : readKeptKeys)(inner, subKeys);
|
|
1085
1095
|
}
|
|
1086
1096
|
}
|
|
1087
1097
|
copy[name] = group;
|
|
@@ -1105,7 +1115,7 @@ __name(dropUnset, "dropUnset");
|
|
|
1105
1115
|
function readOptions(given) {
|
|
1106
1116
|
const options = dropUnset(given);
|
|
1107
1117
|
validateTextOptions(options);
|
|
1108
|
-
return
|
|
1118
|
+
return pinCopied(options);
|
|
1109
1119
|
}
|
|
1110
1120
|
__name(readOptions, "readOptions");
|
|
1111
1121
|
function copyHierarchy(held) {
|
|
@@ -1118,39 +1128,114 @@ function copyHierarchy(held) {
|
|
|
1118
1128
|
]));
|
|
1119
1129
|
}
|
|
1120
1130
|
__name(copyHierarchy, "copyHierarchy");
|
|
1121
|
-
function
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
roles: pinIn(roles, [
|
|
1131
|
+
function copyList(held) {
|
|
1132
|
+
return Array.isArray(held) ? [
|
|
1133
|
+
...held
|
|
1134
|
+
] : held;
|
|
1135
|
+
}
|
|
1136
|
+
__name(copyList, "copyList");
|
|
1137
|
+
var COPIED = [
|
|
1138
|
+
{
|
|
1139
|
+
path: [
|
|
1140
|
+
"roles"
|
|
1141
|
+
],
|
|
1142
|
+
keys: [
|
|
1134
1143
|
"hierarchy",
|
|
1135
1144
|
"platformHierarchy"
|
|
1136
|
-
]
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1145
|
+
],
|
|
1146
|
+
copy: copyHierarchy
|
|
1147
|
+
},
|
|
1148
|
+
{
|
|
1149
|
+
path: [
|
|
1150
|
+
"workspaces",
|
|
1151
|
+
"roles"
|
|
1152
|
+
],
|
|
1153
|
+
keys: [
|
|
1154
|
+
"hierarchy"
|
|
1155
|
+
],
|
|
1156
|
+
copy: copyHierarchy
|
|
1157
|
+
},
|
|
1158
|
+
{
|
|
1159
|
+
path: [
|
|
1160
|
+
"workspaces",
|
|
1161
|
+
"permissions"
|
|
1162
|
+
],
|
|
1163
|
+
keys: [
|
|
1164
|
+
"manageWorkspace",
|
|
1165
|
+
"deleteWorkspace",
|
|
1166
|
+
"manageMembers",
|
|
1167
|
+
"viewMembers"
|
|
1168
|
+
],
|
|
1169
|
+
copy: copyList
|
|
1170
|
+
},
|
|
1171
|
+
{
|
|
1172
|
+
path: [
|
|
1173
|
+
"jwt"
|
|
1174
|
+
],
|
|
1175
|
+
keys: [
|
|
1176
|
+
"previousSecrets"
|
|
1177
|
+
],
|
|
1178
|
+
copy: copyList
|
|
1179
|
+
},
|
|
1180
|
+
{
|
|
1181
|
+
path: [
|
|
1182
|
+
"mfa"
|
|
1183
|
+
],
|
|
1184
|
+
keys: [
|
|
1185
|
+
"previousEncryptionKeys"
|
|
1186
|
+
],
|
|
1187
|
+
copy: copyList
|
|
1188
|
+
},
|
|
1189
|
+
{
|
|
1190
|
+
path: [
|
|
1191
|
+
"apiKeys"
|
|
1192
|
+
],
|
|
1193
|
+
keys: [
|
|
1194
|
+
"scopes"
|
|
1195
|
+
],
|
|
1196
|
+
copy: copyList
|
|
1197
|
+
}
|
|
1198
|
+
];
|
|
1199
|
+
function pinCopied(options) {
|
|
1200
|
+
for (const { path, keys, copy } of COPIED) {
|
|
1201
|
+
let group = options;
|
|
1202
|
+
for (const step of path) group = Object(group) === group ? group[step] : void 0;
|
|
1203
|
+
if (Object(group) !== group) continue;
|
|
1204
|
+
const plain = group;
|
|
1205
|
+
for (const key of keys) if (plain[key] !== void 0) plain[key] = copy(plain[key]);
|
|
1206
|
+
}
|
|
1207
|
+
return options;
|
|
1146
1208
|
}
|
|
1147
|
-
__name(
|
|
1209
|
+
__name(pinCopied, "pinCopied");
|
|
1148
1210
|
function validateOptionValues(userOptions) {
|
|
1149
1211
|
validateNumericOptions(userOptions);
|
|
1150
1212
|
validateEnumAndBooleanOptions(userOptions);
|
|
1151
1213
|
}
|
|
1152
1214
|
__name(validateOptionValues, "validateOptionValues");
|
|
1153
1215
|
|
|
1216
|
+
// src/server/config/platform-options.ts
|
|
1217
|
+
function validatePlatformAdmin(platform, roles) {
|
|
1218
|
+
if (!platform?.enabled) return;
|
|
1219
|
+
const hierarchy = roles.platformHierarchy;
|
|
1220
|
+
if (!hierarchy) {
|
|
1221
|
+
throw new Error(`[BymaxAuthModule] roles.platformHierarchy is required when platform.enabled is true. Define the platform role hierarchy (e.g. { SUPER_ADMIN: ['SUPPORT'], SUPPORT: [] }).`);
|
|
1222
|
+
}
|
|
1223
|
+
assertObject("roles.platformHierarchy", hierarchy);
|
|
1224
|
+
const names = new Set(Object.keys(hierarchy));
|
|
1225
|
+
if (names.size === 0) {
|
|
1226
|
+
throw new Error(`[BymaxAuthModule] roles.platformHierarchy must not be an empty object. Define at least one role (e.g. { SUPER_ADMIN: [] }).`);
|
|
1227
|
+
}
|
|
1228
|
+
for (const [role, children] of Object.entries(hierarchy)) {
|
|
1229
|
+
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
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
}
|
|
1237
|
+
__name(validatePlatformAdmin, "validatePlatformAdmin");
|
|
1238
|
+
|
|
1154
1239
|
// src/server/constants/workspace-roles.ts
|
|
1155
1240
|
var ANY_WORKSPACE_MEMBER = /* @__PURE__ */ Symbol("ANY_WORKSPACE_MEMBER");
|
|
1156
1241
|
|
|
@@ -1753,12 +1838,6 @@ function validateRolesHierarchy(roles) {
|
|
|
1753
1838
|
}
|
|
1754
1839
|
}
|
|
1755
1840
|
__name(validateRolesHierarchy, "validateRolesHierarchy");
|
|
1756
|
-
function validatePlatformAdmin(platform, roles) {
|
|
1757
|
-
if (platform?.enabled && !roles.platformHierarchy) {
|
|
1758
|
-
throw new Error(`[BymaxAuthModule] roles.platformHierarchy is required when platform.enabled is true. Define the platform role hierarchy (e.g. { SUPER_ADMIN: ['SUPPORT'], SUPPORT: [] }).`);
|
|
1759
|
-
}
|
|
1760
|
-
}
|
|
1761
|
-
__name(validatePlatformAdmin, "validatePlatformAdmin");
|
|
1762
1841
|
function assertIntegralScryptParameter(name, value) {
|
|
1763
1842
|
if (value === void 0 || Number.isInteger(value)) return;
|
|
1764
1843
|
throw new Error(`[BymaxAuthModule] password.${name} must be an integer (received ${describeReceived(value)}). Node's crypto.scrypt rejects a non-integral cost parameter, and it does so on the first derivation \u2014 which is the first login after deploy, not at startup.`);
|
|
@@ -6700,12 +6779,13 @@ function _ts_param11(paramIndex, decorator) {
|
|
|
6700
6779
|
}
|
|
6701
6780
|
__name(_ts_param11, "_ts_param");
|
|
6702
6781
|
async function releasingCooldownOnFailure(redis, logger, cooldownKey, work) {
|
|
6782
|
+
const release = /* @__PURE__ */ __name(() => redis.del(cooldownKey).then(() => void 0, (err) => {
|
|
6783
|
+
logStore(logger, "AUTH_STORE_FAILED", "resend_cooldown_release", err);
|
|
6784
|
+
}), "release");
|
|
6703
6785
|
try {
|
|
6704
|
-
|
|
6786
|
+
if (await work() === false) await release();
|
|
6705
6787
|
} catch (error) {
|
|
6706
|
-
await
|
|
6707
|
-
logStore(logger, "AUTH_STORE_FAILED", "resend_cooldown_release", err);
|
|
6708
|
-
});
|
|
6788
|
+
await release();
|
|
6709
6789
|
throw error;
|
|
6710
6790
|
}
|
|
6711
6791
|
}
|
|
@@ -7220,7 +7300,7 @@ PasswordService = _ts_decorate20([
|
|
|
7220
7300
|
var RECORD_CONTRACTS = {
|
|
7221
7301
|
workspace: {
|
|
7222
7302
|
fields: {
|
|
7223
|
-
id: "
|
|
7303
|
+
id: "id",
|
|
7224
7304
|
tenantId: "string",
|
|
7225
7305
|
name: "~string",
|
|
7226
7306
|
status: "string",
|
|
@@ -7232,8 +7312,8 @@ var RECORD_CONTRACTS = {
|
|
|
7232
7312
|
membership: {
|
|
7233
7313
|
fields: {
|
|
7234
7314
|
tenantId: "string",
|
|
7235
|
-
workspaceId: "
|
|
7236
|
-
userId: "
|
|
7315
|
+
workspaceId: "id",
|
|
7316
|
+
userId: "id",
|
|
7237
7317
|
role: "string",
|
|
7238
7318
|
status: "string",
|
|
7239
7319
|
invitedByUserId: "~id",
|
|
@@ -7244,7 +7324,7 @@ var RECORD_CONTRACTS = {
|
|
|
7244
7324
|
},
|
|
7245
7325
|
user: {
|
|
7246
7326
|
fields: {
|
|
7247
|
-
id: "
|
|
7327
|
+
id: "id",
|
|
7248
7328
|
email: "~string",
|
|
7249
7329
|
name: "~string",
|
|
7250
7330
|
passwordHash: "string|null",
|
|
@@ -7264,7 +7344,7 @@ var RECORD_CONTRACTS = {
|
|
|
7264
7344
|
},
|
|
7265
7345
|
platformUser: {
|
|
7266
7346
|
fields: {
|
|
7267
|
-
id: "
|
|
7347
|
+
id: "id",
|
|
7268
7348
|
email: "~string",
|
|
7269
7349
|
name: "~string",
|
|
7270
7350
|
passwordHash: "string",
|
|
@@ -7282,7 +7362,7 @@ var RECORD_CONTRACTS = {
|
|
|
7282
7362
|
},
|
|
7283
7363
|
apiKey: {
|
|
7284
7364
|
fields: {
|
|
7285
|
-
id: "
|
|
7365
|
+
id: "id",
|
|
7286
7366
|
label: "~string",
|
|
7287
7367
|
digest: "string",
|
|
7288
7368
|
scopes: "strings",
|
|
@@ -7295,7 +7375,7 @@ var RECORD_CONTRACTS = {
|
|
|
7295
7375
|
},
|
|
7296
7376
|
removedMembership: {
|
|
7297
7377
|
fields: {
|
|
7298
|
-
workspaceId: "
|
|
7378
|
+
workspaceId: "id",
|
|
7299
7379
|
role: "string"
|
|
7300
7380
|
},
|
|
7301
7381
|
nested: {}
|
|
@@ -7538,12 +7618,16 @@ function copyStrings(value, read) {
|
|
|
7538
7618
|
return copy;
|
|
7539
7619
|
}
|
|
7540
7620
|
__name(copyStrings, "copyStrings");
|
|
7621
|
+
var NOT_AN_ID_TEXT = /* @__PURE__ */ new Set([
|
|
7622
|
+
"undefined",
|
|
7623
|
+
"null"
|
|
7624
|
+
]);
|
|
7541
7625
|
function readId(value) {
|
|
7542
|
-
if (typeof value === "string") return accept(value !== "", value);
|
|
7543
7626
|
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
|
|
7546
|
-
|
|
7627
|
+
if (typeof value !== "string" && (!isHostInstance(value) || types.isDate(value) || types.isRegExp(value) || types.isNativeError(value) || types.isArrayBufferView(value))) throw new Error(WRONG_KIND);
|
|
7628
|
+
const text = String(value);
|
|
7629
|
+
const printed = typeof value !== "string";
|
|
7630
|
+
return accept(text.trim() !== "" && !NOT_AN_ID_TEXT.has(text) && !(printed && text.startsWith("[object ")), text);
|
|
7547
7631
|
}
|
|
7548
7632
|
__name(readId, "readId");
|
|
7549
7633
|
function readInforming(value) {
|
|
@@ -7562,6 +7646,7 @@ __name(readInformingDate, "readInformingDate");
|
|
|
7562
7646
|
var READERS = {
|
|
7563
7647
|
boolean: /* @__PURE__ */ __name((value) => accept(typeof value === "boolean", value), "boolean"),
|
|
7564
7648
|
string: /* @__PURE__ */ __name((value) => accept(typeof value === "string", value), "string"),
|
|
7649
|
+
id: readId,
|
|
7565
7650
|
number: /* @__PURE__ */ __name((value) => accept(Number.isFinite(value), value), "number"),
|
|
7566
7651
|
date: copyDate,
|
|
7567
7652
|
strings: copyStrings,
|
|
@@ -10475,7 +10560,7 @@ var AuthService = class _AuthService {
|
|
|
10475
10560
|
email,
|
|
10476
10561
|
tenantId
|
|
10477
10562
|
}), tenantId);
|
|
10478
|
-
|
|
10563
|
+
return user && !user.emailVerified ? this.sendVerificationOtp(tenantId, email) : void 0;
|
|
10479
10564
|
});
|
|
10480
10565
|
await sleep(Math.max(0, ANTI_ENUM_MIN_MS - (Date.now() - start)));
|
|
10481
10566
|
}
|
|
@@ -10726,12 +10811,12 @@ var AuthService = class _AuthService {
|
|
|
10726
10811
|
logEvent(this.logger, "AUTH_PROVIDER_MISSING", {
|
|
10727
10812
|
flow: "email_verification_otp"
|
|
10728
10813
|
});
|
|
10729
|
-
return;
|
|
10814
|
+
return true;
|
|
10730
10815
|
}
|
|
10731
10816
|
const identifier = this.otpIdentifier(tenantId, email);
|
|
10732
10817
|
const otp = this.otpService.generate(6);
|
|
10733
10818
|
const { otpTtlSeconds: ttl } = this.options.emailVerification;
|
|
10734
|
-
if (!await storeVerificationCode(this.otpService, this.logger, identifier, otp, ttl)) return;
|
|
10819
|
+
if (!await storeVerificationCode(this.otpService, this.logger, identifier, otp, ttl)) return false;
|
|
10735
10820
|
const provider = this.emailProvider;
|
|
10736
10821
|
void (async () => {
|
|
10737
10822
|
try {
|
|
@@ -10740,6 +10825,7 @@ var AuthService = class _AuthService {
|
|
|
10740
10825
|
logDelivery(this.logger, "email_verification_otp", err);
|
|
10741
10826
|
}
|
|
10742
10827
|
})();
|
|
10828
|
+
return true;
|
|
10743
10829
|
}
|
|
10744
10830
|
};
|
|
10745
10831
|
AuthService = _ts_decorate23([
|
|
@@ -18107,7 +18193,7 @@ var WorkspaceAccessService = class _WorkspaceAccessService {
|
|
|
18107
18193
|
if (membership?.status !== "active" || workspace === null) return {
|
|
18108
18194
|
kind: "denied"
|
|
18109
18195
|
};
|
|
18110
|
-
if (workspace.tenantId !== ref.tenantId || membership.tenantId !== ref.tenantId) return {
|
|
18196
|
+
if (workspace.tenantId !== ref.tenantId || membership.tenantId !== ref.tenantId || workspace.id !== ref.workspaceId || membership.workspaceId !== ref.workspaceId || membership.userId !== ref.userId) return {
|
|
18111
18197
|
kind: "denied"
|
|
18112
18198
|
};
|
|
18113
18199
|
const member = {
|
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.14",
|
|
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",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"gen:openapi-schemas": "UPDATE_OPENAPI_SCHEMAS=1 jest src/server/openapi/request-schemas.conformance.spec.ts",
|
|
99
99
|
"gen:openapi-security": "UPDATE_OPENAPI_SECURITY=1 jest src/server/openapi/operation-security.conformance.spec.ts",
|
|
100
100
|
"format:check": "prettier --check .",
|
|
101
|
-
"lint": "eslint src",
|
|
101
|
+
"lint": "eslint src && node --test scripts/check-dist-fresh.test.mjs",
|
|
102
102
|
"lint:fix": "eslint src --fix",
|
|
103
103
|
"mutation": "stryker run",
|
|
104
104
|
"mutation:full": "node -e \"require('node:fs').rmSync('reports/stryker-incremental.json',{force:true,recursive:true})\" && stryker run",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"prepare": "husky",
|
|
107
107
|
"prepublishOnly": "pnpm clean && pnpm typecheck && pnpm lint && pnpm test:cov:all && pnpm build && pnpm size && pnpm check:exports && pnpm check:published && pnpm check:runtime",
|
|
108
108
|
"release": "npm publish --provenance --access public",
|
|
109
|
-
"size": "node scripts/check-size.mjs",
|
|
109
|
+
"size": "node scripts/check-dist-fresh.mjs --also tsup.config.ts --also package.json --also tsconfig.json --also tsconfig.build.json --also tsconfig.build.web.json && node scripts/check-size.mjs",
|
|
110
110
|
"test": "jest",
|
|
111
111
|
"test:all": "pnpm test && pnpm test:e2e",
|
|
112
112
|
"test:cov": "jest --coverage",
|