kryptheon 0.1.53 → 0.1.54

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.
@@ -17,6 +17,7 @@ const crypto = require('crypto');
17
17
  const base = require('@playwright/test');
18
18
 
19
19
  const OUT = process.env.KRYPTHEON_PROBE_OUT || '';
20
+ const READS = process.env.KRYPTHEON_PROBE_READS === '1';
20
21
  const GAP_MS = Number(process.env.KRYPTHEON_PROBE_GAP_MS || 1000);
21
22
  // After a "too many requests", the app is asked to wait this long before the
22
23
  // next run, so one 429 does not turn every run after it into another.
@@ -512,7 +513,8 @@ const test = base.test.extend({
512
513
  // keeps - it is never listed as test data left behind.
513
514
  const signIn = JSON.stringify(kept).indexOf('[hidden]') !== -1;
514
515
  const event = Object.assign({ kind: 'write', method: method, host: at.host, origin: at.origin, path: at.path, status: status, signIn: signIn },
515
- redirectOf(res.url(), status, req.headers(), res.headers(), secrets), kept);
516
+ redirectOf(res.url(), status, req.headers(), res.headers(), secrets), kept,
517
+ READS ? { encoding: /json/i.test(type) ? 'json' : /x-www-form-urlencoded/i.test(type) ? 'form' : 'other' } : {});
516
518
  const placed = add(event);
517
519
  // What the server answered - often the record it saved, with its id.
518
520
  // That is the proof that two saves made two records, and of what was
@@ -532,6 +534,18 @@ const test = base.test.extend({
532
534
  answers.add(reading);
533
535
  }
534
536
  }
537
+ // What the app was asked to show, for the roles check, which learns the
538
+ // app's own requests from the recordings. Off unless asked for: no other
539
+ // check reads these, and a page makes a great many of them.
540
+ else if (READS && method === 'GET' && /^(fetch|xhr)$/.test(req.resourceType()) && siteOf(res.url()) === siteOf(page.url())) {
541
+ let query = '';
542
+ try {
543
+ query = new URL(res.url()).search;
544
+ } catch (err) {
545
+ query = '';
546
+ }
547
+ add({ kind: 'read', method: 'GET', host: at.host, origin: at.origin, path: at.path, query: hideValues(query, secrets).slice(0, 200), status: status });
548
+ }
535
549
  });
536
550
  // Answers still being read. Counted before a mark and before the end.
537
551
  const answers = new Set();
