kryptheon 0.1.55 → 0.1.56

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.
@@ -302,7 +302,7 @@
302
302
  });
303
303
  }
304
304
 
305
- var CHECK_NAME = { regression: 'Recorded flows', frontend: 'Frontend code', data: 'Database', edge: 'Input and edge cases', reliability: 'Reliability', payments: 'Payments', roles: 'Roles and tenants' };
305
+ var CHECK_NAME = { regression: 'Recorded flows', frontend: 'Frontend code', backend: 'Backend map', data: 'Database', edge: 'Input and edge cases', reliability: 'Reliability', payments: 'Payments', roles: 'Roles and tenants' };
306
306
  var CHECK_TONE = { regression: 'sun', frontend: 'amber', data: 'dusk', edge: 'ember', reliability: 'ember', payments: 'ember', roles: 'ember' };
307
307
 
308
308
  function counts() {
@@ -56,8 +56,10 @@ const CHECKS = [
56
56
  what: 'Signs in as each account your recordings use and tries every recorded action as every one of them, against the permissions-policy.json in your app folder: a role that may not do it must be refused, one that may must still work, and one organization must not reach another organization records. Judged from what comes back and what your app stored before and after. It runs only against an app on this computer.' },
57
57
  { id: 'payments', label: 'Payments: a webhook sent twice', available: true,
58
58
  what: 'Real payments in Razorpay\'s or Stripe\'s TEST mode, through a proxy on this computer, each checked as it comes until you press Stop. Its signed webhook is sent to your app again, then once with a wrong signature, and your database is read before and after each - reporting the plan, credits or order given a second time, a repeat answered with an error, or a forged webhook accepted. Live mode is never sent again. It runs only when you press its button.' },
59
- { id: 'api', label: 'API', available: false },
60
- { id: 'backend', label: 'Backend', available: false },
59
+ { id: 'api', label: 'API: every route, tried on your running app', available: true,
60
+ what: 'Takes every route the backend map read and tries it on your app on this computer: each account aimed at another organization\'s records, every route with no sign-in, and bad values in fields the code never checks - judged from what comes back and from your own lists before and after, and said as a verdict on each thing the map pointed at. It adds test data and never deletes it, so it runs only in a terminal, on a test copy, with your yes (npx kryptheon api).' },
61
+ { id: 'backend', label: 'Backend map: routes, guards, tables', available: true,
62
+ what: 'Reads your server code - Express, Supabase Edge Functions, Next.js API routes - and lists every route with its sign-in, role and webhook-signature checks, the tables it reads and writes and whether those rows are limited to the signed-in organisation, and the checks on each field it is sent. Nothing is run or sent. What it points at is to check, never proven: npx kryptheon roles proves it on the running app (npx kryptheon map).' },
61
63
  { id: 'synthetic', label: 'Synthetic test users', available: false },
62
64
  ];
63
65
 
@@ -68,7 +70,7 @@ const CHECK_IDS = new Set(CHECKS.map((c) => c.id));
68
70
  // here (rounds 19 and 20: roles, payment rules, counts and searches).
