@clear-capabilities/agentic-security-scanner 0.145.0 → 0.147.5

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 (195) hide show
  1. package/CHANGELOG.md +266 -0
  2. package/bin/agentic-security.js +3508 -69
  3. package/dist/1122.index.js +779 -0
  4. package/dist/{301.index.js → 1301.index.js} +2 -2
  5. package/dist/1379.index.js +591 -0
  6. package/dist/{444.index.js → 1444.index.js} +2 -2
  7. package/dist/{660.index.js → 1660.index.js} +2 -2
  8. package/dist/{700.index.js → 1700.index.js} +2 -2
  9. package/dist/{905.index.js → 1905.index.js} +3 -3
  10. package/dist/{920.index.js → 1920.index.js} +3 -3
  11. package/dist/{238.index.js → 2238.index.js} +3 -3
  12. package/dist/{271.index.js → 2271.index.js} +2 -2
  13. package/dist/{985.index.js → 2376.index.js} +1260 -340
  14. package/dist/2432.index.js +793 -0
  15. package/dist/2659.index.js +93 -0
  16. package/dist/{826.index.js → 2826.index.js} +2 -2
  17. package/dist/{830.index.js → 2830.index.js} +2 -2
  18. package/dist/2923.index.js +298 -0
  19. package/dist/{1.index.js → 3001.index.js} +5 -5
  20. package/dist/{117.index.js → 3117.index.js} +3 -3
  21. package/dist/3180.index.js +379 -0
  22. package/dist/3276.index.js +117 -0
  23. package/dist/{415.index.js → 3415.index.js} +2 -2
  24. package/dist/{499.index.js → 3499.index.js} +2 -2
  25. package/dist/3518.index.js +450 -0
  26. package/dist/{526.index.js → 3526.index.js} +5 -5
  27. package/dist/{736.index.js → 3736.index.js} +4 -4
  28. package/dist/{839.index.js → 3839.index.js} +4 -4
  29. package/dist/{113.index.js → 4113.index.js} +5 -5
  30. package/dist/{265.index.js → 4265.index.js} +2 -2
  31. package/dist/{384.index.js → 4384.index.js} +3 -3
  32. package/dist/4547.index.js +268 -0
  33. package/dist/4863.index.js +422 -0
  34. package/dist/{970.index.js → 4970.index.js} +2 -2
  35. package/dist/5051.index.js +841 -0
  36. package/dist/{144.index.js → 5144.index.js} +5 -5
  37. package/dist/{333.index.js → 5333.index.js} +3 -3
  38. package/dist/5343.index.js +185 -0
  39. package/dist/5350.index.js +866 -0
  40. package/dist/5561.index.js +436 -0
  41. package/dist/{637.index.js → 5637.index.js} +3 -3
  42. package/dist/{449.index.js → 5830.index.js} +2 -2
  43. package/dist/6626.index.js +532 -0
  44. package/dist/6662.index.js +297 -0
  45. package/dist/{675.index.js → 6675.index.js} +5 -5
  46. package/dist/{730.index.js → 6730.index.js} +6 -6
  47. package/dist/6829.index.js +225 -0
  48. package/dist/6944.index.js +130 -0
  49. package/dist/{178.index.js → 7178.index.js} +3 -3
  50. package/dist/{227.index.js → 7227.index.js} +2 -2
  51. package/dist/7310.index.js +520 -0
  52. package/dist/{552.index.js → 7552.index.js} +4 -4
  53. package/dist/7709.index.js +78 -0
  54. package/dist/8218.index.js +160 -0
  55. package/dist/{476.index.js → 8476.index.js} +4 -4
  56. package/dist/{513.index.js → 8513.index.js} +5 -5
  57. package/dist/{520.index.js → 8520.index.js} +2 -2
  58. package/dist/{718.index.js → 8718.index.js} +2 -2
  59. package/dist/{752.index.js → 8752.index.js} +2 -2
  60. package/dist/8846.index.js +100 -0
  61. package/dist/{435.index.js → 9091.index.js} +560 -189
  62. package/dist/{207.index.js → 9207.index.js} +2 -2
  63. package/dist/{220.index.js → 9220.index.js} +2 -2
  64. package/dist/9390.index.js +163 -0
  65. package/dist/{503.index.js → 9503.index.js} +2 -2
  66. package/dist/{801.index.js → 9801.index.js} +2 -2
  67. package/dist/{824.index.js → 9824.index.js} +2 -2
  68. package/dist/agentic-security.mjs +16 -16
  69. package/dist/agentic-security.mjs.sha256 +1 -1
  70. package/dist/compliance-frameworks/hipaa-security-rule.json +3 -2
  71. package/dist/frontend/index.html +21 -0
  72. package/dist/frontend/src/app.js +176 -0
  73. package/dist/frontend/src/components/evidence-inspector.js +141 -0
  74. package/dist/frontend/src/components/filter-rail.js +119 -0
  75. package/dist/frontend/src/components/query-bar.js +126 -0
  76. package/dist/frontend/src/data/flagship-graph.js +1460 -0
  77. package/dist/frontend/src/export-entry.js +36 -0
  78. package/dist/frontend/src/lib/api-client.js +92 -0
  79. package/dist/frontend/src/lib/contrast.js +34 -0
  80. package/dist/frontend/src/lib/dom.js +24 -0
  81. package/dist/frontend/src/lib/escape-html.js +16 -0
  82. package/dist/frontend/src/lib/flow-path.js +40 -0
  83. package/dist/frontend/src/lib/focus-controls.js +149 -0
  84. package/dist/frontend/src/lib/protection-visual.js +46 -0
  85. package/dist/frontend/src/lib/query-language.js +240 -0
  86. package/dist/frontend/src/lib/row-filters.js +43 -0
  87. package/dist/frontend/src/lib/state.js +84 -0
  88. package/dist/frontend/src/main.js +83 -0
  89. package/dist/frontend/src/shell.js +184 -0
  90. package/dist/frontend/src/views/architecture-view.js +798 -0
  91. package/dist/frontend/src/views/inventory-view.js +292 -0
  92. package/dist/frontend/src/views/privacy-view.js +172 -0
  93. package/dist/frontend/src/views/trace-view.js +206 -0
  94. package/dist/frontend/styles/architecture-view.css +93 -0
  95. package/dist/frontend/styles/filter-rail.css +34 -0
  96. package/dist/frontend/styles/inspector.css +69 -0
  97. package/dist/frontend/styles/inventory-view.css +74 -0
  98. package/dist/frontend/styles/privacy-view.css +86 -0
  99. package/dist/frontend/styles/query-bar.css +107 -0
  100. package/dist/frontend/styles/shell.css +155 -0
  101. package/dist/frontend/styles/tokens.css +128 -0
  102. package/dist/frontend/styles/trace-view.css +95 -0
  103. package/package.json +13 -6
  104. package/src/dataflow/CLAUDE.md +1 -1
  105. package/src/dataflow/catalog.js +42 -0
  106. package/src/dataflow/orm-write-catalog.js +175 -0
  107. package/src/engine.js +92 -1
  108. package/src/ir/CLAUDE.md +1 -0
  109. package/src/ir/chrome-probe.mjs +150 -0
  110. package/src/ir/parser-js.js +94 -7
  111. package/src/lineage/CLAUDE.md +1203 -0
  112. package/src/lineage/DESIGN_DESTINATION_RESOLVER.md +156 -0
  113. package/src/lineage/DESIGN_GRAPH_BUILDER.md +938 -0
  114. package/src/lineage/DESIGN_HANDLING_ANALYZER.md +355 -0
  115. package/src/lineage/DESIGN_INTRAPROCEDURAL.md +628 -0
  116. package/src/lineage/DESIGN_PATH_PROVENANCE.md +3451 -0
  117. package/src/lineage/DESIGN_QUEUE_DETAIL.md +120 -0
  118. package/src/lineage/DESIGN_REGISTRIES.md +880 -0
  119. package/src/lineage/DESIGN_STORE_DETAIL.md +143 -0
  120. package/src/lineage/DESIGN_TRANSIT_PROTECTION.md +245 -0
  121. package/src/lineage/classification.js +56 -0
  122. package/src/lineage/coverage.js +658 -0
  123. package/src/lineage/cross-repo-link.js +107 -0
  124. package/src/lineage/dataflow-graph.schema.json +184 -0
  125. package/src/lineage/decision-story.js +206 -0
  126. package/src/lineage/drift-policy.js +279 -0
  127. package/src/lineage/driver.js +135 -0
  128. package/src/lineage/engine.js +992 -0
  129. package/src/lineage/export-briefing.js +628 -0
  130. package/src/lineage/export-csv.js +62 -0
  131. package/src/lineage/export-json.js +238 -0
  132. package/src/lineage/export-privacy.js +258 -0
  133. package/src/lineage/federation-loader.js +111 -0
  134. package/src/lineage/field-identity.js +78 -0
  135. package/src/lineage/fixtures/build-flagship-fixture.mjs +272 -0
  136. package/src/lineage/fixtures/flagship-graph.json +1453 -0
  137. package/src/lineage/flow-grade.js +221 -0
  138. package/src/lineage/governance-edit.js +169 -0
  139. package/src/lineage/graph-builder.js +1114 -0
  140. package/src/lineage/graph-diff.js +431 -0
  141. package/src/lineage/graph-snapshot.js +180 -0
  142. package/src/lineage/handling-analyzer.js +168 -0
  143. package/src/lineage/ids.js +349 -0
  144. package/src/lineage/impact-assessment.js +76 -0
  145. package/src/lineage/impact-engine.js +268 -0
  146. package/src/lineage/index.js +281 -0
  147. package/src/lineage/language-coverage-tiers.js +58 -0
  148. package/src/lineage/obligation-mapping.js +126 -0
  149. package/src/lineage/obligation-predicates.js +235 -0
  150. package/src/lineage/observation-adapters.js +282 -0
  151. package/src/lineage/observation-correlation.js +622 -0
  152. package/src/lineage/observation-store.js +497 -0
  153. package/src/lineage/path-query.js +410 -0
  154. package/src/lineage/path-store.js +400 -0
  155. package/src/lineage/protection.js +53 -0
  156. package/src/lineage/recipient-profile.js +192 -0
  157. package/src/lineage/recipient-registry.js +394 -0
  158. package/src/lineage/redact-graph.js +224 -0
  159. package/src/lineage/remediation.js +417 -0
  160. package/src/lineage/resolve-destination.js +91 -0
  161. package/src/lineage/runtime-observation.js +464 -0
  162. package/src/lineage/scenario-diff.js +84 -0
  163. package/src/lineage/scenario-engine.js +251 -0
  164. package/src/lineage/scenario.js +101 -0
  165. package/src/lineage/schema.js +167 -0
  166. package/src/lineage/sink-registry.js +427 -0
  167. package/src/lineage/source-registry.js +357 -0
  168. package/src/lineage/source-seeding.js +212 -0
  169. package/src/lineage/summaries.js +590 -0
  170. package/src/lineage/transform-catalog.js +397 -0
  171. package/src/lineage/transit-protection.js +150 -0
  172. package/src/lineage/validate.js +285 -0
  173. package/src/mcp/CLAUDE.md +7 -1
  174. package/src/mcp/dataflow-tools.js +160 -0
  175. package/src/mcp/server.js +1 -1
  176. package/src/mcp/tools.js +2 -1
  177. package/src/pipeline/scan-health.js +19 -1
  178. package/src/posture/CLAUDE.md +19 -0
  179. package/src/posture/artifact-registry.js +52 -0
  180. package/src/posture/auditor-walkthrough.js +76 -0
  181. package/src/posture/compliance-frameworks/hipaa-security-rule.json +3 -2
  182. package/src/posture/obligation-evidence-pack.js +202 -0
  183. package/src/posture/remediation-ledger.js +337 -0
  184. package/src/server/CLAUDE.md +47 -0
  185. package/src/server/graph-loader.js +141 -0
  186. package/src/server/http-server.js +325 -0
  187. package/src/server/routes.js +129 -0
  188. package/src/server/security.js +111 -0
  189. package/src/server/static-assets.js +144 -0
  190. package/src/shared/frontend-root.js +52 -0
  191. package/dist/11.index.js +0 -353
  192. package/dist/259.index.js +0 -975
  193. package/dist/317.index.js +0 -300
  194. package/dist/609.index.js +0 -741
  195. package/dist/838.index.js +0 -152