@@ -89,8 +89,7 @@ function consentLines(what, addresses, options) {
89
89
  what,
90
90
  '',
91
91
  'It runs against: ' + (addresses.length ? addresses.join(', ') : 'the addresses in your recordings'),
92
- 'It ADDS TEST DATA to your app, and that data STAYS there - Kryptheon does not delete it.',
93
- ].concat(marked ? [
92
+ ].concat(options && options.dataLines ? ['It CHANGES DATA in your app.'] : ['It ADDS TEST DATA to your app, and that data STAYS there - Kryptheon does not delete it.']).concat(options && options.dataLines ? options.dataLines : marked ? [
94
93
  'Most of it contains the word "' + TEST_WORD + '", so you can find it. Empty, negative and date values cannot carry it;',
95
94
  'every write that was accepted is listed when it ends.',
96
95
  ] : [
@@ -261,7 +260,7 @@ function runProbes(root, probes, options) {
261
260
  }
262
261
 
263
262
  // Each probe check keeps its last press in the store under this name.
264
- const REPORT_FILES = { edge: 'edge-last.json', reliability: 'reliability-last.json' };
263
+ const REPORT_FILES = { edge: 'edge-last.json', reliability: 'reliability-last.json', roles: 'roles-last.json' };
265
264
 
266
265
  function reportFile(root, check, env) {
267
266
  return path.join(store.pathsFor(root, env).dir, REPORT_FILES[check]);
@@ -238,7 +238,38 @@ function sameValue(a, b) {
238
238
  const x = String(a == null ? '' : a).trim();
239
239
  const y = String(b == null ? '' : b).trim();
240
240
  if (x === y) return true;
241
- return x !== '' && y !== '' && Number.isFinite(Number(x)) && Number.isFinite(Number(y)) && Number(x) === Number(y);
241
+ if (x !== '' && y !== '' && Number.isFinite(Number(x)) && Number.isFinite(Number(y)) && Number(x) === Number(y)) return true;
242
+ // A date field's "2026-10-14" and the server's "2026-10-13T18:30:00.000Z"
243
+ // (the same day, stored at a timezone's midnight) are the same date.
244
+ const day = /^\d{4}-\d{2}-\d{2}(T[\d:.]+(Z|[+-]\d{2}:?\d{2})?)?$/;
245
+ return day.test(x) && day.test(y) && (x.length === 10 || y.length === 10) && Math.abs(Date.parse(x) - Date.parse(y)) < 86400000;
246
+ }
247
+
248
+ /**
249
+ * What the save's own answer says a field now holds, when it names it: the
250
+ * field "Pickup date" as pickup_date, pickupDate or "pickup date", in the
251
+ * answer or one named record inside it ({ shipment: {...} }). The server's
252
+ * word beats the form opened again. Found on blind round 23: the form opened
253
+ * again in a new tab was another form with an empty "Pickup date", and a date
254
+ * the app never cleared was read as cleared. undefined when not named.
255
+ */
256
+ function answeredValue(writes, field) {
257
+ const key = String((field && field.name) || '').toLowerCase().replace(/[^a-z0-9]/g, '');
258
+ if (!key) return undefined;
259
+ for (const w of writes || []) {
260
+ const a = w && w.answer;
261
+ if (!a || typeof a !== 'object' || Array.isArray(a)) continue;
262
+ const rows = [a].concat(Object.values(a).filter((v) => v && typeof v === 'object' && !Array.isArray(v)));
263
+ for (const row of rows) {
264
+ for (const k of Object.keys(row)) {
265
+ if (k.toLowerCase().replace(/[^a-z0-9]/g, '') !== key) continue;
266
+ const v = row[k];
267
+ if (v === null) return '';
268
+ if (typeof v !== 'object') return String(v);
269
+ }
270
+ }
271
+ }
272
+ return undefined;
242
273
  }
243
274
 
244
275
  /**
@@ -286,10 +317,12 @@ function judgeKept(flow, step, runs) {
286
317
  judged += 1;
287
318
  for (const e of back) {
288
319
  const f = fields.find((x) => x.line === e.line);
289
- if (notEdit(f, e) || e.now === null) continue;
290
- const item = { run: counted.indexOf(r) + 1, field: f, was: e.was, now: e.now, write: took[0] };
291
- if (sameValue(e.now, f.value)) kept += 1;
292
- else if (sameValue(e.now, e.was)) lost.push(item);
320
+ const said = f ? answeredValue(took, f) : undefined;
321
+ const now = said !== undefined ? said : e.now;
322
+ if (notEdit(f, e) || now === null) continue;
323
+ const item = { run: counted.indexOf(r) + 1, field: f, was: e.was, now: now, write: took[0], said: said !== undefined };
324
+ if (sameValue(now, f.value)) kept += 1;
325
+ else if (sameValue(now, e.was)) lost.push(item);
293
326
  else changed.push(item);
294
327
  }
295
328
  }
@@ -316,12 +349,14 @@ function judgeKept(flow, step, runs) {
316
349
  findings.push({
317
350
  flow: flow.title, where: flow.file + ':' + step.line, kind: 'kept', type: 'lost', step: step.name, field: first.field.name || 'line ' + first.field.line,
318
351
  severity: sure ? 'MEDIUM' : 'LOW', status: sure ? 'confirmed' : 'verification required',
319
- headline: 'After "' + step.name + '", ' + thing(first) + ' was ' + typedWords(first) + ', but the form opened again still shows ' + JSON.stringify(first.was) + ' - the change was not kept.',
352
+ headline: 'After "' + step.name + '", ' + thing(first) + ' was ' + typedWords(first) + ', but ' + (first.said ? 'the app\'s answer still has ' : 'the form opened again still shows ') +
353
+ JSON.stringify(first.was) + ' - the change was not kept.',
320
354
  proof: [
321
355
  'Flow: ' + flow.title + ' (' + flow.file + ':' + first.field.line + ', saved at line ' + step.line + ')',
322
356
  'Before typing, ' + thing(first) + ' held ' + JSON.stringify(first.was) + '; the recording ' + (String(first.field.value).trim() === '' ? 'cleared it' : 'typed ' + JSON.stringify(first.field.value)) + '.',
323
357
  'The save: ' + words(first.write) + ' - the app took it.',
324
- 'The same form opened again in a new tab: ' + thing(first) + ' shows ' + JSON.stringify(first.now) + ', what it held before.',
358
+ first.said ? 'The server\'s own answer to that save: ' + thing(first) + ' is ' + JSON.stringify(first.now) + ', what it held before.'
359
+ : 'The same form opened again in a new tab: ' + thing(first) + ' shows ' + JSON.stringify(first.now) + ', what it held before.',
325
360
  'Seen in ' + runsLost + ' of ' + judged + (judged === 1 ? ' run' : ' runs') + ' that saved.',
326
361
  ],
327
362
  });
@@ -1383,6 +1418,8 @@ module.exports = {
1383
1418
  judgeDouble: judgeDouble,
1384
1419
  judgeShown: judgeShown,
1385
1420
  judgeKept: judgeKept,
1421
+ sameValue: sameValue,
1422
+ answeredValue: answeredValue,
1386
1423
  keepSteps: keepSteps,
1387
1424
  keptFields: keptFields,
1388
1425
  judgeTwice: judgeTwice,
@@ -447,6 +447,7 @@ module.exports = {
447
447
  scrubSecrets: scrubSecrets,
448
448
  dropTrailingLogout: dropTrailingLogout,
449
449
  isSecretField: isSecretField,
450
+ accountPart: accountPart,
450
451
  nameInLine: nameInLine,
451
452
  CREATES: CREATES,
452
453
  ROW_PICK: ROW_PICK,