kryptheon 0.1.68 → 0.1.69
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/bin/kryptheon.js +67 -5
- package/kryptheon-api.js +144 -4
- package/kryptheon-authz.js +26 -4
- package/kryptheon-baselines.js +232 -232
- package/kryptheon-changes.js +222 -222
- package/kryptheon-daily.js +192 -0
- package/kryptheon-dashboard-page.js +264 -2
- package/kryptheon-dashboard.html +25 -0
- package/kryptheon-dashboard.js +65 -3
- 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-questions.js +217 -0
- package/kryptheon-roles.js +4 -3
- package/kryptheon-selectors.js +301 -301
- package/kryptheon-store.js +334 -334
- package/kryptheon-testfiles.js +98 -98
- package/package.json +8 -2
- package/playwright.config.js +73 -73
package/LICENSE
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
-
Kryptheon Software License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Kryptheon (https://kryptheon.tech). All rights reserved.
|
|
4
|
-
|
|
5
|
-
This software is proprietary. It is not open source.
|
|
6
|
-
|
|
7
|
-
1. Use. You may install and run this software, as published by Kryptheon,
|
|
8
|
-
at no charge, to check software and databases that you own or are
|
|
9
|
-
authorised to test. Features that kryptheon.tech offers on a paid plan
|
|
10
|
-
are provided only under that plan and the Terms at
|
|
11
|
-
https://kryptheon.tech/terms.
|
|
12
|
-
|
|
13
|
-
2. Restrictions. Without Kryptheon's written permission you may not:
|
|
14
|
-
(a) copy, modify, translate or create derivative works of this software,
|
|
15
|
-
except as needed to run it;
|
|
16
|
-
(b) sell, sublicense, rent, publish or otherwise distribute it, or offer
|
|
17
|
-
it, or anything derived from it, as a hosted or managed service;
|
|
18
|
-
(c) remove, disable or work around any licence, plan or usage limit, or
|
|
19
|
-
any part of the software that enforces them;
|
|
20
|
-
(d) use it, or any part of it, to build a competing product.
|
|
21
|
-
|
|
22
|
-
3. No warranty. The software is provided "as is", without warranty of any
|
|
23
|
-
kind, express or implied, including fitness for a particular purpose.
|
|
24
|
-
It may miss problems; a check that finds nothing does not mean that
|
|
25
|
-
nothing is wrong. You are responsible for what you test and for keeping
|
|
26
|
-
your own backups.
|
|
27
|
-
|
|
28
|
-
4. Limitation of liability. To the extent the law allows, Kryptheon is not
|
|
29
|
-
liable for any damages arising from the use of, or inability to use,
|
|
30
|
-
this software.
|
|
31
|
-
|
|
32
|
-
5. Earlier versions. Versions published before this licence was added keep
|
|
33
|
-
the licence they were published with.
|
|
34
|
-
|
|
35
|
-
6. Termination. This licence ends automatically if you break it. When it
|
|
36
|
-
ends, you must stop using the software and delete your copies.
|
|
37
|
-
|
|
38
|
-
Questions: company@kryptheon.tech
|
|
1
|
+
Kryptheon Software License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kryptheon (https://kryptheon.tech). All rights reserved.
|
|
4
|
+
|
|
5
|
+
This software is proprietary. It is not open source.
|
|
6
|
+
|
|
7
|
+
1. Use. You may install and run this software, as published by Kryptheon,
|
|
8
|
+
at no charge, to check software and databases that you own or are
|
|
9
|
+
authorised to test. Features that kryptheon.tech offers on a paid plan
|
|
10
|
+
are provided only under that plan and the Terms at
|
|
11
|
+
https://kryptheon.tech/terms.
|
|
12
|
+
|
|
13
|
+
2. Restrictions. Without Kryptheon's written permission you may not:
|
|
14
|
+
(a) copy, modify, translate or create derivative works of this software,
|
|
15
|
+
except as needed to run it;
|
|
16
|
+
(b) sell, sublicense, rent, publish or otherwise distribute it, or offer
|
|
17
|
+
it, or anything derived from it, as a hosted or managed service;
|
|
18
|
+
(c) remove, disable or work around any licence, plan or usage limit, or
|
|
19
|
+
any part of the software that enforces them;
|
|
20
|
+
(d) use it, or any part of it, to build a competing product.
|
|
21
|
+
|
|
22
|
+
3. No warranty. The software is provided "as is", without warranty of any
|
|
23
|
+
kind, express or implied, including fitness for a particular purpose.
|
|
24
|
+
It may miss problems; a check that finds nothing does not mean that
|
|
25
|
+
nothing is wrong. You are responsible for what you test and for keeping
|
|
26
|
+
your own backups.
|
|
27
|
+
|
|
28
|
+
4. Limitation of liability. To the extent the law allows, Kryptheon is not
|
|
29
|
+
liable for any damages arising from the use of, or inability to use,
|
|
30
|
+
this software.
|
|
31
|
+
|
|
32
|
+
5. Earlier versions. Versions published before this licence was added keep
|
|
33
|
+
the licence they were published with.
|
|
34
|
+
|
|
35
|
+
6. Termination. This licence ends automatically if you break it. When it
|
|
36
|
+
ends, you must stop using the software and delete your copies.
|
|
37
|
+
|
|
38
|
+
Questions: company@kryptheon.tech
|
package/bin/kryptheon.js
CHANGED
|
@@ -2552,7 +2552,7 @@ async function apiCommand(args) {
|
|
|
2552
2552
|
console.log('');
|
|
2553
2553
|
return written.ok ? 0 : 2;
|
|
2554
2554
|
}
|
|
2555
|
-
if (!args.includes('--run')) {
|
|
2555
|
+
if (!args.includes('--run') && !args.includes('--live')) {
|
|
2556
2556
|
for (const line of api.planLines(api.planOf(USER_DIR, { packageDir: PACKAGE_DIR }))) console.log(line);
|
|
2557
2557
|
console.log(' To try them on your app on this computer: npx kryptheon api --run --origin http://localhost:3000 --yes');
|
|
2558
2558
|
console.log(' Use a test copy: it adds test data and never deletes it.');
|
|
@@ -2560,6 +2560,31 @@ async function apiCommand(args) {
|
|
|
2560
2560
|
return 0;
|
|
2561
2561
|
}
|
|
2562
2562
|
const origin = flagValue(args, '--origin');
|
|
2563
|
+
// --live: an app that is not on this computer, read-only (GET only, values never kept)
|
|
2564
|
+
if (args.includes('--live')) {
|
|
2565
|
+
if (!origin) { console.error('\n --live needs --origin, the address of your live app (for example https://my-app.lovable.app).\n'); return 2; }
|
|
2566
|
+
if (!args.includes('--yes')) {
|
|
2567
|
+
console.log('');
|
|
2568
|
+
console.log(' This signs in to ' + origin + ' as the test accounts in your .env and only READS: every page and list the');
|
|
2569
|
+
console.log(' code serves, as each account, aimed at another organization\'s records, and with no session. It never creates,');
|
|
2570
|
+
console.log(' changes or deletes anything - any other request is refused before it is sent - and it never keeps the');
|
|
2571
|
+
console.log(' values it reads, only field names and counts. Checks that write run only on a test copy. To go ahead, add --yes.');
|
|
2572
|
+
console.log('');
|
|
2573
|
+
return 2;
|
|
2574
|
+
}
|
|
2575
|
+
const mm = reader.mapProject(USER_DIR, { packageDir: PACKAGE_DIR });
|
|
2576
|
+
const liveRun = await api.runLive(USER_DIR, { map: mm, toCheck: mm.ran ? reader.toCheck(mm) : [], origin: origin, packageDir: PACKAGE_DIR, say: (line) => console.log(' ' + line) });
|
|
2577
|
+
for (const line of api.apiLines(liveRun)) console.log(line);
|
|
2578
|
+
if (liveRun.ran) {
|
|
2579
|
+
console.log(' Not run on a live app (each writes - run them on a test copy):');
|
|
2580
|
+
for (const l of api.LIVE_LEFT_OUT) console.log(' - ' + l);
|
|
2581
|
+
const saved = api.saveReport(opened.dir, liveRun);
|
|
2582
|
+
console.log(saved.ok ? ' Saved: ' + saved.file : ' (could not save this run: ' + saved.why + ')');
|
|
2583
|
+
console.log('');
|
|
2584
|
+
}
|
|
2585
|
+
if (!liveRun.ran) return 2;
|
|
2586
|
+
return liveRun.findings.some((f) => f.status === 'confirmed') ? 1 : 0;
|
|
2587
|
+
}
|
|
2563
2588
|
if (!origin) {
|
|
2564
2589
|
console.error('');
|
|
2565
2590
|
console.error(' --run needs --origin, the address of your app on this computer (for example http://localhost:3000).');
|
|
@@ -2892,6 +2917,38 @@ async function probeRecheckCommand(target, options) {
|
|
|
2892
2917
|
return r.verdict === 'fixed' && !r.newProblems.length ? 0 : 1;
|
|
2893
2918
|
}
|
|
2894
2919
|
|
|
2920
|
+
async function apiRecheckCommand(target, opened) {
|
|
2921
|
+
const api = require(path.join(PACKAGE_DIR, 'kryptheon-api.js'));
|
|
2922
|
+
let last = null;
|
|
2923
|
+
try { last = JSON.parse(fs.readFileSync(path.join(opened.dir, 'api-last.json'), 'utf8')); } catch (err) { last = null; }
|
|
2924
|
+
const origin = last && last.origin;
|
|
2925
|
+
const attempt = { id: target.id, at: new Date().toISOString(), check: 'api', where: target.where, headline: target.headline, verdict: 'could not confirm', why: '', newProblems: [], alsoFixed: [] };
|
|
2926
|
+
console.log('');
|
|
2927
|
+
console.log(' RE-CHECK ' + target.id + ' ' + target.where);
|
|
2928
|
+
console.log(' ' + target.headline);
|
|
2929
|
+
console.log('');
|
|
2930
|
+
if (!origin) {
|
|
2931
|
+
attempt.why = 'the address it was found on is not known - run Check my app again';
|
|
2932
|
+
} else if (!/^(GET|HEAD) /.test(String(target.where))) {
|
|
2933
|
+
attempt.why = 'it was proven by a change (' + String(target.where).split(' ')[0] + '), which a re-check does not send - run Check my app again on a test copy to see it held';
|
|
2934
|
+
} else {
|
|
2935
|
+
console.log(' Reading ' + origin + ' again, read-only - nothing is added to your app...');
|
|
2936
|
+
const run = await api.runLive(USER_DIR, { origin, packageDir: PACKAGE_DIR, say: () => {} });
|
|
2937
|
+
if (!run.ran) attempt.why = run.why;
|
|
2938
|
+
else {
|
|
2939
|
+
const still = run.findings.find((f) => f.where === target.where && f.kind === (String(target.headline).match(/another organization/i) ? 'tenant' : f.kind) && f.status === 'confirmed');
|
|
2940
|
+
const tried = run.wall && run.wall.ran && run.wall.result.attempts.some((a) => a.method + ' ' + a.template === target.where && !a.notTried);
|
|
2941
|
+
if (still) { attempt.verdict = 'still open'; attempt.why = 'it still answered: ' + still.headline; }
|
|
2942
|
+
else if (tried || (run.roles && run.roles.ran)) attempt.verdict = 'fixed';
|
|
2943
|
+
else attempt.why = 'that address could not be tried again (no record to aim it at, or no account that may not read it)';
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
try { fs.appendFileSync(opened.fixes, JSON.stringify(attempt) + '\n', 'utf8'); } catch (err) { attempt.saveError = err.message; }
|
|
2947
|
+
console.log(' VERDICT ' + VERDICT_WORDS[attempt.verdict] + (attempt.why ? ' - ' + attempt.why : ''));
|
|
2948
|
+
console.log('');
|
|
2949
|
+
return attempt.verdict === 'fixed' ? 0 : attempt.verdict === 'still open' ? 1 : 2;
|
|
2950
|
+
}
|
|
2951
|
+
|
|
2895
2952
|
function recheckCommand(id, options) {
|
|
2896
2953
|
const here = project.inspectProject(USER_DIR);
|
|
2897
2954
|
if (!here.ok) {
|
|
@@ -2937,6 +2994,11 @@ function recheckCommand(id, options) {
|
|
|
2937
2994
|
const probeTarget = dash.buildState(USER_DIR).findings.find((f) => f.id === String(id).trim() && PROBE_CHECKS[f.check]);
|
|
2938
2995
|
if (probeTarget) return probeRecheckCommand(probeTarget, options);
|
|
2939
2996
|
|
|
2997
|
+
// A finding of the API check: tried again READ-ONLY on the address it was found on - nothing is added to the app,
|
|
2998
|
+
// so nothing is asked. A read is proven again or not; a finding proven by a change cannot be, and says so.
|
|
2999
|
+
const apiTarget = dash.buildState(USER_DIR).findings.find((f) => f.id === String(id).trim() && f.check === 'api');
|
|
3000
|
+
if (apiTarget) return apiRecheckCommand(apiTarget, opened);
|
|
3001
|
+
|
|
2940
3002
|
const r = looker.recheck(USER_DIR, { frontend: () => readCodeAndSave(opened), backend: () => readMapAndSave(opened), regression: replayForLoop }, String(id).trim());
|
|
2941
3003
|
console.log('');
|
|
2942
3004
|
if (!r.found) {
|
|
@@ -3122,12 +3184,12 @@ function appAnswers(origin) {
|
|
|
3122
3184
|
* person types, with --roles, as a child. It listens for no stop message, and
|
|
3123
3185
|
* sends only HTTP requests - no browser to close - so Stop ends it outright.
|
|
3124
3186
|
*/
|
|
3125
|
-
async function apiFromDashboard(origin, say, control) {
|
|
3187
|
+
async function apiFromDashboard(origin, say, control, readOnly) {
|
|
3126
3188
|
if (!(await appAnswers(origin))) {
|
|
3127
|
-
return { ok: false, why: 'your app at ' + origin + ' is not answering - start it (for example npm run dev), then press Check my app again' };
|
|
3189
|
+
return { ok: false, why: 'your app at ' + origin + ' is not answering' + (readOnly ? '' : ' - start it (for example npm run dev), then press Check my app again') };
|
|
3128
3190
|
}
|
|
3129
3191
|
let stopped = false;
|
|
3130
|
-
const { code } = await kryptheonChild(['api', '--run', '--origin', origin, '--roles', '--yes'], say, (child) => control.onStop(() => {
|
|
3192
|
+
const { code } = await kryptheonChild(readOnly ? ['api', '--live', '--origin', origin, '--yes'] : ['api', '--run', '--origin', origin, '--roles', '--yes'], say, (child) => control.onStop(() => {
|
|
3131
3193
|
stopped = true;
|
|
3132
3194
|
try { child.kill(); } catch (err) { /* already gone */ }
|
|
3133
3195
|
}));
|
|
@@ -3162,7 +3224,7 @@ async function everythingFromDashboard(steps, opened, say, control, info) {
|
|
|
3162
3224
|
stopStep = null;
|
|
3163
3225
|
let r;
|
|
3164
3226
|
try {
|
|
3165
|
-
if (s.id === 'api') r = await apiFromDashboard(s.origin, say, step);
|
|
3227
|
+
if (s.id === 'api') r = await apiFromDashboard(s.origin, say, step, s.readOnly === true);
|
|
3166
3228
|
else if (PROBE_CHECKS[s.id]) r = await probeFromDashboard(s.id, say, step, info.confirmed);
|
|
3167
3229
|
else r = await runFromDashboard(s.id, opened, say);
|
|
3168
3230
|
} catch (err) {
|
package/kryptheon-api.js
CHANGED
|
@@ -122,6 +122,27 @@ function accountsOf(root, env) {
|
|
|
122
122
|
return { usable, left };
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
+
const TOKEN_PREFIX = 'KRYPTHEON_TOKEN_';
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* The accounts of an app that signs people in with a token, not a password: each KRYPTHEON_TOKEN_<NAME> in .env or
|
|
129
|
+
* the environment is one account, named <name> (KRYPTHEON_TOKEN_NORTHSTAR_OWNER -> northstar-owner). A token is
|
|
130
|
+
* never read from a README or guessed, as a password never is. [{ email: name, password: token, envName, token }].
|
|
131
|
+
*/
|
|
132
|
+
function tokenAccountsOf(root, env) {
|
|
133
|
+
const fromFile = secrets.readEnvFile(secrets.envFileFor(root));
|
|
134
|
+
const here = env || process.env;
|
|
135
|
+
const out = new Map();
|
|
136
|
+
for (const from of [fromFile, here]) {
|
|
137
|
+
for (const k of Object.keys(from || {})) {
|
|
138
|
+
if (!k.startsWith(TOKEN_PREFIX) || !secrets.isSet(from[k])) continue;
|
|
139
|
+
const name = k.slice(TOKEN_PREFIX.length).toLowerCase().replace(/_+/g, '-').replace(/^-|-$/g, '');
|
|
140
|
+
if (name) out.set(k, { email: name, password: String(from[k]).trim(), envName: k, from: from === fromFile ? '.env' : 'the environment', token: true });
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return Array.from(out.values());
|
|
144
|
+
}
|
|
145
|
+
|
|
125
146
|
/** The words of a field name: recipientEmail, weight_kg -> ['recipient', 'email'], ['weight', 'kg']. */
|
|
126
147
|
function wordsOf(name) {
|
|
127
148
|
return String(name).replace(/([a-z0-9])([A-Z])/g, '$1 $2').toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
|
|
@@ -290,7 +311,14 @@ function journeyFromMap(m, root, env, roleNames) {
|
|
|
290
311
|
}
|
|
291
312
|
actions.push(action);
|
|
292
313
|
}
|
|
293
|
-
|
|
314
|
+
// No sign-in route, and tokens in .env: the app signs people in with a token (blind round 35)
|
|
315
|
+
const tokens = s.none ? tokenAccountsOf(root, env) : [];
|
|
316
|
+
if (tokens.length) {
|
|
317
|
+
return { signIn: { method: authz.BEARER_SIGN_IN, path: '(a token in each request)', emailField: 'email', passwordField: 'password', extra: {}, encoding: 'json', bearer: true },
|
|
318
|
+
signInWhy: null, accounts: { usable: tokens, left: [] }, actions, notTried };
|
|
319
|
+
}
|
|
320
|
+
const why = s.none ? s.why + '. If your app signs people in with a token instead (Authorization: Bearer), put each account\'s token in .env as ' + TOKEN_PREFIX + '<NAME>' : null;
|
|
321
|
+
return { signIn: s.none ? null : s, signInWhy: why, accounts, actions, notTried };
|
|
294
322
|
}
|
|
295
323
|
|
|
296
324
|
/**
|
|
@@ -334,7 +362,7 @@ function planLines(plan) {
|
|
|
334
362
|
if (!plan.ran) return out.concat([' Could not read the code: ' + plan.why, '']);
|
|
335
363
|
out.push(' A dry run: nothing was sent. This is what the API check would try.');
|
|
336
364
|
out.push('');
|
|
337
|
-
out.push(plan.signIn ? ' Sign in: ' + plan.signIn.method + ' ' + plan.signIn.path + ' (' + plan.signIn.emailField + ', ' + plan.signIn.passwordField + ' - ' + plan.signIn.file + ':' + plan.signIn.line + ')' : ' Sign in: not found - ' + plan.signInWhy);
|
|
365
|
+
out.push(plan.signIn && plan.signIn.bearer ? ' Sign in: with a token in each request (Authorization: Bearer), one per ' + TOKEN_PREFIX + '<NAME> in .env' : plan.signIn ? ' Sign in: ' + plan.signIn.method + ' ' + plan.signIn.path + ' (' + plan.signIn.emailField + ', ' + plan.signIn.passwordField + ' - ' + plan.signIn.file + ':' + plan.signIn.line + ')' : ' Sign in: not found - ' + plan.signInWhy);
|
|
338
366
|
out.push(' Accounts that can sign in: ' + (plan.accounts.length ? plan.accounts.map((a) => a.email).join(', ') : 'none'));
|
|
339
367
|
for (const a of plan.accountsLeft) out.push(' not usable: ' + a.email + ' (' + a.from + ') - ' + a.why);
|
|
340
368
|
out.push(' Permissions: ' + (plan.policy.ok ? roles.POLICY_FILE + ', ' + Object.keys(plan.policy.policy.roles).length + ' roles' + (plan.policy.policy.tenants ? ', organizations kept apart' : '') : (plan.policy.problems || []).join(' ')));
|
|
@@ -748,7 +776,14 @@ async function runRefs(root, options) {
|
|
|
748
776
|
const sess = authz.makeSession(ctx, 'account', acc.email, acc.password);
|
|
749
777
|
const lf = { [j.signIn.emailField]: acc.email, [j.signIn.passwordField]: acc.password };
|
|
750
778
|
const r = authz.replyOf(await sess.send(j.signIn.method, j.signIn.path, j.signIn.encoding === 'form' ? { form: lf } : { json: lf }));
|
|
751
|
-
|
|
779
|
+
let email = acc.email;
|
|
780
|
+
if (acc.token) {
|
|
781
|
+
const meRoute = (plan.map.routes || []).find((r) => r.method === 'GET' && !r.unmounted && r.path && IDENTITY_ROUTE.test(r.path));
|
|
782
|
+
const me = meRoute ? await sess.send('GET', meRoute.path, {}) : null;
|
|
783
|
+
const found = me && me.status === 200 && JSON.stringify(me.json || {}).match(/"email"\s*:\s*"([^"]+)"/);
|
|
784
|
+
if (found) email = found[1];
|
|
785
|
+
}
|
|
786
|
+
const row = rowsOf(first, users).find((u) => String(u.email).toLowerCase() === String(email).toLowerCase());
|
|
752
787
|
if (r.kind !== 'refused' && r.kind !== 'server-error' && r.kind !== 'no-answer' && row) sessions.push({ sess, email: acc.email, org: row[orgColOf(users)] });
|
|
753
788
|
}
|
|
754
789
|
if (!sessions.length) return { ran: false, why: 'no account with a password in .env could sign in' };
|
|
@@ -3237,6 +3272,7 @@ function reportOf(run) {
|
|
|
3237
3272
|
const wallTries = run.wall && run.wall.ran ? run.wall.result.attempts.filter((a) => !a.notTried).length : 0;
|
|
3238
3273
|
return {
|
|
3239
3274
|
ran: run.ran, why: run.why || null, checkedAt: run.checkedAt, origin: run.origin || null,
|
|
3275
|
+
live: run.live === true, leftOut: run.live === true ? (run.leftOut || []).slice() : [],
|
|
3240
3276
|
accounts: run.wall && run.wall.ran ? run.wall.result.accounts.map((a) => a.email) : run.invalid && run.invalid.ran ? [run.invalid.account] : [],
|
|
3241
3277
|
tries: { acrossOrganizationsAndNoSession: wallTries, badValues: run.invalid && run.invalid.ran ? run.invalid.tried.length : 0 },
|
|
3242
3278
|
findings: run.findings.map((f) => ({ kind: f.kind, severity: f.severity, status: f.status, where: f.where, from: f.from, headline: f.headline, proof: f.proof, fixPrompt: f.fixPrompt })),
|
|
@@ -3245,6 +3281,110 @@ function reportOf(run) {
|
|
|
3245
3281
|
};
|
|
3246
3282
|
}
|
|
3247
3283
|
|
|
3284
|
+
// --- a live app: read-only ----------------------------------------------------------
|
|
3285
|
+
|
|
3286
|
+
/** Every value in a JSON excerpt replaced: "email":"a@b.c" -> "email":"…", "total":120 -> "total":#. Field names stay. */
|
|
3287
|
+
function maskValues(text) {
|
|
3288
|
+
return String(text == null ? '' : text)
|
|
3289
|
+
.replace(/("[^"\\]{1,80}"\s*:\s*)"(?:[^"\\]|\\.)*"/g, '$1"…"')
|
|
3290
|
+
.replace(/("[^"\\]{1,80}"\s*:\s*)-?\d+(?:\.\d+)?/g, '$1#');
|
|
3291
|
+
}
|
|
3292
|
+
|
|
3293
|
+
// The checks a live run never makes, each with why: all of them write.
|
|
3294
|
+
const LIVE_LEFT_OUT = [
|
|
3295
|
+
'creates and changes across organizations, and bad values - they write to your app',
|
|
3296
|
+
'roles for anything that changes data - it would change data',
|
|
3297
|
+
'webhooks, payments and refunds - they write',
|
|
3298
|
+
'two requests at the same moment, repeats, jobs and limits - they write',
|
|
3299
|
+
'exports with a marked value - it is made by a write first',
|
|
3300
|
+
];
|
|
3301
|
+
|
|
3302
|
+
/**
|
|
3303
|
+
* The API check on a LIVE app (an address that is not this computer): reads only. As each account and with no
|
|
3304
|
+
* session: every GET the map read, aimed across organizations, and - with permissions-policy.json - as the roles
|
|
3305
|
+
* that may not read it. Nothing is created, changed or deleted: the connection itself refuses any request but GET,
|
|
3306
|
+
* HEAD and the one sign-in. The answers' values are never shown or kept, only field names and counts. Run on a
|
|
3307
|
+
* test copy for everything else. Same shape as runApi, so the report and the page read it the same way.
|
|
3308
|
+
*/
|
|
3309
|
+
async function runLive(root, options) {
|
|
3310
|
+
const opts = options || {};
|
|
3311
|
+
const say = typeof opts.say === 'function' ? opts.say : () => {};
|
|
3312
|
+
const m = opts.map || map.mapProject(root, { packageDir: opts.packageDir || __dirname });
|
|
3313
|
+
if (!m.ran) return { ran: false, why: m.why };
|
|
3314
|
+
const plan = planOf(root, Object.assign({}, opts, { map: m }));
|
|
3315
|
+
if (!plan.ran) return { ran: false, why: plan.why };
|
|
3316
|
+
const j = plan.journey;
|
|
3317
|
+
let origin;
|
|
3318
|
+
try {
|
|
3319
|
+
origin = authz.assertLocalTarget(opts.origin, null, { readOnly: true });
|
|
3320
|
+
} catch (err) {
|
|
3321
|
+
return { ran: false, why: 'not an address: ' + (opts.origin || 'none was given') };
|
|
3322
|
+
}
|
|
3323
|
+
if (!j.signIn) return { ran: false, why: j.signInWhy };
|
|
3324
|
+
if (j.accounts.usable.length < 2) return { ran: false, why: 'fewer than two test accounts can sign in, so there is nothing to compare - add them in "Who Kryptheon signs in as"' };
|
|
3325
|
+
const gets = j.actions.filter((a) => a.method === 'GET');
|
|
3326
|
+
say('Reading only: ' + gets.length + ' pages and lists of ' + origin + ', as ' + j.accounts.usable.length + ' test accounts and with no session. Nothing is created, changed or deleted.');
|
|
3327
|
+
const base = { origin, fetch: opts.fetch, say, stopped: opts.stopped, maxAttempts: opts.maxAttempts, readOnly: true, seed: false, anonymous: true };
|
|
3328
|
+
let wallResult;
|
|
3329
|
+
try {
|
|
3330
|
+
wallResult = await roles.checkAccess(Object.assign({}, base, { policy: wallPolicy(j), journey: { signIn: j.signIn, actions: gets }, accounts: j.accounts.usable, only: (p) => p.kind !== 'role' }));
|
|
3331
|
+
} catch (err) {
|
|
3332
|
+
if (err && err.code === authz.READ_ONLY) return { ran: false, why: 'stopped: ' + err.message + ' - nothing was written' };
|
|
3333
|
+
throw err;
|
|
3334
|
+
}
|
|
3335
|
+
const wall = { ran: true, plan, result: wallResult, findings: findingsOf(wallResult.attempts, j) };
|
|
3336
|
+
let roleRun = { ran: false, why: 'no ' + roles.POLICY_FILE };
|
|
3337
|
+
if (plan.policy.ok) {
|
|
3338
|
+
const withInferred = inferPermissions(plan, plan.policy.policy);
|
|
3339
|
+
try {
|
|
3340
|
+
const result = await roles.checkAccess(Object.assign({}, base, { policy: withInferred.policy, journey: { signIn: j.signIn, actions: gets }, accounts: j.accounts.usable, tryUnruled: false }));
|
|
3341
|
+
const findings = roles.findingsOf(result.attempts.filter((a) => a.kind !== 'signin'), withInferred.policy);
|
|
3342
|
+
for (const f of findings) { const inf = withInferred.inferred.get(f.where); if (inf && f.kind === 'role') f.status = 'verification required'; }
|
|
3343
|
+
roleRun = { ran: true, plan, result, findings, policy: withInferred.policy };
|
|
3344
|
+
} catch (err) {
|
|
3345
|
+
if (!(err && err.code === authz.READ_ONLY)) throw err;
|
|
3346
|
+
roleRun = { ran: false, why: 'stopped: ' + err.message + ' - nothing was written' };
|
|
3347
|
+
}
|
|
3348
|
+
}
|
|
3349
|
+
const stub = { ran: false, why: 'not on a live app - it writes; run it on a test copy' };
|
|
3350
|
+
// Judged first, then every string kept from the tries masked - the answers, their excerpts, the lines printed from
|
|
3351
|
+
// them: a live app's records are real people's, and none of their values is shown or saved.
|
|
3352
|
+
const maskDeep = (v, depth) => {
|
|
3353
|
+
if (depth > 8 || v === null || v === undefined) return v;
|
|
3354
|
+
if (typeof v === 'string') return maskValues(v);
|
|
3355
|
+
if (Array.isArray(v)) return v.map((x) => maskDeep(x, depth + 1));
|
|
3356
|
+
if (typeof v === 'object') { const o = {}; for (const k of Object.keys(v)) o[k] = /^(json|item|items|body|data|record|records|response|value|values|before|after|answer)$/i.test(k) && v[k] && typeof v[k] === 'object' ? maskObject(v[k], depth + 1) : maskDeep(v[k], depth + 1); return o; }
|
|
3357
|
+
return v;
|
|
3358
|
+
};
|
|
3359
|
+
// a whole record or answer as an object: every leaf value goes, the keys stay
|
|
3360
|
+
const maskObject = (v, depth) => {
|
|
3361
|
+
if (depth > 8 || v === null || typeof v !== 'object') return typeof v === 'string' ? '…' : typeof v === 'number' ? '#' : v;
|
|
3362
|
+
if (Array.isArray(v)) return v.map((x) => maskObject(x, depth + 1));
|
|
3363
|
+
const o = {};
|
|
3364
|
+
for (const k of Object.keys(v)) o[k] = maskObject(v[k], depth + 1);
|
|
3365
|
+
return o;
|
|
3366
|
+
};
|
|
3367
|
+
wall.result = maskDeep(wall.result, 0);
|
|
3368
|
+
wall.findings = maskDeep(wall.findings, 0);
|
|
3369
|
+
if (roleRun.ran) { roleRun.result = maskDeep(roleRun.result, 0); roleRun.findings = maskDeep(roleRun.findings, 0); }
|
|
3370
|
+
// the roles run keeps organizations apart too, so it finds the same reads across organizations again: said once
|
|
3371
|
+
const seenLive = new Set();
|
|
3372
|
+
const findings = (wall.findings || []).concat(roleRun.ran ? roleRun.findings : []).filter((f) => {
|
|
3373
|
+
const k = f.kind + '|' + f.where + '|' + (f.field || '');
|
|
3374
|
+
return seenLive.has(k) ? false : (seenLive.add(k), true);
|
|
3375
|
+
}).map((f) => maskDeep(Object.assign({}, f, { live: true }), 0));
|
|
3376
|
+
const toCheck = opts.toCheck || map.toCheck(m);
|
|
3377
|
+
return {
|
|
3378
|
+
ran: true, live: true, why: null, checkedAt: new Date().toISOString(), origin,
|
|
3379
|
+
wall, forged: stub, webhooks: stub, exports: stub, jobs: stub, kept: stub, creates: stub, limits: stub, steps: stub, redirects: stub, refunds: stub, stepsAtOnce: stub,
|
|
3380
|
+
roles: roleRun, invalid: stub, grants: stub, refs: stub,
|
|
3381
|
+
findings, left: [], leftOut: LIVE_LEFT_OUT,
|
|
3382
|
+
verdicts: verdictsFor(toCheck, wall, stub, roleRun.ran ? roleRun : null, stub, stub, stub, stub),
|
|
3383
|
+
notTried: wall.plan ? wall.plan.notTried : [],
|
|
3384
|
+
writes: writesOf(m, wall),
|
|
3385
|
+
};
|
|
3386
|
+
}
|
|
3387
|
+
|
|
3248
3388
|
/** Writes api-last.json in the store folder. Never throws. */
|
|
3249
3389
|
function saveReport(dir, run) {
|
|
3250
3390
|
try {
|
|
@@ -3427,4 +3567,4 @@ function apiLines(run) {
|
|
|
3427
3567
|
return out;
|
|
3428
3568
|
}
|
|
3429
3569
|
|
|
3430
|
-
module.exports = { limitPairsIn, dbDoubleEffects, oneLeft, inferPermissions, grantRulesOf, runGrants, runRefs, probesOf, stepEffectOf, reconcile, isUpdateRoute, storedAs, updateProbesOf, heldStrength, runSteps, runRedirects, OUTSIDE, runRefundCap, PLUMBING, runStepsAtOnce, doubleEffects, numbersMoved, runKept, runCreates, COSTLY_RECORD, runLimits, limitPairOf, valueIn, plainFieldOf, runJobs, countsIn, JOB_PATH, runForged, personIn, REPORT_FILE, verdictsFor, runApi, reportOf, saveReport, apiLines, badValueFor, runInvalid, signInOf, emailsIn, accountsOf, wordsOf, sampleValue, allowedByName, actionOf, journeyFromMap, planOf, planLines, wallPolicy, runWall, findingsOf, fixPrompt, leftBehind, wallLines, DRAFT_FILE, permissionName, draftPolicy, writeDraft, runRoles };
|
|
3570
|
+
module.exports = { runLive, maskValues, LIVE_LEFT_OUT, tokenAccountsOf, TOKEN_PREFIX, limitPairsIn, dbDoubleEffects, oneLeft, inferPermissions, grantRulesOf, runGrants, runRefs, probesOf, stepEffectOf, reconcile, isUpdateRoute, storedAs, updateProbesOf, heldStrength, runSteps, runRedirects, OUTSIDE, runRefundCap, PLUMBING, runStepsAtOnce, doubleEffects, numbersMoved, runKept, runCreates, COSTLY_RECORD, runLimits, limitPairOf, valueIn, plainFieldOf, runJobs, countsIn, JOB_PATH, runForged, personIn, REPORT_FILE, verdictsFor, runApi, reportOf, saveReport, apiLines, badValueFor, runInvalid, signInOf, emailsIn, accountsOf, wordsOf, sampleValue, allowedByName, actionOf, journeyFromMap, planOf, planLines, wallPolicy, runWall, findingsOf, fixPrompt, leftBehind, wallLines, DRAFT_FILE, permissionName, draftPolicy, writeDraft, runRoles };
|
package/kryptheon-authz.js
CHANGED
|
@@ -53,7 +53,7 @@ const EXCERPT = 240;
|
|
|
53
53
|
* The origin requests may go to. Only this computer, and only an origin named
|
|
54
54
|
* in `allow` when one is given: anything else throws, before any request.
|
|
55
55
|
*/
|
|
56
|
-
function assertLocalTarget(baseUrl, allow) {
|
|
56
|
+
function assertLocalTarget(baseUrl, allow, how) {
|
|
57
57
|
let u;
|
|
58
58
|
try {
|
|
59
59
|
u = new URL(String(baseUrl));
|
|
@@ -61,7 +61,9 @@ function assertLocalTarget(baseUrl, allow) {
|
|
|
61
61
|
throw new Error('authz: "' + baseUrl + '" is not an address');
|
|
62
62
|
}
|
|
63
63
|
if (!/^https?:$/.test(u.protocol)) throw new Error('authz: only http or https addresses are allowed');
|
|
64
|
-
|
|
64
|
+
// Another computer's address (a live app) only for a read-only run: GET, and the one sign-in POST - kept in
|
|
65
|
+
// ctx.request below, where every request is sent. Never for a run that may write.
|
|
66
|
+
if (!LOCAL_HOSTS.includes(u.hostname.toLowerCase()) && !(how && how.readOnly === true)) {
|
|
65
67
|
throw new Error('authz: refused ' + u.origin + ' - this only runs against localhost or 127.0.0.1');
|
|
66
68
|
}
|
|
67
69
|
if (allow && allow.length && !allow.includes(u.origin)) {
|
|
@@ -477,14 +479,28 @@ function storeCookies(jar, res) {
|
|
|
477
479
|
}
|
|
478
480
|
|
|
479
481
|
function makeContext(options) {
|
|
480
|
-
const origin = assertLocalTarget(options.baseUrl, options.allowOrigins);
|
|
482
|
+
const origin = assertLocalTarget(options.baseUrl, options.allowOrigins, { readOnly: options.readOnly === true });
|
|
483
|
+
// read-only: what may still be sent besides GET and HEAD - the sign-in, as "POST /path"
|
|
484
|
+
const writesAllowed = new Set((options.readOnly === true ? options.allowWrites || [] : []).map(String));
|
|
481
485
|
const fetchImpl = options.fetch || globalThis.fetch;
|
|
482
486
|
const secrets = Object.values(options.passwords || {}).filter(Boolean);
|
|
483
487
|
// ctx.limit can be raised by a check that knows how big the app is (runSteps); it never goes away.
|
|
484
|
-
const ctx = { origin: origin, requests: 0, secrets: secrets, limit: options.maxRequests || MAX_REQUESTS };
|
|
488
|
+
const ctx = { origin: origin, requests: 0, secrets: secrets, limit: options.maxRequests || MAX_REQUESTS, readOnly: options.readOnly === true };
|
|
485
489
|
ctx.request = async function (session, method, p, opts) {
|
|
486
490
|
method = String(method).toUpperCase();
|
|
491
|
+
// An app that signs people in with a token (blind round 35: Authorization: Bearer <token>, no sign-in route): the
|
|
492
|
+
// "sign-in" sends nothing; it gives the session its token, and every request after it carries the header.
|
|
493
|
+
if (method === BEARER_SIGN_IN) {
|
|
494
|
+
if (!session.password) return { status: 0, error: 'no token for this account' };
|
|
495
|
+
session.bearer = String(session.password);
|
|
496
|
+
return { status: 200, location: '', text: '', json: { signedIn: 'with a token' } };
|
|
497
|
+
}
|
|
487
498
|
if (method === 'DELETE') throw new Error('authz: this check never deletes anything');
|
|
499
|
+
if (ctx.readOnly && method !== 'GET' && method !== 'HEAD' && method !== BEARER_SIGN_IN && !writesAllowed.has(method + ' ' + String(p).split('?')[0])) {
|
|
500
|
+
const stop = new Error('authz: read-only - ' + method + ' ' + String(p).split('?')[0] + ' was not sent');
|
|
501
|
+
stop.code = READ_ONLY;
|
|
502
|
+
throw stop;
|
|
503
|
+
}
|
|
488
504
|
if (String(p).startsWith('//') || /^[a-z]+:/i.test(String(p))) throw new Error('authz: refused a request to "' + p + '" - paths only, on the allowed origin');
|
|
489
505
|
if (ctx.requests + 1 > ctx.limit) {
|
|
490
506
|
// A stop, not a crash: the caller keeps what it found so far and says it stopped (blind round 32,
|
|
@@ -500,6 +516,7 @@ function makeContext(options) {
|
|
|
500
516
|
const headers = { accept: 'application/json, text/html;q=0.8' };
|
|
501
517
|
const cookie = cookieHeader(session.jar);
|
|
502
518
|
if (cookie) headers.cookie = cookie;
|
|
519
|
+
if (session.bearer) headers.authorization = 'Bearer ' + session.bearer;
|
|
503
520
|
for (const k of Object.keys(opts.headers || {})) if (!/^(cookie|host|content-type|content-length)$/i.test(k)) headers[k.toLowerCase()] = String(opts.headers[k]);
|
|
504
521
|
let body;
|
|
505
522
|
if (opts.json !== undefined) {
|
|
@@ -916,7 +933,12 @@ function reportLines(run) {
|
|
|
916
933
|
return lines;
|
|
917
934
|
}
|
|
918
935
|
|
|
936
|
+
const BEARER_SIGN_IN = 'BEARER';
|
|
937
|
+
const READ_ONLY = 'KRYPTHEON_READ_ONLY';
|
|
938
|
+
|
|
919
939
|
module.exports = {
|
|
940
|
+
BEARER_SIGN_IN,
|
|
941
|
+
READ_ONLY,
|
|
920
942
|
VERDICT: VERDICT,
|
|
921
943
|
KINDS: KINDS,
|
|
922
944
|
assertLocalTarget: assertLocalTarget,
|