kryptheon 0.1.46 → 0.1.48

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/kryptheon-code.js CHANGED
@@ -264,6 +264,19 @@ function classify(node, scope, code, depth, aliases) {
264
264
  return 'safe';
265
265
  }
266
266
  if (node.callee.type === 'MemberExpression' && node.callee.object && node.callee.object.name === 'Math') return 'safe';
267
+ // crypto.randomUUID(): hex digits and dashes, made on this page - never a
268
+ // tag. Found on blind round 17: a row id made this way and written into
269
+ // the page was reported as a risk.
270
+ if (name === 'randomUUID' && node.callee.type === 'MemberExpression' &&
271
+ /^(crypto|self\.crypto|window\.crypto|globalThis\.crypto)$/.test(memberPath(node.callee.object))) {
272
+ return 'safe';
273
+ }
274
+ // list.reduce((t, s) => t + s.count, 0) - as dangerous as where it starts
275
+ // and what each step returns. A sum of counts from zero is a number;
276
+ // names joined from '' are as dangerous as the names. Found on blind
277
+ // round 17: a total written into the page was reported as a risk.
278
+ const reduced = reduceCallback(node, scope, code, depth, aliases);
279
+ if (reduced) return reduced;
267
280
  // items.map(i => `<li>${i.name}</li>`).join('') - judge what map builds.
268
281
  const mapped = mapCallback(node, scope, code, depth, aliases);
