kryptheon 0.1.57 → 0.1.61
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/README.md +8 -1
- package/kryptheon-api.js +614 -20
- package/kryptheon-baselines.js +232 -232
- package/kryptheon-changes.js +222 -222
- package/kryptheon-code.js +61 -1
- package/kryptheon-dashboard.js +8 -2
- package/kryptheon-fonts-OFL.txt +98 -98
- package/kryptheon-keys.js +353 -353
- package/kryptheon-map.js +152 -12
- package/kryptheon-probe-reporter.js +29 -29
- package/kryptheon-probe.config.js +37 -37
- package/kryptheon-project.js +600 -600
- package/kryptheon-roles.js +239 -37
- package/kryptheon-selectors.js +301 -301
- package/kryptheon-store.js +334 -334
- package/kryptheon-testfiles.js +98 -98
- package/kryptheon-webhook.js +332 -67
- package/package.json +1 -1
- package/playwright.config.js +73 -73
package/kryptheon-map.js
CHANGED
|
@@ -61,7 +61,10 @@ const OTHER_FRAMEWORKS = /^(fastify|koa|@koa\/router|koa-router|hono|@hono\/hono
|
|
|
61
61
|
const IDENTITY_SEGS = /^(user|users|session|auth|actor|account|member|currentUser|identity|principal|claims|userId|user_id|uid|sub|me|profile|viewer|isAuthenticated|isLoggedIn|token|kauth|apiKey|api_key|tenant|org|workspace)$/;
|
|
62
62
|
const IDENTITY_NAMES = /^(user|currentUser|current_user|me|actor|member|account|profile|viewer|identity|principal|session|sessionUser|authUser|auth|claims)$/i;
|
|
63
63
|
// A cookie or header that says who is calling: a session token (sid, token) or, worse, the user id itself.
|
|
64
|
-
|
|
64
|
+
// a session cookie, not a bare id: its value is a secret only the caller holds
|
|
65
|
+
const SESSION_COOKIE = /^(?!.*(csrf|xsrf))(?:[a-z0-9]+[_.-])*(sid|session|sessionId|session_id|token|jwt|access_token|accessToken)$/i;
|
|
66
|
+
// the name may carry the app's own prefix: wayline_sid, app-session, myapp.token (round 26) - never a CSRF token
|
|
67
|
+
const COOKIE_IDENTITY = /^(?!.*(csrf|xsrf))(?:[a-z0-9]+[_.-])*(uid|user|userId|user_id|userid|id|sid|session|sessionId|session_id|token|auth|jwt|access_token|accessToken)$/i;
|
|
65
68
|
const HEADER_IDENTITY = /^x-(user|uid|user-id|userid|account|account-id|member|member-id|actor|actor-id)$/i;
|
|
66
69
|
// Of those, the ones that hold the bare id - nothing a server signed, so anyone can write another person's.
|
|
67
70
|
const BARE_ID = /^(uid|user|userId|user_id|userid|id)$/i;
|
|
@@ -644,12 +647,15 @@ function refText(p) {
|
|
|
644
647
|
return chain ? chain.join('.') : '(' + n.type + ')';
|
|
645
648
|
}
|
|
646
649
|
|
|
647
|
-
/**
|
|
650
|
+
/**
|
|
651
|
+
* '/api' + '/x/' -> '/api/x'. A parameter written with a pattern is the same parameter: /work-orders/:id(\d+) is
|
|
652
|
+
* /work-orders/:id (round 27: the detail route kept its pattern and was never aimed).
|
|
653
|
+
*/
|
|
648
654
|
function joinPath(a, b) {
|
|
649
655
|
const x = (a || '').replace(/\/+$/, '');
|
|
650
656
|
const y = (b || '/').startsWith('/') ? b || '/' : '/' + b;
|
|
651
657
|
const out = (x + (y === '/' ? '' : y)) || '/';
|
|
652
|
-
return out.replace(/\/{2,}/g, '/');
|
|
658
|
+
return out.replace(/\/{2,}/g, '/').replace(/(:[A-Za-z_]\w*)\((?:[^()\\]|\\.)*\)/g, '$1');
|
|
653
659
|
}
|
|
654
660
|
|
|
655
661
|
/** Whether middleware used at `prefix` runs for a request to `full`. */
|
|
@@ -1302,6 +1308,7 @@ const OTHER_DB = /^(knex|sequelize|typeorm|drizzle-orm|mongoose|mongodb|kysely|o
|
|
|
1302
1308
|
function readSchema(ctx, root) {
|
|
1303
1309
|
const tables = new Map();
|
|
1304
1310
|
const rlsTables = new Set();
|
|
1311
|
+
const types = new Map(); // column name -> the types it is declared with, in any table
|
|
1305
1312
|
const texts = [];
|
|
1306
1313
|
(function walk(dir, depth) {
|
|
1307
1314
|
if (depth > 6) return;
|
|
@@ -1351,8 +1358,17 @@ function readSchema(ctx, root) {
|
|
|
1351
1358
|
}
|
|
1352
1359
|
parts.push(cur);
|
|
1353
1360
|
for (const p of parts) {
|
|
1354
|
-
const
|
|
1355
|
-
|
|
1361
|
+
const words = p.trim().split(/\s+/);
|
|
1362
|
+
const w = words[0];
|
|
1363
|
+
if (w && !/^(constraint|primary|foreign|unique|check|exclude|like|index|key)$/i.test(w)) {
|
|
1364
|
+
const col = w.replace(/["`]/g, '').toLowerCase();
|
|
1365
|
+
cols.add(col);
|
|
1366
|
+
// the column's type, so a request can send a value it can hold (round 25: "true kx-..." into a boolean)
|
|
1367
|
+
if (words[1]) {
|
|
1368
|
+
if (!types.has(col)) types.set(col, new Set());
|
|
1369
|
+
types.get(col).add(words[1].replace(/\(.*$/, '').toLowerCase());
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1356
1372
|
}
|
|
1357
1373
|
tables.set(bare(m[1]), cols);
|
|
1358
1374
|
}
|
|
@@ -1367,6 +1383,7 @@ function readSchema(ctx, root) {
|
|
|
1367
1383
|
while ((m = rls.exec(text))) rlsTables.add(bare(m[1]));
|
|
1368
1384
|
}
|
|
1369
1385
|
tables.rls = rlsTables;
|
|
1386
|
+
tables.types = types;
|
|
1370
1387
|
return tables;
|
|
1371
1388
|
}
|
|
1372
1389
|
|
|
@@ -1434,7 +1451,9 @@ function parseSql(text) {
|
|
|
1434
1451
|
}
|
|
1435
1452
|
const upd = new RegExp('update\\s+(?:only\\s+)?' + name + '(?:\\s+(?:as\\s+)?(\\w+))?\\s+set\\b', 'gi');
|
|
1436
1453
|
while ((m = upd.exec(sql))) {
|
|
1437
|
-
|
|
1454
|
+
const rest = sql.slice(upd.lastIndex);
|
|
1455
|
+
const w = rest.search(/\b(where|returning|from)\b/i);
|
|
1456
|
+
out.push({ op: 'UPDATE', table: clean(m[1]), alias: m[2] && m[2].toLowerCase(), where: whereAfter(sql, upd.lastIndex), set: w < 0 ? rest : rest.slice(0, w) });
|
|
1438
1457
|
writes.add(clean(m[1]));
|
|
1439
1458
|
}
|
|
1440
1459
|
const del = new RegExp('delete\\s+from\\s+(?:only\\s+)?' + name + '(?:\\s+(?:as\\s+)?(?!where\\b|using\\b|returning\\b)(\\w+))?', 'gi');
|
|
@@ -1502,6 +1521,9 @@ function sourceReader(ctx, fnRef, env) {
|
|
|
1502
1521
|
if (!chain) return null;
|
|
1503
1522
|
if (locals.has(chain[0])) return locals.get(chain[0]);
|
|
1504
1523
|
if (reqName && chain[0] === reqName) {
|
|
1524
|
+
// the caller's own session cookie: a token nobody else holds, so a row found by it is the caller's own
|
|
1525
|
+
// (round 26: DELETE FROM app_sessions WHERE session_token = req.cookies.wayline_sid). A bare id (uid) is not.
|
|
1526
|
+
if (/^(cookies|signedCookies)$/.test(chain[1] || '') && chain[2] && SESSION_COOKIE.test(chain[2])) return 'identity';
|
|
1505
1527
|
if (/^(body|query|params|headers|cookies|files|file|nextUrl|url)$/.test(chain[1] || '')) return 'client';
|
|
1506
1528
|
if (chain[1] && IDENTITY_SEGS.test(chain[1])) return 'identity';
|
|
1507
1529
|
if (/^(db|client|tx)$/.test(chain[1] || '')) return null;
|
|
@@ -1624,6 +1646,7 @@ function readDb(ctx, fnRef, schema, opts = {}) {
|
|
|
1624
1646
|
const mod = fnRef.mod;
|
|
1625
1647
|
const seenCalls = new Set();
|
|
1626
1648
|
const recordScopes = new Map();
|
|
1649
|
+
const scopedLookups = []; // const po = await query('SELECT ... WHERE id=$1 AND organization_id=$2', [req.params.id, ...])
|
|
1627
1650
|
const visitCall = (q) => {
|
|
1628
1651
|
if (seenCalls.has(q.node)) return;
|
|
1629
1652
|
seenCalls.add(q.node);
|
|
@@ -1659,8 +1682,32 @@ function readDb(ctx, fnRef, schema, opts = {}) {
|
|
|
1659
1682
|
return;
|
|
1660
1683
|
}
|
|
1661
1684
|
const here = [];
|
|
1662
|
-
|
|
1685
|
+
const idOf = [];
|
|
1686
|
+
for (const tx of texts) {
|
|
1687
|
+
for (const st of parseSql(tx.text)) {
|
|
1688
|
+
const v = judgeSql(ctx, mod, line, st, tx, paramsArg, src, schema, recordScopes);
|
|
1689
|
+
// SET status = 'received': a step of the record's life; WHERE status = ...: a look at where it is now
|
|
1690
|
+
const stateSet = st.set && /(?:^|[\s,])"?(status|state|stage)"?\s*=\s*'([^']+)'/i.exec(st.set);
|
|
1691
|
+
if (stateSet) v.setsState = { col: stateSet[1].toLowerCase(), value: stateSet[2] };
|
|
1692
|
+
if (st.where && /\b(status|state|stage)\b/i.test(st.where)) v.readsState = true;
|
|
1693
|
+
here.push(v);
|
|
1694
|
+
idOf.push(idValueText(st, paramsArg, mod));
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1663
1697
|
joinWith(here);
|
|
1698
|
+
// UPDATE ... WHERE id=$1 after SELECT ... WHERE id=$1 AND organization_id=$2 of the same row,
|
|
1699
|
+
// which stops the route when nothing was found: limited by that lookup (round 25's receive)
|
|
1700
|
+
here.forEach((x, i) => {
|
|
1701
|
+
if (x.op === 'SELECT' || x.scoping.status !== STATUS.NOT || x.scoping.clientChosen || x.scoping.applies === false || !idOf[i]) return;
|
|
1702
|
+
const before = scopedLookups.find((l) => l.table === x.table && l.idText === idOf[i] && l.line < line && stopsWhenMissing(t, fnRef.path, l.name, l.line, line));
|
|
1703
|
+
if (before) x.scoping = { status: STATUS.DETECTED, evidence: { file: mod.rel, line, code: snippet(mod, line), how: 'the same ' + x.table + ' row was looked up with the organisation limit at ' + before.file + ':' + before.line + ', and the route stops when it is not found' } };
|
|
1704
|
+
});
|
|
1705
|
+
const lookupDecl = q.findParent((p) => p.isVariableDeclarator() || p.isFunction());
|
|
1706
|
+
here.forEach((x, i) => {
|
|
1707
|
+
if (x.op === 'SELECT' && !x.joinedTo && x.scoping.status === STATUS.DETECTED && idOf[i] && lookupDecl && lookupDecl.isVariableDeclarator() && t.isIdentifier(lookupDecl.node.id)) {
|
|
1708
|
+
scopedLookups.push({ table: x.table, idText: idOf[i], name: lookupDecl.node.id.name, line, file: mod.rel });
|
|
1709
|
+
}
|
|
1710
|
+
});
|
|
1664
1711
|
out.push(...here);
|
|
1665
1712
|
// const shipment = (await query('SELECT ... WHERE id=$1 AND org_id=$2')).rows[0]: remember how its row was found
|
|
1666
1713
|
const decl = q.findParent((x) => x.isVariableDeclarator() || x.isFunction());
|
|
@@ -1701,9 +1748,22 @@ function readDb(ctx, fnRef, schema, opts = {}) {
|
|
|
1701
1748
|
for (const st of parseSql(text)) out.push(judgeSql(ctx, mod, line, st, { text, dynamic: false }, { tagged: values }, src, schema));
|
|
1702
1749
|
},
|
|
1703
1750
|
});
|
|
1751
|
+
// if (po.status !== 'approved') ... / ['draft', 'sent'].includes(order.status): the code looks at where the record is now
|
|
1752
|
+
if (out.some((d) => d.setsState)) {
|
|
1753
|
+
const body = mod.source.slice(fnRef.path.node.start, fnRef.path.node.end);
|
|
1754
|
+
if (STATE_CHECK.some((re) => re.test(body))) for (const d of out) if (d.setsState) d.stateChecked = true;
|
|
1755
|
+
}
|
|
1704
1756
|
return out;
|
|
1705
1757
|
}
|
|
1706
1758
|
|
|
1759
|
+
// a status read and compared - never res.status(404), which is a call
|
|
1760
|
+
const STATE_CHECK = [
|
|
1761
|
+
/\.(status|state|stage)\b(?!\s*\()\s*(!==|===|!=|==)/,
|
|
1762
|
+
/(!==|===|!=|==)\s*[\w$.[\]]+\.(status|state|stage)\b(?!\s*\()/,
|
|
1763
|
+
/\.includes\(\s*[\w$.[\]]+\.(status|state|stage)\s*\)/,
|
|
1764
|
+
/switch\s*\(\s*[\w$.[\]]+\.(status|state|stage)\s*\)/,
|
|
1765
|
+
];
|
|
1766
|
+
|
|
1707
1767
|
/** The outermost call of a supabase chain that has .from('x') in it. */
|
|
1708
1768
|
function fromCall(t, q) {
|
|
1709
1769
|
let n = q.node.callee.object;
|
|
@@ -1835,6 +1895,40 @@ function isQueryWrapper(ctx, mod, calleePath) {
|
|
|
1835
1895
|
return yes;
|
|
1836
1896
|
}
|
|
1837
1897
|
|
|
1898
|
+
/** The code of the value a statement finds its row by - `id = $1` with [req.params.id] -> "req.params.id" - or null. */
|
|
1899
|
+
function idValueText(st, paramsArg, mod) {
|
|
1900
|
+
const m = st.where && /(?:^|[^\w.])(?:\w+\.)?"?id"?\s*=\s*\$(\d+)/i.exec(st.where);
|
|
1901
|
+
if (!m || !paramsArg || paramsArg.tagged) return null;
|
|
1902
|
+
const pa = unwrapTs(paramsArg);
|
|
1903
|
+
if (!pa.isArrayExpression()) return null;
|
|
1904
|
+
const el = pa.node.elements[Number(m[1]) - 1];
|
|
1905
|
+
if (!el || !memberChain(el)) return null;
|
|
1906
|
+
return mod.source.slice(el.start, el.end).replace(/\s+/g, '');
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
/**
|
|
1910
|
+
* Whether, between the lookup at `from` and the write at `to`, the route
|
|
1911
|
+
* stops when the lookup named `name` found nothing: if (!po.rowCount) return ...
|
|
1912
|
+
*/
|
|
1913
|
+
function stopsWhenMissing(t, fnPath, name, from, to) {
|
|
1914
|
+
let yes = false;
|
|
1915
|
+
fnPath.traverse({
|
|
1916
|
+
IfStatement(p) {
|
|
1917
|
+
const l = p.node.loc.start.line;
|
|
1918
|
+
if (yes || l < from || l > to) return;
|
|
1919
|
+
const test = p.node.test;
|
|
1920
|
+
const subject = test.type === 'UnaryExpression' && test.operator === '!' ? test.argument
|
|
1921
|
+
: test.type === 'BinaryExpression' && /^(===|==|<|<=)$/.test(test.operator) && test.right.type === 'NumericLiteral' && test.right.value <= 0 ? test.left : null;
|
|
1922
|
+
const chain = subject && memberChain(subject);
|
|
1923
|
+
if (!chain || chain[0] !== name || !(chain.length === 1 || /^(rowCount|length|rows)$/.test(chain[1]))) return;
|
|
1924
|
+
let stops = t.isReturnStatement(p.node.consequent) || t.isThrowStatement(p.node.consequent);
|
|
1925
|
+
p.get('consequent').traverse({ Function(f) { f.skip(); }, ReturnStatement() { stops = true; }, ThrowStatement() { stops = true; } });
|
|
1926
|
+
if (stops) yes = true;
|
|
1927
|
+
},
|
|
1928
|
+
});
|
|
1929
|
+
return yes;
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1838
1932
|
/** One SQL statement's touch on one table, judged for scoping. */
|
|
1839
1933
|
function judgeSql(ctx, mod, line, st, tx, paramsArg, src, schema, recordScopes) {
|
|
1840
1934
|
// the values behind $1, $2..., and the row each one was read from, if any
|
|
@@ -1922,7 +2016,8 @@ function scopeVerdict(mod, line, st, filters, insertCols, schema, via, partlyUnr
|
|
|
1922
2016
|
const tenantList = all.filter((f) => TENANT_COLS.test(f.col) || (TENANT_TABLES.test(table) && f.col === 'id'));
|
|
1923
2017
|
const list = tenantList.length ? Array.from(new Set(tenantList.concat(all.filter(viaRow)))) : all;
|
|
1924
2018
|
const cols = (fs2) => Array.from(new Set(fs2.map((f) => f.col))).join(', ');
|
|
1925
|
-
|
|
2019
|
+
// a session or token column found by the caller's own session is the caller's own row too
|
|
2020
|
+
const byIdentity = list.filter((f) => (scopeCol(f.col) || /(^|_)(session|token|sid)(_?(id|hash|token))?$/i.test(f.col)) && f.src === 'identity');
|
|
1926
2021
|
const byScopedRow = list.filter((f) => viaRow(f) && f.row.status === STATUS.DETECTED);
|
|
1927
2022
|
const byClient = list.filter((f) => scopeCol(f.col) && f.src === 'client');
|
|
1928
2023
|
const byOpenRow = list.filter((f) => viaRow(f) && f.row.status === STATUS.NOT);
|
|
@@ -2036,7 +2131,9 @@ function readValidation(ctx, fnRef, elements, db) {
|
|
|
2036
2131
|
const id = q.node.id;
|
|
2037
2132
|
const init = q.node.init;
|
|
2038
2133
|
if (!init) return;
|
|
2039
|
-
|
|
2134
|
+
// req.body || {} / req.body ?? {}: still the body (round 25 lost its sign-in, and so its whole API run, to this)
|
|
2135
|
+
const bare = init.type === 'TSAsExpression' ? init.expression : init;
|
|
2136
|
+
let chain = memberChain(bare.type === 'LogicalExpression' && (bare.operator === '||' || bare.operator === '??') && bare.right.type === 'ObjectExpression' ? bare.left : bare);
|
|
2040
2137
|
// await req.json() / await req.formData() in a Fetch-style handler is the body
|
|
2041
2138
|
const awaited = init.type === 'AwaitExpression' ? init.argument : init;
|
|
2042
2139
|
if (!chain && awaited.type === 'CallExpression' && reqName) {
|
|
@@ -2210,9 +2307,40 @@ function readValidation(ctx, fnRef, elements, db) {
|
|
|
2210
2307
|
if (el.kind === 'package' && /express-validator|celebrate|joi/.test(el.source || '')) schemas.push({ from: 'body', file: el.usedFile, line: el.usedLine, code: el.name, fields: null, why: 'checked by ' + el.source + ' middleware (its rules are not read)' });
|
|
2211
2308
|
}
|
|
2212
2309
|
const unread = (elements || []).some((e) => e.kind === 'package' && /express-validator|celebrate|joi/.test(e.source || ''));
|
|
2310
|
+
// a list of items in the body (lines = [{ product_id, quantity }]): the names read off each item, in
|
|
2311
|
+
// for (const line of lines) and lines.some((x) => ...) - so a request can send one item (round 25's transfer)
|
|
2312
|
+
const itemNames = new Map();
|
|
2313
|
+
const itemsOfLocal = (local, fnOrBody, itemName) => {
|
|
2314
|
+
const f = localField.get(local);
|
|
2315
|
+
if (!f || typeof f !== 'object') return;
|
|
2316
|
+
const k = key(f.from, f.name);
|
|
2317
|
+
if (!itemNames.has(k)) itemNames.set(k, new Set());
|
|
2318
|
+
fnOrBody.traverse({
|
|
2319
|
+
MemberExpression(m) {
|
|
2320
|
+
if (t.isIdentifier(m.node.object, { name: itemName }) && !m.node.computed && t.isIdentifier(m.node.property)) itemNames.get(k).add(m.node.property.name);
|
|
2321
|
+
},
|
|
2322
|
+
});
|
|
2323
|
+
};
|
|
2324
|
+
fn.traverse({
|
|
2325
|
+
ForOfStatement(q) {
|
|
2326
|
+
const right = q.node.right;
|
|
2327
|
+
const left = q.node.left;
|
|
2328
|
+
const v = left.type === 'VariableDeclaration' && left.declarations[0] && left.declarations[0].id;
|
|
2329
|
+
if (t.isIdentifier(right) && t.isIdentifier(v)) itemsOfLocal(right.name, q.get('body'), v.name);
|
|
2330
|
+
},
|
|
2331
|
+
CallExpression(q) {
|
|
2332
|
+
const c = q.node.callee;
|
|
2333
|
+
const cb = q.node.arguments[0];
|
|
2334
|
+
if (!t.isMemberExpression(c) || !t.isIdentifier(c.object) || !t.isIdentifier(c.property) || !/^(some|every|map|forEach|filter|find)$/.test(c.property.name)) return;
|
|
2335
|
+
if (!cb || !/Function/.test(cb.type) || !cb.params[0] || !t.isIdentifier(cb.params[0])) return;
|
|
2336
|
+
itemsOfLocal(c.object.name, q.get('arguments.0'), cb.params[0].name);
|
|
2337
|
+
},
|
|
2338
|
+
});
|
|
2213
2339
|
const out = Array.from(fields.values()).map((e) => {
|
|
2214
2340
|
let status = e.checks.length ? STATUS.DETECTED : (e.schemaUnread || unread ? STATUS.UNKNOWN : STATUS.NOT);
|
|
2215
|
-
|
|
2341
|
+
const items = itemNames.get(key(e.from, e.name));
|
|
2342
|
+
return Object.assign({ name: e.name, from: e.from, line: e.line, file: mod.rel, status, checks: e.checks, reachesWrite: e.reachesWrite || [], why: status === STATUS.UNKNOWN ? 'checked by a schema or middleware whose rules are not read' : null },
|
|
2343
|
+
items && items.size ? { items: Array.from(items).sort() } : {});
|
|
2216
2344
|
});
|
|
2217
2345
|
return { fields: out.sort((a, b) => a.line - b.line), schemas };
|
|
2218
2346
|
}
|
|
@@ -2646,7 +2774,10 @@ function nextRoutes(ctx, schema) {
|
|
|
2646
2774
|
|
|
2647
2775
|
/** What kind of route this is, beside an ordinary one: a webhook, or a way to start a job. */
|
|
2648
2776
|
function routeKind(r) {
|
|
2649
|
-
if (/(^|\/)(webhooks?|hooks?|callbacks?|ipn|notify)(\/|$)/i.test(r.path || '')
|
|
2777
|
+
if (/(^|\/)(webhooks?|hooks?|callbacks?|ipn|notify)(\/|$)/i.test(r.path || '')) return 'webhook';
|
|
2778
|
+
// a sign-in compares a password hash with timingSafeEqual too: that is not a signed body (round 25)
|
|
2779
|
+
const signIn = /(^|\/)(log-?in|sign-?in|session|auth)(\/|$)/i.test(r.path || '');
|
|
2780
|
+
if (!signIn && (r.signature.status === STATUS.DETECTED || r.signature.presenceOnly)) return 'webhook';
|
|
2650
2781
|
if (/(^|\/)(jobs?|cron|tasks?|workers?|queues?|schedules?)(\/|$)/i.test(r.path || '')) return 'job';
|
|
2651
2782
|
return 'route';
|
|
2652
2783
|
}
|
|
@@ -2758,7 +2889,9 @@ function mapProject(root, options) {
|
|
|
2758
2889
|
seen.add(k);
|
|
2759
2890
|
return true;
|
|
2760
2891
|
});
|
|
2761
|
-
|
|
2892
|
+
const columnTypes = {};
|
|
2893
|
+
for (const [col, set] of schema.types || []) columnTypes[col] = Array.from(set);
|
|
2894
|
+
return { ran: true, filesRead: files.length, routes, jobs, notRead, unreadable: ctx.unreadable, tablesKnown: schema.size, columnTypes };
|
|
2762
2895
|
}
|
|
2763
2896
|
|
|
2764
2897
|
// --- what is worth a look: read from code, never proven ---------------------------------
|
|
@@ -2775,6 +2908,7 @@ const ADVICE = {
|
|
|
2775
2908
|
'tenant-from-request': 'take the organisation from the signed-in person\'s session, never from the request body or query string; for an id the request sends, look the record up with the organisation condition before using it.',
|
|
2776
2909
|
'tenant-unscoped': 'add the signed-in person\'s organisation (or owner) to the statement - WHERE org_id = <the session\'s org> - or, for a row found by its id, check that the row belongs to that organisation before using it.',
|
|
2777
2910
|
'no-role': 'allow only the roles that should be able to do this, and answer 403 for the others.',
|
|
2911
|
+
'no-state-check': 'look at the record\'s status first and refuse the step when the record is not in the status it must come from (WHERE status = <the one before> in the same statement, or a check that answers 409). A second call must change nothing - no stock, money or log entry added again.',
|
|
2778
2912
|
'identity-from-request': 'take who is calling only from something the server itself issued and can check - a signed session cookie (express-session, a signed JWT) - never from a bare user id in a cookie or a header the browser can set. Look the session up on the server and set req.user from that.',
|
|
2779
2913
|
};
|
|
2780
2914
|
|
|
@@ -2833,6 +2967,12 @@ function toCheck(map) {
|
|
|
2833
2967
|
const byOrg = open.some((d) => d.level !== 'owner');
|
|
2834
2968
|
add(r, 'tenant-unscoped', open.some((d) => d.op !== 'SELECT') ? 'HIGH' : 'MEDIUM', name + ' ' + tables(open) + (byOrg ? ' with no limit to the signed-in person\'s organisation' : ' with no check that the rows belong to the signed-in person') + (fromRow ? ' (rows found by an id that was itself looked up without one)' : ''), open.map(at));
|
|
2835
2969
|
}
|
|
2970
|
+
// SET status = 'received' with no look at what the status is now: sent twice, the step is done twice (round 25's receive)
|
|
2971
|
+
const steps = writes ? (r.db || []).filter((d) => d.setsState && !d.stateChecked && !(r.db || []).some((x) => x.readsState && x.table === d.table)) : [];
|
|
2972
|
+
if (steps.length) {
|
|
2973
|
+
const s = steps[0];
|
|
2974
|
+
add(r, 'no-state-check', 'MEDIUM', name + ' sets ' + s.table + '.' + s.setsState.col + " to '" + s.setsState.value + "' without looking at what it is now: sent again, or out of order, it does the step again", steps.map((d) => d.file + ':' + d.line + ' ' + d.sql));
|
|
2975
|
+
}
|
|
2836
2976
|
if (checksRoles && writes && r.role.status === STATUS.NOT && SENSITIVE_PATH.test(r.path || '')) {
|
|
2837
2977
|
add(r, 'no-role', 'MEDIUM', name + ' is a sensitive change, and no role check was found in front of it, while other routes of this app check roles', [r.file + ':' + r.line]);
|
|
2838
2978
|
}
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
// Says one line per probe run as it ends, in a form kryptheon-probe.js reads
|
|
2
|
-
// back and turns into words: "KXPROBE <done> <total> <id> <status>". Nothing
|
|
3
|
-
// else - a probe that fails is usually the app refusing a bad value, and a
|
|
4
|
-
// failure report for it would say the opposite of what happened.
|
|
5
|
-
|
|
6
|
-
class ProbeReporter {
|
|
7
|
-
onBegin(config, suite) {
|
|
8
|
-
this.total = suite.allTests().length;
|
|
9
|
-
this.done = 0;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
onTestEnd(test, result) {
|
|
13
|
-
this.done += 1;
|
|
14
|
-
const id = String(test.location.file).replace(/^.*[\\/]/, '').replace(/\.kxprobe\.js$/, '');
|
|
15
|
-
console.log('KXPROBE ' + this.done + ' ' + this.total + ' ' + id + ' ' + result.status);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
onError(error) {
|
|
19
|
-
// The run itself could not start - a broken copy, a missing browser.
|
|
20
|
-
const text = String((error && error.message) || error).split(/\r?\n/)[0];
|
|
21
|
-
console.log('KXPROBE-ERROR ' + text.slice(0, 300));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
printsToStdio() {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
module.exports = ProbeReporter;
|
|
1
|
+
// Says one line per probe run as it ends, in a form kryptheon-probe.js reads
|
|
2
|
+
// back and turns into words: "KXPROBE <done> <total> <id> <status>". Nothing
|
|
3
|
+
// else - a probe that fails is usually the app refusing a bad value, and a
|
|
4
|
+
// failure report for it would say the opposite of what happened.
|
|
5
|
+
|
|
6
|
+
class ProbeReporter {
|
|
7
|
+
onBegin(config, suite) {
|
|
8
|
+
this.total = suite.allTests().length;
|
|
9
|
+
this.done = 0;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
onTestEnd(test, result) {
|
|
13
|
+
this.done += 1;
|
|
14
|
+
const id = String(test.location.file).replace(/^.*[\\/]/, '').replace(/\.kxprobe\.js$/, '');
|
|
15
|
+
console.log('KXPROBE ' + this.done + ' ' + this.total + ' ' + id + ' ' + result.status);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
onError(error) {
|
|
19
|
+
// The run itself could not start - a broken copy, a missing browser.
|
|
20
|
+
const text = String((error && error.message) || error).split(/\r?\n/)[0];
|
|
21
|
+
console.log('KXPROBE-ERROR ' + text.slice(0, 300));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
printsToStdio() {
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
module.exports = ProbeReporter;
|
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
// The Playwright config for probe copies (kryptheon-probe.js). Kept apart from
|
|
3
|
-
// playwright.config.js on purpose: probes live in the store, not in tests/;
|
|
4
|
-
// they report through their own reporter; and their screenshots and traces
|
|
5
|
-
// go to a folder of their own - Playwright empties its output folder on every
|
|
6
|
-
// run, and the last check's evidence must not be wiped by a probe.
|
|
7
|
-
const path = require('path');
|
|
8
|
-
const { defineConfig } = require('@playwright/test');
|
|
9
|
-
|
|
10
|
-
const PACKAGE_DIR = __dirname;
|
|
11
|
-
const USER_DIR = process.cwd();
|
|
12
|
-
const PROBE_DIR = process.env.KRYPTHEON_PROBE_DIR || path.join(USER_DIR, 'tests');
|
|
13
|
-
|
|
14
|
-
// The same .env reading as playwright.config.js, for the same reasons.
|
|
15
|
-
const secrets = require(path.join(PACKAGE_DIR, 'kryptheon-secrets.js'));
|
|
16
|
-
const values = secrets.readEnvFile(path.join(USER_DIR, '.env'));
|
|
17
|
-
for (const name of Object.keys(values)) {
|
|
18
|
-
if (!secrets.isSet(process.env[name])) process.env[name] = values[name];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
module.exports = defineConfig({
|
|
22
|
-
testDir: PROBE_DIR,
|
|
23
|
-
testMatch: ['**/*.kxprobe.js'],
|
|
24
|
-
outputDir: path.join(PROBE_DIR, 'output'),
|
|
25
|
-
fullyParallel: false,
|
|
26
|
-
workers: 1,
|
|
27
|
-
retries: 0,
|
|
28
|
-
// Room for the gap before each run and for opening the page again after it.
|
|
29
|
-
timeout: 60000,
|
|
30
|
-
reporter: [[path.join(PACKAGE_DIR, 'kryptheon-probe-reporter.js')]],
|
|
31
|
-
use: {
|
|
32
|
-
headless: true,
|
|
33
|
-
channel: 'chromium',
|
|
34
|
-
screenshot: 'off',
|
|
35
|
-
trace: 'off',
|
|
36
|
-
},
|
|
37
|
-
});
|
|
1
|
+
// @ts-check
|
|
2
|
+
// The Playwright config for probe copies (kryptheon-probe.js). Kept apart from
|
|
3
|
+
// playwright.config.js on purpose: probes live in the store, not in tests/;
|
|
4
|
+
// they report through their own reporter; and their screenshots and traces
|
|
5
|
+
// go to a folder of their own - Playwright empties its output folder on every
|
|
6
|
+
// run, and the last check's evidence must not be wiped by a probe.
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const { defineConfig } = require('@playwright/test');
|
|
9
|
+
|
|
10
|
+
const PACKAGE_DIR = __dirname;
|
|
11
|
+
const USER_DIR = process.cwd();
|
|
12
|
+
const PROBE_DIR = process.env.KRYPTHEON_PROBE_DIR || path.join(USER_DIR, 'tests');
|
|
13
|
+
|
|
14
|
+
// The same .env reading as playwright.config.js, for the same reasons.
|
|
15
|
+
const secrets = require(path.join(PACKAGE_DIR, 'kryptheon-secrets.js'));
|
|
16
|
+
const values = secrets.readEnvFile(path.join(USER_DIR, '.env'));
|
|
17
|
+
for (const name of Object.keys(values)) {
|
|
18
|
+
if (!secrets.isSet(process.env[name])) process.env[name] = values[name];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = defineConfig({
|
|
22
|
+
testDir: PROBE_DIR,
|
|
23
|
+
testMatch: ['**/*.kxprobe.js'],
|
|
24
|
+
outputDir: path.join(PROBE_DIR, 'output'),
|
|
25
|
+
fullyParallel: false,
|
|
26
|
+
workers: 1,
|
|
27
|
+
retries: 0,
|
|
28
|
+
// Room for the gap before each run and for opening the page again after it.
|
|
29
|
+
timeout: 60000,
|
|
30
|
+
reporter: [[path.join(PACKAGE_DIR, 'kryptheon-probe-reporter.js')]],
|
|
31
|
+
use: {
|
|
32
|
+
headless: true,
|
|
33
|
+
channel: 'chromium',
|
|
34
|
+
screenshot: 'off',
|
|
35
|
+
trace: 'off',
|
|
36
|
+
},
|
|
37
|
+
});
|