69
71
  const NOT_CHECKED = [
70
72
  { what: 'Who can do what',
71
- why: 'Whether a lower role - a member, a customer - can open, change or delete what only a higher role should, or reach another account\'s record by changing an id in the address. Kryptheon replays each recording as the person who made it. The Roles and tenants check does try one account\'s actions as another, but only against the permissions-policy.json you write; without that file, or for anything it was not told, this is still not checked.',
73
+ why: 'Whether a lower role - a member, a customer - can open, change or delete what only a higher role should, or reach another account\'s record by changing an id in the address. Kryptheon replays each recording as the person who made it. The Roles and tenants check does try one account\'s actions as another, but only against the permissions-policy.json you write; without that file, or for anything it was not told, this is still not checked. The backend map points at routes whose code shows no role or organisation check, but a reading of code proves nothing.',
72
74
  yourself: 'Sign in as each role and open the higher role\'s pages and actions directly, by their address.' },
73
75
  { what: 'Payment rules beyond a repeat',
74
76
  why: 'Only the same webhook sent again, and a copy with a wrong signature, are tried. Not tried: a webhook with no signature at all, an amount or currency that does not match the order, buying again while a plan is active, or when a refund takes access away.',
@@ -553,6 +555,10 @@ function buildState(root, env) {
553
555
  const history = readHistory(paths.history, 20);
554
556
  const baselines = readJson(paths.baselines) || {};
555
557
  const code = readJson(paths.codeFindings);
558
+ // The last backend map (npx kryptheon map, or its button here).
559
+ const backendMap = readJson(path.join(paths.dir, 'map-last.json'));
560
+ // The last API run (npx kryptheon api --run): tries on the running app.
561
+ const apiLast = readJson(path.join(paths.dir, 'api-last.json'));
556
562
  const night = readJson(paths.nightLast);
557
563
  // What the nightly run inside the database last said, kept by
558
564
  // kryptheon-night whenever it connects. Not the same answer as night:
@@ -622,6 +628,41 @@ function buildState(root, env) {
622
628
  }
623
629
  }
624
630
 
631
+ // The backend map: what it points at, each one to check - a reading of the
632
+ // code, so never "confirmed".
633
+ if (backendMap && config.enabled.backend) {
634
+ for (const t of backendMap.toCheck || []) {
635
+ findings.push({
636
+ check: 'backend',
637
+ severity: t.severity,
638
+ status: 'verification required',
639
+ where: t.where,
640
+ headline: t.headline,
641
+ detail: (t.evidence || []).join('\n') + apiVerdictLine(apiLast, t),
642
+ fixPrompt: t.fixPrompt,
643
+ when: backendMap.checkedAt,
644
+ });
645
+ }
646
+ }
647
+
648
+ // The API run: what got through on the running app, each with its proof.
649
+ if (apiLast && config.enabled.api) {
650
+ for (const f of apiLast.findings || []) {
651
+ findings.push({
652
+ check: 'api',
653
+ severity: f.severity,
654
+ status: f.status,
655
+ evidence: f.status === 'confirmed' ? 'runtime confirmed' : 'seen once',
656
+ confidence: f.status === 'confirmed' ? 'high' : 'medium',
657
+ where: f.where,
658
+ headline: f.headline,
659
+ detail: (f.proof || []).join('\n'),
660
+ fixPrompt: f.fixPrompt,
661
+ when: apiLast.checkedAt,
662
+ });
663
+ }
664
+ }
665
+
625
666
  // Input and edge cases, and reliability: the last press of each one's
626
667
  // button. Each finding carries its proof, and what it was about - the
627
668
  // field and value, the flow, the step - so a re-check can try exactly that
@@ -792,6 +833,13 @@ function buildState(root, env) {
792
833
  : 'last run held';
793
834
  }
794
835
  else if (c.id === 'frontend') state = !code ? 'never run' : (code.findings || []).length ? 'things to check' : 'nothing found';
836
+ else if (c.id === 'backend') state = !backendMap ? 'never run' : !(backendMap.routes || []).length ? 'no routes read' : (backendMap.toCheck || []).length ? 'things to check' : 'nothing found';
837
+ else if (c.id === 'api') {
838
+ state = !apiLast ? 'never run' : !apiLast.ran ? 'nothing was tried'
839
+ : findings.some((f) => f.check === 'api' && f.status === 'confirmed') ? 'problems found'
840
+ : findings.some((f) => f.check === 'api') ? 'things to check'
841
+ : 'last run held';
842
+ }
795
843
  else if (c.id === 'payments') {
796
844
  state = !paymentsLast ? 'never run'
797
845
  : findings.some((f) => f.check === 'payments') ? 'problems found'
@@ -822,7 +870,7 @@ function buildState(root, env) {
822
870
  } : null,
823
871
  // Runnable from the page: what needs nothing the page cannot supply. The
824
872
  // database check needs a connection string, which stays in the terminal.
825
- runnable: c.available && (c.id === 'frontend' || (c.id === 'regression' && recordings > 0)),
873
+ runnable: c.available && (c.id === 'frontend' || c.id === 'backend' || (c.id === 'regression' && recordings > 0)),
826
874
  };
827
875
  });
