kryptheon 0.1.76 → 0.1.78
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/README.md +10 -4
- package/kryptheon-api.js +46 -4
- package/kryptheon-authz.js +7 -1
- package/kryptheon-doors.js +224 -0
- package/kryptheon-fixture.js +11 -5
- package/kryptheon-heal.js +64 -4
- package/kryptheon-probe-fixture.js +3 -1
- package/kryptheon-replay.js +52 -13
- package/kryptheon-reporter.js +10 -4
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
# kryptheon
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
plain English what broke.
|
|
3
|
+
Scanners check your settings. Kryptheon tries to break in.
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
It signs in as your users and tries what an attacker would: one customer
|
|
6
|
+
reading another's data, a payment counted twice, a coupon used twice at once,
|
|
7
|
+
a refund bigger than the payment, an AI route anyone can call. Every finding
|
|
8
|
+
comes with its proof, and a fix prompt you paste into your AI. After the fix,
|
|
9
|
+
one press checks it again and says FIXED - or what the fix broke.
|
|
10
|
+
|
|
11
|
+
Runs on your machine, against your app on this computer or your own test copy.
|
|
12
|
+
No API key, and not one row of your data leaves your computer. Recordings and
|
|
13
|
+
browser runs use [Playwright](https://playwright.dev).
|
|
8
14
|
|
|
9
15
|
## The one command
|
|
10
16
|
|
package/kryptheon-api.js
CHANGED
|
@@ -28,6 +28,7 @@ const webhook = require('./kryptheon-webhook.js');
|
|
|
28
28
|
const csv = require('./kryptheon-csv.js');
|
|
29
29
|
const witnessDb = require('./kryptheon-witness.js');
|
|
30
30
|
const aiapp = require('./kryptheon-aiapp.js');
|
|
31
|
+
const doors = require('./kryptheon-doors.js');
|
|
31
32
|
|
|
32
33
|
const EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
|
|
33
34
|
const SIGN_IN = /(^|\/)(log-?in|sign-?in|session|auth\/(login|signin|token))$/i;
|
|
@@ -3409,6 +3410,26 @@ async function runAnswers(root, options) {
|
|
|
3409
3410
|
return out;
|
|
3410
3411
|
}
|
|
3411
3412
|
|
|
3413
|
+
/**
|
|
3414
|
+
* The open doors (kryptheon-doors.js) for this app: the GET lists the map read, for CORS, and its sign-in, for the
|
|
3415
|
+
* wrong-password limit. `how`: { readOnly, live } for a live address - then it only reads.
|
|
3416
|
+
*/
|
|
3417
|
+
async function runDoors(root, options, how) {
|
|
3418
|
+
const opts = options || {};
|
|
3419
|
+
const plan = planOf(root, opts);
|
|
3420
|
+
const gets = [];
|
|
3421
|
+
if (plan.ran) {
|
|
3422
|
+
for (const r of plan.map.routes || []) {
|
|
3423
|
+
if (r.unmounted || !r.path || r.method !== 'GET' || r.kind === 'webhook') continue;
|
|
3424
|
+
const p = normRoute(r.path);
|
|
3425
|
+
if (/[{*]/.test(p) || PLUMBING.test(p) || /log-?out|sign-?out/i.test(p) || gets.includes(p)) continue;
|
|
3426
|
+
gets.push(p);
|
|
3427
|
+
}
|
|
3428
|
+
}
|
|
3429
|
+
const signIn = plan.ran && plan.journey.signIn ? plan.journey.signIn : null;
|
|
3430
|
+
return doors.run(Object.assign({ origin: opts.origin, fetch: opts.fetch, gets: gets, signIn: signIn }, how || {}));
|
|
3431
|
+
}
|
|
3432
|
+
|
|
3412
3433
|
/** Which answer finding a headline is, for a re-check that has only the headline: 'secret-in-answer', 'quiz-answers-sent' or null. */
|
|
3413
3434
|
function answerKindOf(headline) {
|
|
3414
3435
|
const h = String(headline || '');
|
|
@@ -3465,17 +3486,19 @@ async function runApi(root, options) {
|
|
|
3465
3486
|
const grantsRun = opts.roles ? await contained('Who may give which role', () => runGrants(root, shared)) : { ran: false, why: 'not asked for' };
|
|
3466
3487
|
// the bad values always last: one of them may stop the app (round 24 lost its whole roles run that way)
|
|
3467
3488
|
const invalid = await contained('Bad values', () => runInvalid(root, shared));
|
|
3489
|
+
// after everything: its wrong passwords may trip the app's sign-in limit, which must not stop a check above
|
|
3490
|
+
const doorsRun = await contained('Open doors', () => runDoors(root, shared));
|
|
3468
3491
|
if (witness.ok && !opts.witness) await witness.close();
|
|
3469
3492
|
const verdicts = verdictsFor(toCheck, wall, invalid, roleRun, forged, webhooks, stepsRun, redirectsRun);
|
|
3470
3493
|
const seen = new Set();
|
|
3471
|
-
const findings = (grantsRun.ran ? grantsRun.findings : []).concat(answersRun.ran ? answersRun.findings : []).concat(refsRun.ran ? refsRun.findings : []).concat(wall.ran ? wall.findings : []).concat(redirectsRun.ran ? redirectsRun.findings : []).concat(refundsRun.ran ? refundsRun.findings : []).concat(forged.ran ? forged.findings : []).concat(webhooks.ran ? webhooks.findings : []).concat(exportsRun.ran ? exportsRun.findings : []).concat(jobsRun.ran ? jobsRun.findings : []).concat(keptRun.ran ? keptRun.findings : []).concat(createsRun.ran ? createsRun.findings : []).concat(limitsRun.ran ? limitsRun.findings : []).concat(stepsRun.ran ? stepsRun.findings : []).concat(onceRun.ran ? onceRun.findings : []).concat(roleRun && roleRun.ran ? roleRun.findings : []).concat(invalid.ran ? invalid.findings : []).filter((f) => {
|
|
3494
|
+
const findings = (grantsRun.ran ? grantsRun.findings : []).concat(answersRun.ran ? answersRun.findings : []).concat(refsRun.ran ? refsRun.findings : []).concat(wall.ran ? wall.findings : []).concat(redirectsRun.ran ? redirectsRun.findings : []).concat(refundsRun.ran ? refundsRun.findings : []).concat(forged.ran ? forged.findings : []).concat(webhooks.ran ? webhooks.findings : []).concat(exportsRun.ran ? exportsRun.findings : []).concat(jobsRun.ran ? jobsRun.findings : []).concat(keptRun.ran ? keptRun.findings : []).concat(createsRun.ran ? createsRun.findings : []).concat(limitsRun.ran ? limitsRun.findings : []).concat(stepsRun.ran ? stepsRun.findings : []).concat(onceRun.ran ? onceRun.findings : []).concat(roleRun && roleRun.ran ? roleRun.findings : []).concat(invalid.ran ? invalid.findings : []).concat(doorsRun.ran ? doorsRun.findings : []).filter((f) => {
|
|
3472
3495
|
const k = f.kind + '|' + f.where + '|' + (f.field || '');
|
|
3473
3496
|
return seen.has(k) ? false : (seen.add(k), true);
|
|
3474
3497
|
});
|
|
3475
3498
|
const left = (grantsRun.ran ? grantsRun.left : []).concat(refsRun.ran ? refsRun.left : []).concat(webhooks.ran ? webhooks.left : []).concat(refundsRun.ran ? refundsRun.left : []).concat(exportsRun.ran ? exportsRun.left : []).concat(jobsRun.ran ? jobsRun.left : []).concat(keptRun.ran ? keptRun.left : []).concat(createsRun.ran ? createsRun.left : []).concat(limitsRun.ran ? limitsRun.left : []).concat(stepsRun.ran ? stepsRun.left : []).concat(onceRun.ran ? onceRun.left : []).concat(wall.ran ? wall.result.seeded || [] : []).concat(roleRun && roleRun.ran ? roleRun.result.seeded || [] : []).concat(wall.ran ? leftBehind(wall.result.attempts) : []).concat(invalid.ran ? invalid.left : []).concat(roleRun && roleRun.ran ? leftBehind(roleRun.result.attempts) : []);
|
|
3476
3499
|
return {
|
|
3477
3500
|
ran: wall.ran || invalid.ran, why: wall.ran || invalid.ran ? null : wall.why, checkedAt: new Date().toISOString(),
|
|
3478
|
-
origin: opts.origin, grants: grantsRun, refs: refsRun, wall: wall, forged: forged, webhooks: webhooks, exports: exportsRun, jobs: jobsRun, kept: keptRun, creates: createsRun, limits: limitsRun, steps: stepsRun, redirects: redirectsRun, refunds: refundsRun, stepsAtOnce: onceRun, answers: answersRun, invalid: invalid, roles: roleRun, verdicts: verdicts, findings: findings, left: left,
|
|
3501
|
+
origin: opts.origin, grants: grantsRun, refs: refsRun, wall: wall, forged: forged, webhooks: webhooks, exports: exportsRun, jobs: jobsRun, kept: keptRun, creates: createsRun, limits: limitsRun, steps: stepsRun, redirects: redirectsRun, refunds: refundsRun, stepsAtOnce: onceRun, answers: answersRun, invalid: invalid, roles: roleRun, doors: doorsRun, verdicts: verdicts, findings: findings, left: left,
|
|
3479
3502
|
notTried: (wall.plan ? wall.plan.notTried : []).concat(invalid.ran ? invalid.notTried : []),
|
|
3480
3503
|
writes: writesOf(m, wall),
|
|
3481
3504
|
};
|
|
@@ -3591,6 +3614,14 @@ async function runLive(root, options) {
|
|
|
3591
3614
|
if (!(err && (err.code === authz.READ_ONLY || authz.isRequestLimit(err)))) throw err;
|
|
3592
3615
|
answersRun = { ran: false, why: 'stopped: ' + err.message };
|
|
3593
3616
|
}
|
|
3617
|
+
// the open doors, by reading only: files served, API docs, CORS and (on a live site) source maps; no password sent
|
|
3618
|
+
let doorsRun;
|
|
3619
|
+
try {
|
|
3620
|
+
doorsRun = await runDoors(root, Object.assign({}, opts, { map: m, origin }), { readOnly: true, live: true });
|
|
3621
|
+
} catch (err) {
|
|
3622
|
+
if (!(err && (err.code === authz.READ_ONLY || authz.isRequestLimit(err)))) throw err;
|
|
3623
|
+
doorsRun = { ran: false, why: 'stopped: ' + err.message };
|
|
3624
|
+
}
|
|
3594
3625
|
// Judged first, then every string kept from the tries masked - the answers, their excerpts, the lines printed from
|
|
3595
3626
|
// them: a live app's records are real people's, and none of their values is shown or saved.
|
|
3596
3627
|
const maskDeep = (v, depth) => {
|
|
@@ -3613,7 +3644,7 @@ async function runLive(root, options) {
|
|
|
3613
3644
|
if (roleRun.ran) { roleRun.result = maskDeep(roleRun.result, 0); roleRun.findings = maskDeep(roleRun.findings, 0); }
|
|
3614
3645
|
// the roles run keeps organizations apart too, so it finds the same reads across organizations again: said once
|
|
3615
3646
|
const seenLive = new Set();
|
|
3616
|
-
const findings = (wall.findings || []).concat(roleRun.ran ? roleRun.findings : []).concat(answersRun.ran ? answersRun.findings : []).filter((f) => {
|
|
3647
|
+
const findings = (wall.findings || []).concat(roleRun.ran ? roleRun.findings : []).concat(answersRun.ran ? answersRun.findings : []).concat(doorsRun.ran ? doorsRun.findings : []).filter((f) => {
|
|
3617
3648
|
const k = f.kind + '|' + f.where + '|' + (f.field || '');
|
|
3618
3649
|
return seenLive.has(k) ? false : (seenLive.add(k), true);
|
|
3619
3650
|
}).map((f) => maskDeep(Object.assign({}, f, { live: true }), 0));
|
|
@@ -3621,7 +3652,7 @@ async function runLive(root, options) {
|
|
|
3621
3652
|
return {
|
|
3622
3653
|
ran: true, live: true, why: null, checkedAt: new Date().toISOString(), origin,
|
|
3623
3654
|
wall, forged: stub, webhooks: stub, exports: stub, jobs: stub, kept: stub, creates: stub, limits: stub, steps: stub, redirects: stub, refunds: stub, stepsAtOnce: stub,
|
|
3624
|
-
roles: roleRun, invalid: stub, grants: stub, refs: stub, answers: answersRun,
|
|
3655
|
+
roles: roleRun, invalid: stub, grants: stub, refs: stub, answers: answersRun, doors: doorsRun,
|
|
3625
3656
|
findings, left: [], leftOut: LIVE_LEFT_OUT,
|
|
3626
3657
|
verdicts: verdictsFor(toCheck, wall, stub, roleRun.ran ? roleRun : null, stub, stub, stub, stub),
|
|
3627
3658
|
notTried: wall.plan ? wall.plan.notTried : [],
|
|
@@ -3700,6 +3731,17 @@ function apiLines(run) {
|
|
|
3700
3731
|
}
|
|
3701
3732
|
out.push('');
|
|
3702
3733
|
}
|
|
3734
|
+
if (run.doors && run.doors.ran) {
|
|
3735
|
+
out.push(' Open doors (files served, API docs, CORS' + (run.live ? ', source maps' : ', wrong passwords at sign-in') + '):');
|
|
3736
|
+
for (const f of run.doors.findings) {
|
|
3737
|
+
out.push(' ' + (f.status === 'confirmed' ? 'PROBLEM' : 'TO CHECK') + ' ' + f.severity + ' ' + f.headline);
|
|
3738
|
+
for (const l of f.proof) out.push(' ' + l);
|
|
3739
|
+
}
|
|
3740
|
+
for (const h of run.doors.held) out.push(' held: ' + h);
|
|
3741
|
+
for (const n of run.doors.notTried) out.push(' not tried: ' + n);
|
|
3742
|
+
if (!run.doors.findings.length && !run.doors.held.length) out.push(' nothing open was found');
|
|
3743
|
+
out.push('');
|
|
3744
|
+
}
|
|
3703
3745
|
if (run.kept && run.kept.ran) {
|
|
3704
3746
|
for (const t of run.kept.tried) out.push(' Change ' + t.what + (t.field ? ' (' + t.field + ')' : '') + ': ' + t.verdict);
|
|
3705
3747
|
for (const f of run.kept.findings) {
|
package/kryptheon-authz.js
CHANGED
|
@@ -545,7 +545,13 @@ function makeContext(options) {
|
|
|
545
545
|
} catch (err) {
|
|
546
546
|
json = undefined;
|
|
547
547
|
}
|
|
548
|
-
|
|
548
|
+
// the few answer headers a check judges by (the open-doors check: CORS, and what kind of file came back)
|
|
549
|
+
const headersKept = {};
|
|
550
|
+
for (const h of ['access-control-allow-origin', 'access-control-allow-credentials', 'content-type', 'retry-after']) {
|
|
551
|
+
const v = res.headers.get(h);
|
|
552
|
+
if (v !== null && v !== undefined) headersKept[h] = v;
|
|
553
|
+
}
|
|
554
|
+
return { status: res.status, location: res.headers.get('location') || '', text: text, json: json, headers: headersKept };
|
|
549
555
|
};
|
|
550
556
|
return ctx;
|
|
551
557
|
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* The app's open doors, tried from outside like any visitor, through the same connection the API check uses (this
|
|
5
|
+
* computer or the saved address only, never a DELETE, nothing but GET on a live app):
|
|
6
|
+
*
|
|
7
|
+
* - files that must never be served: .env (its setting NAMES are said, never a value) and the .git folder;
|
|
8
|
+
* - API docs anyone can read (said as a thing to check: often meant to be public);
|
|
9
|
+
* - CORS that lets any other website read what a signed-in person's browser is sent;
|
|
10
|
+
* - on a LIVE site only: source maps that hand out the app's original source code (a dev server on this computer
|
|
11
|
+
* serves them on purpose, so there it is never said);
|
|
12
|
+
* - on an app on THIS computer only: a sign-in that takes 20 wrong passwords and never slows down. The passwords go
|
|
13
|
+
* to a made-up address (kx-nobody-...@example.test), so no real account is ever locked.
|
|
14
|
+
*
|
|
15
|
+
* Every door has a safe look-alike it must stay quiet on - above all the single-page app that answers every address
|
|
16
|
+
* with its own page: an address answered exactly like a made-up one is never a finding. Deterministic: no AI, no key.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const crypto = require('crypto');
|
|
20
|
+
const authz = require('./kryptheon-authz.js');
|
|
21
|
+
|
|
22
|
+
const ENV_PATHS = ['/.env', '/.env.local', '/.env.production'];
|
|
23
|
+
const GIT_PATHS = [['/.git/config', /^\s*\[core\]/m], ['/.git/HEAD', /^ref: refs\//m]];
|
|
24
|
+
const DOC_PATHS = ['/openapi.json', '/swagger.json', '/api-docs', '/v3/api-docs', '/swagger', '/swagger-ui.html', '/api/docs', '/docs'];
|
|
25
|
+
// a setting whose name says it is a secret
|
|
26
|
+
const SECRET_NAME = /(SECRET|PRIVATE|PASSWORD|PASSWD|TOKEN|API_?KEY|ACCESS_?KEY|DATABASE_URL|DB_URL|SERVICE_ROLE|CONNECTION|DSN|WEBHOOK)/i;
|
|
27
|
+
const SETTING = /^\s*(?:export\s+)?([A-Za-z_][A-Za-z0-9_]{1,80})\s*=\s*(.*)$/;
|
|
28
|
+
const LOGIN_TRIES = 20;
|
|
29
|
+
// the made-up website that asks to read the app's answers
|
|
30
|
+
const OTHER_SITE = 'https://kx-other-site.example';
|
|
31
|
+
const SLOWED = /too many|try again (later|in)|rate.?limit|locked|slow down|wait a (minute|moment|bit)/i;
|
|
32
|
+
|
|
33
|
+
const rand = () => crypto.randomBytes(5).toString('hex');
|
|
34
|
+
const looksHtml = (text) => /^\s*<(!doctype|html|head|body|div|script)/i.test(String(text || ''));
|
|
35
|
+
const answeredLikeNothing = (res, missing) => Boolean(missing) && res.status === missing.status && String(res.text || '').trim() === String(missing.text || '').trim();
|
|
36
|
+
|
|
37
|
+
/** The settings in a served .env-like text: [{ name, set }]. Empty when it is not one. */
|
|
38
|
+
function settingsIn(text) {
|
|
39
|
+
const out = [];
|
|
40
|
+
for (const line of String(text || '').split(/\r?\n/)) {
|
|
41
|
+
if (/^\s*(#|$)/.test(line)) continue;
|
|
42
|
+
const m = SETTING.exec(line);
|
|
43
|
+
if (!m) return []; // a line that is neither a setting nor a comment: not a .env file
|
|
44
|
+
out.push({ name: m[1], set: m[2].replace(/^["']|["']$/g, '').trim() !== '' });
|
|
45
|
+
}
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* options: { origin, fetch, readOnly, live, gets: ['/api/items', ...] (GET paths without a parameter, for CORS),
|
|
51
|
+
* signIn: { method, path, emailField, passwordField, encoding, bearer } }.
|
|
52
|
+
* { ran, why, tried: [{ what, as, status }], findings, held: [text], notTried: [text] }
|
|
53
|
+
*/
|
|
54
|
+
async function run(options) {
|
|
55
|
+
const opts = options || {};
|
|
56
|
+
const readOnly = opts.readOnly === true;
|
|
57
|
+
let origin;
|
|
58
|
+
try {
|
|
59
|
+
origin = authz.assertLocalTarget(opts.origin, null, { readOnly: readOnly });
|
|
60
|
+
} catch (err) {
|
|
61
|
+
return { ran: false, why: 'the app must be on this computer (localhost or 127.0.0.1): ' + (opts.origin || 'no address was given') };
|
|
62
|
+
}
|
|
63
|
+
const ctx = authz.makeContext({ baseUrl: origin, allowOrigins: [origin], fetch: opts.fetch, readOnly: readOnly, maxRequests: 120 });
|
|
64
|
+
const nobody = authz.makeSession(ctx, 'nobody', 'nobody', '');
|
|
65
|
+
const out = { ran: true, tried: [], findings: [], held: [], notTried: [] };
|
|
66
|
+
const get = async (p, headers) => {
|
|
67
|
+
const res = await nobody.send('GET', p, headers ? { headers: headers } : {});
|
|
68
|
+
out.tried.push({ what: 'GET ' + p, as: 'nobody signed in', status: res.status });
|
|
69
|
+
return res;
|
|
70
|
+
};
|
|
71
|
+
const add = (f) => {
|
|
72
|
+
f.fixPrompt = ['Kryptheon tried my running app from outside, like any visitor:', '', f.headline + '.', '', f.proof.join('\n'), '', f.fix, '', 'Change nothing else.'].join('\n');
|
|
73
|
+
delete f.fix;
|
|
74
|
+
out.findings.push(f);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// what the app answers for an address that cannot exist: a single-page app sends its own page for every address
|
|
78
|
+
const missing = await get('/kx-no-such-page-' + rand());
|
|
79
|
+
|
|
80
|
+
// 1. the settings file
|
|
81
|
+
for (const p of ENV_PATHS) {
|
|
82
|
+
const res = await get(p);
|
|
83
|
+
if (res.status !== 200 || answeredLikeNothing(res, missing) || looksHtml(res.text)) continue;
|
|
84
|
+
const settings = settingsIn(res.text);
|
|
85
|
+
if (!settings.length) continue;
|
|
86
|
+
const secrets = settings.filter((s) => s.set && SECRET_NAME.test(s.name)).map((s) => s.name);
|
|
87
|
+
const named = (secrets.length ? secrets : settings.map((s) => s.name)).slice(0, 6);
|
|
88
|
+
add({
|
|
89
|
+
kind: 'door-env', where: 'GET ' + p, status: 'confirmed', severity: secrets.length ? 'CRITICAL' : 'HIGH',
|
|
90
|
+
headline: 'GET ' + p + ' hands your app\'s settings file to anyone: ' + settings.length + ' setting' + (settings.length === 1 ? '' : 's') +
|
|
91
|
+
(secrets.length ? ', including ' + named.join(', ') : ''),
|
|
92
|
+
proof: ['Sent GET ' + p + ' with no session; the app answered 200 with ' + settings.length + ' lines of NAME=value.', 'Names: ' + settings.map((s) => s.name).slice(0, 20).join(', ') + ' (no value is shown or kept).'],
|
|
93
|
+
fix: 'Stop serving this file: the folder the server hands to browsers must not hold it - move .env out of the public or static folder, or refuse every address that starts with a dot. Then treat every secret in it as stolen: make a new one at each provider (' + (secrets.length ? secrets.join(', ') : 'each key in it') + ') and delete the old one.',
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// 2. the code's history
|
|
98
|
+
for (const [p, sign] of GIT_PATHS) {
|
|
99
|
+
const res = await get(p);
|
|
100
|
+
if (res.status !== 200 || answeredLikeNothing(res, missing) || looksHtml(res.text) || !sign.test(String(res.text || ''))) continue;
|
|
101
|
+
add({
|
|
102
|
+
kind: 'door-git', where: 'GET ' + p, status: 'confirmed', severity: 'HIGH',
|
|
103
|
+
headline: 'GET ' + p + ' is served to anyone: the whole history of your code can be downloaded, with every key or password that was ever in it',
|
|
104
|
+
proof: ['Sent GET ' + p + ' with no session; the app answered 200 with a git file (' + (p.endsWith('HEAD') ? '"ref: refs/..."' : '"[core]"') + ').'],
|
|
105
|
+
fix: 'Stop serving the .git folder: deploy only the built app, never the project folder, or refuse every address that starts with a dot. Then make new keys for any secret that was ever committed.',
|
|
106
|
+
});
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 3. API docs anyone can read
|
|
111
|
+
for (const p of DOC_PATHS) {
|
|
112
|
+
const res = await get(p);
|
|
113
|
+
if (res.status !== 200 || answeredLikeNothing(res, missing)) continue;
|
|
114
|
+
const j = res.json;
|
|
115
|
+
const isDocs = (j && typeof j === 'object' && (j.openapi || j.swagger) && j.paths) || /swagger-ui|redoc|"openapi"\s*:|"swagger"\s*:/i.test(String(res.text || ''));
|
|
116
|
+
if (!isDocs) continue;
|
|
117
|
+
add({
|
|
118
|
+
kind: 'door-apidocs', where: 'GET ' + p, status: 'verification required', severity: 'LOW',
|
|
119
|
+
headline: 'GET ' + p + ' shows anyone the full list of your API\'s routes and fields - to check: fine if your API is meant to be public',
|
|
120
|
+
proof: ['Sent GET ' + p + ' with no session; the app answered 200 with API docs (OpenAPI / Swagger).'],
|
|
121
|
+
fix: 'If these docs are only for you or your team, put them behind sign-in or turn them off outside development. If the API is meant to be public, leave it.',
|
|
122
|
+
});
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// 4. CORS: may another website read what a signed-in person's browser is sent?
|
|
127
|
+
const corsPaths = (opts.gets || []).filter((p) => typeof p === 'string' && p.startsWith('/') && !/[{:*]/.test(p)).slice(0, 5);
|
|
128
|
+
if (!corsPaths.length) corsPaths.push('/');
|
|
129
|
+
const opened = [];
|
|
130
|
+
for (const p of corsPaths) {
|
|
131
|
+
const res = await get(p, { origin: OTHER_SITE });
|
|
132
|
+
const allow = (res.headers && res.headers['access-control-allow-origin']) || '';
|
|
133
|
+
const creds = (res.headers && res.headers['access-control-allow-credentials']) || '';
|
|
134
|
+
if ((allow === OTHER_SITE || allow === 'null') && /^true$/i.test(creds)) opened.push({ p: p, allow: allow });
|
|
135
|
+
}
|
|
136
|
+
if (opened.length) {
|
|
137
|
+
const bearer = Boolean(opts.signIn && opts.signIn.bearer);
|
|
138
|
+
add({
|
|
139
|
+
kind: 'door-cors', where: 'GET ' + opened[0].p, status: bearer ? 'verification required' : 'confirmed', severity: bearer ? 'MEDIUM' : 'HIGH',
|
|
140
|
+
headline: 'Any website can read what ' + opened.map((o) => 'GET ' + o.p).join(', ') + ' sends to a signed-in person: the app allows whichever site asks, with its cookies (CORS)' +
|
|
141
|
+
(bearer ? ' - to check: this app signs in with a token, which another site cannot send' : ''),
|
|
142
|
+
proof: opened.map((o) => 'Sent GET ' + o.p + ' as if from ' + OTHER_SITE + '; the app answered Access-Control-Allow-Origin: ' + o.allow + ' and Access-Control-Allow-Credentials: true.'),
|
|
143
|
+
fix: 'Allow only your own site\'s address in the CORS settings (a fixed list, never the Origin the request sends, and never "null"). Keep credentials allowed only for that list.',
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// 5. source maps: on a live site, the app's own code handed to anyone
|
|
148
|
+
if (opts.live === true) {
|
|
149
|
+
const page = await get('/');
|
|
150
|
+
const scripts = [];
|
|
151
|
+
for (const m of String(page.text || '').matchAll(/<script[^>]+src=["']([^"']+)["']/gi)) {
|
|
152
|
+
let u;
|
|
153
|
+
try { u = new URL(m[1], origin); } catch (err) { continue; }
|
|
154
|
+
if (u.origin === origin && !scripts.includes(u.pathname)) scripts.push(u.pathname);
|
|
155
|
+
}
|
|
156
|
+
let found = null;
|
|
157
|
+
for (const src of scripts.slice(0, 6)) {
|
|
158
|
+
const js = await get(src);
|
|
159
|
+
if (js.status !== 200) continue;
|
|
160
|
+
const named = /\/\/[#@]\s*sourceMappingURL=([^\s'"]+)\s*$/m.exec(String(js.text || ''));
|
|
161
|
+
const candidates = [];
|
|
162
|
+
if (named && !/^data:/i.test(named[1])) {
|
|
163
|
+
try { const u = new URL(named[1], origin + src); if (u.origin === origin) candidates.push(u.pathname); } catch (err) { /* not an address */ }
|
|
164
|
+
}
|
|
165
|
+
if (!candidates.length) candidates.push(src + '.map');
|
|
166
|
+
for (const c of candidates) {
|
|
167
|
+
const res = await get(c);
|
|
168
|
+
const j = res.json;
|
|
169
|
+
if (res.status === 200 && j && Array.isArray(j.sources) && Array.isArray(j.sourcesContent) && j.sourcesContent.some((x) => typeof x === 'string' && x.length)) {
|
|
170
|
+
found = { map: c, sources: j.sources.filter((s) => typeof s === 'string') };
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (found) break;
|
|
175
|
+
}
|
|
176
|
+
if (found) {
|
|
177
|
+
add({
|
|
178
|
+
kind: 'door-sourcemap', where: 'GET ' + found.map, status: 'confirmed', severity: 'MEDIUM',
|
|
179
|
+
headline: 'The live site hands out your app\'s original source code: ' + found.map + ' holds ' + found.sources.length + ' file' + (found.sources.length === 1 ? '' : 's') + ' as you wrote them',
|
|
180
|
+
proof: ['Sent GET ' + found.map + ' with no session; it answered with a source map holding the files\' own code: ' + found.sources.slice(0, 5).join(', ') + (found.sources.length > 5 ? ', ...' : '') + '.'],
|
|
181
|
+
fix: 'Turn off source maps in the production build (for Vite: build.sourcemap false; for Next.js: productionBrowserSourceMaps false), or keep them off the public site. Anything secret that was in that code must be changed too.',
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
} else {
|
|
185
|
+
out.notTried.push('source maps: on this computer a dev server serves them on purpose - they are checked on your live address');
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// 6. the sign-in: does it ever slow down? Only on this computer, only with a made-up address.
|
|
189
|
+
const s = opts.signIn;
|
|
190
|
+
if (readOnly) out.notTried.push('wrong passwords at sign-in: never sent to a live app');
|
|
191
|
+
else if (!s || !s.path || s.bearer) out.notTried.push('wrong passwords at sign-in: ' + (!s || !s.path ? 'no sign-in with an email and a password was found' : 'this app signs in with a token'));
|
|
192
|
+
else {
|
|
193
|
+
const email = 'kx-nobody-' + rand() + '@example.test';
|
|
194
|
+
const method = String(s.method || 'POST').toUpperCase();
|
|
195
|
+
const what = method + ' ' + s.path;
|
|
196
|
+
const session = authz.makeSession(ctx, 'nobody', email, '');
|
|
197
|
+
const t0 = Date.now();
|
|
198
|
+
let held = null;
|
|
199
|
+
let stopped = null;
|
|
200
|
+
let sent = 0;
|
|
201
|
+
for (let i = 0; i < LOGIN_TRIES; i++) {
|
|
202
|
+
const fields = { [s.emailField || 'email']: email, [s.passwordField || 'password']: 'kx-wrong-' + rand() };
|
|
203
|
+
const res = await session.send(method, s.path, s.encoding === 'form' ? { form: fields } : { json: fields });
|
|
204
|
+
sent += 1;
|
|
205
|
+
out.tried.push({ what: what, as: email, status: res.status });
|
|
206
|
+
if (res.status === 429 || res.status === 423 || SLOWED.test(String(res.text || ''))) { held = res.status; break; }
|
|
207
|
+
if (res.status === 0 || res.status >= 500) { stopped = res.status || 'no answer'; break; }
|
|
208
|
+
}
|
|
209
|
+
const secs = Math.max(1, Math.round((Date.now() - t0) / 1000));
|
|
210
|
+
if (held !== null) out.held.push(what + ' slowed down after ' + sent + ' wrong password' + (sent === 1 ? '' : 's') + ' (answered ' + held + ')');
|
|
211
|
+
else if (stopped !== null) out.notTried.push('wrong passwords at sign-in: ' + what + ' answered ' + stopped + ' - not judged');
|
|
212
|
+
else {
|
|
213
|
+
add({
|
|
214
|
+
kind: 'door-login-limit', where: what, status: 'confirmed', severity: 'MEDIUM',
|
|
215
|
+
headline: what + ' took ' + LOGIN_TRIES + ' wrong passwords in ' + secs + ' s and never slowed down: a script can guess passwords for as long as it likes',
|
|
216
|
+
proof: ['Sent ' + LOGIN_TRIES + ' sign-ins with wrong passwords for a made-up address (' + email + '), one after another; none was refused as too many (no 429, no "try again later").'],
|
|
217
|
+
fix: 'Limit sign-in attempts on the server: for example 5 a minute per address and per IP, then answer 429 with a wait. Do the same for any one-time code (OTP) check.',
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
return out;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
module.exports = { run, settingsIn, ENV_PATHS, DOC_PATHS, LOGIN_TRIES };
|
package/kryptheon-fixture.js
CHANGED
|
@@ -471,14 +471,20 @@ const test = base.test.extend({
|
|
|
471
471
|
// A value the recording types and then finds its record by gets this
|
|
472
472
|
// run's own number, so a second run does not find two (replay
|
|
473
473
|
// freshValues). Before heal.watch, which keeps getByRole as it is now.
|
|
474
|
+
// A value typed into a field the app keeps unique (a slug, a handle, a promo code) gets this run's number after
|
|
475
|
+
// a dash, so the second run is not refused as "already taken" (replay uniqueValues, round 34).
|
|
474
476
|
let freshToken = null;
|
|
475
477
|
let freshShown = [];
|
|
478
|
+
let uniqueShown = [];
|
|
476
479
|
try {
|
|
477
|
-
const
|
|
478
|
-
|
|
480
|
+
const source = fs.readFileSync(testInfo.file, 'utf8');
|
|
481
|
+
const values = replay.freshValues(source);
|
|
482
|
+
const unique = replay.uniqueValues(source);
|
|
483
|
+
if (values.length || unique.length) {
|
|
479
484
|
freshToken = String(Date.now()).slice(-6);
|
|
480
485
|
freshShown = values.map((v) => signature.normaliseText(v));
|
|
481
|
-
|
|
486
|
+
uniqueShown = unique.map((v) => signature.normaliseText(v));
|
|
487
|
+
replay.useFreshNames(page, values, freshToken, unique);
|
|
482
488
|
}
|
|
483
489
|
} catch (e) {
|
|
484
490
|
freshToken = null; /* replayed exactly as recorded */
|
|
@@ -549,7 +555,7 @@ const test = base.test.extend({
|
|
|
549
555
|
// to reporter stdio hooks that this reporter does not implement, so
|
|
550
556
|
// anything printed from here is dropped before it reaches a terminal.
|
|
551
557
|
// This run's number taken back out, so the page reads as it did when recorded.
|
|
552
|
-
const captured = replay.withoutFresh(await signature.collectSignature(page, failedRequests), freshToken, freshShown);
|
|
558
|
+
const captured = replay.withoutFresh(await signature.collectSignature(page, failedRequests), freshToken, freshShown, uniqueShown);
|
|
553
559
|
if (signature.signatureEnabled()) signature.recordSignature(testInfo.title, captured);
|
|
554
560
|
|
|
555
561
|
// Said once per run by the reporter, not once per test: it is a fact about
|
|
@@ -579,7 +585,7 @@ const test = base.test.extend({
|
|
|
579
585
|
failedRequests: failedRequests,
|
|
580
586
|
signature: captured,
|
|
581
587
|
recordingId: recordingId,
|
|
582
|
-
steps: heal.mergeMemory(sameRecording ? previousEntry.steps : null, replay.withoutFresh(healer.learned, freshToken, freshShown)),
|
|
588
|
+
steps: heal.mergeMemory(sameRecording ? previousEntry.steps : null, replay.withoutFresh(healer.learned, freshToken, freshShown, uniqueShown)),
|
|
583
589
|
};
|
|
584
590
|
} catch (e) {
|
|
585
591
|
current = null; // page closed by the test - leave any baseline untouched
|
package/kryptheon-heal.js
CHANGED
|
@@ -55,6 +55,26 @@ const FIELD_ROLES = new Set(['textbox', 'searchbox', 'combobox', 'listbox', 'spi
|
|
|
55
55
|
const LOOK_ROLES = new Set(['cell', 'gridcell']);
|
|
56
56
|
const lookClick = (role, name, method) => method === 'click' && LOOK_ROLES.has(role) && /\d/.test(String(name || ''));
|
|
57
57
|
|
|
58
|
+
// A step that can be done only once per record: Confirm, Approve, Check in, Redeem, Mark as paid, Release ...
|
|
59
|
+
// Found on round 34 (2026-11-22): the first replay confirmed the one pending order, and on every replay after it
|
|
60
|
+
// the Confirm button was gone - nothing left to confirm - and the flow was said to break on an app that was fine.
|
|
61
|
+
// Such a click is skipped and said, and only when the page proves it: the step found this very button on an earlier
|
|
62
|
+
// passing run, the page around it is the same page, and the button is now not there at all. Never "Save", "Add",
|
|
63
|
+
// "Next", "Delete", "Cancel" or "Close": those are not done once per record. Never a password confirmation.
|
|
64
|
+
// Steps that move a record that is already there - never one that makes a new one ("Reserve a table", "Book",
|
|
65
|
+
// "Join", "Enroll" create, and the next replay has a fresh one to click).
|
|
66
|
+
const ONCE_STEP = /^(confirm|approve|accept|reject|decline|check[\s-]?in|redeem|claim|publish|unpublish|complete|mark( as)? (paid|done|complete|completed|read|shipped|delivered)|archive|unarchive|activate|deactivate|verify|release|settle|refund|void|ship|fulfil|fulfill|dispatch|deliver|reopen|resolve)\b/i;
|
|
67
|
+
// how much of the page around the step must still be there: stricter than a rename's, since nothing is clicked
|
|
68
|
+
// in its place
|
|
69
|
+
const ONCE_SAME_PAGE = 0.8;
|
|
70
|
+
const NOT_ONCE = /password|email|account|sign|log ?in|delete|remove/i;
|
|
71
|
+
|
|
72
|
+
/** Whether a button or link name is a step done once per record ("Confirm", "Approve", "Check in" ...). */
|
|
73
|
+
function isOnceStep(name) {
|
|
74
|
+
const n = String(name == null ? '' : name).trim();
|
|
75
|
+
return !!n && n.length <= 40 && ONCE_STEP.test(n) && !NOT_ONCE.test(n);
|
|
76
|
+
}
|
|
77
|
+
|
|
58
78
|
function norm(text) {
|
|
59
79
|
return String(text == null ? '' : text).replace(/\s+/g, ' ').trim().toLowerCase();
|
|
60
80
|
}
|
|
@@ -185,6 +205,23 @@ function watch(page, options) {
|
|
|
185
205
|
return decideRename(name, fallback[kind], now, ofRole);
|
|
186
206
|
}
|
|
187
207
|
|
|
208
|
+
// A one-time step an earlier replay already did (isOnceStep): this step found the very button on a passing run,
|
|
209
|
+
// the page around it now is that page, and the button is not on it at all.
|
|
210
|
+
async function usedUp(key, role, name, method, locator) {
|
|
211
|
+
if (!/^(click|dblclick|tap)$/.test(method) || !ACTION_ROLES.has(role) || !isOnceStep(name)) return false;
|
|
212
|
+
if (!memory || !Array.isArray(memory[key]) || !memory[key].some((n) => norm(n) === norm(name))) return false;
|
|
213
|
+
const around = memory[key + PAGE_KEY];
|
|
214
|
+
if (!Array.isArray(around) || !around.length) return false;
|
|
215
|
+
const roles = await readRoles();
|
|
216
|
+
if (!roles) return false;
|
|
217
|
+
const here = new Set(pageNames(roles, role).map(norm));
|
|
218
|
+
// what held the button itself (its row "Order 7 pending Confirm", its cell) changes with it: left out
|
|
219
|
+
const placed = around.filter((n) => !norm(n).includes(norm(name)));
|
|
220
|
+
if (!placed.length || placed.filter((n) => here.has(norm(n))).length < placed.length * ONCE_SAME_PAGE) return false;
|
|
221
|
+
const count = await locator.count().catch(() => 1);
|
|
222
|
+
return count === 0;
|
|
223
|
+
}
|
|
224
|
+
|
|
188
225
|
async function act(locator, real, method, args, role, name) {
|
|
189
226
|
const key = counter++ + ' ' + role + ' ' + name;
|
|
190
227
|
const there = await locator
|
|
@@ -213,6 +250,10 @@ function watch(page, options) {
|
|
|
213
250
|
renamed.push({ role: role, was: name, skipped: true });
|
|
214
251
|
return undefined;
|
|
215
252
|
}
|
|
253
|
+
if (await usedUp(key, role, name, method, locator)) {
|
|
254
|
+
renamed.push({ role: role, was: name, skipped: true, once: true });
|
|
255
|
+
return undefined;
|
|
256
|
+
}
|
|
216
257
|
// Not a rename this can prove: the step fails the way it always did.
|
|
217
258
|
return real.apply(locator, args);
|
|
218
259
|
}
|
|
@@ -257,10 +298,9 @@ function watch(page, options) {
|
|
|
257
298
|
return locator;
|
|
258
299
|
};
|
|
259
300
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
if (!name) return locator;
|
|
301
|
+
// The steps of a locator by role and name - and of the one picked from it with first(), last() or nth(i), which
|
|
302
|
+
// codegen writes when a name is on more than one element ("Check in" on every ticket's row): round 34 again.
|
|
303
|
+
function watchSteps(locator, role, name) {
|
|
264
304
|
for (const method of ACTIONS) {
|
|
265
305
|
const real = locator[method];
|
|
266
306
|
if (typeof real !== 'function') continue;
|
|
@@ -268,7 +308,21 @@ function watch(page, options) {
|
|
|
268
308
|
return act(locator, real, method, Array.prototype.slice.call(arguments), role, name);
|
|
269
309
|
};
|
|
270
310
|
}
|
|
311
|
+
for (const pick of ['first', 'last', 'nth']) {
|
|
312
|
+
const real = locator[pick];
|
|
313
|
+
if (typeof real !== 'function') continue;
|
|
314
|
+
locator[pick] = function () {
|
|
315
|
+
return watchSteps(real.apply(locator, arguments), role, name);
|
|
316
|
+
};
|
|
317
|
+
}
|
|
271
318
|
return locator;
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
page.getByRole = function (role, roleOptions) {
|
|
322
|
+
const locator = byRole(role, roleOptions);
|
|
323
|
+
const name = roleOptions && typeof roleOptions.name === 'string' ? roleOptions.name : null;
|
|
324
|
+
if (!name) return locator;
|
|
325
|
+
return watchSteps(locator, role, name);
|
|
272
326
|
};
|
|
273
327
|
|
|
274
328
|
return {
|
|
@@ -305,6 +359,11 @@ function countPattern(text) {
|
|
|
305
359
|
|
|
306
360
|
/** The report line, shared by the terminal and the history. */
|
|
307
361
|
function describeRename(entry) {
|
|
362
|
+
if (entry.skipped && entry.once) {
|
|
363
|
+
return 'The ' + (entry.role === 'link' ? 'link' : 'button') + ' "' + entry.was + '" was not on the page - an earlier run of this flow already did it, ' +
|
|
364
|
+
'and there was nothing left to "' + entry.was + '". I skipped that click and checked the rest of the flow. To check this step again, ' +
|
|
365
|
+
'add a new one waiting for it in your test data, or record the flow again.';
|
|
366
|
+
}
|
|
308
367
|
if (entry.skipped) {
|
|
309
368
|
return 'The ' + entry.role + ' "' + entry.was + '" was not on the page - it holds an id, date or number that moves with the data, ' +
|
|
310
369
|
'so I skipped clicking it and carried on. If that click mattered, record that step again on something that does not change.';
|
|
@@ -326,4 +385,5 @@ module.exports = {
|
|
|
326
385
|
watch: watch,
|
|
327
386
|
mergeMemory: mergeMemory,
|
|
328
387
|
describeRename: describeRename,
|
|
388
|
+
isOnceStep: isOnceStep,
|
|
329
389
|
};
|
|
@@ -338,7 +338,9 @@ const test = base.test.extend({
|
|
|
338
338
|
// The fresh names first: heal keeps the page's own getByRole as it is now
|
|
339
339
|
// (kryptheon-replay.js freshValues).
|
|
340
340
|
try {
|
|
341
|
-
|
|
341
|
+
// and a unique field's value its dashed form ("ss-482173"), so a replay is never refused as "already taken"
|
|
342
|
+
const source = fs.readFileSync(testInfo.file, 'utf8');
|
|
343
|
+
replay.useFreshNames(page, replay.freshValues(source), String(Date.now()).slice(-6), replay.uniqueValues(source));
|
|
342
344
|
} catch (e) {
|
|
343
345
|
/* replayed exactly as recorded */
|
|
344
346
|
}
|
package/kryptheon-replay.js
CHANGED
|
@@ -371,11 +371,13 @@ const QUOTED = /(['"`])((?:\\.|(?!\1).)*)\1/g;
|
|
|
371
371
|
function freshValues(source) {
|
|
372
372
|
const lines = String(source || '').split('\n');
|
|
373
373
|
const fills = [];
|
|
374
|
+
// a unique field's value gets its own form (uniqueValues): never also a spaced one
|
|
375
|
+
const unique = new Set(uniqueValues(source));
|
|
374
376
|
lines.forEach((line, i) => {
|
|
375
377
|
const m = /\.fill\(\s*(['"`])((?:\\.|(?!\1).)*)\1\s*\)/.exec(line);
|
|
376
378
|
if (!m || /process\.env\./.test(line) || isSecretField(nameInLine(line))) return;
|
|
377
379
|
const value = m[2].trim();
|
|
378
|
-
if (value.length >= 3 && !FRESH_SKIP.test(value)) fills.push({ value: value, line: i });
|
|
380
|
+
if (value.length >= 3 && !FRESH_SKIP.test(value) && !unique.has(value)) fills.push({ value: value, line: i });
|
|
379
381
|
});
|
|
380
382
|
const out = [];
|
|
381
383
|
for (const f of fills) {
|
|
@@ -386,14 +388,39 @@ function freshValues(source) {
|
|
|
386
388
|
return out.sort((a, b) => b.length - a.length);
|
|
387
389
|
}
|
|
388
390
|
|
|
391
|
+
// A field the app keeps unique: replayed as recorded, the second run is refused ("slug already taken") and the
|
|
392
|
+
// flow is said to break on an app that is fine (round 34, 2026-11-21: an event's URL slug "ss"). Its value gets
|
|
393
|
+
// this run's number after a dash - "ss" -> "ss-482173" - the form a slug, a handle or a code takes; a space would
|
|
394
|
+
// be refused. Named by the field's label. Never an email (too often the sign-in's), never a number, never a value
|
|
395
|
+
// with a space, and never a username typed right before a password: that is the sign-in.
|
|
396
|
+
const UNIQUE_FIELD = /\b(slug|handle|user\s?name|login\s?name|subdomain|sku|permalink|url\s?key|short\s?name|identifier|((promo|coupon|discount|invite|invitation|referral|voucher|gift)\s?code))\b/i;
|
|
397
|
+
|
|
398
|
+
function uniqueValues(source) {
|
|
399
|
+
const lines = String(source || '').split('\n');
|
|
400
|
+
const out = [];
|
|
401
|
+
lines.forEach((line, i) => {
|
|
402
|
+
const m = /\.fill\(\s*(['"`])((?:\\.|(?!\1).)*)\1\s*\)/.exec(line);
|
|
403
|
+
if (!m || /process\.env\./.test(line)) return;
|
|
404
|
+
const field = nameInLine(line);
|
|
405
|
+
if (!field || !UNIQUE_FIELD.test(field) || isSecretField(field)) return;
|
|
406
|
+
const value = m[2].trim();
|
|
407
|
+
if (!value || /[\s@]/.test(value) || /^[\d.,:/+#-]+$/.test(value) || value.length > 60) return;
|
|
408
|
+
// the sign-in: a password (or a value kept out of the file) typed within the next lines
|
|
409
|
+
const next = lines.slice(i + 1, i + 4).find((l) => /\.fill\(/.test(l));
|
|
410
|
+
if (next && (/process\.env\./.test(next) || isSecretField(nameInLine(next)))) return;
|
|
411
|
+
if (!out.includes(value)) out.push(value);
|
|
412
|
+
});
|
|
413
|
+
return out.sort((a, b) => b.length - a.length);
|
|
414
|
+
}
|
|
415
|
+
|
|
389
416
|
// Which page gets which fresh names. Set per page, read by the locators it
|
|
390
417
|
// makes, so two tests in one process never share a run's number.
|
|
391
418
|
const FRESH = new WeakMap();
|
|
392
419
|
const GETTERS = ['getByRole', 'getByText', 'getByLabel', 'getByTitle', 'getByAltText', 'getByPlaceholder'];
|
|
393
420
|
|
|
394
|
-
/** "nothing" -> "nothing 482173" wherever a looked-for or typed text holds it. */
|
|
421
|
+
/** "nothing" -> "nothing 482173", and a unique field's "ss" -> "ss-482173", wherever a looked-for or typed text holds it. */
|
|
395
422
|
function freshText(state, text) {
|
|
396
|
-
return state && typeof text === 'string' ? text.replace(state.pattern, (m) => m + ' ' + state.token) : text;
|
|
423
|
+
return state && typeof text === 'string' ? text.replace(state.pattern, (m) => m + (state.dashed && state.dashed.has(m) ? '-' : ' ') + state.token) : text;
|
|
397
424
|
}
|
|
398
425
|
|
|
399
426
|
function wrapGetters(proto, stateOf) {
|
|
@@ -418,11 +445,17 @@ function wrapGetters(proto, stateOf) {
|
|
|
418
445
|
}
|
|
419
446
|
}
|
|
420
447
|
|
|
421
|
-
/** Gives this page's run its own names for the values freshValues found. */
|
|
422
|
-
function useFreshNames(page, values, token) {
|
|
423
|
-
|
|
424
|
-
const
|
|
425
|
-
|
|
448
|
+
/** Gives this page's run its own names for the values freshValues found, and the dashed form to uniqueValues'. */
|
|
449
|
+
function useFreshNames(page, values, token, unique) {
|
|
450
|
+
const dashed = (unique || []).filter((v) => typeof v === 'string' && v);
|
|
451
|
+
const all = (values || []).concat(dashed.filter((v) => !(values || []).includes(v))).sort((a, b) => b.length - a.length);
|
|
452
|
+
if (!page || !all.length) return;
|
|
453
|
+
// a whole word only for a short unique value: "s" must not catch the "s" inside "Save"
|
|
454
|
+
const escaped = all.map((v) => {
|
|
455
|
+
const e = v.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
456
|
+
return dashed.includes(v) ? '(?<![\\w-])' + e + '(?![\\w-])' : e;
|
|
457
|
+
});
|
|
458
|
+
FRESH.set(page, { pattern: new RegExp(escaped.join('|'), 'g'), token: String(token), dashed: new Set(dashed) });
|
|
426
459
|
const pageProto = Object.getPrototypeOf(page);
|
|
427
460
|
wrapGetters(pageProto, (p) => FRESH.get(p));
|
|
428
461
|
const locatorProto = Object.getPrototypeOf(page.locator('body'));
|
|
@@ -437,7 +470,7 @@ function useFreshNames(page, values, token) {
|
|
|
437
470
|
state = null;
|
|
438
471
|
}
|
|
439
472
|
// Only a value typed whole, as the recording typed it, gets the number.
|
|
440
|
-
const typed = state && typeof value === 'string' && new RegExp('^\\s*(?:' + state.pattern.source + ')\\s*$').test(value);
|
|
473
|
+
const typed = state && typeof value === 'string' && new RegExp('^\\s*(?:' + state.pattern.source + ')\\s*$').test(value.trim());
|
|
441
474
|
return fill.call(this, typed ? freshText(state, value) : value, options);
|
|
442
475
|
};
|
|
443
476
|
wrapped.__kxFresh = true;
|
|
@@ -451,15 +484,20 @@ function useFreshNames(page, values, token) {
|
|
|
451
484
|
* '#' ("nothing 2" -> "nothing #"): there the number is already "#", and
|
|
452
485
|
* "nothing # #" goes back to "nothing #".
|
|
453
486
|
*/
|
|
454
|
-
function withoutFresh(value, token, shown) {
|
|
487
|
+
function withoutFresh(value, token, shown, dashedShown) {
|
|
455
488
|
if (!token) return value;
|
|
489
|
+
const esc = (f) => f.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
456
490
|
const forms = (shown || []).filter(Boolean).sort((a, b) => b.length - a.length);
|
|
457
491
|
// One pass, longest form first, so "nothing # #" loses one "#" and keeps
|
|
458
492
|
// the "2" of "nothing 2".
|
|
459
|
-
const numbered = forms.length ? new RegExp('(' + forms.map(
|
|
493
|
+
const numbered = forms.length ? new RegExp('(' + forms.map(esc).join('|') + ') #', 'g') : null;
|
|
494
|
+
// a unique field's "ss-482173", as the signature writes it: "ss-#"
|
|
495
|
+
const dashForms = (dashedShown || []).filter(Boolean).sort((a, b) => b.length - a.length);
|
|
496
|
+
const dashNumbered = dashForms.length ? new RegExp('(' + dashForms.map(esc).join('|') + ')-#', 'g') : null;
|
|
460
497
|
const strip = (s) => {
|
|
461
|
-
|
|
462
|
-
|
|
498
|
+
let out = s.split(' ' + token).join('').split('-' + token).join('');
|
|
499
|
+
if (numbered) out = out.replace(numbered, '$1');
|
|
500
|
+
return dashNumbered ? out.replace(dashNumbered, '$1') : out;
|
|
463
501
|
};
|
|
464
502
|
const walk = (v) => {
|
|
465
503
|
if (typeof v === 'string') return strip(v);
|
|
@@ -477,6 +515,7 @@ function withoutFresh(value, token, shown) {
|
|
|
477
515
|
module.exports = {
|
|
478
516
|
withoutFresh: withoutFresh,
|
|
479
517
|
freshValues: freshValues,
|
|
518
|
+
uniqueValues: uniqueValues,
|
|
480
519
|
useFreshNames: useFreshNames,
|
|
481
520
|
freshText: freshText,
|
|
482
521
|
recordingId: recordingId,
|
package/kryptheon-reporter.js
CHANGED
|
@@ -553,7 +553,8 @@ function readRenamed(attachments) {
|
|
|
553
553
|
if (!found) return [];
|
|
554
554
|
try {
|
|
555
555
|
const list = JSON.parse(found.body.toString('utf8'));
|
|
556
|
-
|
|
556
|
+
// a skipped step has no new name, and is said all the same: dropping it made every skip silent (2026-11-22)
|
|
557
|
+
return Array.isArray(list) ? list.filter(function (e) { return e && e.was && (e.now || e.skipped); }) : [];
|
|
557
558
|
} catch (e) {
|
|
558
559
|
return [];
|
|
559
560
|
}
|
|
@@ -863,7 +864,7 @@ class KryptheonReporter {
|
|
|
863
864
|
const renamed = readRenamed(result.attachments);
|
|
864
865
|
if (renamed.length) record.renamed = renamed;
|
|
865
866
|
const renamedLines = renamed.map(function (entry) {
|
|
866
|
-
return ' Renamed: ' + heal.describeRename(entry);
|
|
867
|
+
return (entry.skipped ? ' Skipped: ' : ' Renamed: ') + heal.describeRename(entry);
|
|
867
868
|
});
|
|
868
869
|
|
|
869
870
|
if (status === 'passed') {
|
|
@@ -876,7 +877,10 @@ class KryptheonReporter {
|
|
|
876
877
|
if (renamedLines.length) {
|
|
877
878
|
if (QUIET) process.stdout.write('OK ' + test.title + '\n');
|
|
878
879
|
process.stdout.write(renamedLines.join('\n') + '\n');
|
|
879
|
-
|
|
880
|
+
// a skipped step was not tried: the rest held, and that one step is said as not checked
|
|
881
|
+
process.stdout.write(renamed.some(function (e) { return e.skipped; })
|
|
882
|
+
? ' The rest of the flow held. The skipped step above was not checked this time.\n'
|
|
883
|
+
: ' Nothing is broken. To stop seeing this, record the flow again.\n');
|
|
880
884
|
}
|
|
881
885
|
return;
|
|
882
886
|
}
|
|
@@ -953,7 +957,7 @@ class KryptheonReporter {
|
|
|
953
957
|
out.push(lastPass ? ' This was working on ' + formatWhen(lastPass) + '.' : ' This has not passed before.');
|
|
954
958
|
// On the way to the failure. It explains why the steps before it worked
|
|
955
959
|
// even though a name in the recording no longer matches.
|
|
956
|
-
for (const entry of renamed) out.push(' Renamed on the way: ' + heal.describeRename(entry));
|
|
960
|
+
for (const entry of renamed) out.push((entry.skipped ? ' Skipped on the way: ' : ' Renamed on the way: ') + heal.describeRename(entry));
|
|
957
961
|
|
|
958
962
|
// A save the form held back in the browser: said with the field, and
|
|
959
963
|
// never blamed on a step that cannot repeat - nothing was sent, so
|
|
@@ -1110,6 +1114,8 @@ module.exports = KryptheonReporter;
|
|
|
1110
1114
|
// Shared with the fixture so baselines strip hosts exactly the same way.
|
|
1111
1115
|
// Attached to the exported class, so `new (require(...))()` keeps working.
|
|
1112
1116
|
module.exports.requestPath = requestPath;
|
|
1117
|
+
// For the checks: which noted steps a run says.
|
|
1118
|
+
module.exports.readRenamed = readRenamed;
|
|
1113
1119
|
|
|
1114
1120
|
// Exported for the checks: what a file that would not load turns into.
|
|
1115
1121
|
module.exports.readLoadError = readLoadError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kryptheon",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.78",
|
|
4
4
|
"description": "Record what you do in your app and get plain-language reports when it breaks.",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"kryptheon-map.js",
|
|
61
61
|
"kryptheon-api.js",
|
|
62
62
|
"kryptheon-aiapp.js",
|
|
63
|
+
"kryptheon-doors.js",
|
|
63
64
|
"kryptheon-webhook.js",
|
|
64
65
|
"kryptheon-csv.js",
|
|
65
66
|
"kryptheon-witness.js",
|
|
@@ -75,7 +76,7 @@
|
|
|
75
76
|
"pg": "^8.23.0"
|
|
76
77
|
},
|
|
77
78
|
"scripts": {
|
|
78
|
-
"check": "node kryptheon-store.check.js && node kryptheon-code.check.js && node kryptheon-constdata.check.js && node kryptheon-listitems.check.js && node kryptheon-accept.check.js && node kryptheon-keys.check.js && node kryptheon-dashboard.check.js && node kryptheon-tour.check.js && node kryptheon-upgrade.check.js && node kryptheon-edge.check.js && node kryptheon-reliability.check.js && node kryptheon-fresh.check.js && node kryptheon-payments-dash.check.js && node kryptheon-embedded.check.js && node kryptheon-autostart.check.js && node kryptheon-changes.check.js && node kryptheon-look.check.js && node kryptheon-verify.check.js && node kryptheon-recheck.check.js && node kryptheon-reporter.check.js && node kryptheon-signature.check.js && node kryptheon-signature.stream.check.js && node kryptheon-signature.baseline.check.js && node kryptheon-signature.settle.check.js && node kryptheon-signature.number.check.js && node kryptheon-signature.rows.check.js && node kryptheon-env.check.js && node kryptheon-watchdog.check.js && node kryptheon-phone.check.js && node kryptheon-homedash.check.js && node kryptheon-record.check.js && node kryptheon-selectors.check.js && node kryptheon-recordings.check.js && node kryptheon-testfiles.check.js && node kryptheon-cleanup.check.js && node kryptheon-orphan.check.js && node kryptheon-project.check.js && node kryptheon-setup.check.js && node kryptheon-browser.check.js && node kryptheon-heal.check.js && node kryptheon-load.check.js && node kryptheon-authz.check.js && node kryptheon-roles.check.js && node kryptheon-map.check.js && node kryptheon-api.check.js && node kryptheon-webhook.check.js && node kryptheon-csv.check.js && node kryptheon-witness.check.js && node kryptheon-round34.check.js && node kryptheon-token.check.js && node kryptheon-questions.check.js && node kryptheon-pwbox.check.js && node kryptheon-quiet.check.js && node kryptheon-speed.check.js && node kryptheon-stopped.check.js && node kryptheon-daily.check.js && node kryptheon-live.check.js && node kryptheon-aim.check.js && node kryptheon-peruser.check.js && node kryptheon-aiapp.check.js && node kryptheon-package.check.js && node kryptheon-newer.check.js",
|
|
79
|
+
"check": "node kryptheon-store.check.js && node kryptheon-code.check.js && node kryptheon-constdata.check.js && node kryptheon-listitems.check.js && node kryptheon-accept.check.js && node kryptheon-keys.check.js && node kryptheon-dashboard.check.js && node kryptheon-tour.check.js && node kryptheon-upgrade.check.js && node kryptheon-edge.check.js && node kryptheon-reliability.check.js && node kryptheon-fresh.check.js && node kryptheon-unique.check.js && node kryptheon-payments-dash.check.js && node kryptheon-embedded.check.js && node kryptheon-autostart.check.js && node kryptheon-changes.check.js && node kryptheon-look.check.js && node kryptheon-verify.check.js && node kryptheon-recheck.check.js && node kryptheon-reporter.check.js && node kryptheon-signature.check.js && node kryptheon-signature.stream.check.js && node kryptheon-signature.baseline.check.js && node kryptheon-signature.settle.check.js && node kryptheon-signature.number.check.js && node kryptheon-signature.rows.check.js && node kryptheon-env.check.js && node kryptheon-watchdog.check.js && node kryptheon-phone.check.js && node kryptheon-homedash.check.js && node kryptheon-record.check.js && node kryptheon-selectors.check.js && node kryptheon-recordings.check.js && node kryptheon-testfiles.check.js && node kryptheon-cleanup.check.js && node kryptheon-orphan.check.js && node kryptheon-project.check.js && node kryptheon-setup.check.js && node kryptheon-browser.check.js && node kryptheon-heal.check.js && node kryptheon-once.check.js && node kryptheon-load.check.js && node kryptheon-authz.check.js && node kryptheon-roles.check.js && node kryptheon-map.check.js && node kryptheon-api.check.js && node kryptheon-webhook.check.js && node kryptheon-csv.check.js && node kryptheon-witness.check.js && node kryptheon-round34.check.js && node kryptheon-token.check.js && node kryptheon-questions.check.js && node kryptheon-pwbox.check.js && node kryptheon-quiet.check.js && node kryptheon-speed.check.js && node kryptheon-stopped.check.js && node kryptheon-daily.check.js && node kryptheon-live.check.js && node kryptheon-aim.check.js && node kryptheon-peruser.check.js && node kryptheon-aiapp.check.js && node kryptheon-doors.check.js && node kryptheon-package.check.js && node kryptheon-newer.check.js",
|
|
79
80
|
"check:store": "node kryptheon-store.check.js",
|
|
80
81
|
"check:code": "node kryptheon-code.check.js",
|
|
81
82
|
"check:constdata": "node kryptheon-constdata.check.js",
|