kryptheon 0.1.69 → 0.1.71
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/LICENSE +38 -38
- package/kryptheon-api.js +131 -13
- package/kryptheon-baselines.js +232 -232
- package/kryptheon-changes.js +222 -222
- package/kryptheon-dashboard-page.js +9 -0
- package/kryptheon-dashboard.html +3 -0
- package/kryptheon-fonts-OFL.txt +98 -98
- package/kryptheon-probe-reporter.js +29 -29
- package/kryptheon-probe.config.js +37 -37
- package/kryptheon-project.js +600 -600
- package/kryptheon-roles.js +54 -17
- package/kryptheon-selectors.js +301 -301
- package/kryptheon-store.js +334 -334
- package/kryptheon-testfiles.js +98 -98
- package/package.json +4 -2
- package/playwright.config.js +73 -73
package/kryptheon-roles.js
CHANGED
|
@@ -716,6 +716,13 @@ async function checkAccess(input) {
|
|
|
716
716
|
s.userId = user.id;
|
|
717
717
|
sessions.push(s);
|
|
718
718
|
}
|
|
719
|
+
// No account says which organization it belongs to: each person is their own owner (an AI chat, a study app - every
|
|
720
|
+
// conversation or note is one user's), and the wall is tried user against user.
|
|
721
|
+
if (policy.tenants && !sessions.some((s) => s.org) && input.perUser !== false) {
|
|
722
|
+
for (const s of sessions) if (s.userId !== undefined && s.userId !== null) s.org = { key: String(s.userId), name: s.email, perUser: true };
|
|
723
|
+
}
|
|
724
|
+
const perUser = sessions.some((s) => s.org && s.org.perUser);
|
|
725
|
+
const ownKey = perUser ? USER_KEY : ORG_KEY;
|
|
719
726
|
out.accounts = sessions.map((s) => ({ email: s.email, role: s.role, org: s.org ? s.org.name : null }));
|
|
720
727
|
if (sessions.length < 2) {
|
|
721
728
|
skipped.push({ what: 'accounts', why: 'fewer than two accounts could be signed in, so there is nothing to compare' });
|
|
@@ -728,6 +735,7 @@ async function checkAccess(input) {
|
|
|
728
735
|
orgs.get(s.org.key).sessions.push(s);
|
|
729
736
|
}
|
|
730
737
|
const tenants = policy.tenants && orgs.size >= 2;
|
|
738
|
+
if (perUser && tenants) notes.push('No account says which organization it belongs to, so each signed-in person was taken as the owner of their own records and tried against the others - what one could open of another\'s is a thing to check (a public profile or a shared post is meant to be seen).');
|
|
731
739
|
if (policy.tenants && !tenants) notes.push('The policy keeps organizations apart, but ' + (orgs.size ? 'all the accounts that could be signed in belong to one organization' : 'the app did not say which organization anyone belongs to') + ' - the organization check was not tried.');
|
|
732
740
|
|
|
733
741
|
// 2. the actions, and the permission each needs
|
|
@@ -816,7 +824,7 @@ async function checkAccess(input) {
|
|
|
816
824
|
if (!fresh && itemsCache.has(k)) return itemsCache.get(k);
|
|
817
825
|
const found = await readerFor(orgKey, template, permOf.get('GET ' + template) || null, true);
|
|
818
826
|
// Records marked as another organization's are not this organization's to aim at, whatever the list holds.
|
|
819
|
-
const list = found ? (listOf(found.res.json) || []).filter((it) => !foreignRecords(it, orgKey).length) : null;
|
|
827
|
+
const list = found ? (listOf(found.res.json) || []).filter((it) => !foreignRecords(it, orgKey, ownKey).length) : null;
|
|
820
828
|
itemsCache.set(k, list && list.length ? list : null);
|
|
821
829
|
return itemsCache.get(k);
|
|
822
830
|
};
|
|
@@ -890,7 +898,13 @@ async function checkAccess(input) {
|
|
|
890
898
|
if (PEOPLE.test(action.segs[action.params[0].index - 1] || '')) {
|
|
891
899
|
const people = accountsOf(orgKey).filter((ss) => ss.userId !== undefined && ss.userId !== null)
|
|
892
900
|
.map((ss) => ({ value: ss.userId, item: { id: ss.userId, email: ss.email, role: ss.role }, listing: listing, field: 'id' }));
|
|
893
|
-
|
|
901
|
+
if (people.length) return people;
|
|
902
|
+
}
|
|
903
|
+
// No list and nothing made: the organization's rows from the app's own database, where it can be read
|
|
904
|
+
// (blind round 35: GET /customers/:id and PATCH /notes/:id were never aimed across organizations).
|
|
905
|
+
if (typeof input.dbTargets === 'function') {
|
|
906
|
+
const rows = await input.dbTargets(action, listing, orgKey, perUser);
|
|
907
|
+
if (rows && rows.length) return rows;
|
|
894
908
|
}
|
|
895
909
|
return null;
|
|
896
910
|
}
|
|
@@ -1006,7 +1020,7 @@ async function checkAccess(input) {
|
|
|
1006
1020
|
const a = p.action;
|
|
1007
1021
|
const label = (p.kind === 'tenant' ? 'across organizations: ' : '') + p.actor.role + ' ' + a.method + ' ' + a.template;
|
|
1008
1022
|
say(' ' + n + ' of ' + chosen.length + ': ' + label);
|
|
1009
|
-
const att = await tryOnce({ p, ctx, policy, orgs, snapshot, compare, targetsFor, itemsOf, markersOf, knownTo, readerFor, rotate, tenants, sessions, hide, getTemplates, snapshotTemplates, actions: journey.actions });
|
|
1023
|
+
const att = await tryOnce({ p, ctx, policy, orgs, snapshot, compare, targetsFor, itemsOf, markersOf, knownTo, readerFor, rotate, tenants, sessions, hide, getTemplates, snapshotTemplates, actions: journey.actions, perUser, ownKey });
|
|
1010
1024
|
if (Array.isArray(att)) out.attempts.push.apply(out.attempts, att);
|
|
1011
1025
|
else if (att) out.attempts.push(att);
|
|
1012
1026
|
}
|
|
@@ -1089,15 +1103,29 @@ async function tryOnce(x) {
|
|
|
1089
1103
|
const base = {
|
|
1090
1104
|
kind: p.kind, permission: a.permission, method: a.method, template: a.template, expected: p.expected,
|
|
1091
1105
|
actor: { email: actor.email, role: actor.role, org: actor.org ? actor.org.name : null },
|
|
1092
|
-
targetOrg: orgName(targetOrg), cross: p.kind === 'tenant',
|
|
1106
|
+
targetOrg: orgName(targetOrg), cross: p.kind === 'tenant', perUser: Boolean(x.perUser),
|
|
1093
1107
|
};
|
|
1094
1108
|
const skip = (why) => Object.assign(base, { verdict: V.AMBIGUOUS, reason: why, notTried: true, request: { method: a.method, path: a.template } });
|
|
1095
1109
|
|
|
1096
1110
|
// where to aim
|
|
1097
1111
|
let target = { value: null, item: null };
|
|
1098
1112
|
if (a.params.length) {
|
|
1099
|
-
|
|
1113
|
+
let targets = await x.targetsFor(a, targetOrg);
|
|
1100
1114
|
if (!targets) return skip('no record of ' + (orgName(targetOrg) || 'that organization') + ' could be found to aim it at (the app lists none at ' + '/' + a.segs.slice(0, a.params[0].index).join('/') + ')');
|
|
1115
|
+
// User against user, a record the caller sees in their own list too is shared (one team's work orders, classes
|
|
1116
|
+
// anyone may book): only what the other user holds and the caller does not see is theirs alone (round 22: notes on
|
|
1117
|
+
// a team's work order, a class booking, were taken for another user's record).
|
|
1118
|
+
if (p.kind === 'tenant' && x.perUser && actor.org) {
|
|
1119
|
+
const listing = '/' + a.segs.slice(0, a.params[0].index).join('/');
|
|
1120
|
+
// the list as the caller gets it, whole - not cut to the records marked as theirs
|
|
1121
|
+
const read = x.getTemplates.has(listing) ? await x.readerFor(actor.org.key, listing, null, false) : null;
|
|
1122
|
+
const seenByMe = read ? listOf(read.res.json) : null;
|
|
1123
|
+
if (seenByMe && seenByMe.length) {
|
|
1124
|
+
const mineToo = new Set(seenByMe.map((it) => (it && typeof it === 'object' ? JSON.stringify(it[targets[0].field || 'id']) : '')));
|
|
1125
|
+
targets = targets.filter((t) => !mineToo.has(JSON.stringify(t.value)));
|
|
1126
|
+
if (!targets.length) return skip('shared: every record of ' + (orgName(targetOrg) || 'that user') + ' at ' + listing + ' is in this user\'s own list too, so none is theirs alone to aim at');
|
|
1127
|
+
}
|
|
1128
|
+
}
|
|
1101
1129
|
const k = targetOrg + '|' + a.template;
|
|
1102
1130
|
const i = (x.rotate.get(k) || 0);
|
|
1103
1131
|
x.rotate.set(k, i + 1);
|
|
@@ -1249,8 +1277,8 @@ async function tryOnce(x) {
|
|
|
1249
1277
|
res = await actor.send(a.method, pathNow, a.encoding === 'form' ? { form: body } : { json: body });
|
|
1250
1278
|
}
|
|
1251
1279
|
const reply = authz.replyOf(res);
|
|
1252
|
-
const foreign = actor.org && isGet ? foreignRecords(res.json, actor.org.key) : [];
|
|
1253
|
-
const ownMarked = actor.org && isGet ? ownRecords(res.json, actor.org.key) : 0;
|
|
1280
|
+
const foreign = actor.org && isGet && !x.perUser ? foreignRecords(res.json, actor.org.key) : [];
|
|
1281
|
+
const ownMarked = actor.org && isGet ? ownRecords(res.json, actor.org.key, x.ownKey || ORG_KEY) : 0;
|
|
1254
1282
|
// Across organizations, a piece found only inside records marked as the caller's own organization is the caller's
|
|
1255
1283
|
// (round 27: every organization's audit says "Status set to open", and one statement stamped both organizations'
|
|
1256
1284
|
// rows alike). A role's try is another matter: its own organization's records are what it may not see.
|
|
@@ -1261,7 +1289,7 @@ async function tryOnce(x) {
|
|
|
1261
1289
|
const shared = p.kind === 'tenant' && isGet && markers.length
|
|
1262
1290
|
? authz.sharedOnly(res.json, theirs, markers).concat(!a.params.length ? authz.sameDefaults(res.json, theirs, markers) : [])
|
|
1263
1291
|
: [];
|
|
1264
|
-
let found = markers.length ? authz.foundIn(p.kind === 'tenant' && isGet && actor.org ? withoutOwn(res, actor.org.key) : res, markers.filter((m) => !shared.includes(m))).length : 0;
|
|
1292
|
+
let found = markers.length ? authz.foundIn(p.kind === 'tenant' && isGet && actor.org ? withoutOwn(res, actor.org.key, x.ownKey || ORG_KEY) : res, markers.filter((m) => !shared.includes(m))).length : 0;
|
|
1265
1293
|
// their record's own words now in our lists: a record of ours points at theirs (round 25: a transfer whose
|
|
1266
1294
|
// destination was another organization's location, shown by name in our list of transfers)
|
|
1267
1295
|
let pointedAt = [];
|
|
@@ -1429,9 +1457,12 @@ function wordsOfAnyRecord(value) {
|
|
|
1429
1457
|
|
|
1430
1458
|
// A record's own mark of the organization it belongs to.
|
|
1431
1459
|
const ORG_KEY = /^(org|organi[sz]ation|tenant|workspace|company)[_-]?id$/i;
|
|
1460
|
+
// ... and, in an app with no organizations, of the person who owns it.
|
|
1461
|
+
const USER_KEY = /^(user|owner|author|creator|student|member|profile)[_-]?id$|^(created|owned)[_-]?by$/i;
|
|
1432
1462
|
|
|
1433
1463
|
/** Records in an answer that carry another organization's mark: [{ key, value }]. */
|
|
1434
|
-
function foreignRecords(json, orgKey) {
|
|
1464
|
+
function foreignRecords(json, orgKey, keyRe) {
|
|
1465
|
+
const KEY = keyRe || ORG_KEY;
|
|
1435
1466
|
const out = [];
|
|
1436
1467
|
const walk = (v, depth) => {
|
|
1437
1468
|
if (depth > 4 || v == null || typeof v !== 'object') return;
|
|
@@ -1440,7 +1471,7 @@ function foreignRecords(json, orgKey) {
|
|
|
1440
1471
|
return;
|
|
1441
1472
|
}
|
|
1442
1473
|
for (const k of Object.keys(v)) {
|
|
1443
|
-
if (
|
|
1474
|
+
if (KEY.test(k) && ['string', 'number'].includes(typeof v[k]) && String(v[k]) !== String(orgKey)) out.push({ key: k, value: v[k] });
|
|
1444
1475
|
else if (typeof v[k] === 'object') walk(v[k], depth + 1);
|
|
1445
1476
|
}
|
|
1446
1477
|
};
|
|
@@ -1449,9 +1480,10 @@ function foreignRecords(json, orgKey) {
|
|
|
1449
1480
|
}
|
|
1450
1481
|
|
|
1451
1482
|
/** An answer with the records marked as this organization's own taken out: { text } to look for markers in. */
|
|
1452
|
-
function withoutOwn(res, orgKey) {
|
|
1483
|
+
function withoutOwn(res, orgKey, keyRe) {
|
|
1453
1484
|
if (res.json === undefined) return res;
|
|
1454
|
-
const
|
|
1485
|
+
const KEY = keyRe || ORG_KEY;
|
|
1486
|
+
const own = (v) => v && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).some((k) => KEY.test(k) && String(v[k]) === String(orgKey));
|
|
1455
1487
|
const strip = (v, depth) => {
|
|
1456
1488
|
if (depth > 4 || v == null || typeof v !== 'object') return v;
|
|
1457
1489
|
if (Array.isArray(v)) return v.filter((x) => !own(x)).map((x) => strip(x, depth + 1));
|
|
@@ -1463,7 +1495,8 @@ function withoutOwn(res, orgKey) {
|
|
|
1463
1495
|
}
|
|
1464
1496
|
|
|
1465
1497
|
/** How many records in an answer carry this organization's own mark. */
|
|
1466
|
-
function ownRecords(json, orgKey) {
|
|
1498
|
+
function ownRecords(json, orgKey, keyRe) {
|
|
1499
|
+
const KEY = keyRe || ORG_KEY;
|
|
1467
1500
|
let n = 0;
|
|
1468
1501
|
const walk = (v, depth) => {
|
|
1469
1502
|
if (depth > 4 || v == null || typeof v !== 'object') return;
|
|
@@ -1472,7 +1505,7 @@ function ownRecords(json, orgKey) {
|
|
|
1472
1505
|
return;
|
|
1473
1506
|
}
|
|
1474
1507
|
for (const k of Object.keys(v)) {
|
|
1475
|
-
if (
|
|
1508
|
+
if (KEY.test(k) && ['string', 'number'].includes(typeof v[k]) && String(v[k]) === String(orgKey)) n++;
|
|
1476
1509
|
else if (typeof v[k] === 'object') walk(v[k], depth + 1);
|
|
1477
1510
|
}
|
|
1478
1511
|
};
|
|
@@ -1565,14 +1598,17 @@ function findingsOf(attempts, policy) {
|
|
|
1565
1598
|
const allowed = first.unruled ? [] : rolesWith(policy, first.permission);
|
|
1566
1599
|
const thing = first.method + ' ' + first.template;
|
|
1567
1600
|
const f = {
|
|
1568
|
-
|
|
1569
|
-
|
|
1601
|
+
// user against user, the line the app draws is only guessed (a profile may be public): a thing to check
|
|
1602
|
+
severity: first.kind === 'tenant' && first.perUser ? 'HIGH' : first.kind === 'tenant' ? 'CRITICAL' : 'HIGH',
|
|
1603
|
+
status: proven && !(first.kind === 'tenant' && first.perUser) ? 'confirmed' : 'verification required',
|
|
1570
1604
|
where: thing,
|
|
1571
1605
|
kind: first.kind,
|
|
1572
1606
|
role: first.kind === 'tenant' ? undefined : first.actor.role,
|
|
1573
1607
|
type: first.permission,
|
|
1574
1608
|
allowedRoles: allowed,
|
|
1575
|
-
headline: first.kind === 'tenant'
|
|
1609
|
+
headline: first.kind === 'tenant' && first.perUser
|
|
1610
|
+
? 'A signed-in user can open another user\'s record: ' + thing + ' answered for a record that belongs to someone else - to check: fine only if it is meant to be seen by others (a public profile, a shared post).'
|
|
1611
|
+
: first.kind === 'tenant'
|
|
1576
1612
|
? 'A user of one organization can reach another organization\'s record: ' + thing + ' answered for a record of a different organization.'
|
|
1577
1613
|
: 'A ' + first.actor.role + ' can use ' + thing + ' (' + first.permission + '), which the policy gives only to ' + roleList(allowed) + '.',
|
|
1578
1614
|
proof: [],
|
|
@@ -1843,6 +1879,7 @@ module.exports = {
|
|
|
1843
1879
|
checkPolicy: checkPolicy,
|
|
1844
1880
|
holds: holds,
|
|
1845
1881
|
ORG_KEY: ORG_KEY,
|
|
1882
|
+
USER_KEY: USER_KEY,
|
|
1846
1883
|
bodyRecords: bodyRecords,
|
|
1847
1884
|
wordsOfAnyRecord: wordsOfAnyRecord,
|
|
1848
1885
|
diffLines: diffLines,
|