269
282
  if (mapped) {
@@ -427,6 +440,43 @@ function mapCallback(node, scope, code, depth, aliases) {
427
440
  return { returns: returns, inner: inner };
428
441
  }
429
442
 
443
+ /** a.b.c as text, '' when the node is not a plain chain of names. */
444
+ function memberPath(node) {
445
+ if (!node) return '';
446
+ if (node.type === 'Identifier') return node.name;
447
+ if (node.type === 'MemberExpression' && !node.computed && node.property && node.property.type === 'Identifier') {
448
+ const left = memberPath(node.object);
449
+ return left ? left + '.' + node.property.name : '';
450
+ }
451
+ return '';
452
+ }
453
+
454
+ /**
455
+ * list.reduce(cb, start): the worst of the start and every value the callback
456
+ * returns, judged with the running total standing for the start, the item for
457
+ * whatever the list holds and the index for a number. Null when node is not
458
+ * that shape. With no start, the first item is the start.
459
+ */
460
+ function reduceCallback(node, scope, code, depth, aliases) {
461
+ const name = calleeName(node.callee);
462
+ if (!/^(reduce|reduceRight)$/.test(name) || !/MemberExpression$/.test(node.callee.type)) return null;
463
+ const fn = node.arguments[0];
464
+ if (!fn || !/Function/.test(fn.type)) return null;
465
+ const listOrigin = classify(node.callee.object, scope, code, depth + 1, aliases);
466
+ const start = node.arguments.length > 1 ? classify(node.arguments[1], scope, code, depth + 1, aliases) : listOrigin;
467
+ const inner = Object.assign({}, aliases || {});
468
+ const params = fn.params || [];
469
+ if (params[0] && params[0].type === 'Identifier') inner[params[0].name] = start;
470
+ if (params[1] && params[1].type === 'Identifier') inner[params[1].name] = listOrigin;
471
+ if (params[2] && params[2].type === 'Identifier') inner[params[2].name] = 'safe';
472
+ const fnPath = FN_PATHS.get(fn);
473
+ const returns = fnPath
474
+ ? returnsOf(fnPath)
475
+ : (returnedBy(fn) ? [{ node: returnedBy(fn), scope: scope }] : []);
476
+ if (!returns.length) return 'unknown';
477
+ return worst([start].concat(returns.map((r) => classify(r.node, r.scope, code, depth + 1, inner))));
478
+ }
479
+
430
480
  /**
431
481
  * Whether a call escapes HTML - by name for the well-known ones, and for a
432
482
  * helper of this file's own, by what it does: every return is a replace()
@@ -302,8 +302,8 @@
302
302
  });
303
303
  }
304
304
 
305
- var CHECK_NAME = { regression: 'Recorded flows', frontend: 'Frontend code', data: 'Database', edge: 'Input and edge cases' };
306
- var CHECK_TONE = { regression: 'sun', frontend: 'amber', data: 'dusk', edge: 'ember' };
305
+ var CHECK_NAME = { regression: 'Recorded flows', frontend: 'Frontend code', data: 'Database', edge: 'Input and edge cases', reliability: 'Reliability' };
306
+ var CHECK_TONE = { regression: 'sun', frontend: 'amber', data: 'dusk', edge: 'ember', reliability: 'ember' };
307
307
 
308
308
  function counts() {
309
309
  var confirmed = state.findings.filter(function (f) { return f.status === 'confirmed'; }).length;
@@ -871,7 +871,7 @@
871
871
  var askingProbe = el('div', 'controls f-quick');
872
872
  askingProbe.appendChild(probeConsentBox(probeAsking.check, 'Yes, try it again', function (body) {
873
873
  runJob('/api/recheck', Object.assign({ id: f.id }, body)).then(function (done) { heard(f, (done && done.result) || {}); }, function () {});
874
- }, 'Re-check: replays this flow as recorded, then once more with the value that found this. Two runs.'));
874
+ }, RECHECK_WORDS[f.check === 'reliability' ? f.kind : 'edge']));
875
875
  card.appendChild(askingProbe);
876
876
  } else if (pending && pending.step === 'finding' && pending.finding && pending.finding.id === f.id) {
877
877
  var asking = el('div', 'controls f-quick');
@@ -949,7 +949,16 @@
949
949
  }
950
950
 
951
951
  var STATE_TONE = { 'problems found': 'ember', 'things to check': 'amber', 'last run held': 'leaf', 'nothing found': 'leaf', 'stopped part way': 'amber', 'nothing was tested': 'amber' };
952
- var PROBE_LABEL = { edge: 'Try inputs - adds test data' };
952
+ var PROBE_LABEL = { edge: 'Try inputs - adds test data', reliability: 'Replay 3x - adds test data' };
953
+ // What one re-check press does, said before the yes.
954
+ var RECHECK_WORDS = {
955
+ edge: 'Re-check: replays this flow as recorded, then once more with the value that found this. Two runs.',
956
+ flaky: 'Re-check: replays this flow five times. It is fixed only if all five work.',
957
+ double: 'Re-check: replays this flow once, then once more with this step double-clicked. Two runs.',
958
+ phone: 'Re-check: replays this flow once, then once more at phone size, clicking every button with saving blocked. Two runs.',
959
+ race: 'Re-check: replays this flow once, then once more with this save sent twice at the same moment. Two runs.',
960
+ shown: 'Re-check: replays this flow three times, looking for what this step saved on the page right after it. It is fixed only if it shows right away.',
961
+ };
953
962
 
954
963
  // Which probe check is asking for a yes right now, and for which finding
955
964
  // when it is a re-check. Nothing that adds data to the app runs without it.
@@ -1120,7 +1129,7 @@
1120
1129
  if (f.check === 'data') { prepare('recheck', 'finding', f); return; }
1121
1130
  // An input finding is re-checked by typing its value again, which adds
1122
1131
  // test data to the app: the same yes as the check's own button, first.
1123
- if (f.check === 'edge') { probeAsking = { check: 'edge', finding: f }; openRow = null; renderFindings(); return; }
1132
+ if (f.check === 'edge' || f.check === 'reliability') { probeAsking = { check: f.check, finding: f }; openRow = null; renderFindings(); return; }
1124
1133
  runJob('/api/recheck', { id: f.id }).then(function (done) { heard(f, (done && done.result) || {}); }, function () {});
1125
1134
  }
1126
1135
  function heard(f, r) {
@@ -1281,7 +1290,15 @@
1281
1290
  function load() {
1282
1291
  return fetch('/api/state', { cache: 'no-store' })
1283
1292
  .then(function (res) { if (!res.ok) throw new Error('the dashboard answered ' + res.status); return res.json(); })
1284
- .then(render)
1293
+ .then(function (next) {
1294
+ // Drawn again only when something changed: a redraw every few
1295
+ // seconds replaced every button under the pointer, and a press that
1296
+ // landed on two drawings of one button was lost.
1297
+ var text = JSON.stringify(next);
1298
+ if (text === load.last) return;
1299
+ load.last = text;
1300
+ render(next);
1301
+ })
1285
1302
  .catch(function (err) { byId('subline').textContent = 'Could not load: ' + err.message; });
1286
1303
  }
1287
1304
 
@@ -212,7 +212,7 @@
212
212
  .detail-box { margin: 0 8px 22px 20px; padding: 18px 0 0; border-top: 1px dashed var(--line); }
213
213
  .d-step { margin-top: 18px; font-size: 10px; color: var(--orange-deep); }
214
214
  .d-step:first-child { margin-top: 0; }
215
- .d-text { margin-top: 6px; font-size: 14px; line-height: 1.6; color: var(--muted); overflow-wrap: anywhere; }
215
+ .d-text { margin-top: 6px; font-size: 14px; line-height: 1.6; color: var(--muted); overflow-wrap: anywhere; white-space: pre-line; }
216
216
  .detail-box pre { max-height: 360px; margin: 10px 0 0; padding: 18px; overflow: auto; font: 12px/1.7 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; color: var(--on-dark); background: var(--ink); }
217
217
  .d-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
218
218
  .attempts { display: grid; gap: 8px; margin-top: 14px; font-size: 13px; color: var(--muted); }