@objectstack/lint 12.5.0 → 13.0.0
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/dist/index.cjs +448 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +104 -27
- package/dist/index.d.ts +104 -27
- package/dist/index.js +436 -6
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -373,7 +373,6 @@ function validateStackExpressions(stack) {
|
|
|
373
373
|
|
|
374
374
|
// src/validate-list-view-mode.ts
|
|
375
375
|
var LIST_VIEW_FILTERS_IN_VIEWS_MODE = "list-view-filters-in-views-mode";
|
|
376
|
-
var FORBIDDEN_FIELDS = ["userFilters", "quickFilters"];
|
|
377
376
|
function asArray3(v) {
|
|
378
377
|
if (Array.isArray(v)) return v;
|
|
379
378
|
if (v && typeof v === "object") {
|
|
@@ -387,17 +386,30 @@ function asArray3(v) {
|
|
|
387
386
|
function scanView(view, where, path, out) {
|
|
388
387
|
if (!view || typeof view !== "object") return;
|
|
389
388
|
const rec = view;
|
|
390
|
-
|
|
391
|
-
if (rec[field] == null) continue;
|
|
389
|
+
if (rec.quickFilters != null) {
|
|
392
390
|
out.push({
|
|
393
391
|
severity: "error",
|
|
394
392
|
rule: LIST_VIEW_FILTERS_IN_VIEWS_MODE,
|
|
395
393
|
where,
|
|
396
|
-
path: `${path}
|
|
397
|
-
message:
|
|
398
|
-
hint:
|
|
394
|
+
path: `${path}.quickFilters`,
|
|
395
|
+
message: '`quickFilters` is a page filters-mode control and is ignored on an object list view ("views" mode) \u2014 the ViewTabBar owns nav here.',
|
|
396
|
+
hint: 'Move `quickFilters` to a page list (InterfaceListPage, "filters" mode), or remove it. See ADR-0047.'
|
|
399
397
|
});
|
|
400
398
|
}
|
|
399
|
+
const uf = rec.userFilters;
|
|
400
|
+
if (uf && typeof uf === "object") {
|
|
401
|
+
const ufRec = uf;
|
|
402
|
+
if (ufRec.element === "tabs" || ufRec.tabs != null) {
|
|
403
|
+
out.push({
|
|
404
|
+
severity: "error",
|
|
405
|
+
rule: LIST_VIEW_FILTERS_IN_VIEWS_MODE,
|
|
406
|
+
where,
|
|
407
|
+
path: `${path}.userFilters`,
|
|
408
|
+
message: '`userFilters` with `element: "tabs"` is page-only and is ignored on an object list view ("views" mode) \u2014 it would collide with the ViewTabBar.',
|
|
409
|
+
hint: 'Use `listViews` for named presets on an object (each becomes a segmented tab), switch to `element: "dropdown"` for value chips, or move the `tabs` filter to a page list (InterfaceListPage, "filters" mode). See ADR-0047.'
|
|
410
|
+
});
|
|
411
|
+
}
|
|
412
|
+
}
|
|
401
413
|
}
|
|
402
414
|
function scanListViews(listViews, wherePrefix, pathPrefix, out) {
|
|
403
415
|
if (!listViews || typeof listViews !== "object") return;
|
|
@@ -1180,7 +1192,414 @@ function validateFormLayout(stack) {
|
|
|
1180
1192
|
}
|
|
1181
1193
|
return findings;
|
|
1182
1194
|
}
|
|
1195
|
+
|
|
1196
|
+
// src/validate-capability-references.ts
|
|
1197
|
+
import { PLATFORM_CAPABILITY_NAMES } from "@objectstack/spec/security";
|
|
1198
|
+
var CAPABILITY_REFERENCE_UNKNOWN = "capability-reference-unknown";
|
|
1199
|
+
function asArray12(v) {
|
|
1200
|
+
if (Array.isArray(v)) return v;
|
|
1201
|
+
if (v && typeof v === "object") {
|
|
1202
|
+
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
1203
|
+
}
|
|
1204
|
+
return [];
|
|
1205
|
+
}
|
|
1206
|
+
function asCapArray(v) {
|
|
1207
|
+
return Array.isArray(v) ? v.filter((s) => typeof s === "string" && s.length > 0) : [];
|
|
1208
|
+
}
|
|
1209
|
+
function flattenObjectRequired(v) {
|
|
1210
|
+
if (Array.isArray(v)) return asCapArray(v).map((cap) => ({ cap }));
|
|
1211
|
+
if (v && typeof v === "object") {
|
|
1212
|
+
const out = [];
|
|
1213
|
+
for (const [key, val] of Object.entries(v)) {
|
|
1214
|
+
for (const cap of asCapArray(val)) out.push({ cap, key });
|
|
1215
|
+
}
|
|
1216
|
+
return out;
|
|
1217
|
+
}
|
|
1218
|
+
return [];
|
|
1219
|
+
}
|
|
1220
|
+
function validateCapabilityReferences(stack) {
|
|
1221
|
+
const findings = [];
|
|
1222
|
+
if (!stack || typeof stack !== "object") return findings;
|
|
1223
|
+
const known = new Set(PLATFORM_CAPABILITY_NAMES);
|
|
1224
|
+
for (const ps of asArray12(stack.permissions)) {
|
|
1225
|
+
for (const cap of asCapArray(ps.systemPermissions)) known.add(cap);
|
|
1226
|
+
}
|
|
1227
|
+
for (const seed of asArray12(stack.data)) {
|
|
1228
|
+
if (seed.object !== "sys_capability") continue;
|
|
1229
|
+
for (const rec of Array.isArray(seed.records) ? seed.records : []) {
|
|
1230
|
+
const name = rec?.name;
|
|
1231
|
+
if (typeof name === "string" && name.length > 0) known.add(name);
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
const hint = "Fix the capability name, declare it on a permission set\u2019s systemPermissions, ship a sys_capability seed row, or ignore this if the capability is provided by another installed package (references fail closed at runtime).";
|
|
1235
|
+
const flag = (cap, where, path) => {
|
|
1236
|
+
if (known.has(cap)) return;
|
|
1237
|
+
findings.push({
|
|
1238
|
+
severity: "warning",
|
|
1239
|
+
rule: CAPABILITY_REFERENCE_UNKNOWN,
|
|
1240
|
+
where,
|
|
1241
|
+
path,
|
|
1242
|
+
message: `requiredPermissions references capability "${cap}" which is registered nowhere \u2014 no built-in capability, no permission set in this package grants it via systemPermissions, and no sys_capability seed declares it`,
|
|
1243
|
+
hint
|
|
1244
|
+
});
|
|
1245
|
+
};
|
|
1246
|
+
const objects = asArray12(stack.objects);
|
|
1247
|
+
for (let i = 0; i < objects.length; i++) {
|
|
1248
|
+
const obj = objects[i];
|
|
1249
|
+
if (!obj || typeof obj !== "object") continue;
|
|
1250
|
+
const objName = typeof obj.name === "string" ? obj.name : `(object ${i})`;
|
|
1251
|
+
const objPath = `objects[${i}]`;
|
|
1252
|
+
for (const { cap, key } of flattenObjectRequired(obj.requiredPermissions)) {
|
|
1253
|
+
flag(cap, `object "${objName}"`, `${objPath}.requiredPermissions${key ? `.${key}` : ""}`);
|
|
1254
|
+
}
|
|
1255
|
+
const fields = asArray12(obj.fields);
|
|
1256
|
+
for (const f of fields) {
|
|
1257
|
+
const fname = typeof f.name === "string" ? f.name : "(field)";
|
|
1258
|
+
for (const cap of asCapArray(f.requiredPermissions)) {
|
|
1259
|
+
flag(cap, `field "${objName}.${fname}"`, `${objPath}.fields.${fname}.requiredPermissions`);
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
for (const [ai, action] of asArray12(obj.actions).entries()) {
|
|
1263
|
+
const aName = typeof action.name === "string" ? action.name : `(action ${ai})`;
|
|
1264
|
+
for (const cap of asCapArray(action.requiredPermissions)) {
|
|
1265
|
+
flag(cap, `action "${objName}.${aName}"`, `${objPath}.actions[${ai}].requiredPermissions`);
|
|
1266
|
+
}
|
|
1267
|
+
}
|
|
1268
|
+
}
|
|
1269
|
+
for (const [i, action] of asArray12(stack.actions).entries()) {
|
|
1270
|
+
const aName = typeof action.name === "string" ? action.name : `(action ${i})`;
|
|
1271
|
+
for (const cap of asCapArray(action.requiredPermissions)) {
|
|
1272
|
+
flag(cap, `action "${aName}"`, `actions[${i}].requiredPermissions`);
|
|
1273
|
+
}
|
|
1274
|
+
}
|
|
1275
|
+
const apps = asArray12(stack.apps);
|
|
1276
|
+
for (let i = 0; i < apps.length; i++) {
|
|
1277
|
+
const app = apps[i];
|
|
1278
|
+
if (!app || typeof app !== "object") continue;
|
|
1279
|
+
const appName = typeof app.name === "string" ? app.name : `(app ${i})`;
|
|
1280
|
+
const walk = (node, path) => {
|
|
1281
|
+
if (!node || typeof node !== "object") return;
|
|
1282
|
+
if (Array.isArray(node)) {
|
|
1283
|
+
node.forEach((child, ci) => walk(child, `${path}[${ci}]`));
|
|
1284
|
+
return;
|
|
1285
|
+
}
|
|
1286
|
+
const rec = node;
|
|
1287
|
+
for (const cap of asCapArray(rec.requiredPermissions)) {
|
|
1288
|
+
flag(cap, `app "${appName}"`, `${path}.requiredPermissions`);
|
|
1289
|
+
}
|
|
1290
|
+
if (rec.navigation) walk(rec.navigation, `${path}.navigation`);
|
|
1291
|
+
if (rec.areas) walk(rec.areas, `${path}.areas`);
|
|
1292
|
+
if (rec.tabs) walk(rec.tabs, `${path}.tabs`);
|
|
1293
|
+
if (rec.children) walk(rec.children, `${path}.children`);
|
|
1294
|
+
if (rec.items) walk(rec.items, `${path}.items`);
|
|
1295
|
+
};
|
|
1296
|
+
walk(app, `apps[${i}]`);
|
|
1297
|
+
}
|
|
1298
|
+
return findings;
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
// src/validate-security-posture.ts
|
|
1302
|
+
import { describeAnchorForbiddenBits } from "@objectstack/spec/security";
|
|
1303
|
+
var SECURITY_OWD_UNSET = "security-owd-unset";
|
|
1304
|
+
var SECURITY_OWD_ALIAS = "security-owd-alias";
|
|
1305
|
+
var SECURITY_EXTERNAL_WIDER = "security-external-wider-than-internal";
|
|
1306
|
+
var SECURITY_WILDCARD_VAMA = "security-wildcard-vama";
|
|
1307
|
+
var SECURITY_ANCHOR_HIGH_PRIVILEGE = "security-anchor-high-privilege";
|
|
1308
|
+
var SECURITY_ROLE_WORD = "security-role-word";
|
|
1309
|
+
var SECURITY_PRIVATE_NO_READSCOPE = "security-private-no-readscope";
|
|
1310
|
+
var CANONICAL_OWD = ["private", "public_read", "public_read_write", "controlled_by_parent"];
|
|
1311
|
+
var OWD_ALIAS_FIX = {
|
|
1312
|
+
read: "public_read",
|
|
1313
|
+
read_write: "public_read_write",
|
|
1314
|
+
full: "public_read_write",
|
|
1315
|
+
public: "public_read_write"
|
|
1316
|
+
};
|
|
1317
|
+
var OWD_WIDTH = {
|
|
1318
|
+
private: 0,
|
|
1319
|
+
public_read: 1,
|
|
1320
|
+
public_read_write: 2
|
|
1321
|
+
};
|
|
1322
|
+
function asArray13(v) {
|
|
1323
|
+
if (Array.isArray(v)) return v;
|
|
1324
|
+
if (v && typeof v === "object") {
|
|
1325
|
+
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
1326
|
+
}
|
|
1327
|
+
return [];
|
|
1328
|
+
}
|
|
1329
|
+
function owdOf(obj) {
|
|
1330
|
+
return obj.sharingModel ?? obj.security?.sharingModel;
|
|
1331
|
+
}
|
|
1332
|
+
function isSystemObject(obj) {
|
|
1333
|
+
return obj.isSystem === true || String(obj.name ?? "").startsWith("sys_");
|
|
1334
|
+
}
|
|
1335
|
+
function identifierHasRoleToken(name) {
|
|
1336
|
+
if (typeof name !== "string") return false;
|
|
1337
|
+
return name.toLowerCase().split(/[^a-z0-9]+/).some((tok) => tok === "role" || tok === "roles");
|
|
1338
|
+
}
|
|
1339
|
+
function labelHasRoleWord(label) {
|
|
1340
|
+
if (typeof label !== "string") return false;
|
|
1341
|
+
return /\brole(s)?\b/i.test(label);
|
|
1342
|
+
}
|
|
1343
|
+
function validateSecurityPosture(stack) {
|
|
1344
|
+
const findings = [];
|
|
1345
|
+
if (!stack || typeof stack !== "object") return findings;
|
|
1346
|
+
const objects = asArray13(stack.objects);
|
|
1347
|
+
const permissionSets = asArray13(stack.permissions);
|
|
1348
|
+
for (let i = 0; i < objects.length; i++) {
|
|
1349
|
+
const obj = objects[i];
|
|
1350
|
+
if (!obj || typeof obj !== "object") continue;
|
|
1351
|
+
const objName = typeof obj.name === "string" ? obj.name : `(object ${i})`;
|
|
1352
|
+
const objPath = `objects[${i}]`;
|
|
1353
|
+
const owd = owdOf(obj);
|
|
1354
|
+
const external = obj.externalSharingModel;
|
|
1355
|
+
if (!isSystemObject(obj)) {
|
|
1356
|
+
if (owd == null) {
|
|
1357
|
+
findings.push({
|
|
1358
|
+
severity: "error",
|
|
1359
|
+
rule: SECURITY_OWD_UNSET,
|
|
1360
|
+
where: `object "${objName}"`,
|
|
1361
|
+
path: `${objPath}.sharingModel`,
|
|
1362
|
+
message: `custom object "${objName}" declares no sharingModel (OWD). The runtime fails CLOSED to 'private' (ADR-0090 D1), but the baseline must be an authored decision, not an accident \u2014 this is the exact shape of the leave_request incident (objectui#2348).`,
|
|
1363
|
+
hint: `Declare sharingModel explicitly: 'private' (owner + shares; recommended default), 'public_read', 'public_read_write', or 'controlled_by_parent' (master-detail children).`
|
|
1364
|
+
});
|
|
1365
|
+
} else if (typeof owd === "string" && OWD_ALIAS_FIX[owd]) {
|
|
1366
|
+
findings.push({
|
|
1367
|
+
severity: "error",
|
|
1368
|
+
rule: SECURITY_OWD_ALIAS,
|
|
1369
|
+
where: `object "${objName}"`,
|
|
1370
|
+
path: `${objPath}.sharingModel`,
|
|
1371
|
+
message: `sharingModel '${owd}' is a retired alias (ADR-0090 D4). The runtime fails CLOSED to 'private' on unknown values, so this object is NOT ${owd === "read" ? "readable" : "writable"} org-wide.`,
|
|
1372
|
+
hint: `Replace with the canonical value: sharingModel: '${OWD_ALIAS_FIX[owd]}'.`
|
|
1373
|
+
});
|
|
1374
|
+
} else if (typeof owd === "string" && !CANONICAL_OWD.includes(owd)) {
|
|
1375
|
+
findings.push({
|
|
1376
|
+
severity: "error",
|
|
1377
|
+
rule: SECURITY_OWD_ALIAS,
|
|
1378
|
+
where: `object "${objName}"`,
|
|
1379
|
+
path: `${objPath}.sharingModel`,
|
|
1380
|
+
message: `sharingModel '${owd}' is not a canonical OWD value; the runtime fails CLOSED to 'private'.`,
|
|
1381
|
+
hint: `Use one of: ${CANONICAL_OWD.join(", ")}.`
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1385
|
+
if (typeof external === "string") {
|
|
1386
|
+
if (OWD_ALIAS_FIX[external]) {
|
|
1387
|
+
findings.push({
|
|
1388
|
+
severity: "error",
|
|
1389
|
+
rule: SECURITY_OWD_ALIAS,
|
|
1390
|
+
where: `object "${objName}"`,
|
|
1391
|
+
path: `${objPath}.externalSharingModel`,
|
|
1392
|
+
message: `externalSharingModel '${external}' is a retired alias (ADR-0090 D4).`,
|
|
1393
|
+
hint: `Replace with the canonical value: externalSharingModel: '${OWD_ALIAS_FIX[external]}'.`
|
|
1394
|
+
});
|
|
1395
|
+
} else if (typeof owd === "string" && external in OWD_WIDTH && owd in OWD_WIDTH && OWD_WIDTH[external] > OWD_WIDTH[owd]) {
|
|
1396
|
+
findings.push({
|
|
1397
|
+
severity: "error",
|
|
1398
|
+
rule: SECURITY_EXTERNAL_WIDER,
|
|
1399
|
+
where: `object "${objName}"`,
|
|
1400
|
+
path: `${objPath}.externalSharingModel`,
|
|
1401
|
+
message: `externalSharingModel '${external}' is WIDER than the internal sharingModel '${owd}' \u2014 the external baseline must never exceed the internal one (ADR-0090 D11).`,
|
|
1402
|
+
hint: `Narrow externalSharingModel to '${owd}' or below (ordering: private < public_read < public_read_write).`
|
|
1403
|
+
});
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
}
|
|
1407
|
+
for (let i = 0; i < permissionSets.length; i++) {
|
|
1408
|
+
const ps = permissionSets[i];
|
|
1409
|
+
if (!ps || typeof ps !== "object") continue;
|
|
1410
|
+
const psName = typeof ps.name === "string" ? ps.name : `(permission set ${i})`;
|
|
1411
|
+
const psPath = `permissions[${i}]`;
|
|
1412
|
+
const objectsMap = ps.objects && typeof ps.objects === "object" ? ps.objects : {};
|
|
1413
|
+
const wildcard = objectsMap["*"];
|
|
1414
|
+
if (wildcard && (wildcard.viewAllRecords === true || wildcard.modifyAllRecords === true)) {
|
|
1415
|
+
findings.push({
|
|
1416
|
+
severity: "error",
|
|
1417
|
+
rule: SECURITY_WILDCARD_VAMA,
|
|
1418
|
+
where: `permission set "${psName}"`,
|
|
1419
|
+
path: `${psPath}.objects.*`,
|
|
1420
|
+
message: `'*' wildcard carrying View All / Modify All Data \u2014 a package-authored superuser. Only the platform's own admin set may combine the wildcard with VAMA (ADR-0066).`,
|
|
1421
|
+
hint: `Enumerate the objects this set really needs, or drop viewAllRecords/modifyAllRecords from the wildcard entry. App-level admins belong in an ordinary set the customer binds to a position of their choosing (ADR-0090 D9).`
|
|
1422
|
+
});
|
|
1423
|
+
}
|
|
1424
|
+
if (ps.isDefault === true) {
|
|
1425
|
+
const offending = describeAnchorForbiddenBits(ps, "everyone");
|
|
1426
|
+
if (offending) {
|
|
1427
|
+
findings.push({
|
|
1428
|
+
severity: "error",
|
|
1429
|
+
rule: SECURITY_ANCHOR_HIGH_PRIVILEGE,
|
|
1430
|
+
where: `permission set "${psName}"`,
|
|
1431
|
+
path: `${psPath}.isDefault`,
|
|
1432
|
+
message: `isDefault:true suggests binding this set to the 'everyone' audience anchor, but it carries ${offending} \u2014 the runtime will refuse the binding (ADR-0090 D5/D9).`,
|
|
1433
|
+
hint: `Split the powerful bits into a separate set granted through ordinary positions, and keep the everyone-suggested set low-privilege.`
|
|
1434
|
+
});
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1437
|
+
}
|
|
1438
|
+
const flagRole = (kind, name, label, where, path) => {
|
|
1439
|
+
if (identifierHasRoleToken(name)) {
|
|
1440
|
+
findings.push({
|
|
1441
|
+
severity: "error",
|
|
1442
|
+
rule: SECURITY_ROLE_WORD,
|
|
1443
|
+
where,
|
|
1444
|
+
path,
|
|
1445
|
+
message: `${kind} name "${String(name)}" uses the reserved word "role" \u2014 the platform vocabulary is permission_set (capability), position (distribution), business_unit (hierarchy) (ADR-0090 D3).`,
|
|
1446
|
+
hint: `Rename using 'position' for distribution groups or a domain word (e.g. 'function', 'duty').`
|
|
1447
|
+
});
|
|
1448
|
+
} else if (labelHasRoleWord(label)) {
|
|
1449
|
+
findings.push({
|
|
1450
|
+
severity: "error",
|
|
1451
|
+
rule: SECURITY_ROLE_WORD,
|
|
1452
|
+
where,
|
|
1453
|
+
path: `${path.replace(/\.name$/, "")}.label`,
|
|
1454
|
+
message: `${kind} label "${String(label)}" uses the reserved word "role" (ADR-0090 D3).`,
|
|
1455
|
+
hint: `Relabel with 'Position' (distribution) or a domain word \u2014 admins must meet ONE vocabulary.`
|
|
1456
|
+
});
|
|
1457
|
+
}
|
|
1458
|
+
};
|
|
1459
|
+
for (let i = 0; i < objects.length; i++) {
|
|
1460
|
+
const obj = objects[i];
|
|
1461
|
+
if (!obj || typeof obj !== "object" || isSystemObject(obj)) continue;
|
|
1462
|
+
const objName = typeof obj.name === "string" ? obj.name : `(object ${i})`;
|
|
1463
|
+
flagRole("object", obj.name, obj.label, `object "${objName}"`, `objects[${i}].name`);
|
|
1464
|
+
for (const f of asArray13(obj.fields)) {
|
|
1465
|
+
flagRole("field", f.name, f.label, `field "${objName}.${String(f.name ?? "?")}"`, `objects[${i}].fields.${String(f.name ?? "?")}.name`);
|
|
1466
|
+
}
|
|
1467
|
+
for (const [ai, action] of asArray13(obj.actions).entries()) {
|
|
1468
|
+
flagRole("action", action.name, action.label, `action "${objName}.${String(action.name ?? "?")}"`, `objects[${i}].actions[${ai}].name`);
|
|
1469
|
+
}
|
|
1470
|
+
}
|
|
1471
|
+
for (let i = 0; i < permissionSets.length; i++) {
|
|
1472
|
+
const ps = permissionSets[i];
|
|
1473
|
+
if (!ps || typeof ps !== "object") continue;
|
|
1474
|
+
flagRole("permission set", ps.name, ps.label, `permission set "${String(ps.name ?? i)}"`, `permissions[${i}].name`);
|
|
1475
|
+
}
|
|
1476
|
+
for (const [i, pos] of asArray13(stack.positions).entries()) {
|
|
1477
|
+
flagRole("position", pos.name, pos.label, `position "${String(pos.name ?? i)}"`, `positions[${i}].name`);
|
|
1478
|
+
}
|
|
1479
|
+
for (const [i, app] of asArray13(stack.apps).entries()) {
|
|
1480
|
+
flagRole("app", app.name, app.label, `app "${String(app.name ?? i)}"`, `apps[${i}].name`);
|
|
1481
|
+
}
|
|
1482
|
+
const privateObjects = new Set(
|
|
1483
|
+
objects.filter((o) => o && typeof o === "object" && !isSystemObject(o)).filter((o) => {
|
|
1484
|
+
const owd = owdOf(o);
|
|
1485
|
+
return owd == null || owd === "private";
|
|
1486
|
+
}).map((o) => String(o.name ?? ""))
|
|
1487
|
+
);
|
|
1488
|
+
if (privateObjects.size > 0) {
|
|
1489
|
+
for (let i = 0; i < permissionSets.length; i++) {
|
|
1490
|
+
const ps = permissionSets[i];
|
|
1491
|
+
if (!ps || typeof ps !== "object") continue;
|
|
1492
|
+
const psName = typeof ps.name === "string" ? ps.name : `(permission set ${i})`;
|
|
1493
|
+
const objectsMap = ps.objects && typeof ps.objects === "object" ? ps.objects : {};
|
|
1494
|
+
for (const [objName, rawPerm] of Object.entries(objectsMap)) {
|
|
1495
|
+
if (!privateObjects.has(objName)) continue;
|
|
1496
|
+
const p = rawPerm ?? {};
|
|
1497
|
+
if (p.allowRead === true && p.readScope == null && p.viewAllRecords !== true) {
|
|
1498
|
+
findings.push({
|
|
1499
|
+
severity: "info",
|
|
1500
|
+
rule: SECURITY_PRIVATE_NO_READSCOPE,
|
|
1501
|
+
where: `permission set "${psName}"`,
|
|
1502
|
+
path: `permissions[${i}].objects.${objName}.readScope`,
|
|
1503
|
+
message: `"${objName}" is private (OWD) and this set grants allowRead without a readScope \u2014 holders see ONLY records they own (plus explicit shares).`,
|
|
1504
|
+
hint: `If that is intended (personal data), ignore this. Otherwise add readScope: 'own_and_reports' | 'unit' | 'unit_and_below' | 'org', or widen the object's sharingModel.`
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
}
|
|
1508
|
+
}
|
|
1509
|
+
}
|
|
1510
|
+
return findings;
|
|
1511
|
+
}
|
|
1512
|
+
|
|
1513
|
+
// src/build-access-matrix.ts
|
|
1514
|
+
function asArray14(v) {
|
|
1515
|
+
if (Array.isArray(v)) return v;
|
|
1516
|
+
if (v && typeof v === "object") {
|
|
1517
|
+
return Object.entries(v).map(([name, def]) => ({ name, ...def }));
|
|
1518
|
+
}
|
|
1519
|
+
return [];
|
|
1520
|
+
}
|
|
1521
|
+
function buildAccessMatrix(stack) {
|
|
1522
|
+
const entries = [];
|
|
1523
|
+
if (!stack || typeof stack !== "object") return { version: 1, entries };
|
|
1524
|
+
const owdByObject = /* @__PURE__ */ new Map();
|
|
1525
|
+
for (const obj of asArray14(stack.objects)) {
|
|
1526
|
+
const name = typeof obj.name === "string" ? obj.name : "";
|
|
1527
|
+
if (!name) continue;
|
|
1528
|
+
const owd = obj.sharingModel ?? obj.security?.sharingModel;
|
|
1529
|
+
if (typeof owd === "string") owdByObject.set(name, owd);
|
|
1530
|
+
}
|
|
1531
|
+
for (const ps of asArray14(stack.permissions)) {
|
|
1532
|
+
const psName = typeof ps.name === "string" ? ps.name : "";
|
|
1533
|
+
if (!psName) continue;
|
|
1534
|
+
const objects = ps.objects && typeof ps.objects === "object" ? ps.objects : {};
|
|
1535
|
+
for (const [objName, rawPerm] of Object.entries(objects)) {
|
|
1536
|
+
const p = rawPerm ?? {};
|
|
1537
|
+
const entry = {
|
|
1538
|
+
permissionSet: psName,
|
|
1539
|
+
object: objName,
|
|
1540
|
+
create: p.allowCreate === true,
|
|
1541
|
+
read: p.allowRead === true || p.viewAllRecords === true || p.modifyAllRecords === true,
|
|
1542
|
+
edit: p.allowEdit === true || p.modifyAllRecords === true,
|
|
1543
|
+
delete: p.allowDelete === true || p.modifyAllRecords === true,
|
|
1544
|
+
viewAllRecords: p.viewAllRecords === true,
|
|
1545
|
+
modifyAllRecords: p.modifyAllRecords === true
|
|
1546
|
+
};
|
|
1547
|
+
if (typeof p.readScope === "string") entry.readScope = p.readScope;
|
|
1548
|
+
if (typeof p.writeScope === "string") entry.writeScope = p.writeScope;
|
|
1549
|
+
const owd = owdByObject.get(objName);
|
|
1550
|
+
if (owd) entry.sharingModel = owd;
|
|
1551
|
+
entries.push(entry);
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
entries.sort(
|
|
1555
|
+
(a, b) => a.permissionSet === b.permissionSet ? a.object.localeCompare(b.object) : a.permissionSet.localeCompare(b.permissionSet)
|
|
1556
|
+
);
|
|
1557
|
+
return { version: 1, entries };
|
|
1558
|
+
}
|
|
1559
|
+
var BIT_LABELS = [
|
|
1560
|
+
["create", "create"],
|
|
1561
|
+
["read", "read"],
|
|
1562
|
+
["edit", "edit"],
|
|
1563
|
+
["delete", "delete"],
|
|
1564
|
+
["viewAllRecords", "View All Data"],
|
|
1565
|
+
["modifyAllRecords", "Modify All Data"]
|
|
1566
|
+
];
|
|
1567
|
+
function diffAccessMatrix(before, after) {
|
|
1568
|
+
const lines = [];
|
|
1569
|
+
const key = (e) => `${e.permissionSet}\0${e.object}`;
|
|
1570
|
+
const beforeMap = new Map((before?.entries ?? []).map((e) => [key(e), e]));
|
|
1571
|
+
const afterMap = new Map((after?.entries ?? []).map((e) => [key(e), e]));
|
|
1572
|
+
for (const [k, b] of beforeMap) {
|
|
1573
|
+
if (!afterMap.has(k)) {
|
|
1574
|
+
lines.push(`'${b.permissionSet}' loses ALL access to '${b.object}' (entry removed)`);
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
for (const [k, a] of afterMap) {
|
|
1578
|
+
const b = beforeMap.get(k);
|
|
1579
|
+
if (!b) {
|
|
1580
|
+
const grants = BIT_LABELS.filter(([bit]) => a[bit] === true).map(([, label]) => label);
|
|
1581
|
+
lines.push(`'${a.permissionSet}' gains access to '${a.object}' (${grants.join(", ") || "no bits set"})`);
|
|
1582
|
+
continue;
|
|
1583
|
+
}
|
|
1584
|
+
for (const [bit, label] of BIT_LABELS) {
|
|
1585
|
+
if (b[bit] !== a[bit]) {
|
|
1586
|
+
lines.push(`'${a.permissionSet}' ${a[bit] ? "gains" : "loses"} ${label} on '${a.object}'`);
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
if ((b.readScope ?? "own") !== (a.readScope ?? "own")) {
|
|
1590
|
+
lines.push(`'${a.permissionSet}' read depth on '${a.object}': ${b.readScope ?? "own"} \u2192 ${a.readScope ?? "own"}`);
|
|
1591
|
+
}
|
|
1592
|
+
if ((b.writeScope ?? "own") !== (a.writeScope ?? "own")) {
|
|
1593
|
+
lines.push(`'${a.permissionSet}' write depth on '${a.object}': ${b.writeScope ?? "own"} \u2192 ${a.writeScope ?? "own"}`);
|
|
1594
|
+
}
|
|
1595
|
+
if ((b.sharingModel ?? "") !== (a.sharingModel ?? "")) {
|
|
1596
|
+
lines.push(`'${a.object}' record baseline (OWD): ${b.sharingModel ?? "(unset)"} \u2192 ${a.sharingModel ?? "(unset)"} (affects every principal)`);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
return lines;
|
|
1600
|
+
}
|
|
1183
1601
|
export {
|
|
1602
|
+
CAPABILITY_REFERENCE_UNKNOWN,
|
|
1184
1603
|
CHART_CONFIG_MISSING,
|
|
1185
1604
|
CHART_FIELD_UNKNOWN,
|
|
1186
1605
|
FIELD_GROUP_EMPTY,
|
|
@@ -1190,6 +1609,13 @@ export {
|
|
|
1190
1609
|
LIST_VIEW_FILTERS_IN_VIEWS_MODE,
|
|
1191
1610
|
MEASURE_AGGREGATE_INCOHERENT,
|
|
1192
1611
|
PAGE_SOURCE_CLASSNAME,
|
|
1612
|
+
SECURITY_ANCHOR_HIGH_PRIVILEGE,
|
|
1613
|
+
SECURITY_EXTERNAL_WIDER,
|
|
1614
|
+
SECURITY_OWD_ALIAS,
|
|
1615
|
+
SECURITY_OWD_UNSET,
|
|
1616
|
+
SECURITY_PRIVATE_NO_READSCOPE,
|
|
1617
|
+
SECURITY_ROLE_WORD,
|
|
1618
|
+
SECURITY_WILDCARD_VAMA,
|
|
1193
1619
|
SEMANTIC_ROLE_FIELD_UNKNOWN,
|
|
1194
1620
|
STYLE_CLASSNAME_TAILWIND,
|
|
1195
1621
|
STYLE_NODE_MISSING_ID,
|
|
@@ -1202,6 +1628,9 @@ export {
|
|
|
1202
1628
|
WIDGET_DATASET_UNKNOWN,
|
|
1203
1629
|
WIDGET_DIMENSION_UNKNOWN,
|
|
1204
1630
|
WIDGET_MEASURE_UNKNOWN,
|
|
1631
|
+
buildAccessMatrix,
|
|
1632
|
+
diffAccessMatrix,
|
|
1633
|
+
validateCapabilityReferences,
|
|
1205
1634
|
validateFormLayout,
|
|
1206
1635
|
validateJsxPages,
|
|
1207
1636
|
validateListViewMode,
|
|
@@ -1210,6 +1639,7 @@ export {
|
|
|
1210
1639
|
validateReactPages,
|
|
1211
1640
|
validateRecordTitle,
|
|
1212
1641
|
validateResponsiveStyles,
|
|
1642
|
+
validateSecurityPosture,
|
|
1213
1643
|
validateSemanticRoles,
|
|
1214
1644
|
validateStackExpressions,
|
|
1215
1645
|
validateWidgetBindings
|