kryptheon 0.1.56 → 0.1.57
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 +38 -5
- package/kryptheon-api.js +269 -9
- package/kryptheon-authz.js +1 -0
- package/kryptheon-code.js +11 -4
- package/kryptheon-csv.js +153 -0
- package/kryptheon-map.js +51 -1
- package/kryptheon-roles.js +12 -0
- package/kryptheon-webhook.js +390 -0
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -305,11 +305,44 @@ anything it could not put back.
|
|
|
305
305
|
- **Across organizations and without a session:** each account is aimed at the
|
|
306
306
|
other organizations' records (found in the app's own lists), and every route
|
|
307
307
|
is tried with no session at all. Judged from what comes back and from what the
|
|
308
|
-
app holds before and after, never from a status code alone.
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
308
|
+
app holds before and after, never from a status code alone. A write to a
|
|
309
|
+
record's own address (a note on `/returns/5/notes`) is read back at that
|
|
310
|
+
address as the record's organization. Needs two accounts.
|
|
311
|
+
- **Who is calling, as the request says:** when the sign-in check takes the user
|
|
312
|
+
id itself from a cookie or a header (`uid=7`, `x-user-id: 7`) instead of a
|
|
313
|
+
session the server signed, Kryptheon asks the "who am I" route with nobody
|
|
314
|
+
signed in, carrying another account's id there. Answered as that person is a
|
|
315
|
+
confirmed problem: anyone can be anyone.
|
|
316
|
+
- **A webhook your app signs itself:** when a payment webhook is checked with an
|
|
317
|
+
HMAC your own code computes (`createHmac('sha256', process.env.SECRET)` over the
|
|
318
|
+
body, the signature in a header), Kryptheon reads how, takes the secret from
|
|
319
|
+
your `.env`, and sends events it makes itself - no real payment needed. First a
|
|
320
|
+
correctly signed one (if your app refuses even that, nothing else is sent), then
|
|
321
|
+
one with no signature, one with a wrong signature, a signed one for the wrong
|
|
322
|
+
amount, and a signed refund for a record nobody had paid. Each is judged from
|
|
323
|
+
your app's own list of those records before and after: an event with no
|
|
324
|
+
signature that changed a record is a confirmed problem. The secret is never
|
|
325
|
+
printed or saved. A signature made from more than the body (a timestamp in
|
|
326
|
+
front, a prefix) is said as not tried. A provider's own signed webhook still
|
|
327
|
+
goes through `npx kryptheon payments`.
|
|
328
|
+
- **Exports:** for a CSV export (a GET ending in `.csv`, or under `/export`),
|
|
329
|
+
a record is made through your own create route with its text fields set to a
|
|
330
|
+
marked value starting with `=`, and the file is downloaded. A cell written as
|
|
331
|
+
typed is a confirmed problem - Excel and Google Sheets run it as a formula; a
|
|
332
|
+
cell with a quote in front is held.
|
|
333
|
+
- **Jobs:** a route that runs a job (`/jobs/...`, `/cron`, `/notify...`) is run
|
|
334
|
+
twice in a row. If its answer counts the same non-zero number both times
|
|
335
|
+
(`created: 11`, then `created: 11`), it is a thing to check: the job may make
|
|
336
|
+
the same reminders or records every time it runs.
|
|
337
|
+
- **Bad values:** for each route that creates something, one field at a time
|
|
338
|
+
gets a value that should be turned away - text for a number and 3000
|
|
339
|
+
characters for a field the code never checks, a blank name or a negative
|
|
340
|
+
number for the rest - on top of a request that is otherwise taken. The app's
|
|
341
|
+
own list says whether it was kept. A value kept is a thing to check (a
|
|
342
|
+
confirmed problem when the code itself claims to check that field); a server
|
|
343
|
+
error is a smaller one. If the app stops answering altogether after a request,
|
|
344
|
+
that is a confirmed problem with the request that did it, and nothing more is
|
|
345
|
+
sent.
|
|
313
346
|
- **Who may do what:** with `--roles` and your `permissions-policy.json`, each
|
|
314
347
|
account also tries what its role may not do. `npx kryptheon api --draft`
|
|
315
348
|
writes `permissions-policy.draft.json`, a guess from your code that the roles
|
package/kryptheon-api.js
CHANGED
|
@@ -24,6 +24,8 @@ const roles = require('./kryptheon-roles.js');
|
|
|
24
24
|
const replay = require('./kryptheon-replay.js');
|
|
25
25
|
const secrets = require('./kryptheon-secrets.js');
|
|
26
26
|
const authz = require('./kryptheon-authz.js');
|
|
27
|
+
const webhook = require('./kryptheon-webhook.js');
|
|
28
|
+
const csv = require('./kryptheon-csv.js');
|
|
27
29
|
|
|
28
30
|
const EMAIL = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
|
|
29
31
|
const SIGN_IN = /(^|\/)(log-?in|sign-?in|session|auth\/(login|signin|token))$/i;
|
|
@@ -206,6 +208,11 @@ function journeyFromMap(m, root, env, roleNames) {
|
|
|
206
208
|
notTried.push({ what, why: 'another sign-in route - signing in is done once, through ' + (s.none ? 'none found' : s.method + ' ' + s.path) });
|
|
207
209
|
continue;
|
|
208
210
|
}
|
|
211
|
+
// the 'who am I' route answers each account with itself: nothing of another organization's to aim at
|
|
212
|
+
if (r.method === 'GET' && IDENTITY_ROUTE.test(r.path)) {
|
|
213
|
+
notTried.push({ what, why: 'the "who am I" route: each account is answered with itself, so there is nothing of another to compare (the forged-identity try uses it)' });
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
209
216
|
if (PLUMBING.test(r.path)) {
|
|
210
217
|
notTried.push({ what, why: 'sign-up, password or health plumbing - not an action to try as another account' });
|
|
211
218
|
continue;
|
|
@@ -639,6 +646,12 @@ async function runInvalid(root, options) {
|
|
|
639
646
|
const before = await read(a.template);
|
|
640
647
|
const res = await session.send(a.method, a.template, a.encoding === 'form' ? { form: body } : { json: body });
|
|
641
648
|
const reply = authz.replyOf(res);
|
|
649
|
+
if (reply.kind === 'no-answer' && await appDown(session, a.template)) {
|
|
650
|
+
out.findings.push(downFinding(who.email, what, f, pr, res));
|
|
651
|
+
out.appDown = what + ' with ' + f.name + ' ' + pr.why;
|
|
652
|
+
out.tried.push({ what: what, field: f.name, mode: pr.mode, sent: pr.why, status: 0, reading: 'no-answer', kept: false, verdict: 'stopped the app', from: f.file + ':' + f.line });
|
|
653
|
+
return out;
|
|
654
|
+
}
|
|
642
655
|
const after = await read(a.template);
|
|
643
656
|
const took = reply.kind === 'accepted' || reply.kind === 'redirect';
|
|
644
657
|
const shown = before !== null && after !== null;
|
|
@@ -697,6 +710,101 @@ async function runInvalid(root, options) {
|
|
|
697
710
|
|
|
698
711
|
const GHOST_ID = '999999999';
|
|
699
712
|
|
|
713
|
+
// --- a job run twice ------------------------------------------------------------
|
|
714
|
+
|
|
715
|
+
// A route that runs a job: /jobs/..., or one named for what jobs do.
|
|
716
|
+
const JOB_PATH = /(^|\/)(jobs?|cron|tasks?\/run|reminders?|digest|notify[\w-]*|sync|overdue|batch)(\/|$)/i;
|
|
717
|
+
// What a job's answer counts: created 3, sent: 12, notified: 2.
|
|
718
|
+
const COUNT_KEY = /^(created|inserted|sent|queued|notified|processed|affected|rows|count|total|emails|events|reminders|jobs)$/i;
|
|
719
|
+
|
|
720
|
+
/** The counts a job's answer gives: { created: 3 }. */
|
|
721
|
+
function countsIn(json) {
|
|
722
|
+
const out = {};
|
|
723
|
+
if (!json || typeof json !== 'object' || Array.isArray(json)) return out;
|
|
724
|
+
for (const k of Object.keys(json)) if (COUNT_KEY.test(k) && typeof json[k] === 'number') out[k] = json[k];
|
|
725
|
+
return out;
|
|
726
|
+
}
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* Each job route run twice in a row by an account it lets in, nothing changed in between. The same
|
|
730
|
+
* non-zero count the second time means the job made the same things again (a second notification
|
|
731
|
+
* for the same overdue return): a thing to check, said with both answers. { ran, why, tried, findings, left }.
|
|
732
|
+
*/
|
|
733
|
+
async function runJobs(root, options) {
|
|
734
|
+
const opts = options || {};
|
|
735
|
+
const plan = planOf(root, opts);
|
|
736
|
+
if (!plan.ran) return { ran: false, why: plan.why };
|
|
737
|
+
const j = plan.journey;
|
|
738
|
+
const routes = j.actions.filter((a) => a.method === 'POST' && !a.params.length && JOB_PATH.test(a.template));
|
|
739
|
+
if (!routes.length) return { ran: false, why: 'the map found no route that runs a job' };
|
|
740
|
+
let origin;
|
|
741
|
+
try {
|
|
742
|
+
origin = authz.assertLocalTarget(opts.origin);
|
|
743
|
+
} catch (err) {
|
|
744
|
+
return { ran: false, why: 'the app must be on this computer (localhost or 127.0.0.1): ' + (opts.origin || 'no address was given') };
|
|
745
|
+
}
|
|
746
|
+
if (!j.signIn) return { ran: false, why: j.signInWhy };
|
|
747
|
+
const ctx = authz.makeContext({ baseUrl: origin, allowOrigins: [origin], fetch: opts.fetch, passwords: Object.fromEntries(j.accounts.usable.map((a) => [a.email, a.password])), maxRequests: 80 });
|
|
748
|
+
const sessions = [];
|
|
749
|
+
for (const a of j.accounts.usable) {
|
|
750
|
+
const s = authz.makeSession(ctx, 'account', a.email, a.password);
|
|
751
|
+
const f = { [j.signIn.emailField]: a.email, [j.signIn.passwordField]: a.password };
|
|
752
|
+
const r = authz.replyOf(await s.send(j.signIn.method, j.signIn.path, j.signIn.encoding === 'form' ? { form: f } : { json: f }));
|
|
753
|
+
if (r.kind !== 'refused' && r.kind !== 'server-error' && r.kind !== 'no-answer') sessions.push(s);
|
|
754
|
+
}
|
|
755
|
+
if (!sessions.length) return { ran: false, why: 'no account with a password in .env could sign in' };
|
|
756
|
+
const out = { ran: true, tried: [], findings: [], left: [] };
|
|
757
|
+
for (const a of routes) {
|
|
758
|
+
const what = a.method + ' ' + a.template;
|
|
759
|
+
const send = (s) => s.send(a.method, a.template, a.encoding === 'form' ? { form: a.fullData || {} } : { json: a.fullData || {} });
|
|
760
|
+
let first = null;
|
|
761
|
+
let by = null;
|
|
762
|
+
for (const s of sessions) {
|
|
763
|
+
const res = await send(s);
|
|
764
|
+
const reply = authz.replyOf(res);
|
|
765
|
+
if (reply.kind === 'accepted' || reply.kind === 'redirect') { first = res; by = s; break; }
|
|
766
|
+
}
|
|
767
|
+
if (!first) { out.tried.push({ what, verdict: 'no account was let in' }); continue; }
|
|
768
|
+
const second = await send(by);
|
|
769
|
+
const c1 = countsIn(first.json);
|
|
770
|
+
const c2 = countsIn(second.json);
|
|
771
|
+
const again = Object.keys(c1).filter((k) => c1[k] > 0 && c2[k] === c1[k]);
|
|
772
|
+
out.tried.push({ what, by: by.email, first: c1, second: c2, verdict: again.length ? 'made the same again' : Object.keys(c1).length ? 'held' : 'no count to compare' });
|
|
773
|
+
out.left.push(what + ' run twice as ' + by.email + (Object.keys(c1).length ? ' (' + JSON.stringify(c1) + ', then ' + JSON.stringify(c2) + ')' : ''));
|
|
774
|
+
if (!again.length) continue;
|
|
775
|
+
const k = again[0];
|
|
776
|
+
const finding = {
|
|
777
|
+
kind: 'job-repeat', where: what, from: a.from.file + ':' + a.from.line, status: 'verification required', severity: 'MEDIUM',
|
|
778
|
+
headline: 'Run twice in a row, ' + what + ' made the same ' + c2[k] + ' again (' + k + ': ' + c1[k] + ', then ' + k + ': ' + c2[k] + '), with nothing changed in between: the same reminders or records may be made every time it runs.',
|
|
779
|
+
proof: ['As ' + by.email + ', sent ' + what + ' twice, one right after the other.', 'first answer: ' + authz.clip(first.text, 120), 'second answer: ' + authz.clip(second.text, 120)],
|
|
780
|
+
};
|
|
781
|
+
finding.fixPrompt = ['Kryptheon ran a job of my app twice in a row:', '', finding.headline, '', 'Where: ' + finding.from, '',
|
|
782
|
+
'First check this is real: look at what the job writes. If running it again makes the same rows again, make it idempotent - remember what it already did (a unique key on the item and the run, or a "notified_at" on the item) and skip what was done. Change nothing else.', '', 'Afterwards I will run: npx kryptheon api'].join(String.fromCharCode(10));
|
|
783
|
+
out.findings.push(finding);
|
|
784
|
+
}
|
|
785
|
+
return out;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
/** Whether the app has stopped answering: a request that got no answer, and then a plain read that gets none either. */
|
|
790
|
+
async function appDown(session, template) {
|
|
791
|
+
const again = await session.send('GET', template, {});
|
|
792
|
+
if (again.status !== 0) return false;
|
|
793
|
+
const root = await session.send('GET', '/', {});
|
|
794
|
+
return root.status === 0;
|
|
795
|
+
}
|
|
796
|
+
|
|
797
|
+
function downFinding(email, what, f, pr, res) {
|
|
798
|
+
const finding = {
|
|
799
|
+
kind: 'app-down', where: what, field: f.name, from: f.file + ':' + f.line, status: 'confirmed', severity: 'HIGH',
|
|
800
|
+
headline: what + ' with ' + f.name + ' ' + pr.why + ' stopped the app: it answered nothing afterwards, to that or any request. One request like this takes the whole app down for everyone.',
|
|
801
|
+
proof: ['As ' + email + ', sent ' + what + ' with ' + f.name + ' ' + pr.why + ' and every other field valid.', 'No answer (' + (res.error || 'the connection failed') + '), and no answer to a plain read of ' + what.split(' ')[1] + ' and of / right after.', 'Nothing more was sent: the rest of the bad-value tries were not made.'],
|
|
802
|
+
};
|
|
803
|
+
finding.fixPrompt = ['Kryptheon sent one bad value to my running app and the whole app stopped:', '', finding.headline, '', 'Where: ' + finding.from, '',
|
|
804
|
+
'First check this is real: start the app, send that request, and see the process exit. Then find why an error in this handler is not caught - an async handler whose rejected promise reaches nothing (Express 4 does not catch those), or a database error thrown outside try/catch. Catch it and answer 400 for a value that is not what the field should hold, and add a last-resort error handler so one bad request can never stop the server. Change nothing else.', '', 'Afterwards I will run: npx kryptheon api'].join(String.fromCharCode(10));
|
|
805
|
+
return finding;
|
|
806
|
+
}
|
|
807
|
+
|
|
700
808
|
// Names of fields that are plainly required, so a blank one is worth trying even where the code checks nothing.
|
|
701
809
|
const REQUIRED_NAME = /^(name|title|subject|address|city|street|postcode|postal|zip|recipient|reason|label)$/;
|
|
702
810
|
const NOT_PLAIN_TEXT = /^(email|mail|date|day|at|on|url|link|website|phone|mobile|role|status|state|currency|country|id|key|token)$/;
|
|
@@ -741,7 +849,7 @@ const normRoute = (name) => String(name).replace(/:\w+\*?/g, '{id}');
|
|
|
741
849
|
* organizations; no-role <- the roles run (needs the owner's permissions file);
|
|
742
850
|
* a webhook is the payments check's.
|
|
743
851
|
*/
|
|
744
|
-
function verdictsFor(toCheck, wall, invalid, roleRun) {
|
|
852
|
+
function verdictsFor(toCheck, wall, invalid, roleRun, forged, webhooks) {
|
|
745
853
|
const out = [];
|
|
746
854
|
const attempts = wall && wall.ran ? wall.result.attempts : [];
|
|
747
855
|
const failures = (wall && wall.findings) || [];
|
|
@@ -751,9 +859,26 @@ function verdictsFor(toCheck, wall, invalid, roleRun) {
|
|
|
751
859
|
const route = normRoute(t.route);
|
|
752
860
|
const v = { route: t.route, kind: t.kind, headline: t.headline };
|
|
753
861
|
const kind = /^no-sign-in$/.test(t.kind) ? 'signin' : /^tenant-/.test(t.kind) ? 'tenant' : /^no-role$/.test(t.kind) ? 'role' : null;
|
|
754
|
-
if (
|
|
755
|
-
|
|
756
|
-
v.
|
|
862
|
+
if (t.kind === 'identity-from-request') {
|
|
863
|
+
const hit = forged && forged.ran && forged.findings.find((f) => f.from === t.where);
|
|
864
|
+
v.verdict = hit ? 'confirmed' : forged && forged.ran && forged.tried.length ? 'held' : 'not tried';
|
|
865
|
+
if (hit) v.finding = hit.headline;
|
|
866
|
+
if (v.verdict === 'not tried') v.why = forged ? forged.why || 'not tried' : 'the forged identity was not tried';
|
|
867
|
+
} else if (/^webhook/.test(t.kind)) {
|
|
868
|
+
const hook = webhooks && webhooks.ran ? webhooks.hooks.find((x) => x.route === t.route) : null;
|
|
869
|
+
const hit = hook && hook.findings.find((f) => /^webhook-(unsigned|forged)$/.test(f.kind) && f.status === 'confirmed');
|
|
870
|
+
if (hit) {
|
|
871
|
+
v.verdict = 'confirmed';
|
|
872
|
+
v.finding = hit.headline;
|
|
873
|
+
} else if (hook && hook.control && hook.control.took && hook.tried.some((x) => x.mode === 'none') && !hook.findings.some((f) => /^webhook-(unsigned|forged)$/.test(f.kind))) {
|
|
874
|
+
v.verdict = 'held';
|
|
875
|
+
} else if (hook && hook.findings.some((f) => /^webhook-(unsigned|forged)$/.test(f.kind))) {
|
|
876
|
+
v.verdict = 'not judged';
|
|
877
|
+
v.why = 'the app answered success without a valid signature, but no change was seen in ' + hook.list;
|
|
878
|
+
} else {
|
|
879
|
+
v.verdict = 'not tried';
|
|
880
|
+
v.why = (hook && hook.notTried ? hook.notTried : webhooks && !webhooks.ran ? webhooks.why : 'a webhook this run did not send to') + '; a provider\'s own webhook is the payments check\'s (npx kryptheon payments)';
|
|
881
|
+
}
|
|
757
882
|
} else if (kind === 'role') {
|
|
758
883
|
// "held" only when the roles run really tried this route as a role the policy forbids
|
|
759
884
|
const tries = roleRun && roleRun.ran ? roleRun.result.attempts.filter((a) => !a.notTried && a.kind === 'role' && a.method + ' ' + a.template === route) : [];
|
|
@@ -799,6 +924,90 @@ function verdictsFor(toCheck, wall, invalid, roleRun) {
|
|
|
799
924
|
return out;
|
|
800
925
|
}
|
|
801
926
|
|
|
927
|
+
// --- who is calling, as the request says: forged on the running app ----------------
|
|
928
|
+
|
|
929
|
+
const IDENTITY_ROUTE = /(^|\/)(me|whoami|session|profile|account)$/i;
|
|
930
|
+
|
|
931
|
+
/** The id of the person an identity answer names: { id, email } or null. */
|
|
932
|
+
function personIn(json) {
|
|
933
|
+
const look = (v, depth) => {
|
|
934
|
+
if (!v || typeof v !== 'object' || depth > 2 || Array.isArray(v)) return null;
|
|
935
|
+
if (['string', 'number'].includes(typeof v.id) && typeof v.email === 'string') return { id: v.id, email: v.email };
|
|
936
|
+
for (const k of Object.keys(v)) {
|
|
937
|
+
const f = look(v[k], depth + 1);
|
|
938
|
+
if (f) return f;
|
|
939
|
+
}
|
|
940
|
+
return null;
|
|
941
|
+
};
|
|
942
|
+
return look(json, 0);
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
/**
|
|
946
|
+
* For each sign-in check the map says takes who is calling from a cookie or header holding the bare
|
|
947
|
+
* user id: with no password at all, a request carrying another account's id there. Answered as that
|
|
948
|
+
* account = confirmed. Reads only (the app's "who am I" route). { ran, why, findings, tried }.
|
|
949
|
+
*/
|
|
950
|
+
async function runForged(root, options) {
|
|
951
|
+
const opts = options || {};
|
|
952
|
+
const say = typeof opts.say === 'function' ? opts.say : () => {};
|
|
953
|
+
const plan = planOf(root, opts);
|
|
954
|
+
if (!plan.ran) return { ran: false, why: plan.why };
|
|
955
|
+
const items = map.toCheck(plan.map).filter((t) => t.kind === 'identity-from-request');
|
|
956
|
+
if (!items.length) return { ran: false, why: 'no sign-in check takes who is calling from a bare id in a cookie or header' };
|
|
957
|
+
let origin;
|
|
958
|
+
try {
|
|
959
|
+
origin = authz.assertLocalTarget(opts.origin);
|
|
960
|
+
} catch (err) {
|
|
961
|
+
return { ran: false, why: 'the app must be on this computer (localhost or 127.0.0.1): ' + (opts.origin || 'no address was given') };
|
|
962
|
+
}
|
|
963
|
+
const j = plan.journey;
|
|
964
|
+
if (!j.signIn) return { ran: false, why: j.signInWhy };
|
|
965
|
+
const me = (plan.map.routes || []).find((r) => r.method === 'GET' && r.path && IDENTITY_ROUTE.test(r.path) && r.auth && r.auth.status === map.STATUS.DETECTED);
|
|
966
|
+
if (!me) return { ran: false, why: 'no "who am I" route (GET /api/me or the like) behind the sign-in check, so an answer cannot be tied to a person' };
|
|
967
|
+
const accounts = j.accounts.usable.slice(0, 4);
|
|
968
|
+
if (accounts.length < 1) return { ran: false, why: 'no account has a password in .env' };
|
|
969
|
+
const passwords = {};
|
|
970
|
+
for (const a of accounts) passwords[a.email] = a.password;
|
|
971
|
+
const ctx = authz.makeContext({ baseUrl: origin, allowOrigins: [origin], fetch: opts.fetch, passwords: passwords, maxRequests: 60 });
|
|
972
|
+
// who each account is, as the app says when they sign in properly
|
|
973
|
+
const people = [];
|
|
974
|
+
for (const a of accounts) {
|
|
975
|
+
const s = authz.makeSession(ctx, 'account', a.email, a.password);
|
|
976
|
+
const fields = { [j.signIn.emailField]: a.email, [j.signIn.passwordField]: a.password };
|
|
977
|
+
const r = authz.replyOf(await s.send(j.signIn.method, j.signIn.path, j.signIn.encoding === 'form' ? { form: fields } : { json: fields }));
|
|
978
|
+
if (r.kind === 'refused' || r.kind === 'server-error' || r.kind === 'no-answer') continue;
|
|
979
|
+
const res = await s.send('GET', me.path, {});
|
|
980
|
+
const who = res.status === 200 ? personIn(res.json) : null;
|
|
981
|
+
if (who && who.email.toLowerCase() === a.email.toLowerCase()) people.push(who);
|
|
982
|
+
}
|
|
983
|
+
if (!people.length) return { ran: false, why: 'signed in, but ' + me.path + ' did not say who anyone is' };
|
|
984
|
+
say('Asking ' + me.path + ' with nobody signed in, carrying another person\'s id where the sign-in check reads it...');
|
|
985
|
+
const out = { ran: true, findings: [], tried: [], route: me.path };
|
|
986
|
+
for (const item of items) {
|
|
987
|
+
const { kind, name } = item.identity;
|
|
988
|
+
for (const person of people) {
|
|
989
|
+
const forger = authz.makeSession(ctx, 'forger', '(nobody signed in)', null);
|
|
990
|
+
if (kind === 'cookie') forger.jar.set(name, String(person.id));
|
|
991
|
+
const res = await forger.send('GET', me.path, kind === 'header' ? { headers: { [name]: String(person.id) } } : {});
|
|
992
|
+
const got = res.status === 200 ? personIn(res.json) : null;
|
|
993
|
+
const isThem = !!(got && String(got.id) === String(person.id) && got.email.toLowerCase() === person.email.toLowerCase());
|
|
994
|
+
out.tried.push({ by: kind + ' ' + name, as: person.email, status: res.status, verdict: isThem ? 'answered as them' : 'refused' });
|
|
995
|
+
if (!isThem) continue;
|
|
996
|
+
const sent = kind === 'cookie' ? 'cookie ' + name + '=' + person.id : 'header ' + name + ': ' + person.id;
|
|
997
|
+
const finding = {
|
|
998
|
+
kind: 'forged-identity', where: 'GET ' + me.path, from: item.where, status: 'confirmed', severity: 'CRITICAL',
|
|
999
|
+
headline: 'Anyone can be any user: with no password and nobody signed in, a request carrying ' + sent + ' was answered as ' + person.email + '. ' + item.headline + '.',
|
|
1000
|
+
proof: ['With nobody signed in (no password sent), set ' + sent + ' - the id ' + me.path + ' gives ' + person.email + ' when they sign in.', 'sent: GET ' + me.path, 'answer: ' + res.status + ' ' + authz.clip(res.text, 160)],
|
|
1001
|
+
};
|
|
1002
|
+
finding.fixPrompt = ['Kryptheon showed that anyone can act as any user of my running app:', '', finding.headline, '', 'Where: ' + item.where, '',
|
|
1003
|
+
'First check this is real: with no session, send that request yourself. If it is, ' + map.ADVICE['identity-from-request'] + ' Change nothing else.', '', 'Afterwards I will run: npx kryptheon api'].join(String.fromCharCode(10));
|
|
1004
|
+
out.findings.push(finding);
|
|
1005
|
+
break; // one person proves it for this check
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
return out;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
802
1011
|
/**
|
|
803
1012
|
* The whole run on an app on this computer: across organizations and without
|
|
804
1013
|
* a session, then bad values, then (only with the owner's permissions file and
|
|
@@ -812,19 +1021,24 @@ async function runApi(root, options) {
|
|
|
812
1021
|
const toCheck = opts.toCheck || map.toCheck(m);
|
|
813
1022
|
const shared = Object.assign({}, opts, { map: m, say: say });
|
|
814
1023
|
const wall = await runWall(root, shared);
|
|
1024
|
+
const forged = await runForged(root, shared);
|
|
1025
|
+
const webhooks = await webhook.run(root, shared);
|
|
1026
|
+
// the export and the jobs come before the bad values, which may stop the app
|
|
1027
|
+
const exportsRun = await csv.run(root, shared);
|
|
1028
|
+
const jobsRun = await runJobs(root, shared);
|
|
815
1029
|
const invalid = await runInvalid(root, shared);
|
|
816
1030
|
let roleRun = null;
|
|
817
1031
|
if (opts.roles) roleRun = await runRoles(root, shared);
|
|
818
|
-
const verdicts = verdictsFor(toCheck, wall, invalid, roleRun);
|
|
1032
|
+
const verdicts = verdictsFor(toCheck, wall, invalid, roleRun, forged, webhooks);
|
|
819
1033
|
const seen = new Set();
|
|
820
|
-
const findings = (wall.ran ? wall.findings : []).concat(roleRun && roleRun.ran ? roleRun.findings : []).concat(invalid.ran ? invalid.findings : []).filter((f) => {
|
|
1034
|
+
const findings = (wall.ran ? wall.findings : []).concat(forged.ran ? forged.findings : []).concat(webhooks.ran ? webhooks.findings : []).concat(exportsRun.ran ? exportsRun.findings : []).concat(jobsRun.ran ? jobsRun.findings : []).concat(roleRun && roleRun.ran ? roleRun.findings : []).concat(invalid.ran ? invalid.findings : []).filter((f) => {
|
|
821
1035
|
const k = f.kind + '|' + f.where + '|' + (f.field || '');
|
|
822
1036
|
return seen.has(k) ? false : (seen.add(k), true);
|
|
823
1037
|
});
|
|
824
|
-
const left = (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) : []);
|
|
1038
|
+
const left = (webhooks.ran ? webhooks.left : []).concat(exportsRun.ran ? exportsRun.left : []).concat(jobsRun.ran ? jobsRun.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) : []);
|
|
825
1039
|
return {
|
|
826
1040
|
ran: wall.ran || invalid.ran, why: wall.ran || invalid.ran ? null : wall.why, checkedAt: new Date().toISOString(),
|
|
827
|
-
origin: opts.origin, wall: wall, invalid: invalid, roles: roleRun, verdicts: verdicts, findings: findings, left: left,
|
|
1041
|
+
origin: opts.origin, wall: wall, forged: forged, webhooks: webhooks, exports: exportsRun, jobs: jobsRun, invalid: invalid, roles: roleRun, verdicts: verdicts, findings: findings, left: left,
|
|
828
1042
|
notTried: (wall.plan ? wall.plan.notTried : []).concat(invalid.ran ? invalid.notTried : []),
|
|
829
1043
|
};
|
|
830
1044
|
}
|
|
@@ -837,6 +1051,7 @@ function reportOf(run) {
|
|
|
837
1051
|
accounts: run.wall && run.wall.ran ? run.wall.result.accounts.map((a) => a.email) : run.invalid && run.invalid.ran ? [run.invalid.account] : [],
|
|
838
1052
|
tries: { acrossOrganizationsAndNoSession: wallTries, badValues: run.invalid && run.invalid.ran ? run.invalid.tried.length : 0 },
|
|
839
1053
|
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 })),
|
|
1054
|
+
webhooks: run.webhooks && run.webhooks.ran ? run.webhooks.hooks.map((h) => ({ route: h.route, from: h.from, signing: h.signing || null, notTried: h.notTried, control: h.control ? { status: h.control.status, took: h.control.took } : null, tries: h.tried.map((t) => ({ what: t.label + ' ' + t.type, record: t.record, status: t.status, changed: t.changed })) })) : [],
|
|
840
1055
|
verdicts: run.verdicts, left: run.left, notTried: run.notTried,
|
|
841
1056
|
};
|
|
842
1057
|
}
|
|
@@ -868,6 +1083,51 @@ function apiLines(run) {
|
|
|
868
1083
|
}
|
|
869
1084
|
out.push('');
|
|
870
1085
|
}
|
|
1086
|
+
if (run.forged && run.forged.ran) {
|
|
1087
|
+
const got = run.forged.tried.filter((t) => t.verdict === 'answered as them').length;
|
|
1088
|
+
out.push(' Who is calling, as the request says (' + run.forged.route + ', nobody signed in): ' + got + ' answered as another person, ' + (run.forged.tried.length - got) + ' refused');
|
|
1089
|
+
for (const f of run.forged.findings) {
|
|
1090
|
+
out.push(' PROBLEM ' + f.severity + ' ' + f.headline + ' (' + f.from + ')');
|
|
1091
|
+
for (const l of f.proof) out.push(' ' + l);
|
|
1092
|
+
}
|
|
1093
|
+
out.push('');
|
|
1094
|
+
}
|
|
1095
|
+
if (run.webhooks && run.webhooks.ran) {
|
|
1096
|
+
for (const h of run.webhooks.hooks) {
|
|
1097
|
+
if (h.notTried) {
|
|
1098
|
+
out.push(' Webhook ' + h.route + ': not tried - ' + h.notTried);
|
|
1099
|
+
continue;
|
|
1100
|
+
}
|
|
1101
|
+
out.push(' Webhook ' + h.route + ' (' + h.signing.header + ', ' + h.signing.algorithm + ' ' + h.signing.encoding + ' over ' + h.signing.signs + '): a correctly signed event was taken; ' + h.tried.filter((t) => t !== h.control && t.took).length + ' of ' + (h.tried.length - 1) + ' other tries were taken, ' + h.tried.filter((t) => t.changed && t !== h.control).length + ' changed a record');
|
|
1102
|
+
for (const f of h.findings) {
|
|
1103
|
+
out.push(' ' + (f.status === 'confirmed' ? 'PROBLEM' : 'TO CHECK') + ' ' + f.severity + ' ' + f.headline + ' (' + f.from + ')');
|
|
1104
|
+
for (const l of f.proof) out.push(' ' + l);
|
|
1105
|
+
}
|
|
1106
|
+
}
|
|
1107
|
+
out.push('');
|
|
1108
|
+
} else if (run.webhooks && run.webhooks.why && !/no webhook route/.test(run.webhooks.why)) {
|
|
1109
|
+
out.push(' Webhooks not tried: ' + run.webhooks.why, '');
|
|
1110
|
+
}
|
|
1111
|
+
if (run.exports && run.exports.ran) {
|
|
1112
|
+
for (const t of run.exports.tried) out.push(' Export ' + t.what + ': ' + (t.verdict === 'raw' ? 'writes ' + t.field + ' as typed' : t.verdict === 'escaped' ? t.field + ' is written with a mark in front of "=" - held' : 'a marked value made through the app did not appear in it - not judged'));
|
|
1113
|
+
for (const f of run.exports.findings) {
|
|
1114
|
+
out.push(' PROBLEM ' + f.severity + ' ' + f.headline + ' (' + f.from + ')');
|
|
1115
|
+
for (const l of f.proof) out.push(' ' + l);
|
|
1116
|
+
}
|
|
1117
|
+
out.push('');
|
|
1118
|
+
}
|
|
1119
|
+
if (run.jobs && run.jobs.ran) {
|
|
1120
|
+
for (const t of run.jobs.tried) out.push(' Job ' + t.what + ' run twice: ' + t.verdict + (t.first ? ' (' + JSON.stringify(t.first) + ', then ' + JSON.stringify(t.second) + ')' : ''));
|
|
1121
|
+
for (const f of run.jobs.findings) {
|
|
1122
|
+
out.push(' TO CHECK ' + f.severity + ' ' + f.headline + ' (' + f.from + ')');
|
|
1123
|
+
for (const l of f.proof) out.push(' ' + l);
|
|
1124
|
+
}
|
|
1125
|
+
out.push('');
|
|
1126
|
+
}
|
|
1127
|
+
if (run.invalid && run.invalid.ran && run.invalid.appDown) {
|
|
1128
|
+
out.push(' THE APP STOPPED ANSWERING after ' + run.invalid.appDown + '. Nothing more was sent; start it again before any other check.');
|
|
1129
|
+
out.push('');
|
|
1130
|
+
}
|
|
871
1131
|
if (run.invalid && run.invalid.ran) {
|
|
872
1132
|
out.push(' Bad values (as ' + run.invalid.account + '): ' + run.invalid.tried.filter((t) => t.verdict === 'turned away').length + ' turned away, ' + run.invalid.tried.filter((t) => t.verdict === 'kept').length + ' kept, ' + run.invalid.tried.filter((t) => t.verdict === 'crashed').length + ' crashed, ' + run.invalid.tried.filter((t) => t.verdict === 'taken, not shown').length + ' taken with nothing to show');
|
|
873
1133
|
for (const f of run.invalid.findings) {
|
|
@@ -893,4 +1153,4 @@ function apiLines(run) {
|
|
|
893
1153
|
return out;
|
|
894
1154
|
}
|
|
895
1155
|
|
|
896
|
-
module.exports = { 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 };
|
|
1156
|
+
module.exports = { 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
|
@@ -383,6 +383,7 @@ function makeContext(options) {
|
|
|
383
383
|
const headers = { accept: 'application/json, text/html;q=0.8' };
|
|
384
384
|
const cookie = cookieHeader(session.jar);
|
|
385
385
|
if (cookie) headers.cookie = cookie;
|
|
386
|
+
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]);
|
|
386
387
|
let body;
|
|
387
388
|
if (opts.json !== undefined) {
|
|
388
389
|
headers['content-type'] = 'application/json';
|
package/kryptheon-code.js
CHANGED
|
@@ -619,10 +619,14 @@ function judgedParts(node, scope, code) {
|
|
|
619
619
|
/**
|
|
620
620
|
* Which parts of a value make it unsafe, in the words of the code - so a fix
|
|
621
621
|
* prompt can say "only ${log.caller_number}" instead of quoting sixty lines of
|
|
622
|
-
* template and leaving the reader to find it.
|
|
622
|
+
* template and leaving the reader to find it. Never repeated; past MAX_PARTS
|
|
623
|
+
* the list says there are more, so a fix prompt never reads as complete when
|
|
624
|
+
* it is not (round 24: a sixth part, a note's body, was dropped at five).
|
|
623
625
|
*/
|
|
626
|
+
const MAX_PARTS = 24;
|
|
624
627
|
function riskyParts(node, scope, code, aliases, out, depth) {
|
|
625
|
-
|
|
628
|
+
// one past the cap is kept, so whoever lists them can tell the list was cut
|
|
629
|
+
if (!node || out.length > MAX_PARTS || depth > MAX_DEPTH) return;
|
|
626
630
|
const origin = classify(node, scope, code, 0, aliases);
|
|
627
631
|
if (origin === 'safe') return;
|
|
628
632
|
const go = (n, s, a) => riskyParts(n, s || scope, code, a || aliases, out, depth + 1);
|
|
@@ -2027,12 +2031,14 @@ function describe(f) {
|
|
|
2027
2031
|
];
|
|
2028
2032
|
// A long template is mostly harmless markup. Naming the part that decides it
|
|
2029
2033
|
// keeps the fix - and the AI tool doing it - to that part alone.
|
|
2030
|
-
const
|
|
2034
|
+
const more = (f.parts || []).length > MAX_PARTS;
|
|
2035
|
+
const parts = (f.parts || []).slice(0, MAX_PARTS).filter((p) => p.text && p.text !== f.expression);
|
|
2031
2036
|
const only = parts.length
|
|
2032
2037
|
? [''].concat(
|
|
2033
2038
|
[(parts.length === 1 ? 'Only this part' : 'Only these parts') + ' of it can carry text from outside the page, ' +
|
|
2034
2039
|
'so only ' + (parts.length === 1 ? 'it needs' : 'they need') + ' changing:'],
|
|
2035
2040
|
parts.map((p) => ' ${' + p.text + '}'),
|
|
2041
|
+
more ? ['There are more such parts in this template than are listed here: treat every ${} in it the same way.'] : [],
|
|
2036
2042
|
)
|
|
2037
2043
|
: [];
|
|
2038
2044
|
const fixPrompt = [
|
|
@@ -2064,7 +2070,8 @@ function describe(f) {
|
|
|
2064
2070
|
sink: f.sink,
|
|
2065
2071
|
expression: f.expression,
|
|
2066
2072
|
origin: f.origin,
|
|
2067
|
-
parts: (f.parts || []).map((p) => ({ text: p.text, origin: p.origin })),
|
|
2073
|
+
parts: (f.parts || []).slice(0, MAX_PARTS).map((p) => ({ text: p.text, origin: p.origin })),
|
|
2074
|
+
moreParts: more,
|
|
2068
2075
|
via: f.via || null,
|
|
2069
2076
|
helper: f.helper || null,
|
|
2070
2077
|
headline: 'Text ' + (f.origin === 'unknown' ? 'of unknown origin' : ORIGIN_WORDS[f.origin].split(',')[0]) +
|
package/kryptheon-csv.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
// The export check: does a value someone typed come out of a CSV export as a
|
|
2
|
+
// formula?
|
|
3
|
+
//
|
|
4
|
+
// A cell that starts with = + - or @ is a formula to Excel and Google Sheets.
|
|
5
|
+
// An export that writes what customers typed as it was typed lets one customer
|
|
6
|
+
// put =HYPERLINK(...) or worse in front of whoever opens the file. Reading the
|
|
7
|
+
// export code cannot say whether a value is escaped further down; the file can.
|
|
8
|
+
//
|
|
9
|
+
// So: a record is made through the app's own create route with each plain text
|
|
10
|
+
// field set to a marked value that starts with "=", the export is downloaded
|
|
11
|
+
// before and after, and the cell is read. Written as sent = confirmed; written
|
|
12
|
+
// with a quote or a space in front = held; not in the file = said, not judged.
|
|
13
|
+
//
|
|
14
|
+
// Promises: only an app on this computer; the record it makes is listed as
|
|
15
|
+
// test data (nothing is deleted); the marked value is inert - it names no
|
|
16
|
+
// function and no address.
|
|
17
|
+
|
|
18
|
+
const crypto = require('crypto');
|
|
19
|
+
|
|
20
|
+
const EXPORT_PATH = /(\.csv$|(^|\/)(export|exports|download|downloads)(\/|$|\.))/i;
|
|
21
|
+
const NOT_TEXT = /(^|_)(id|email|mail|date|day|at|on|url|link|website|phone|mobile|role|status|state|currency|country|password|token|key|type|kind)$/i;
|
|
22
|
+
const MAX_ROUTES = 3;
|
|
23
|
+
|
|
24
|
+
/** The cells of a CSV text, rows of strings, quotes undone. */
|
|
25
|
+
function cellsOf(text) {
|
|
26
|
+
const rows = [];
|
|
27
|
+
let row = [];
|
|
28
|
+
let cell = '';
|
|
29
|
+
let quoted = false;
|
|
30
|
+
for (let i = 0; i < text.length; i++) {
|
|
31
|
+
const c = text[i];
|
|
32
|
+
if (quoted) {
|
|
33
|
+
if (c === '"' && text[i + 1] === '"') { cell += '"'; i++; }
|
|
34
|
+
else if (c === '"') quoted = false;
|
|
35
|
+
else cell += c;
|
|
36
|
+
} else if (c === '"' && cell === '') quoted = true;
|
|
37
|
+
else if (c === ',') { row.push(cell); cell = ''; }
|
|
38
|
+
else if (c === '\n' || c === '\r') {
|
|
39
|
+
if (c === '\r' && text[i + 1] === '\n') i++;
|
|
40
|
+
row.push(cell); rows.push(row); row = []; cell = '';
|
|
41
|
+
} else cell += c;
|
|
42
|
+
}
|
|
43
|
+
if (cell !== '' || row.length) { row.push(cell); rows.push(row); }
|
|
44
|
+
return rows;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** How a marked value came out: 'raw' (a formula), 'escaped', or null when it is not in the file. */
|
|
48
|
+
function cellVerdict(rows, mark) {
|
|
49
|
+
for (const row of rows) {
|
|
50
|
+
for (const cell of row) {
|
|
51
|
+
if (cell === mark) return { verdict: 'raw', cell, row };
|
|
52
|
+
if (cell.endsWith(mark) && cell.length <= mark.length + 2) return { verdict: 'escaped', cell, row };
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The text fields of a create action that could hold what a person typed. */
|
|
59
|
+
function textFields(action) {
|
|
60
|
+
return (action.fields || []).filter((f) => typeof f.sample === 'string' && !f.kinds.includes('enum') && !NOT_TEXT.test(f.name)).map((f) => f.name);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Exports tried with a marked value. { ran, why, tried: [...], findings, left }.
|
|
65
|
+
* `options`: origin, env, say, fetch, map, packageDir.
|
|
66
|
+
*/
|
|
67
|
+
async function run(root, options) {
|
|
68
|
+
const api = require('./kryptheon-api.js');
|
|
69
|
+
const authz = require('./kryptheon-authz.js');
|
|
70
|
+
const opts = options || {};
|
|
71
|
+
const plan = api.planOf(root, opts);
|
|
72
|
+
if (!plan.ran) return { ran: false, why: plan.why };
|
|
73
|
+
const exports = (plan.map.routes || []).filter((r) => r.method === 'GET' && !r.unmounted && r.path && !/[:{]/.test(r.path) && EXPORT_PATH.test(r.path)).slice(0, MAX_ROUTES);
|
|
74
|
+
if (!exports.length) return { ran: false, why: 'the map found no export route (a GET ending in .csv, or under /export or /download)' };
|
|
75
|
+
let origin;
|
|
76
|
+
try {
|
|
77
|
+
origin = authz.assertLocalTarget(opts.origin);
|
|
78
|
+
} catch (err) {
|
|
79
|
+
return { ran: false, why: 'the app must be on this computer (localhost or 127.0.0.1): ' + (opts.origin || 'no address was given') };
|
|
80
|
+
}
|
|
81
|
+
const j = plan.journey;
|
|
82
|
+
if (!j.signIn) return { ran: false, why: j.signInWhy };
|
|
83
|
+
const creates = j.actions.filter((a) => a.method === 'POST' && !a.params.length && textFields(a).length);
|
|
84
|
+
if (!creates.length) return { ran: false, why: 'no route that creates something takes a text field to put a marked value in' };
|
|
85
|
+
const out = { ran: true, tried: [], findings: [], left: [] };
|
|
86
|
+
// The account that may export: the first one the export answers with a file.
|
|
87
|
+
let session = null;
|
|
88
|
+
const ctx = authz.makeContext({ baseUrl: origin, allowOrigins: [origin], fetch: opts.fetch, passwords: Object.fromEntries(j.accounts.usable.map((a) => [a.email, a.password])), maxRequests: 120 });
|
|
89
|
+
for (const a of j.accounts.usable) {
|
|
90
|
+
const s = authz.makeSession(ctx, 'account', a.email, a.password);
|
|
91
|
+
const fields = { [j.signIn.emailField]: a.email, [j.signIn.passwordField]: a.password };
|
|
92
|
+
const r = authz.replyOf(await s.send(j.signIn.method, j.signIn.path, j.signIn.encoding === 'form' ? { form: fields } : { json: fields }));
|
|
93
|
+
if (r.kind === 'refused' || r.kind === 'server-error' || r.kind === 'no-answer') continue;
|
|
94
|
+
const probe = await s.send('GET', exports[0].path, {});
|
|
95
|
+
if (probe.status === 200 && typeof probe.text === 'string') { session = s; break; }
|
|
96
|
+
}
|
|
97
|
+
if (!session) return { ran: false, why: 'no account with a password in .env could download ' + exports[0].path };
|
|
98
|
+
|
|
99
|
+
for (const exp of exports) {
|
|
100
|
+
const name = 'GET ' + exp.path;
|
|
101
|
+
const t = { what: name, from: exp.file + ':' + exp.line, verdict: 'not seen', field: null, through: null };
|
|
102
|
+
out.tried.push(t);
|
|
103
|
+
for (const a of creates) {
|
|
104
|
+
const fieldsHere = textFields(a);
|
|
105
|
+
const marks = {};
|
|
106
|
+
const body = Object.assign({}, a.fullData);
|
|
107
|
+
for (const f of fieldsHere) {
|
|
108
|
+
marks[f] = '=KX' + crypto.randomBytes(3).toString('hex').toUpperCase();
|
|
109
|
+
body[f] = marks[f];
|
|
110
|
+
}
|
|
111
|
+
let res = await session.send('POST', a.template, a.encoding === 'form' ? { form: body } : { json: body });
|
|
112
|
+
let reply = authz.replyOf(res);
|
|
113
|
+
// the app may refuse a value that starts with "=" in one field only: one field at a time, then
|
|
114
|
+
if (reply.kind !== 'accepted' && reply.kind !== 'redirect') {
|
|
115
|
+
for (const f of fieldsHere) {
|
|
116
|
+
const one = Object.assign({}, a.fullData, { [f]: marks[f] });
|
|
117
|
+
res = await session.send('POST', a.template, a.encoding === 'form' ? { form: one } : { json: one });
|
|
118
|
+
reply = authz.replyOf(res);
|
|
119
|
+
if (reply.kind === 'accepted' || reply.kind === 'redirect') {
|
|
120
|
+
for (const g of fieldsHere) if (g !== f) delete marks[g];
|
|
121
|
+
break;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (reply.kind !== 'accepted' && reply.kind !== 'redirect') continue;
|
|
126
|
+
out.left.push(a.method + ' ' + a.template + ' with ' + Object.keys(marks).join(', ') + ' starting with "=" - made to look inside ' + exp.path);
|
|
127
|
+
const after = await session.send('GET', exp.path, {});
|
|
128
|
+
const rows = after.status === 200 ? cellsOf(after.text || '') : [];
|
|
129
|
+
for (const f of Object.keys(marks)) {
|
|
130
|
+
const v = cellVerdict(rows, marks[f]);
|
|
131
|
+
if (!v) continue;
|
|
132
|
+
t.field = f;
|
|
133
|
+
t.through = a.method + ' ' + a.template;
|
|
134
|
+
t.verdict = v.verdict;
|
|
135
|
+
if (v.verdict === 'raw') {
|
|
136
|
+
const finding = {
|
|
137
|
+
kind: 'csv-formula', where: name, field: f, from: t.from, status: 'confirmed', severity: 'MEDIUM',
|
|
138
|
+
headline: name + ' writes ' + f + ' as it was typed: a value starting with "=" comes out as a formula when the file is opened in Excel or Google Sheets.',
|
|
139
|
+
proof: ['As ' + session.email + ', made a record through ' + t.through + ' with ' + f + ' = ' + marks[f] + '.', 'Downloaded ' + exp.path + ': the cell reads ' + marks[f] + ', with nothing in front of the "=".'],
|
|
140
|
+
};
|
|
141
|
+
finding.fixPrompt = ['Kryptheon put a value starting with "=" into my app and downloaded its export:', '', finding.headline, '', 'Where: ' + finding.from, '',
|
|
142
|
+
'First check this is real: open the export in a spreadsheet. If it is, in the code that writes the CSV, put a single quote in front of every cell that starts with = + - @ or a tab, and quote every cell. Do it for every column, not only ' + f + '. Change nothing else.', '', 'Afterwards I will run: npx kryptheon api'].join(String.fromCharCode(10));
|
|
143
|
+
out.findings.push(finding);
|
|
144
|
+
}
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
if (t.verdict !== 'not seen') break;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
module.exports = { run, cellsOf, cellVerdict, textFields, EXPORT_PATH };
|
package/kryptheon-map.js
CHANGED
|
@@ -60,6 +60,11 @@ const OTHER_FRAMEWORKS = /^(fastify|koa|@koa\/router|koa-router|hono|@hono\/hono
|
|
|
60
60
|
// Where the signed-in person lives on a request, in the apps this was built on.
|
|
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
|
+
// A cookie or header that says who is calling: a session token (sid, token) or, worse, the user id itself.
|
|
64
|
+
const COOKIE_IDENTITY = /^(uid|user|userId|user_id|userid|id|sid|session|sessionId|session_id|token|auth|jwt|access_token|accessToken|connect\.sid)$/i;
|
|
65
|
+
const HEADER_IDENTITY = /^x-(user|uid|user-id|userid|account|account-id|member|member-id|actor|actor-id)$/i;
|
|
66
|
+
// Of those, the ones that hold the bare id - nothing a server signed, so anyone can write another person's.
|
|
67
|
+
const BARE_ID = /^(uid|user|userId|user_id|userid|id)$/i;
|
|
63
68
|
const ROLE_SEGS = /^(role|roles|isAdmin|is_admin|isOwner|is_owner|admin|permissions|perms|scopes|scope|capabilities|access|accessLevel|access_level|level)$/;
|
|
64
69
|
const SIGNATURE_CALLS = /^(createHmac|timingSafeEqual|validateWebhookSignature|constructEvent|constructEventAsync|verifyWebhook|verifySignature|validateSignature|verify)$/;
|
|
65
70
|
const SIGNATURE_NAMES = /sign|hmac|webhook|valid/i;
|
|
@@ -780,11 +785,16 @@ function readGuardFn(ctx, ref, opts = {}) {
|
|
|
780
785
|
const chain = memberChain(n);
|
|
781
786
|
if (!chain) return false;
|
|
782
787
|
if (reqName && chain[0] === reqName && chain.length > 1 && IDENTITY_SEGS.test(chain[1])) return true;
|
|
788
|
+
// req.cookies.uid / req.signedCookies.sid: who is calling, as the browser sent it
|
|
789
|
+
if (reqName && chain[0] === reqName && /^(cookies|signedCookies)$/.test(chain[1] || '') && chain[2] && COOKIE_IDENTITY.test(chain[2])) return true;
|
|
783
790
|
if (chain[0] === 'res' && chain[1] === 'locals' && chain[2] && IDENTITY_SEGS.test(chain[2])) return true;
|
|
784
791
|
if (identityLocals.has(chain[0])) return true;
|
|
785
792
|
return false;
|
|
786
793
|
};
|
|
787
794
|
const isIdentityNode = (n) => {
|
|
795
|
+
// req.headers['x-user-id'] / req.get('x-user-id'): who is calling, as a header says
|
|
796
|
+
const h = headerName(n);
|
|
797
|
+
if (h && HEADER_IDENTITY.test(h)) return true;
|
|
788
798
|
if (n.type === 'MemberExpression' || n.type === 'OptionalMemberExpression') return identityChain(n);
|
|
789
799
|
if (n.type === 'Identifier') return identityLocals.has(n.name);
|
|
790
800
|
if (n.type === 'CallExpression' || n.type === 'OptionalCallExpression') {
|
|
@@ -1139,6 +1149,25 @@ function readGuardFn(ctx, ref, opts = {}) {
|
|
|
1139
1149
|
for (const m of g.methods) out.methods.add(m);
|
|
1140
1150
|
}
|
|
1141
1151
|
}
|
|
1152
|
+
// who is calling, taken from a cookie or header that holds the bare user id: the caller can write anyone's
|
|
1153
|
+
if (out.auth && !opts.asHelper && reqName) {
|
|
1154
|
+
let bare = null;
|
|
1155
|
+
fn.traverse({
|
|
1156
|
+
enter(q) {
|
|
1157
|
+
if (bare) return;
|
|
1158
|
+
const n = q.node;
|
|
1159
|
+
const h = headerName(n);
|
|
1160
|
+
if (h && HEADER_IDENTITY.test(h)) bare = { kind: 'header', name: h.toLowerCase(), node: n };
|
|
1161
|
+
const c = (n.type === 'MemberExpression' || n.type === 'OptionalMemberExpression') && memberChain(n);
|
|
1162
|
+
if (c && c[0] === reqName && c[1] === 'cookies' && c[2] && BARE_ID.test(c[2])) bare = { kind: 'cookie', name: c[2], node: n };
|
|
1163
|
+
},
|
|
1164
|
+
});
|
|
1165
|
+
if (bare) {
|
|
1166
|
+
const line = bare.node.loc.start.line;
|
|
1167
|
+
out.identityFromRequest = { file: mod.rel, line, code: snippet(mod, line), kind: bare.kind, name: bare.name,
|
|
1168
|
+
how: bare.kind === 'cookie' ? 'takes who is calling from the cookie "' + bare.name + '", which holds the user id itself and is not signed' : 'takes who is calling from the request header "' + bare.name + '", which anyone can send' };
|
|
1169
|
+
}
|
|
1170
|
+
}
|
|
1142
1171
|
// a role check implies a signed-in one: nobody signed in has no role to pass
|
|
1143
1172
|
if (out.role && !out.auth) out.auth = Object.assign({}, out.role, { how: 'turns away anyone without an allowed role, which nobody signed out has' });
|
|
1144
1173
|
if (out.apiKey && !out.auth) out.auth = Object.assign({}, out.apiKey, { how: 'turns away a request without a valid API key', kind: 'api-key' });
|
|
@@ -1241,6 +1270,8 @@ function judge(route, elements) {
|
|
|
1241
1270
|
const out = { auth: verdict('auth'), role: verdict('role'), signature: verdict('signature') };
|
|
1242
1271
|
const authPartial = elements.find((e) => e.guards && e.guards.authPartial);
|
|
1243
1272
|
if (authPartial && out.auth.status === STATUS.NOT) out.auth = { status: STATUS.UNKNOWN, why: [authPartial.text + ': ' + authPartial.guards.authPartial.how + ' (' + authPartial.guards.authPartial.file + ':' + authPartial.guards.authPartial.line + ')'] };
|
|
1273
|
+
const fromRequest = elements.find((e) => e.guards && e.guards.identityFromRequest);
|
|
1274
|
+
if (fromRequest && out.auth.status === STATUS.DETECTED) out.auth.fromRequest = fromRequest.guards.identityFromRequest;
|
|
1244
1275
|
const skippable = elements.find((e) => e.guards && e.guards.signatureSkippable);
|
|
1245
1276
|
if (skippable && out.signature.status === STATUS.DETECTED) out.signature.skippable = true;
|
|
1246
1277
|
const presence = elements.find((e) => e.guards && e.guards.sigPresenceOnly);
|
|
@@ -2744,6 +2775,7 @@ const ADVICE = {
|
|
|
2744
2775
|
'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.',
|
|
2745
2776
|
'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.',
|
|
2746
2777
|
'no-role': 'allow only the roles that should be able to do this, and answer 403 for the others.',
|
|
2778
|
+
'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.',
|
|
2747
2779
|
};
|
|
2748
2780
|
|
|
2749
2781
|
/**
|
|
@@ -2806,6 +2838,24 @@ function toCheck(map) {
|
|
|
2806
2838
|
}
|
|
2807
2839
|
}
|
|
2808
2840
|
}
|
|
2841
|
+
// who is calling, written by the caller: said once for the guard, with how many routes stand behind it
|
|
2842
|
+
const byGuard = new Map();
|
|
2843
|
+
for (const r of routes) {
|
|
2844
|
+
const f = r.auth && r.auth.fromRequest;
|
|
2845
|
+
if (!f) continue;
|
|
2846
|
+
const k = f.file + ':' + f.line;
|
|
2847
|
+
if (!byGuard.has(k)) byGuard.set(k, { f, routes: [] });
|
|
2848
|
+
byGuard.get(k).routes.push(r);
|
|
2849
|
+
}
|
|
2850
|
+
for (const { f, routes: behind } of byGuard.values()) {
|
|
2851
|
+
const first = behind[0];
|
|
2852
|
+
items.push({
|
|
2853
|
+
kind: 'identity-from-request', severity: 'HIGH', route: first.method + ' ' + (first.path || '(path not read)'), where: f.file + ':' + f.line,
|
|
2854
|
+
headline: 'The sign-in check ' + f.how + ': anyone can send another person\'s id and be them, on the ' + behind.length + ' route' + (behind.length === 1 ? '' : 's') + ' behind it',
|
|
2855
|
+
evidence: [f.file + ':' + f.line + ' ' + (f.code || '')],
|
|
2856
|
+
identity: { kind: f.kind, name: f.name },
|
|
2857
|
+
});
|
|
2858
|
+
}
|
|
2809
2859
|
const rank = { HIGH: 0, MEDIUM: 1 };
|
|
2810
2860
|
items.sort((a, b) => rank[a.severity] - rank[b.severity] || a.where.localeCompare(b.where, undefined, { numeric: true }));
|
|
2811
2861
|
for (const i of items) i.fixPrompt = fixPromptFor(i);
|
|
@@ -2907,4 +2957,4 @@ function reportLines(map, opts = {}) {
|
|
|
2907
2957
|
return out;
|
|
2908
2958
|
}
|
|
2909
2959
|
|
|
2910
|
-
module.exports = { mapProject, listFiles, joinPath, covers, STATUS, snippet, toCheck, summary, reportLines };
|
|
2960
|
+
module.exports = { mapProject, listFiles, joinPath, covers, STATUS, snippet, toCheck, summary, reportLines, ADVICE };
|
package/kryptheon-roles.js
CHANGED
|
@@ -911,6 +911,14 @@ async function tryOnce(x) {
|
|
|
911
911
|
// what the app holds now
|
|
912
912
|
const reader = targetOrg !== null || p.kind === 'signin' || x.orgs.size === 0;
|
|
913
913
|
const before = reader ? await x.snapshot(targetOrg) : {};
|
|
914
|
+
// a write to an address that is also read (POST /returns/5/notes, GET /returns/5/notes) shows there
|
|
915
|
+
const sameGet = reader && !isGet && a.params.length && x.getTemplates.has(a.template) ? pathNow : null;
|
|
916
|
+
const readSame = async () => {
|
|
917
|
+
const f = sameGet ? await x.readerFor(targetOrg, sameGet, null, false) : null;
|
|
918
|
+
return f ? stable(f.res.json) : undefined;
|
|
919
|
+
};
|
|
920
|
+
const sameBefore = await readSame();
|
|
921
|
+
if (sameBefore !== undefined) before[sameGet] = sameBefore;
|
|
914
922
|
const known = await x.knownTo(actor);
|
|
915
923
|
|
|
916
924
|
// truth: the records a read would disclose
|
|
@@ -935,6 +943,10 @@ async function tryOnce(x) {
|
|
|
935
943
|
const ownMarked = actor.org && isGet ? ownRecords(res.json, actor.org.key) : 0;
|
|
936
944
|
const found = markers.length ? authz.foundIn(res, markers).length : 0;
|
|
937
945
|
const after = reader ? await x.snapshot(targetOrg) : {};
|
|
946
|
+
if (sameBefore !== undefined) {
|
|
947
|
+
const sameAfter = await readSame();
|
|
948
|
+
if (sameAfter !== undefined) after[sameGet] = sameAfter;
|
|
949
|
+
}
|
|
938
950
|
const changes = x.compare(before, after);
|
|
939
951
|
const changed = Object.keys(before).length ? changes.length > 0 : null;
|
|
940
952
|
|
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
// The webhook check for an app that signs its own events: no real payment needed.
|
|
2
|
+
//
|
|
3
|
+
// kryptheon-payments.js needs one real test-mode payment so a provider's own
|
|
4
|
+
// signed webhook can be sent again. Many apps - and every app a person builds
|
|
5
|
+
// to try a provider - also take events they sign themselves, with a secret in
|
|
6
|
+
// their .env. For those the event can be made here:
|
|
7
|
+
//
|
|
8
|
+
// 1. the app's webhook handler is read: which header holds the signature,
|
|
9
|
+
// how it is computed (createHmac, the algorithm, hex or base64, over the
|
|
10
|
+
// body), where the secret comes from (process.env.NAME) and which fields
|
|
11
|
+
// and event types the handler looks at. Anything it signs in a way this
|
|
12
|
+
// file does not know (a timestamp in front, a prefix) is said as not
|
|
13
|
+
// tried, never guessed;
|
|
14
|
+
// 2. a correctly signed event is sent first. If the app refuses even that,
|
|
15
|
+
// nothing else means anything and the check stops, saying so;
|
|
16
|
+
// 3. then, each on a record of its own, and judged from the app's own list
|
|
17
|
+
// of those records before and after (never from a status code alone):
|
|
18
|
+
// - the same event with no signature at all,
|
|
19
|
+
// - with a wrong signature,
|
|
20
|
+
// - correctly signed but for an amount that is not the record's,
|
|
21
|
+
// - a refund event for a record nobody had paid or approved.
|
|
22
|
+
//
|
|
23
|
+
// Promises: only an app on this computer; the secret is read from the app's
|
|
24
|
+
// .env, used to sign, and never printed or saved; nothing is ever deleted;
|
|
25
|
+
// every record an event changed is listed, since a webhook cannot be undone.
|
|
26
|
+
|
|
27
|
+
const fs = require('fs');
|
|
28
|
+
const path = require('path');
|
|
29
|
+
const crypto = require('crypto');
|
|
30
|
+
const secrets = require('./kryptheon-secrets.js');
|
|
31
|
+
|
|
32
|
+
const VOLATILE_KEY = /^(updated_?at|modified_?at|last_?seen|now|server_?time|timestamp|request_?id|etag|generated_?at|processed_?at)$/i;
|
|
33
|
+
const ALGORITHMS = /^(sha1|sha224|sha256|sha384|sha512)$/i;
|
|
34
|
+
const SIG_HEADER = /sig|hmac|token|secret|signature/i;
|
|
35
|
+
const TYPE_NAME = /^(event_?type|type|event|kind|action|topic|eventType)$/i;
|
|
36
|
+
const ID_NAME = /^(event_?id|eventId|id|uuid)$/i;
|
|
37
|
+
const AMOUNT_NAME = /amount|cents|paise|total|price/i;
|
|
38
|
+
const CURRENCY_NAME = /^currency$/i;
|
|
39
|
+
const MAX_TYPES = 3;
|
|
40
|
+
const MAX_TRIES = 12;
|
|
41
|
+
|
|
42
|
+
const wordsOf = (name) => String(name).replace(/([a-z0-9])([A-Z])/g, '$1 $2').toLowerCase().split(/[^a-z0-9]+/).filter(Boolean);
|
|
43
|
+
|
|
44
|
+
/** a.b.c / a['b'].c as ['a','b','c'], or null */
|
|
45
|
+
function chainOf(n) {
|
|
46
|
+
const out = [];
|
|
47
|
+
let c = n;
|
|
48
|
+
while (c && (c.type === 'MemberExpression' || c.type === 'OptionalMemberExpression')) {
|
|
49
|
+
if (!c.computed && c.property.type === 'Identifier') out.unshift(c.property.name);
|
|
50
|
+
else if (c.computed && c.property.type === 'StringLiteral') out.unshift(c.property.value);
|
|
51
|
+
else return null;
|
|
52
|
+
c = c.object;
|
|
53
|
+
}
|
|
54
|
+
if (c && c.type === 'Identifier') {
|
|
55
|
+
out.unshift(c.name);
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** The handler function of the route written at file:line, as { path, reqName } or null. */
|
|
62
|
+
function handlerAt(parser, ast, line) {
|
|
63
|
+
let found = null;
|
|
64
|
+
parser.traverse(ast, {
|
|
65
|
+
CallExpression(p) {
|
|
66
|
+
if (found) return;
|
|
67
|
+
const n = p.node;
|
|
68
|
+
if (!n.loc || n.loc.start.line !== line) return;
|
|
69
|
+
if (!n.callee || n.callee.type !== 'MemberExpression') return;
|
|
70
|
+
const verb = n.callee.property && n.callee.property.name;
|
|
71
|
+
if (!/^(post|put|patch|all)$/.test(verb || '')) return;
|
|
72
|
+
const argIndex = n.arguments.map((a) => a.type).lastIndexOf('ArrowFunctionExpression');
|
|
73
|
+
const fnIndex = argIndex >= 0 ? argIndex : n.arguments.map((a) => a.type).lastIndexOf('FunctionExpression');
|
|
74
|
+
if (fnIndex < 0) return;
|
|
75
|
+
found = { path: p.get('arguments.' + fnIndex), node: n.arguments[fnIndex] };
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
if (!found) return null;
|
|
79
|
+
const first = found.node.params[0];
|
|
80
|
+
return { path: found.path, reqName: first && first.type === 'Identifier' ? first.name : null };
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* How the handler signs: { ok, header, algorithm, encoding, secret: { env, fallback }, fields, types, why }.
|
|
85
|
+
* Reading code only. `fields` are the body fields the map saw the route read.
|
|
86
|
+
*/
|
|
87
|
+
function readSigning(parser, root, route, fields) {
|
|
88
|
+
let source;
|
|
89
|
+
const abs = path.join(root, route.file);
|
|
90
|
+
try {
|
|
91
|
+
source = fs.readFileSync(abs, 'utf8');
|
|
92
|
+
} catch (err) {
|
|
93
|
+
return { ok: false, why: 'the file ' + route.file + ' could not be read' };
|
|
94
|
+
}
|
|
95
|
+
let ast;
|
|
96
|
+
try {
|
|
97
|
+
ast = parser.babelParse(source, abs, true);
|
|
98
|
+
} catch (err) {
|
|
99
|
+
try {
|
|
100
|
+
ast = parser.babelParse(source, abs, false);
|
|
101
|
+
} catch (err2) {
|
|
102
|
+
return { ok: false, why: route.file + ' could not be parsed' };
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const h = handlerAt(parser, ast, route.line);
|
|
106
|
+
if (!h || !h.reqName) return { ok: false, why: 'the handler at ' + route.file + ':' + route.line + ' is not a function written in the route itself' };
|
|
107
|
+
const req = h.reqName;
|
|
108
|
+
const resolve = (node, depth) => {
|
|
109
|
+
let n = node;
|
|
110
|
+
for (let i = 0; i < (depth || 3); i++) {
|
|
111
|
+
if (n && n.type === 'Identifier') {
|
|
112
|
+
const b = h.path.scope.getBinding(n.name);
|
|
113
|
+
const init = b && b.path && b.path.node && b.path.node.type === 'VariableDeclarator' ? b.path.node.init : null;
|
|
114
|
+
if (!init) return n;
|
|
115
|
+
n = init;
|
|
116
|
+
} else if (n && (n.type === 'AwaitExpression' || n.type === 'TSAsExpression' || n.type === 'ParenthesizedExpression')) n = n.argument || n.expression;
|
|
117
|
+
else break;
|
|
118
|
+
}
|
|
119
|
+
return n;
|
|
120
|
+
};
|
|
121
|
+
let header = null;
|
|
122
|
+
let hmac = null;
|
|
123
|
+
const literals = new Set();
|
|
124
|
+
h.path.traverse({
|
|
125
|
+
CallExpression(p) {
|
|
126
|
+
const n = p.node;
|
|
127
|
+
const chain = chainOf(n.callee);
|
|
128
|
+
// req.get('x-sig') / req.header('x-sig')
|
|
129
|
+
if (chain && chain[0] === req && /^(get|header)$/.test(chain[chain.length - 1]) && n.arguments[0] && n.arguments[0].type === 'StringLiteral' && SIG_HEADER.test(n.arguments[0].value) && !header) header = n.arguments[0].value.toLowerCase();
|
|
130
|
+
// .digest('hex') of .update(x) of createHmac(alg, secret)
|
|
131
|
+
if (n.callee && n.callee.type === 'MemberExpression' && n.callee.property.name === 'digest' && n.callee.object && n.callee.object.type === 'CallExpression') {
|
|
132
|
+
const upd = n.callee.object;
|
|
133
|
+
const mk = upd.callee && upd.callee.type === 'MemberExpression' && upd.callee.property.name === 'update' ? upd.callee.object : null;
|
|
134
|
+
const mkName = mk && mk.type === 'CallExpression' ? (mk.callee.type === 'MemberExpression' ? mk.callee.property.name : mk.callee.name) : null;
|
|
135
|
+
if (mkName === 'createHmac' && !hmac) hmac = { alg: mk.arguments[0], key: mk.arguments[1], payload: upd.arguments[0], enc: n.arguments[0] };
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
MemberExpression(p) {
|
|
139
|
+
const chain = chainOf(p.node);
|
|
140
|
+
if (chain && chain[0] === req && chain[1] === 'headers' && chain[2] && SIG_HEADER.test(chain[2]) && !header) header = chain[2].toLowerCase();
|
|
141
|
+
},
|
|
142
|
+
BinaryExpression(p) {
|
|
143
|
+
const n = p.node;
|
|
144
|
+
if (!/^[!=]==?$/.test(n.operator)) return;
|
|
145
|
+
const [a, b] = [n.left, n.right];
|
|
146
|
+
const name = (x) => (x.type === 'Identifier' ? x.name : (chainOf(x) || []).slice(-1)[0] || '');
|
|
147
|
+
if (b.type === 'StringLiteral' && TYPE_NAME.test(name(a))) literals.add(b.value);
|
|
148
|
+
if (a.type === 'StringLiteral' && TYPE_NAME.test(name(b))) literals.add(a.value);
|
|
149
|
+
},
|
|
150
|
+
SwitchStatement(p) {
|
|
151
|
+
const d = p.node.discriminant;
|
|
152
|
+
const nm = d.type === 'Identifier' ? d.name : (chainOf(d) || []).slice(-1)[0] || '';
|
|
153
|
+
if (!TYPE_NAME.test(nm)) return;
|
|
154
|
+
for (const c of p.node.cases) if (c.test && c.test.type === 'StringLiteral') literals.add(c.test.value);
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
if (!header) return { ok: false, why: 'no signature header is read in the handler (looked for a header with sig, hmac or token in its name)' };
|
|
158
|
+
if (!hmac) return { ok: false, why: 'the handler reads ' + header + ' but does not compute an HMAC the way this check knows (createHmac(alg, secret).update(body).digest(encoding))' };
|
|
159
|
+
const alg = hmac.alg && hmac.alg.type === 'StringLiteral' ? hmac.alg.value.toLowerCase() : null;
|
|
160
|
+
const enc = hmac.enc && hmac.enc.type === 'StringLiteral' ? hmac.enc.value.toLowerCase() : null;
|
|
161
|
+
if (!alg || !ALGORITHMS.test(alg)) return { ok: false, why: 'the HMAC algorithm is not a plain name written in the code' };
|
|
162
|
+
if (enc !== 'hex' && enc !== 'base64') return { ok: false, why: 'the signature is not read out as hex or base64' };
|
|
163
|
+
// what is signed: JSON.stringify(req.body), or the raw body
|
|
164
|
+
const pay = resolve(hmac.payload);
|
|
165
|
+
const payChain = pay && chainOf(pay);
|
|
166
|
+
const stringifies = pay && pay.type === 'CallExpression' && (chainOf(pay.callee) || []).join('.') === 'JSON.stringify' && (chainOf(pay.arguments[0]) || []).join('.') === req + '.body';
|
|
167
|
+
const rawBody = payChain && payChain[0] === req && /^(rawBody|body)$/.test(payChain[1] || '') && payChain.length === 2;
|
|
168
|
+
if (!stringifies && !rawBody) return { ok: false, why: 'what is signed is more than the body (a timestamp or a prefix in front, say), which this check does not make' };
|
|
169
|
+
// the secret
|
|
170
|
+
const key = resolve(hmac.key);
|
|
171
|
+
let secret = null;
|
|
172
|
+
const envName = (n) => { const c = n && chainOf(n); return c && c[0] === 'process' && c[1] === 'env' && c[2] ? c[2] : null; };
|
|
173
|
+
if (key && key.type === 'LogicalExpression' && /^(\|\||\?\?)$/.test(key.operator)) {
|
|
174
|
+
const e = envName(key.left);
|
|
175
|
+
if (e) secret = { env: e, fallback: key.right.type === 'StringLiteral' ? key.right.value : null };
|
|
176
|
+
} else if (envName(key)) secret = { env: envName(key), fallback: null };
|
|
177
|
+
else if (key && key.type === 'StringLiteral') secret = { env: null, fallback: key.value };
|
|
178
|
+
if (!secret) return { ok: false, why: 'the secret is not process.env.NAME or a plain string in the code' };
|
|
179
|
+
return { ok: true, header, algorithm: alg, encoding: enc, secret, fields: (fields || []).slice(), types: Array.from(literals), signs: stringifies ? 'JSON.stringify(req.body)' : 'the raw body' };
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/** Which body field is which, from names. { id, type, record, amount, currency, others } or why not. */
|
|
183
|
+
function shapeOf(fields) {
|
|
184
|
+
const names = fields.map((f) => f.name);
|
|
185
|
+
const type = names.find((n) => TYPE_NAME.test(n));
|
|
186
|
+
const id = names.find((n) => ID_NAME.test(n) && n !== type);
|
|
187
|
+
const amount = names.find((n) => AMOUNT_NAME.test(n));
|
|
188
|
+
const currency = names.find((n) => CURRENCY_NAME.test(n));
|
|
189
|
+
const record = names.find((n) => n !== id && n !== type && n !== amount && (/_?id$/i.test(n) || /ref$/i.test(n) || /Id$/.test(n)));
|
|
190
|
+
if (!type) return { ok: false, why: 'no field of the body names the kind of event (event_type, type, event ...)' };
|
|
191
|
+
if (!record) return { ok: false, why: 'no field of the body names the record the event is about (return_id, order_id ...)' };
|
|
192
|
+
return { ok: true, id, type, record, amount, currency };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/** The signature the app would accept for these exact bytes. Never printed. */
|
|
196
|
+
function sign(signing, secret, body) {
|
|
197
|
+
const mac = crypto.createHmac(signing.algorithm, secret).update(body).digest(signing.encoding);
|
|
198
|
+
return mac;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** A signature of the right shape that is not right. */
|
|
202
|
+
function wrongSignature(signing, secret, body) {
|
|
203
|
+
const good = sign(signing, secret, body);
|
|
204
|
+
// flip the first character, staying inside the alphabet it is written in
|
|
205
|
+
const first = good[0];
|
|
206
|
+
const swap = signing.encoding === 'hex' ? (first === '0' ? '1' : '0') : (first === 'A' ? 'B' : 'A');
|
|
207
|
+
return swap + good.slice(1);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const stableItem = (item) => {
|
|
211
|
+
if (!item || typeof item !== 'object') return item;
|
|
212
|
+
const out = {};
|
|
213
|
+
for (const k of Object.keys(item).sort()) if (!VOLATILE_KEY.test(k)) out[k] = item[k];
|
|
214
|
+
return out;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const listOf = (json) => {
|
|
218
|
+
if (Array.isArray(json)) return json;
|
|
219
|
+
if (json && typeof json === 'object') for (const k of Object.keys(json)) if (Array.isArray(json[k])) return json[k];
|
|
220
|
+
return null;
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
/** The words of the order a status runs in: what has been paid or approved before a refund. */
|
|
224
|
+
const PAID = /approv|paid|captur|complet|process|settl|success|confirm/i;
|
|
225
|
+
const REFUNDED = /refund/i;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Tries each signed-event case on the running app. { ran, why, hooks: [...], findings, left }.
|
|
229
|
+
* `options`: origin, env, say, stopped, fetch, map (a map already read), packageDir.
|
|
230
|
+
*/
|
|
231
|
+
async function run(root, options) {
|
|
232
|
+
const api = require('./kryptheon-api.js');
|
|
233
|
+
const authz = require('./kryptheon-authz.js');
|
|
234
|
+
const code = require('./kryptheon-code.js');
|
|
235
|
+
const mapper = require('./kryptheon-map.js');
|
|
236
|
+
const opts = options || {};
|
|
237
|
+
const say = typeof opts.say === 'function' ? opts.say : () => {};
|
|
238
|
+
const plan = api.planOf(root, opts);
|
|
239
|
+
if (!plan.ran) return { ran: false, why: plan.why };
|
|
240
|
+
const hooks = (plan.map.routes || []).filter((r) => r.kind === 'webhook' && !r.unmounted && r.method === 'POST' && r.path);
|
|
241
|
+
if (!hooks.length) return { ran: false, why: 'the map found no webhook route' };
|
|
242
|
+
let origin;
|
|
243
|
+
try {
|
|
244
|
+
origin = authz.assertLocalTarget(opts.origin);
|
|
245
|
+
} catch (err) {
|
|
246
|
+
return { ran: false, why: 'the app must be on this computer (localhost or 127.0.0.1): ' + (opts.origin || 'no address was given') };
|
|
247
|
+
}
|
|
248
|
+
const j = plan.journey;
|
|
249
|
+
if (!j.signIn) return { ran: false, why: j.signInWhy };
|
|
250
|
+
if (!j.accounts.usable.length) return { ran: false, why: 'no account has a password in .env, so the records an event is about cannot be read' };
|
|
251
|
+
const parser = code.loadParser(opts.packageDir || __dirname);
|
|
252
|
+
if (!parser) return { ran: false, why: 'the JavaScript parser this check uses was not found' };
|
|
253
|
+
const who = j.accounts.usable[0];
|
|
254
|
+
const appEnv = Object.assign({}, secrets.readEnvFile(secrets.envFileFor(root)), opts.env || {});
|
|
255
|
+
const ctx = authz.makeContext({ baseUrl: origin, allowOrigins: [origin], fetch: opts.fetch, passwords: { [who.email]: who.password }, maxRequests: 200 });
|
|
256
|
+
const reader = authz.makeSession(ctx, 'account', who.email, who.password);
|
|
257
|
+
const fields = { [j.signIn.emailField]: who.email, [j.signIn.passwordField]: who.password };
|
|
258
|
+
const signed = authz.replyOf(await reader.send(j.signIn.method, j.signIn.path, j.signIn.encoding === 'form' ? { form: fields } : { json: fields }));
|
|
259
|
+
if (signed.kind === 'refused' || signed.kind === 'server-error' || signed.kind === 'no-answer') return { ran: false, why: 'could not sign in as ' + who.email + ' (' + signed.note + ')' };
|
|
260
|
+
const out = { ran: true, hooks: [], findings: [], left: [] };
|
|
261
|
+
|
|
262
|
+
for (const route of hooks) {
|
|
263
|
+
const name = route.method + ' ' + route.path;
|
|
264
|
+
const hook = { route: name, from: route.file + ':' + route.line, tried: [], findings: [], notTried: null, control: null };
|
|
265
|
+
out.hooks.push(hook);
|
|
266
|
+
const bodyFields = ((route.validation && route.validation.fields) || []).filter((f) => f.from === 'body');
|
|
267
|
+
const signing = readSigning(parser, root, route, bodyFields);
|
|
268
|
+
if (!signing.ok) { hook.notTried = signing.why; continue; }
|
|
269
|
+
hook.signing = { header: signing.header, algorithm: signing.algorithm, encoding: signing.encoding, secretFrom: signing.secret.env ? signing.secret.env + ' in .env' : 'a string in the code', signs: signing.signs };
|
|
270
|
+
const secret = (signing.secret.env && appEnv[signing.secret.env]) || signing.secret.fallback;
|
|
271
|
+
if (!secret) { hook.notTried = 'the secret ' + signing.secret.env + ' is not in the app\'s .env, and the code has no fallback'; continue; }
|
|
272
|
+
// whatever the app answers is cleaned of it before anything is said
|
|
273
|
+
if (!ctx.secrets.includes(secret)) ctx.secrets.push(secret);
|
|
274
|
+
const shape = shapeOf(bodyFields);
|
|
275
|
+
if (!shape.ok) { hook.notTried = shape.why; continue; }
|
|
276
|
+
const types = signing.types.slice(0, MAX_TYPES);
|
|
277
|
+
if (!types.length) { hook.notTried = 'no event type is written in the handler (an if on ' + shape.type + ' or a switch), so there is nothing to send'; continue; }
|
|
278
|
+
// the records an event is about: the app's own list of them, as the signed-in account sees it
|
|
279
|
+
const resource = wordsOf(shape.record)[0];
|
|
280
|
+
const listRoute = (plan.map.routes || []).find((r) => r.method === 'GET' && !r.unmounted && r.path && !/[:{]/.test(r.path) && new RegExp('(^|/)' + resource + '(s|es)?$', 'i').test(r.path));
|
|
281
|
+
if (!listRoute) { hook.notTried = 'the app has no list of ' + resource + 's (GET /...' + resource + 's) to read the effect of an event from'; continue; }
|
|
282
|
+
const readList = async () => {
|
|
283
|
+
const res = await reader.send('GET', listRoute.path, {});
|
|
284
|
+
return res.status === 200 ? listOf(res.json) : null;
|
|
285
|
+
};
|
|
286
|
+
const items0 = await readList();
|
|
287
|
+
if (!items0 || !items0.length) { hook.notTried = 'GET ' + listRoute.path + ' answered no records to aim an event at'; continue; }
|
|
288
|
+
const records = items0.filter((it) => it && it.id !== undefined);
|
|
289
|
+
const amountKey = records[0] && Object.keys(records[0]).find((k) => AMOUNT_NAME.test(k));
|
|
290
|
+
const statusKey = records[0] && Object.keys(records[0]).find((k) => /^status$|^state$/i.test(k));
|
|
291
|
+
hook.list = listRoute.path;
|
|
292
|
+
|
|
293
|
+
const used = new Set();
|
|
294
|
+
const nextRecord = (want) => records.find((r) => !used.has(r.id) && (!statusKey || !REFUNDED.test(String(r[statusKey]))) && (!want || want(r)));
|
|
295
|
+
// a refund event is tried first on a record nobody has paid or approved: the case it should refuse
|
|
296
|
+
const unpaidFor = (type) => (REFUNDED.test(type) && statusKey ? (r) => !PAID.test(String(r[statusKey])) : null);
|
|
297
|
+
const bodyFor = (type, rec, amount) => {
|
|
298
|
+
const b = {};
|
|
299
|
+
if (shape.id) b[shape.id] = 'kx-evt-' + crypto.randomBytes(5).toString('hex');
|
|
300
|
+
b[shape.type] = type;
|
|
301
|
+
b[shape.record] = rec.id;
|
|
302
|
+
if (shape.amount) b[shape.amount] = amount !== undefined ? amount : amountKey ? rec[amountKey] : 1;
|
|
303
|
+
return b;
|
|
304
|
+
};
|
|
305
|
+
const post = async (mode, body) => {
|
|
306
|
+
const text = JSON.stringify(body);
|
|
307
|
+
const session = authz.makeSession(ctx, null, '(nobody signed in)', null);
|
|
308
|
+
const headers = {};
|
|
309
|
+
if (mode === 'signed') headers[signing.header] = sign(signing, secret, text);
|
|
310
|
+
if (mode === 'wrong') headers[signing.header] = wrongSignature(signing, secret, text);
|
|
311
|
+
return session.send('POST', route.path, { json: body, headers });
|
|
312
|
+
};
|
|
313
|
+
const attempt = async (mode, type, rec, amount, label) => {
|
|
314
|
+
const before = await readList();
|
|
315
|
+
const body = bodyFor(type, rec, amount);
|
|
316
|
+
used.add(rec.id);
|
|
317
|
+
const res = await post(mode, body);
|
|
318
|
+
const reply = authz.replyOf(res);
|
|
319
|
+
const after = await readList();
|
|
320
|
+
const was = before && before.find((x) => x.id === rec.id);
|
|
321
|
+
const now = after && after.find((x) => x.id === rec.id);
|
|
322
|
+
const changed = !!(was && now && JSON.stringify(stableItem(was)) !== JSON.stringify(stableItem(now)));
|
|
323
|
+
const took = reply.kind === 'accepted' || reply.kind === 'redirect';
|
|
324
|
+
const t = { mode, label: label || mode, type, record: rec.id, status: res.status, took, changed, from: was && statusKey ? was[statusKey] : null, to: now && statusKey ? now[statusKey] : null };
|
|
325
|
+
hook.tried.push(t);
|
|
326
|
+
if (changed) out.left.push(name + ' ' + (label || mode) + ' ' + type + ' for ' + resource + ' ' + rec.id + (t.from !== null ? ': ' + statusKey + ' ' + t.from + ' -> ' + t.to : ' changed it'));
|
|
327
|
+
else if (took) out.left.push(name + ' ' + (label || mode) + ' ' + type + ' for ' + resource + ' ' + rec.id + ' answered ' + res.status + ' (no change seen in ' + listRoute.path + '); the event id is in the app\'s webhook table');
|
|
328
|
+
return t;
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// 1. a correctly signed event first: if the app refuses its own, nothing after it means anything
|
|
332
|
+
say('Sending a correctly signed ' + types[0] + ' to ' + name + ' first...');
|
|
333
|
+
const first = nextRecord(unpaidFor(types[0])) || nextRecord();
|
|
334
|
+
if (!first) { hook.notTried = 'no record left to aim an event at'; continue; }
|
|
335
|
+
const control = await attempt('signed', types[0], first, undefined, 'signed');
|
|
336
|
+
hook.control = control;
|
|
337
|
+
if (!control.took) {
|
|
338
|
+
hook.notTried = 'the app refused even a correctly signed event (' + control.status + '), so either the signature is made differently from how the code reads, or the event needs more than ' + Object.keys(bodyFor(types[0], first)).join(', ') + ': nothing after it would mean anything';
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
// the tries, in the order that tells the most when records run out
|
|
342
|
+
const cases = [];
|
|
343
|
+
for (const type of types) cases.push({ mode: 'none', type, label: 'unsigned' });
|
|
344
|
+
cases.push({ mode: 'wrong', type: types[0], label: 'wrong signature' });
|
|
345
|
+
for (const type of types.slice(1)) cases.push({ mode: 'signed', type, label: 'signed' });
|
|
346
|
+
if (shape.amount && amountKey) for (const type of types) if (!REFUNDED.test(type) && /pay|captur|charge|paid|success/i.test(type)) { cases.push({ mode: 'signed', type, label: 'signed, wrong amount', wrongAmount: true }); break; }
|
|
347
|
+
for (const c of cases) {
|
|
348
|
+
if (opts.stopped && opts.stopped()) break;
|
|
349
|
+
if (hook.tried.length >= MAX_TRIES) break;
|
|
350
|
+
const rec = (c.mode === 'signed' && nextRecord(unpaidFor(c.type))) || nextRecord();
|
|
351
|
+
if (!rec) break;
|
|
352
|
+
let amount;
|
|
353
|
+
if (c.wrongAmount) amount = (Number(rec[amountKey]) || 0) + 100;
|
|
354
|
+
await attempt(c.mode, c.type, rec, amount, c.label);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// judged
|
|
358
|
+
const at = hook.from;
|
|
359
|
+
const finding = (kind, severity, status, headline, proof, fix) => {
|
|
360
|
+
const f = { kind, where: name, from: at, status, severity, headline, proof, fixPrompt: ['Kryptheon sent my running app an event it signs itself, and it was taken when it should not have been:', '', headline, '', 'Where: ' + at, '', fix, '', 'Afterwards I will run: npx kryptheon api'].join(String.fromCharCode(10)) };
|
|
361
|
+
hook.findings.push(f);
|
|
362
|
+
out.findings.push(f);
|
|
363
|
+
};
|
|
364
|
+
const lineOf = (t) => t.label + ' ' + t.type + ' for ' + resource + ' ' + t.record + ': answered ' + t.status + (t.changed ? ', and ' + (t.from !== null ? statusKey + ' went ' + t.from + ' -> ' + t.to : 'the record changed') + ' in GET ' + listRoute.path : t.took ? ', nothing changed in GET ' + listRoute.path : ', refused');
|
|
365
|
+
for (const t of hook.tried) {
|
|
366
|
+
// the first signed event is a control for the signature, but what it did is judged like any other signed event
|
|
367
|
+
if (t === control && !(t.changed && REFUNDED.test(String(t.to)) && t.from !== null && !PAID.test(String(t.from)))) continue;
|
|
368
|
+
if (t.mode === 'none' && t.took) {
|
|
369
|
+
finding('webhook-unsigned', t.changed ? 'CRITICAL' : 'HIGH', t.changed ? 'confirmed' : 'verification required',
|
|
370
|
+
t.changed ? name + ' took ' + t.type + ' with no signature at all and changed ' + resource + ' ' + t.record + (t.from !== null ? ' (' + statusKey + ' ' + t.from + ' -> ' + t.to + ')' : '') + ': anyone who can reach it can send one.' : name + ' answered ' + t.status + ' to ' + t.type + ' with no signature, though no change was seen in ' + listRoute.path + '.',
|
|
371
|
+
['With nobody signed in and no ' + signing.header + ' header: ' + lineOf(t)], 'Treat a request with no signature as invalid: answer 401 before anything is saved, the same as a wrong signature. The check that reads "if the header is there and it is wrong" lets every request without the header through.');
|
|
372
|
+
} else if (t.mode === 'wrong' && t.took) {
|
|
373
|
+
finding('webhook-forged', t.changed ? 'CRITICAL' : 'HIGH', t.changed ? 'confirmed' : 'verification required',
|
|
374
|
+
name + ' took ' + t.type + ' with a wrong signature' + (t.changed ? ' and changed ' + resource + ' ' + t.record : '') + '.',
|
|
375
|
+
['A signature of the right length, one character wrong: ' + lineOf(t)], 'Compare the signature with a timing-safe compare (crypto.timingSafeEqual) over the exact raw body, and answer 401 when it does not match, before anything is saved.');
|
|
376
|
+
} else if (t.label === 'signed, wrong amount' && t.took && t.changed) {
|
|
377
|
+
finding('webhook-amount', 'HIGH', 'confirmed',
|
|
378
|
+
name + ' applied ' + t.type + ' for an amount that is not ' + resource + ' ' + t.record + '\'s: the status changed all the same.',
|
|
379
|
+
['Correctly signed, with the amount 100 higher than the record\'s: ' + lineOf(t)], 'Compare the amount (and currency) in the event with the amount the ' + resource + ' was created for, and ignore or flag the event when they differ.');
|
|
380
|
+
} else if (t.mode === 'signed' && t.changed && REFUNDED.test(String(t.to)) && t.from !== null && !PAID.test(String(t.from))) {
|
|
381
|
+
finding('webhook-lifecycle', 'MEDIUM', 'verification required',
|
|
382
|
+
name + ' marked ' + resource + ' ' + t.record + ' as ' + t.to + ' from ' + t.from + ': a refund event for something nobody had paid or approved.',
|
|
383
|
+
['Correctly signed: ' + lineOf(t)], 'Apply a refund event only to a record that was paid or approved first, in the same tenant, for no more than was paid; answer and log anything else without changing it.');
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return out;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
module.exports = { readSigning, shapeOf, sign, wrongSignature, run, MAX_TRIES };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kryptheon",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.57",
|
|
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",
|
|
@@ -56,7 +56,9 @@
|
|
|
56
56
|
"kryptheon-authz.js",
|
|
57
57
|
"kryptheon-roles.js",
|
|
58
58
|
"kryptheon-map.js",
|
|
59
|
-
"kryptheon-api.js"
|
|
59
|
+
"kryptheon-api.js",
|
|
60
|
+
"kryptheon-webhook.js",
|
|
61
|
+
"kryptheon-csv.js"
|
|
60
62
|
],
|
|
61
63
|
"engines": {
|
|
62
64
|
"node": ">=20.6.0"
|
|
@@ -66,7 +68,7 @@
|
|
|
66
68
|
"pg": "^8.23.0"
|
|
67
69
|
},
|
|
68
70
|
"scripts": {
|
|
69
|
-
"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-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-package.check.js",
|
|
71
|
+
"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-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-package.check.js",
|
|
70
72
|
"check:store": "node kryptheon-store.check.js",
|
|
71
73
|
"check:code": "node kryptheon-code.check.js",
|
|
72
74
|
"check:constdata": "node kryptheon-constdata.check.js",
|
|
@@ -109,7 +111,9 @@
|
|
|
109
111
|
"check:roles": "node kryptheon-roles.check.js",
|
|
110
112
|
"check:roles-mutants": "node kryptheon-roles.mutants.js",
|
|
111
113
|
"check:map": "node kryptheon-map.check.js",
|
|
112
|
-
"check:api": "node kryptheon-api.check.js"
|
|
114
|
+
"check:api": "node kryptheon-api.check.js",
|
|
115
|
+
"check:webhook": "node kryptheon-webhook.check.js",
|
|
116
|
+
"check:csv": "node kryptheon-csv.check.js"
|
|
113
117
|
},
|
|
114
118
|
"keywords": [
|
|
115
119
|
"playwright",
|