828
876
 
@@ -892,11 +940,18 @@ function buildState(root, env) {
892
940
 
893
941
  // What each run is called on the page, and the command that does the same in
894
942
  // a terminal - shown under every button, for when the page cannot be used.
895
- const RUN_TITLE = { frontend: 'Reading your code', regression: 'Replaying your recordings', edge: 'Trying unusual inputs in your forms', reliability: 'Replaying your flows three times, and double-clicking',
943
+ const RUN_TITLE = { frontend: 'Reading your code', backend: 'Mapping your server code', regression: 'Replaying your recordings', edge: 'Trying unusual inputs in your forms', reliability: 'Replaying your flows three times, and double-clicking',
896
944
  roles: 'Trying every recorded action as each account',
897
945
  payments: 'Waiting for test payments, and sending each webhook again' };
898
- const RUN_COMMAND = { frontend: 'npx kryptheon code', regression: 'npx kryptheon check', edge: 'npx kryptheon edge', reliability: 'npx kryptheon reliability', roles: 'npx kryptheon roles',
946
+ const RUN_COMMAND = { frontend: 'npx kryptheon code', backend: 'npx kryptheon map', regression: 'npx kryptheon check', edge: 'npx kryptheon edge', reliability: 'npx kryptheon reliability', roles: 'npx kryptheon roles',
947
+ api: 'npx kryptheon api --run --origin http://localhost:3000 --yes',
899
948
  payments: 'npx kryptheon payments' };
949
+
950
+ /** The line a backend-map item gets once the API run has tried that route: "On the running app: held." */
951
+ function apiVerdictLine(apiLast, item) {
952
+ const v = apiLast && (apiLast.verdicts || []).find((x) => x.route === item.route && x.kind === item.kind);
953
+ return v ? '\nOn the running app (' + String(apiLast.checkedAt || '').slice(0, 10) + '): ' + v.verdict + (v.why ? ' - ' + v.why : '') + '.' : '';
954
+ }
900
955
  const DB_ACTIONS = {
901
956
  scan: { title: 'Checking your database', command: 'npx kryptheon-night' },
902
957
  install: { title: 'Setting up the nightly check', command: 'npx kryptheon-night install' },
package/kryptheon-look.js CHANGED
@@ -50,6 +50,7 @@ function owedReplay(paths) {
50
50
  /**
51
51
  * Looks once. `runners` does the work that needs the caller's tools:
52
52
  * runners.frontend() -> { ran, why } (the code read)
53
+ * runners.backend() -> { ran, why } (the backend map, read from the server code)
53
54
  * runners.regression() -> exit code, or null (replaying the recordings)
54
55
  * `options.replay` false keeps the recordings from being replayed - the
55
56
  * dashboard's automatic look does that by default, because a replay while the
@@ -96,6 +97,13 @@ function look(root, runners, options) {
96
97
  if (step.id === 'frontend') {
97
98
  const r = runners.frontend();
98
99
  step.state = r.ran ? 'ran' : 'could not run: ' + r.why;
100
+ } else if (step.id === 'backend') {
101
+ // a reading of the server code: cheap, and never run without a runner that can do it
102
+ if (typeof runners.backend !== 'function') step.state = 'not run here - npx kryptheon map';
103
+ else {
104
+ const r = runners.backend();
105
+ step.state = r.ran ? 'ran' : 'could not run: ' + r.why;
106
+ }
99
107
  } else if (step.id === 'regression') {
100
108
  regressionExit = runners.regression();
101
109
  step.state = regressionExit === 0 ? 'ran - every recording held'