package/dist/317.index.js DELETED
@@ -1,300 +0,0 @@
1
- export const id = 317;
2
- export const ids = [317];
3
- export const modules = {
4
-
5
- /***/ 8317:
6
- /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
-
8
- /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9
- /* harmony export */ buildEvidenceBundle: () => (/* binding */ buildEvidenceBundle),
10
- /* harmony export */ ensureKeyPair: () => (/* binding */ ensureKeyPair),
11
- /* harmony export */ keyPaths: () => (/* binding */ keyPaths),
12
- /* harmony export */ signEvidenceBundle: () => (/* binding */ signEvidenceBundle),
13
- /* harmony export */ verifyEvidenceBundle: () => (/* binding */ verifyEvidenceBundle)
14
- /* harmony export */ });
15
- /* unused harmony exports BUNDLE_SCHEMA, canonicalBytes, canonicalJson */
16
- /* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(3024);
17
- /* harmony import */ var node_os__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8161);
18
- /* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6760);
19
- /* harmony import */ var node_crypto__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(7598);
20
- // Per-finding evidence bundles, signed so a THIRD PARTY can verify them.
21
- // PRD Phase 2 / D2.
22
- //
23
- // WHAT WAS MISSING
24
- // ----------------
25
- // `attestation.js` already turns a run into a checkable digest, and it is
26
- // explicit about its own ceiling: the signature is a per-install SYMMETRIC HMAC,
27
- // so it is "tamper-evidence for the operator, not third-party non-repudiation."
28
- // Anyone who can verify it can also forge it. That is fine for detecting local
29
- // corruption and useless for handing a finding to somebody else.
30
- //
31
- // This module closes that gap for the artefact that actually travels: a single
32
- // finding plus the evidence behind it. A buyer, an auditor, or a downstream
33
- // consumer can check the bundle with the PUBLIC key alone, having never had
34
- // access to ours.
35
- //
36
- // WHY A SEPARATE MODULE RATHER THAN EXTENDING attestation.js
37
- // ----------------------------------------------------------
38
- // They answer different questions and must not be conflated. A run attestation
39
- // says "this set of findings came from this engine, ruleset and bundle". An
40
- // evidence bundle says "THIS finding is backed by THIS evidence, and here is
41
- // proof the claim was not edited after the fact." One is about reproducibility,
42
- // the other about portability. Merging them would produce an artefact that is
43
- // worse at both.
44
- //
45
- // WHAT A BUNDLE PROVES, AND WHAT IT DOES NOT
46
- // -------------------------------------------
47
- // PROVES — the bundle's contents are exactly what the holder of the signing key
48
- // attested, unmodified. Nothing in it has been added, removed, or edited since.
49
- //
50
- // DOES NOT PROVE — that the finding is real. A signature is an integrity claim,
51
- // never a correctness claim. An `unproven` finding in a signed bundle is still
52
- // an unproven finding; the signature only stops someone silently upgrading the
53
- // word `unproven` to `execution-proven` in transit. Both statements are carried
54
- // INSIDE the bundle so they travel with it and cannot be dropped by a
55
- // summariser.
56
- //
57
- // The evidence chain is deliberately the honest one this engine already
58
- // computes: the proof tier, what the sandbox observed, which backend ran it, the
59
- // taint path if there is one. A bundle for a regex finding says so plainly
60
- // rather than dressing it up.
61
-
62
-
63
-
64
-
65
-
66
-
67
- const BUNDLE_SCHEMA = 'agentic-security/finding-evidence@1';
68
-
69
- /** Where the Ed25519 signing key lives. Mirrors integrity.js's key handling. */
70
- function keyDir() {
71
- const xdg = process.env.XDG_CONFIG_HOME || node_path__WEBPACK_IMPORTED_MODULE_2__.join(node_os__WEBPACK_IMPORTED_MODULE_1__.homedir(), '.config');
72
- return node_path__WEBPACK_IMPORTED_MODULE_2__.join(xdg, 'agentic-security');
73
- }
74
- const PRIVATE_KEY_FILE = 'attest-key.pem';
75
- const PUBLIC_KEY_FILE = 'attest-key.pub.pem';
76
-
77
- function keyPaths(dir = keyDir()) {
78
- return {
79
- privateKey: node_path__WEBPACK_IMPORTED_MODULE_2__.join(dir, PRIVATE_KEY_FILE),
80
- publicKey: node_path__WEBPACK_IMPORTED_MODULE_2__.join(dir, PUBLIC_KEY_FILE),
81
- };
82
- }
83
-
84
- /**
85
- * Load the signing key pair, generating one on first use.
86
- *
87
- * Ed25519 from node:crypto — no new dependency, and deliberately not a
88
- * transparency-log scheme: those need a network round trip, and this project
89
- * does not make runtime cloud calls. A log-backed option can layer on later
90
- * without changing the bundle format.
91
- */
92
- function ensureKeyPair(dir = keyDir()) {
93
- const p = keyPaths(dir);
94
-
95
- // NO existsSync-then-read. This project's own scanner flagged the first
96
- // version of this function for TOCTOU (CWE-367) and it was right: between an
97
- // existence check and the read, an attacker who can write this directory can
98
- // swap the file, and the thing being swapped is a SIGNING KEY. Winning that
99
- // race means we sign with a key the attacker controls, which defeats the
100
- // entire point of the module. Read first and treat absence as the exceptional
101
- // case — there is then no window between the check and the use, because there
102
- // is no check.
103
- try {
104
- const privateKeyPem = node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync(p.privateKey, 'utf8');
105
- const publicKeyPem = node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync(p.publicKey, 'utf8');
106
- if (privateKeyPem && publicKeyPem) {
107
- return { privateKeyPem, publicKeyPem, created: false, ...p };
108
- }
109
- } catch { /* missing or unreadable — fall through and generate */ }
110
-
111
- const { privateKey, publicKey } = node_crypto__WEBPACK_IMPORTED_MODULE_3__.generateKeyPairSync('ed25519');
112
- const privateKeyPem = privateKey.export({ type: 'pkcs8', format: 'pem' });
113
- const publicKeyPem = publicKey.export({ type: 'spki', format: 'pem' });
114
- node_fs__WEBPACK_IMPORTED_MODULE_0__.mkdirSync(dir, { recursive: true, mode: 0o700 });
115
-
116
- // `wx` — exclusive create. If another process generated a key between our
117
- // failed read and this write, we must NOT clobber it: every bundle already
118
- // signed with that key would silently stop verifying. On collision, re-read
119
- // and use the winner's key.
120
- try {
121
- node_fs__WEBPACK_IMPORTED_MODULE_0__.writeFileSync(p.privateKey, privateKeyPem, { mode: 0o600, flag: 'wx' });
122
- node_fs__WEBPACK_IMPORTED_MODULE_0__.writeFileSync(p.publicKey, publicKeyPem, { mode: 0o644, flag: 'w' });
123
- return { privateKeyPem, publicKeyPem, created: true, ...p };
124
- } catch (e) {
125
- if (e.code !== 'EEXIST') throw e;
126
- // We lost the race on the private key — someone else's 'wx' won.
127
- // Their public-key write follows immediately after their private-key
128
- // write but is not itself atomic with it, so it may not have landed
129
- // yet: a bare read here would throw an uncaught ENOENT on a genuinely
130
- // transient state, not a real error. Retry briefly rather than crash.
131
- const sleepBuf = new Int32Array(new SharedArrayBuffer(4));
132
- for (let attempt = 0; ; attempt++) {
133
- try {
134
- return {
135
- privateKeyPem: node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync(p.privateKey, 'utf8'),
136
- publicKeyPem: node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync(p.publicKey, 'utf8'),
137
- created: false,
138
- ...p,
139
- };
140
- } catch (readErr) {
141
- if (readErr.code !== 'ENOENT' || attempt >= 50) throw readErr;
142
- Atomics.wait(sleepBuf, 0, 0, 10); // 10ms; ~500ms total budget
143
- }
144
- }
145
- }
146
- }
147
-
148
- /**
149
- * Canonical bytes for signing.
150
- *
151
- * An ALLOWLIST, exactly as attestation.js canonicalises: a field that is not
152
- * named here is not signed, so a future addition cannot silently enter the
153
- * signed surface. Sorted keys, so serialisation order cannot change the
154
- * signature.
155
- */
156
- function canonicalBytes(bundle) {
157
- const signed = {
158
- schema: bundle.schema,
159
- finding: bundle.finding,
160
- evidence: bundle.evidence,
161
- engine: bundle.engine,
162
- proves: bundle.proves,
163
- doesNotProve: bundle.doesNotProve,
164
- };
165
- return Buffer.from(canonicalJson(signed), 'utf8');
166
- }
167
-
168
- /**
169
- * Deterministic JSON: keys sorted at EVERY level, arrays order-preserving.
170
- *
171
- * Written by hand rather than using JSON.stringify's replacer argument, and the
172
- * reason matters. The first version of this function did
173
- * `JSON.stringify(signed, Object.keys(signed).sort())`, believing the array
174
- * argument was a top-level field allowlist. It is not — a replacer ARRAY is a
175
- * key filter applied at every nesting depth, so every nested object serialised
176
- * as `{}` and the signature covered nothing but the two prose strings. A bundle
177
- * whose severity was edited from `high` to `critical` verified as authentic.
178
- *
179
- * That is the worst possible failure for this module: a security feature that
180
- * appears to work, produces a valid-looking signature, and protects nothing. It
181
- * was caught by tampering with a bundle and expecting verification to fail —
182
- * which is why the tamper cases in the test file are not optional extras.
183
- */
184
- function canonicalJson(value) {
185
- if (value === null || typeof value !== 'object') return JSON.stringify(value ?? null);
186
- if (Array.isArray(value)) return `[${value.map(canonicalJson).join(',')}]`;
187
- const keys = Object.keys(value).sort();
188
- return `{${keys.map(k => `${JSON.stringify(k)}:${canonicalJson(value[k])}`).join(',')}}`;
189
- }
190
-
191
- const PROVES =
192
- 'The contents of this bundle are exactly what the signer attested, unmodified.';
193
- const DOES_NOT_PROVE =
194
- 'That the finding is real. A signature is an integrity claim, never a correctness ' +
195
- 'claim — read `evidence.proofTier` for how well-supported the finding actually is. ' +
196
- 'An unproven finding in a signed bundle is still an unproven finding.';
197
-
198
- /**
199
- * Build an unsigned bundle from a finding.
200
- *
201
- * Everything here is copied from what the engine already computed. Nothing is
202
- * inferred, and a missing field stays missing rather than being defaulted into
203
- * something more confident-looking than the truth.
204
- */
205
- function buildEvidenceBundle(finding, { engineVersion, rulesetVersion, bundleSha, commit } = {}) {
206
- if (!finding || typeof finding !== 'object') return null;
207
- return {
208
- schema: BUNDLE_SCHEMA,
209
- finding: {
210
- id: finding.id ?? null,
211
- stableId: finding.stableId ?? null,
212
- severity: finding.severity ?? null,
213
- file: finding.file ?? null,
214
- line: finding.line ?? null,
215
- vuln: finding.vuln ?? null,
216
- cwe: finding.cwe ?? null,
217
- family: finding.family ?? null,
218
- parser: finding.parser ?? null,
219
- },
220
- evidence: {
221
- // The honest chain, in the vocabulary the engine already uses.
222
- proofTier: finding.proofTier ?? null,
223
- proofEvidence: finding.proofEvidence ?? null,
224
- confidence: finding.confidence ?? null,
225
- exploitability: finding.exploitability ?? null,
226
- unreachable: finding.unreachable ?? null,
227
- // Present only for the layers that produce them; absent means absent.
228
- taintPath: finding.pathSteps ?? finding.exampleFlows ?? null,
229
- discovery: finding.discovery ?? null,
230
- },
231
- engine: {
232
- engineVersion: engineVersion ?? null,
233
- rulesetVersion: rulesetVersion ?? null,
234
- bundleSha: bundleSha ?? null,
235
- commit: commit ?? null,
236
- },
237
- proves: PROVES,
238
- doesNotProve: DOES_NOT_PROVE,
239
- };
240
- }
241
-
242
- /** Sign a bundle. Returns a new object; the input is not mutated. */
243
- function signEvidenceBundle(bundle, privateKeyPem) {
244
- const sig = node_crypto__WEBPACK_IMPORTED_MODULE_3__.sign(null, canonicalBytes(bundle), privateKeyPem);
245
- return {
246
- ...bundle,
247
- signature: {
248
- algorithm: 'ed25519',
249
- canonicalisation: BUNDLE_SCHEMA,
250
- value: sig.toString('base64'),
251
- },
252
- };
253
- }
254
-
255
- /**
256
- * Verify a bundle with a PUBLIC key. This is the whole point: the verifier
257
- * never needs, and never had, the signing key.
258
- *
259
- * Returns {ok, reason}. Never throws — a malformed bundle from an untrusted
260
- * source is an expected input, not an exceptional one.
261
- */
262
- // The complete set of top-level keys a legitimately-built, signed bundle can
263
- // carry — buildEvidenceBundle's six plus signEvidenceBundle's `signature`.
264
- // EA-03 (Stage-0 audit, 2026): canonicalBytes SIGNS an allowlist of fields;
265
- // verifyEvidenceBundle never checked for keys OUTSIDE that allowlist, so a
266
- // bundle with a fabricated `verdict`/`proofLevel`/anything-else stapled on
267
- // after signing verified as authentic — the signature simply never covered
268
- // those bytes. Rejecting unknown keys here closes that; it must exactly match
269
- // what buildEvidenceBundle+signEvidenceBundle actually produce, or a
270
- // legitimate bundle would start failing verification.
271
- const BUNDLE_TOP_LEVEL_KEYS = new Set([
272
- 'schema', 'finding', 'evidence', 'engine', 'proves', 'doesNotProve', 'signature',
273
- ]);
274
-
275
- function verifyEvidenceBundle(bundle, publicKeyPem) {
276
- if (!bundle || typeof bundle !== 'object') return { ok: false, reason: 'bundle is not an object' };
277
- if (bundle.schema !== BUNDLE_SCHEMA) return { ok: false, reason: `unrecognised schema: ${bundle.schema}` };
278
- const unknownKeys = Object.keys(bundle).filter(k => !BUNDLE_TOP_LEVEL_KEYS.has(k));
279
- if (unknownKeys.length) {
280
- return { ok: false, reason: `unrecognised top-level key(s) not covered by the signature: ${unknownKeys.join(', ')}` };
281
- }
282
- const sig = bundle.signature;
283
- if (!sig?.value) return { ok: false, reason: 'bundle is unsigned' };
284
- if (sig.algorithm !== 'ed25519') return { ok: false, reason: `unsupported algorithm: ${sig.algorithm}` };
285
- if (!publicKeyPem) return { ok: false, reason: 'no public key supplied' };
286
- let ok = false;
287
- try {
288
- ok = node_crypto__WEBPACK_IMPORTED_MODULE_3__.verify(null, canonicalBytes(bundle), publicKeyPem, Buffer.from(sig.value, 'base64'));
289
- } catch (e) {
290
- return { ok: false, reason: `verification error: ${e.message}` };
291
- }
292
- return ok
293
- ? { ok: true, reason: null }
294
- : { ok: false, reason: 'signature does not match the bundle contents — it was modified after signing' };
295
- }
296
-
297
-
298
- /***/ })
299
-
300
- };