@clear-capabilities/agentic-security-scanner 0.185.0 → 0.186.2

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.
Files changed (174) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/bin/agentic-security.js +66 -18
  3. package/dist/1128.index.js +25 -21
  4. package/dist/{5817.index.js → 1602.index.js} +378 -29
  5. package/dist/2584.index.js +1 -1
  6. package/dist/4171.index.js +2 -2
  7. package/dist/{0b301d45b231f144a1b4.json → 4d06c8944ae121d7085c.json} +8 -8
  8. package/dist/5752.index.js +466 -0
  9. package/dist/7405.index.js +1 -1
  10. package/dist/8158.index.js +1713 -0
  11. package/dist/8798.index.js +1 -1
  12. package/dist/9382.index.js +2 -2
  13. package/dist/9560.index.js +1 -1
  14. package/dist/9579.index.js +1 -1
  15. package/dist/agentic-security.mjs +29 -29
  16. package/dist/agentic-security.mjs.sha256 +1 -1
  17. package/package.json +8 -8
  18. package/src/dataflow/CLAUDE.md +6 -3
  19. package/src/dataflow/access-paths.js +12 -2
  20. package/src/dataflow/demand-query.js +279 -40
  21. package/src/dataflow/dep-fingerprint.js +1 -1
  22. package/src/dataflow/exploit-prover.js +6 -2
  23. package/src/dataflow/ir-cache.js +268 -0
  24. package/src/dataflow/privacy-taint.js +7 -0
  25. package/src/engine.js +62 -5
  26. package/src/ir/CLAUDE.md +4 -0
  27. package/src/ir/callgraph.js +36 -8
  28. package/src/ir/index.js +18 -4
  29. package/src/ir/parser-js.js +10 -0
  30. package/src/language/CLAUDE.md +13 -0
  31. package/src/language/nix-option-types.js +170 -0
  32. package/src/language/nix-script-taint.js +46 -3
  33. package/src/language/nix-secrets.js +20 -2
  34. package/src/lineage/CLAUDE.md +2 -1
  35. package/src/lineage/smt-orchestrator.js +47 -11
  36. package/src/lineage/smt-z3-backend.js +294 -0
  37. package/src/posture/CLAUDE.md +5 -1
  38. package/src/posture/business-logic.js +16 -7
  39. package/src/posture/dag-commands.js +442 -0
  40. package/src/posture/finding-defaults.js +19 -0
  41. package/src/posture/git-history.js +91 -1
  42. package/src/posture/proof-fabric/cli.js +1 -1
  43. package/src/posture/proof-fabric/container.js +2 -2
  44. package/src/posture/proof-fabric/generate-haskell.js +205 -0
  45. package/src/posture/proof-fabric/generate.js +6 -3
  46. package/src/posture/proof-fabric/reproducer.js +4 -2
  47. package/src/posture/proof-fabric/runner.js +4 -4
  48. package/src/sast/CLAUDE.md +2 -0
  49. package/src/sast/_call-args.js +70 -0
  50. package/src/sast/init-scope.js +87 -0
  51. package/src/sast/listen-bind-address.js +49 -0
  52. package/src/sast/redirect-target.js +106 -0
  53. package/src/sast/reflected-input.js +76 -0
  54. package/src/sast/send-file-root.js +27 -0
  55. package/src/sast/sensitive-data-logging.js +38 -1
  56. package/dist/119.index.js +0 -197
  57. package/dist/128.index.js +0 -129
  58. package/dist/1293.index.js +0 -5689
  59. package/dist/1336.index.js +0 -16331
  60. package/dist/1351.index.js +0 -133
  61. package/dist/1387.index.js +0 -271
  62. package/dist/1437.index.js +0 -23
  63. package/dist/1445.index.js +0 -110
  64. package/dist/1505.index.js +0 -151
  65. package/dist/1557.index.js +0 -293
  66. package/dist/1621.index.js +0 -311
  67. package/dist/1751.index.js +0 -160
  68. package/dist/1765.index.js +0 -727
  69. package/dist/1861.index.js +0 -690
  70. package/dist/1906.index.js +0 -433
  71. package/dist/208.index.js +0 -1631
  72. package/dist/2223.index.js +0 -159
  73. package/dist/2238.index.js +0 -295
  74. package/dist/2530.index.js +0 -152
  75. package/dist/2565.index.js +0 -116
  76. package/dist/2574.index.js +0 -127
  77. package/dist/2620.index.js +0 -345
  78. package/dist/2773.index.js +0 -98
  79. package/dist/2775.index.js +0 -32
  80. package/dist/2966.index.js +0 -171
  81. package/dist/2972.index.js +0 -87
  82. package/dist/2991.index.js +0 -131
  83. package/dist/3063.index.js +0 -833
  84. package/dist/3075.index.js +0 -227
  85. package/dist/3121.index.js +0 -297
  86. package/dist/3314.index.js +0 -263
  87. package/dist/3480.index.js +0 -1822
  88. package/dist/3481.index.js +0 -24
  89. package/dist/3506.index.js +0 -268
  90. package/dist/3533.index.js +0 -591
  91. package/dist/3653.index.js +0 -450
  92. package/dist/3740.index.js +0 -722
  93. package/dist/3822.index.js +0 -131
  94. package/dist/3868.index.js +0 -292
  95. package/dist/3918.index.js +0 -192
  96. package/dist/4090.index.js +0 -288
  97. package/dist/4113.index.js +0 -1286
  98. package/dist/4121.index.js +0 -1190
  99. package/dist/4142.index.js +0 -690
  100. package/dist/4168.index.js +0 -509
  101. package/dist/4281.index.js +0 -993
  102. package/dist/4336.index.js +0 -436
  103. package/dist/4387.index.js +0 -532
  104. package/dist/4413.index.js +0 -302
  105. package/dist/4476.index.js +0 -4510
  106. package/dist/4491.index.js +0 -133
  107. package/dist/4538.index.js +0 -185
  108. package/dist/4684.index.js +0 -319
  109. package/dist/4740.index.js +0 -165
  110. package/dist/4780.index.js +0 -209
  111. package/dist/4802.index.js +0 -225
  112. package/dist/4812.index.js +0 -379
  113. package/dist/4835.index.js +0 -126
  114. package/dist/494.index.js +0 -226
  115. package/dist/4991.index.js +0 -549
  116. package/dist/5199.index.js +0 -305
  117. package/dist/5216.index.js +0 -109
  118. package/dist/5439.index.js +0 -301
  119. package/dist/5443.index.js +0 -97
  120. package/dist/5496.index.js +0 -377
  121. package/dist/5738.index.js +0 -240
  122. package/dist/5801.index.js +0 -588
  123. package/dist/5858.index.js +0 -223
  124. package/dist/5933.index.js +0 -143
  125. package/dist/601.index.js +0 -23
  126. package/dist/6173.index.js +0 -273
  127. package/dist/6291.index.js +0 -1871
  128. package/dist/6312.index.js +0 -666
  129. package/dist/634.index.js +0 -16182
  130. package/dist/644.index.js +0 -87
  131. package/dist/6508.index.js +0 -283
  132. package/dist/6560.index.js +0 -645
  133. package/dist/6576.index.js +0 -422
  134. package/dist/6579.index.js +0 -271
  135. package/dist/6655.index.js +0 -3221
  136. package/dist/6745.index.js +0 -305
  137. package/dist/6818.index.js +0 -21642
  138. package/dist/6932.index.js +0 -1190
  139. package/dist/6972.index.js +0 -167
  140. package/dist/6995.index.js +0 -163
  141. package/dist/7249.index.js +0 -191
  142. package/dist/7372.index.js +0 -1197
  143. package/dist/7546.index.js +0 -541
  144. package/dist/76.index.js +0 -448
  145. package/dist/7879.index.js +0 -163
  146. package/dist/8025.index.js +0 -130
  147. package/dist/8054.index.js +0 -248
  148. package/dist/808.index.js +0 -1330
  149. package/dist/8097.index.js +0 -201
  150. package/dist/8126.index.js +0 -191
  151. package/dist/8178.index.js +0 -78
  152. package/dist/8382.index.js +0 -93
  153. package/dist/8408.index.js +0 -261
  154. package/dist/8540.index.js +0 -174
  155. package/dist/8635.index.js +0 -802
  156. package/dist/8688.index.js +0 -410
  157. package/dist/8699.index.js +0 -779
  158. package/dist/8891.index.js +0 -457
  159. package/dist/8916.index.js +0 -885
  160. package/dist/9146.index.js +0 -170
  161. package/dist/9168.index.js +0 -841
  162. package/dist/9292.index.js +0 -369
  163. package/dist/9422.index.js +0 -866
  164. package/dist/9440.index.js +0 -453
  165. package/dist/9479.index.js +0 -152
  166. package/dist/9481.index.js +0 -220
  167. package/dist/9539.index.js +0 -100
  168. package/dist/9547.index.js +0 -103
  169. package/dist/9692.index.js +0 -90
  170. package/dist/9800.index.js +0 -462
  171. package/dist/9899.index.js +0 -138
  172. package/dist/9981.index.js +0 -206
  173. package/dist/999.index.js +0 -117
  174. package/dist/9999.index.js +0 -1698
@@ -1,130 +0,0 @@
1
- export const id = 8025;
2
- export const ids = [8025];
3
- export const modules = {
4
-
5
- /***/ 18025:
6
- /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
-
8
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
- /* harmony export */ HO: () => (/* binding */ isValidHost),
10
- /* harmony export */ SK: () => (/* binding */ constantTimeEqual),
11
- /* harmony export */ Xv: () => (/* binding */ CSP_HEADER_VALUE),
12
- /* harmony export */ generateSessionToken: () => (/* binding */ generateSessionToken)
13
- /* harmony export */ });
14
- /* harmony import */ var node_crypto__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(77598);
15
- // security.js — Milestone 3, sub-project Server, increment 1.
16
- //
17
- // Security primitives for the `explore` loopback HTTP server: session-token
18
- // generation/comparison and Host-header validation (the T2 DNS-rebinding
19
- // defense — see docs/DATA_FLOW_EXPLORER_THREAT_MODEL.md). No node:http
20
- // usage here — this module is pure and independently unit-testable.
21
-
22
-
23
-
24
- /** 32 random bytes, hex-encoded (64 hex chars) — the per-session token. */
25
- function generateSessionToken() {
26
- return node_crypto__WEBPACK_IMPORTED_MODULE_0__.randomBytes(32).toString('hex');
27
- }
28
-
29
- /**
30
- * Constant-time string comparison. Wraps crypto.timingSafeEqual, which
31
- * THROWS on unequal-length buffers — guarded here the same way
32
- * posture/integrity.js's verifyLastScan guards its own HMAC comparison
33
- * (`stored.length !== expected.length`), which this function mirrors as
34
- * its template. Never throws; returns false on any malformed input.
35
- */
36
- function constantTimeEqual(a, b) {
37
- if (typeof a !== 'string' || typeof b !== 'string') return false;
38
- const bufA = Buffer.from(a, 'utf8');
39
- const bufB = Buffer.from(b, 'utf8');
40
- if (bufA.length !== bufB.length) return false;
41
- try {
42
- return node_crypto__WEBPACK_IMPORTED_MODULE_0__.timingSafeEqual(bufA, bufB);
43
- } catch {
44
- return false;
45
- }
46
- }
47
-
48
- // Loopback hostnames this server ever legitimately answers to. Anything
49
- // else in a Host header is either a stray/misconfigured client or a
50
- // DNS-rebinding attempt from a hostile page — reject it (T2).
51
- const LOOPBACK_HOSTS = new Set(['127.0.0.1', 'localhost', '::1']);
52
-
53
- /**
54
- * Validates a request's `Host` header against the port the server is
55
- * actually listening on. Accepts only `127.0.0.1`/`localhost`/`::1`
56
- * (`::1` written either bare or bracketed, `[::1]`), each carrying the
57
- * expected port explicitly — this is the ENTIRE T2 (DNS rebinding)
58
- * defense: a hostile page that points a fetch() at 127.0.0.1:<port> still
59
- * sends the ATTACKER'S origin's Host header value (its own hostname), not
60
- * "127.0.0.1", so this check rejects it regardless of same-origin policy
61
- * quirks in any particular browser.
62
- *
63
- * A bare host with no port suffix is accepted ONLY when expectedPort is
64
- * the default HTTP port (80) — browsers omit :80 for a default-port
65
- * http:// request. In practice this server always listens on a
66
- * non-default port, so that branch is effectively unreachable but is kept
67
- * for RFC-correctness rather than special-cased away.
68
- *
69
- * @param {string|undefined} hostHeader
70
- * @param {number} expectedPort
71
- * @returns {boolean}
72
- */
73
- function isValidHost(hostHeader, expectedPort) {
74
- if (typeof hostHeader !== 'string' || hostHeader.length === 0) return false;
75
- if (typeof expectedPort !== 'number' || !Number.isInteger(expectedPort) || expectedPort <= 0) return false;
76
-
77
- const host = hostHeader.trim();
78
- if (host.length !== hostHeader.length) return false; // reject leading/trailing whitespace outright
79
- if (/\s/.test(host)) return false; // no embedded whitespace/control chars in a well-formed Host header
80
-
81
- let hostname;
82
- let port = null;
83
-
84
- if (host.startsWith('[')) {
85
- // Bracketed IPv6 literal form: [::1] or [::1]:port
86
- const closeIdx = host.indexOf(']');
87
- if (closeIdx === -1) return false;
88
- hostname = host.slice(1, closeIdx); // strip brackets
89
- const rest = host.slice(closeIdx + 1);
90
- if (rest.length) {
91
- if (!rest.startsWith(':')) return false;
92
- const portStr = rest.slice(1);
93
- if (!/^\d+$/.test(portStr)) return false;
94
- port = Number(portStr);
95
- }
96
- } else {
97
- const parts = host.split(':');
98
- if (parts.length === 1) {
99
- hostname = parts[0];
100
- } else if (parts.length === 2) {
101
- hostname = parts[0];
102
- if (!/^\d+$/.test(parts[1])) return false;
103
- port = Number(parts[1]);
104
- } else {
105
- // More than one colon with no brackets: either a malformed header or
106
- // a bare (unbracketed) IPv6 literal, which is not valid Host syntax
107
- // (RFC 7230 §5.4 requires brackets for an IPv6 literal). Reject.
108
- return false;
109
- }
110
- }
111
-
112
- hostname = hostname.toLowerCase();
113
- if (!LOOPBACK_HOSTS.has(hostname)) return false;
114
-
115
- if (port === null) return expectedPort === 80;
116
- return port === expectedPort;
117
- }
118
-
119
- // This server serves JSON only in this increment (no HTML, no inline
120
- // script/style, no static assets) — `frontend/`'s own static assets are a
121
- // later increment's (Wire's) job, not S1's. `default-src 'none'` is
122
- // therefore the correct, maximally-restrictive policy: nothing this
123
- // server ever returns should load or execute ANY sub-resource. Revisit
124
- // only when a future increment starts serving HTML/JS itself.
125
- const CSP_HEADER_VALUE = "default-src 'none'; frame-ancestors 'none'";
126
-
127
-
128
- /***/ })
129
-
130
- };
@@ -1,248 +0,0 @@
1
- export const id = 8054;
2
- export const ids = [8054];
3
- export const modules = {
4
-
5
- /***/ 68054:
6
- /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
-
8
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
- /* harmony export */ verifyPatchNegative: () => (/* binding */ verifyPatchNegative)
10
- /* harmony export */ });
11
- /* harmony import */ var _assurance_identity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(91026);
12
- /* harmony import */ var _assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(99666);
13
- /* harmony import */ var _assurance_config_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(20622);
14
- /* harmony import */ var _replay_replay_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(30891);
15
- /* harmony import */ var _oracles_registry_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(45603);
16
- /* harmony import */ var _patch_promotion_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(58144);
17
- /* harmony import */ var _repair_records_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(41458);
18
- // Patch-negative verification (X-204).
19
- //
20
- // A re-scan that no longer fires proves the DETECTOR went quiet; a cosmetic edit can do that. A repair is `verified-fix` here
21
- // only when three things are shown, each by an executed oracle run in an equivalent disposable environment:
22
- //
23
- // 1. original-positive the original revision reproduces the exploit (oracle outcome: confirmed)
24
- // 2. patched-negative the patched revision no longer does, same oracle (oracle outcome: refuted)
25
- // 3. functional-regression declared legitimate behaviour is intact on the patched revision, with the same expectations
26
- // holding on the original first (a baseline), so a wrong expectation is reported rather than blamed on the patch.
27
- //
28
- // All four runs (the baseline is one) go through `replayManifest`, so each is pinned by commit, fixture hash, patch hash,
29
- // toolchain, oracle version and inputs, executes inside the trust boundary, and issues a verifier receipt. The result is then
30
- // handed to `promotePatch`, which re-derives the diff and revision from the proposal and refuses any receipt that does not
31
- // match them. `verified-fix` needs the promotion; nothing else grants it.
32
- //
33
- // A failure never degrades to a vague "not verified": it names the SPECIFIC step that is incomplete and a typed failure code:
34
- // original-not-reproduced the original did not reproduce under the oracle (nothing to fix, or the scenario is wrong)
35
- // patched-still-exploitable the exploit still works on the patched revision
36
- // patched-build-broken the patched revision did not load or its benign control failed
37
- // patched-negative-inconclusive the patched run decided nothing
38
- // functional-omitted no functional check was supplied
39
- // functional-baseline-invalid the declared expectations do not hold on the ORIGINAL revision
40
- // functional-regression-detected the patched revision behaves differently from the declared expectations
41
- // oracle-changed the oracle, its version or its inputs differ between the original and patched runs
42
- // revision-unbound no exact commit: a verdict cannot be tied to a revision
43
- // prerequisite-unmet a toolchain, feature or isolation prerequisite is missing; resumable where stated
44
- // environment-mismatch the runs were not in equivalent environments
45
- // promotion-refused the receipts do not match the exact proposed diff and revision
46
- //
47
- // The behaviour check is the functional-regression oracle by default. A requester may name `business-state` as `functional.oracleId`
48
- // (X-406, `invariants/repair.js`): the same two runs and the same expectation, with an authorized-workflow scenario as the declared
49
- // case, and `promotePatch` then requires the functional receipts to come from that oracle class instead.
50
- //
51
- // Scope, stated so no caller overclaims: the exploit scenario and the functional cases are the REQUESTER's; this verifies the
52
- // declared scenario and cases, not that the patch is correct elsewhere. Linux is not claimed (the oracle platform statements
53
- // stay `unverified`). Receipts are valid inside this process only (see patch-promotion.js).
54
-
55
-
56
-
57
-
58
-
59
-
60
-
61
-
62
- const PATCH_NEGATIVE_FEATURE = 'patch-negative-verification';
63
- const FUNCTIONAL_ORACLE = 'functional-regression';
64
- // The check that behaviour is preserved is normally the functional-regression oracle. A requester may name `business-state`
65
- // instead (X-406): the same two runs, the same expectation (refuted), with an authorized-workflow scenario as the declared case.
66
- const FUNCTIONAL_ORACLES = Object.freeze([FUNCTIONAL_ORACLE, 'business-state']);
67
-
68
- const STEPS = Object.freeze(['original-positive', 'patched-negative', 'functional-baseline', 'functional-regression']);
69
-
70
- const ROLE_OF_STEP = Object.freeze({ 'original-positive': 'original', 'patched-negative': 'patched', 'functional-baseline': 'functionalBaseline', 'functional-regression': 'functional' });
71
- const EXPECTED = Object.freeze({ 'original-positive': 'confirmed', 'patched-negative': 'refuted', 'functional-baseline': 'refuted', 'functional-regression': 'refuted' });
72
-
73
- const stepResult = (step, status, extra = {}) => ({ step, status, expected: EXPECTED[step], outcome: null, code: null, reason: null, recordId: null, receiptDigest: null, ...extra });
74
-
75
- function replayCode(run) {
76
- const first = (run.errors || [])[0];
77
- if (!first) return 'manifest-rejected';
78
- if (first.code === 'ORACLE_MISMATCH') return 'oracle-changed';
79
- if (first.code === 'HASH_MISMATCH') return 'content-hash-mismatch';
80
- return 'manifest-rejected';
81
- }
82
-
83
- function classify(step, run) {
84
- if (run.status === 'rejected') return { status: 'incomplete', code: replayCode(run), reason: (run.errors || []).map((e) => e.message).join('; ').slice(0, 300) || 'the replay manifest was rejected' };
85
- if (run.status === 'awaiting-prerequisites') {
86
- const resumable = (run.prerequisites || []).every((p) => p.resumable);
87
- return { status: 'incomplete', code: 'prerequisite-unmet', outcome: run.outcome ?? null, resumable, reason: `${(run.prerequisites || []).map((p) => `${p.kind} ${p.id} (${p.state})`).join('; ') || 'a prerequisite is unmet'}; nothing was executed${resumable ? ' (resumable)' : ''}` };
88
- }
89
- const outcome = run.outcome;
90
- const observed = run.receipt?.observed || {};
91
- // a business-state run reports its control flow under `preconditions`: a control flow that no longer works is a broken revision
92
- const loadBroken = observed.targetLoaded === false || observed.benignCompleted === false || observed.preconditions?.controlRan === false || observed.preconditions?.controlDurableEffect === false;
93
- if (outcome === 'error') return { status: 'incomplete', code: 'harness-error', reason: String(run.record?.reason || 'the oracle run failed').slice(0, 300), outcome };
94
- if (outcome === EXPECTED[step]) return { status: 'passed', code: null, reason: run.record?.reason ?? null, outcome };
95
- const reason = String(run.record?.reason || '').slice(0, 300);
96
- switch (step) {
97
- case 'original-positive':
98
- return { status: 'failed', code: 'original-not-reproduced', reason: `the original revision did not reproduce the exploit (outcome '${outcome}'): ${reason}`, outcome };
99
- case 'patched-negative':
100
- if (outcome === 'confirmed') return { status: 'failed', code: 'patched-still-exploitable', reason: `the exploit still works on the patched revision: ${reason}`, outcome };
101
- return loadBroken
102
- ? { status: 'failed', code: 'patched-build-broken', reason: `the patched revision did not load or its benign control failed: ${reason}`, outcome }
103
- : { status: 'failed', code: 'patched-negative-inconclusive', reason: `the patched run decided nothing (outcome '${outcome}'): ${reason}`, outcome };
104
- case 'functional-baseline':
105
- return { status: 'failed', code: 'functional-baseline-invalid', reason: `the declared functional expectations do not hold on the original revision (outcome '${outcome}'): ${reason}`, outcome };
106
- default:
107
- if (outcome === 'confirmed') return { status: 'failed', code: 'functional-regression-detected', reason: `the patched revision behaves differently from the declared expectations: ${reason}`, outcome };
108
- return loadBroken
109
- ? { status: 'failed', code: 'patched-build-broken', reason: `the patched revision did not load for the functional check: ${reason}`, outcome }
110
- : { status: 'failed', code: 'functional-inconclusive', reason: `the functional check decided nothing (outcome '${outcome}'): ${reason}`, outcome };
111
- }
112
- }
113
-
114
- function summaryOf(steps, verified, incomplete, code) {
115
- const label = (s) => ({ passed: 'PASS', failed: 'FAIL', incomplete: 'INCOMPLETE', 'not-run': 'not run' })[s.status];
116
- const lines = steps.map((s) => `${s.step}: ${label(s)}${s.code ? ` (${s.code})` : ''}${s.reason && s.status !== 'passed' ? ` - ${s.reason}` : ''}`);
117
- lines.push(verified
118
- ? 'verified-fix: the exploit reproduced on the original revision, did not reproduce on the patched revision, and the declared functional cases still hold. Only the declared scenario and cases were exercised.'
119
- : `NOT verified-fix: incomplete step '${incomplete}'${code ? ` (${code})` : ''}.`);
120
- return lines.join('\n');
121
- }
122
-
123
- /**
124
- * Run the three-part patch-negative verification for one proposed patch. Never throws.
125
- *
126
- * @param {object} req
127
- * @param {string} req.hypothesisId the finding's stable id
128
- * @param {string} req.commit exact revision the patch is proposed against (40 or 64 hex)
129
- * @param {object} req.original { files, entry, oracleId, inputs, budgets? } the exploit scenario on the original files
130
- * @param {object} req.patch { files } the proposed diff: the new content of each changed file
131
- * @param {object} [req.patched] { oracleId?, inputs?, entry? }: must equal the original's; anything else is `oracle-changed`
132
- * @param {object} [req.functional] { inputs, budgets? } for the functional-regression oracle; omitting it prevents verified-fix
133
- * @param {object} [req.pinnedOracle] { id, version, logicDigest } the oracle identity the requester recorded earlier
134
- * @param {object[]} [req.ledger] earlier repair records to extend
135
- * @param {object} [o] { config, runOptions } config is the assurance config; runOptions go to the oracle runner (test seams)
136
- */
137
- async function verifyPatchNegative(req, o = {}) {
138
- const config = o.config || (0,_assurance_config_js__WEBPACK_IMPORTED_MODULE_2__.resolveAssuranceConfig)({ env: process.env });
139
- const gate = (0,_assurance_config_js__WEBPACK_IMPORTED_MODULE_2__/* .featureStatus */ .FX)(config, PATCH_NEGATIVE_FEATURE);
140
- const steps = STEPS.map((s) => stepResult(s, 'not-run', { reason: 'not reached' }));
141
- const base = {
142
- status: 'not-verified-fix', verifiedFix: false, incompleteStep: null, failureCode: null, reason: null, steps,
143
- patchDigest: null, promotion: null, receipts: null, records: {}, verificationRecord: null, repairRecords: Array.isArray(req?.ledger) ? req.ledger : [], summary: '',
144
- };
145
- if (gate.status !== 'ok') {
146
- return { ...base, status: 'disabled', incompleteStep: 'feature-gate', failureCode: gate.code || 'disabled', reason: `${PATCH_NEGATIVE_FEATURE} is not available: ${gate.reason}`, summary: `patch-negative verification did not run: ${gate.reason}` };
147
- }
148
- const refuse = (step, code, reason, extra = {}) => {
149
- const rejected = req && (0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(req.patch) && (0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(req.patch.files) && Object.keys(req.patch.files).length && typeof req.hypothesisId === 'string'
150
- ? ledgerFor(base.repairRecords, req, base.patchDigest ?? (0,_assurance_identity_js__WEBPACK_IMPORTED_MODULE_0__/* .digestOf */ .ol)(req.patch.files), { rejected: { step, code, reason } }) : { records: base.repairRecords };
151
- return { ...base, ...extra, patchDigest: req?.patch?.files ? (0,_assurance_identity_js__WEBPACK_IMPORTED_MODULE_0__/* .digestOf */ .ol)(req.patch.files) : null, incompleteStep: step, failureCode: code, reason, repairRecords: rejected.records, summary: summaryOf(steps, false, step, code) };
152
- };
153
-
154
- // ---- shape and preconditions that need no execution
155
- const patchFiles = req?.patch?.files;
156
- if (!(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(req) || typeof req.hypothesisId !== 'string' || !req.hypothesisId || !(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(req.original) || !(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(req.original.files)
157
- || typeof req.original.entry !== 'string' || typeof req.original.oracleId !== 'string' || !(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(req.original.inputs)
158
- || !(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(patchFiles) || Object.keys(patchFiles).length === 0) {
159
- return refuse('input-validation', 'bad-request', 'a request needs a hypothesis id, the original files, entry, oracle and inputs, and a non-empty patch');
160
- }
161
- if (!(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isCommit */ .WM)(req.commit)) return refuse('input-validation', 'revision-unbound', 'no exact commit was given: a verdict cannot be tied to a revision');
162
- const original = req.original;
163
- const oracle = _oracles_registry_js__WEBPACK_IMPORTED_MODULE_4__.getOracle(original.oracleId);
164
- if (!oracle) return refuse('input-validation', 'unknown-oracle', `the exploit oracle '${String(original.oracleId).slice(0, 60)}' is not registered`);
165
- if (oracle.id === FUNCTIONAL_ORACLE) return refuse('input-validation', 'bad-request', 'the exploit oracle cannot be the functional-regression oracle');
166
- const patched = (0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(req.patched) ? req.patched : {};
167
- if ((patched.oracleId !== undefined && patched.oracleId !== original.oracleId) || (patched.inputs !== undefined && (0,_assurance_identity_js__WEBPACK_IMPORTED_MODULE_0__/* .digestOf */ .ol)(patched.inputs) !== (0,_assurance_identity_js__WEBPACK_IMPORTED_MODULE_0__/* .digestOf */ .ol)(original.inputs)) || (patched.entry !== undefined && patched.entry !== original.entry)) {
168
- return refuse('oracle-consistency', 'oracle-changed', 'the patched run names a different oracle, entry or inputs than the original run: a changed oracle cannot show the exploit is closed');
169
- }
170
- const pin = req.pinnedOracle;
171
- if (pin !== undefined && (!(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(pin) || pin.id !== oracle.id || pin.version !== oracle.version || pin.logicDigest !== oracle.logicDigest)) {
172
- return refuse('oracle-consistency', 'oracle-changed', 'the oracle differs from the identity the requester pinned (id, version or logic digest)');
173
- }
174
- const fn = req.functional;
175
- if (!(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(fn) || !(0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isPlainObject */ .Qd)(fn.inputs)) {
176
- return refuse('functional-regression', 'functional-omitted', 'no functional regression check was supplied: a patch that was never checked for behaviour cannot be a verified fix');
177
- }
178
- const functionalOracle = fn.oracleId === undefined ? FUNCTIONAL_ORACLE : fn.oracleId;
179
- if (!FUNCTIONAL_ORACLES.includes(functionalOracle)) {
180
- return refuse('input-validation', 'bad-request', `the functional check oracle must be one of ${FUNCTIONAL_ORACLES.join(', ')}`);
181
- }
182
-
183
- const patchDigest = (0,_assurance_identity_js__WEBPACK_IMPORTED_MODULE_0__/* .digestOf */ .ol)(patchFiles);
184
- base.patchDigest = patchDigest;
185
- let ledger = ledgerFor(base.repairRecords, req, patchDigest, {}).records; // proposed
186
- const common = { hypothesisId: req.hypothesisId, commit: req.commit };
187
- const plan = [
188
- ['original-positive', { oracleId: original.oracleId, entry: original.entry, inputs: original.inputs, patchFiles: null, budgets: original.budgets }],
189
- ['patched-negative', { oracleId: original.oracleId, entry: original.entry, inputs: original.inputs, patchFiles, budgets: original.budgets }],
190
- ['functional-baseline', { oracleId: functionalOracle, entry: original.entry, inputs: fn.inputs, patchFiles: null, budgets: fn.budgets }],
191
- ['functional-regression', { oracleId: functionalOracle, entry: original.entry, inputs: fn.inputs, patchFiles, budgets: fn.budgets }],
192
- ];
193
- const runs = {};
194
- let failed = null;
195
- for (const [i, [step, spec]] of plan.entries()) {
196
- if (failed) continue;
197
- let run;
198
- try {
199
- const manifest = (0,_replay_replay_js__WEBPACK_IMPORTED_MODULE_3__/* .createReplayManifest */ .$A)({ ...common, fixtureFiles: original.files, patchFiles: spec.patchFiles, oracleId: spec.oracleId, entry: spec.entry, inputs: spec.inputs, budgets: spec.budgets || {}, expected: { outcome: EXPECTED[step] } });
200
- run = await (0,_replay_replay_js__WEBPACK_IMPORTED_MODULE_3__/* .replayManifest */ .TY)({ manifest, fixtureFiles: original.files, patchFiles: spec.patchFiles }, { config: o.config || config, runOptions: o.runOptions });
201
- } catch (e) {
202
- run = { status: 'rejected', errors: [{ code: 'RUN_FAILED', message: String(e?.message || e).slice(0, 200) }] };
203
- }
204
- const c = classify(step, run);
205
- steps[i] = stepResult(step, c.status, { ...c, recordId: run.record?.id ?? null, receiptDigest: run.receipt?.receiptDigest ?? null });
206
- if (run.executed && run.receipt) runs[ROLE_OF_STEP[step]] = run;
207
- if (c.status !== 'passed') failed = { step, ...c };
208
- }
209
- base.records = Object.fromEntries(Object.entries(runs).map(([k, r]) => [k, r.record]));
210
- if (failed) {
211
- ledger = ledgerFor(ledger, req, patchDigest, { rejected: { step: failed.step, code: failed.code, reason: failed.reason } }).records;
212
- const original0 = base.records.original ? (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .withRepairStatus */ .m$)(base.records.original, (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .verificationRepairFor */ .Kf)(ledger, req.hypothesisId, patchDigest)) : null;
213
- return { ...base, incompleteStep: failed.step, failureCode: failed.code, reason: failed.reason, resumable: failed.resumable ?? false, repairRecords: ledger, verificationRecord: original0, summary: summaryOf(steps, false, failed.step, failed.code) };
214
- }
215
-
216
- // ---- the receipts must match the exact proposed diff and revision before anything is promoted
217
- const receipts = Object.fromEntries(Object.entries(runs).map(([k, r]) => [k, r.receipt]));
218
- const promotion = (0,_patch_promotion_js__WEBPACK_IMPORTED_MODULE_5__/* .promotePatch */ .l)({ proposal: { hypothesisId: req.hypothesisId, revision: req.commit, originalFiles: original.files, patchFiles, functionalOracle }, receipts });
219
- if (!promotion.ok) {
220
- const envBroken = promotion.reasons.some((r) => r.code === 'environment-mismatch');
221
- const code = envBroken ? 'environment-mismatch' : promotion.reasons.some((r) => r.code === 'oracle-changed') ? 'oracle-changed' : 'promotion-refused';
222
- const step = envBroken ? 'environment-equivalence' : code === 'oracle-changed' ? 'oracle-consistency' : 'promotion';
223
- const reason = promotion.reasons.map((r) => r.message).join('; ').slice(0, 400);
224
- ledger = ledgerFor(ledger, req, patchDigest, { rejected: { step, code, reason } }).records;
225
- return { ...base, promotion, incompleteStep: step, failureCode: code, reason, repairRecords: ledger, verificationRecord: base.records.original ? (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .withRepairStatus */ .m$)(base.records.original, (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .verificationRepairFor */ .Kf)(ledger, req.hypothesisId, patchDigest)) : null, summary: summaryOf(steps, false, step, code) };
226
- }
227
- const promoted = (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .recordPromotion */ .Zw)(ledger, promotion, { verificationRecordId: base.records.patched?.id ?? null });
228
- ledger = promoted.records;
229
- const verificationRecord = (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .withRepairStatus */ .m$)(base.records.original, (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .verificationRepairFor */ .Kf)(ledger, req.hypothesisId, patchDigest, base.records.patched?.id));
230
- return {
231
- ...base, status: 'verified-fix', verifiedFix: true, promotion, receipts, repairRecords: ledger, verificationRecord,
232
- reason: 'verified', summary: summaryOf(steps, true, null, null),
233
- };
234
- }
235
-
236
- // The ledger for one verification: always starts with a `proposed` record, and records a rejection when verification stopped.
237
- function ledgerFor(records, req, patchDigest, { rejected } = {}) {
238
- let list = Array.isArray(records) ? records : [];
239
- const fields = { hypothesisId: req.hypothesisId, revision: (0,_assurance_schema_kit_js__WEBPACK_IMPORTED_MODULE_1__/* .isCommit */ .WM)(req.commit) ? req.commit : null, diffDigest: patchDigest };
240
- if (!list.some((r) => r.hypothesisId === fields.hypothesisId && r.diffDigest === patchDigest)) list = (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .appendRepairRecord */ .f7)(list, { ...fields, kind: 'proposed', reason: 'a patch was proposed for verification' }).records;
241
- if (rejected) list = (0,_repair_records_js__WEBPACK_IMPORTED_MODULE_6__/* .appendRepairRecord */ .f7)(list, { ...fields, kind: 'rejected', step: rejected.step, reason: `${rejected.code}: ${String(rejected.reason || '').slice(0, 300)}` }).records;
242
- return { records: list };
243
- }
244
-
245
-
246
- /***/ })
247
-
248
- };