@clear-capabilities/agentic-security-scanner 0.144.0 → 0.147.0
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/CHANGELOG.md +390 -0
- package/bin/agentic-security.js +3813 -83
- package/dist/1122.index.js +702 -0
- package/dist/{301.index.js → 1301.index.js} +2 -2
- package/dist/1379.index.js +591 -0
- package/dist/{444.index.js → 1444.index.js} +13 -4
- package/dist/{660.index.js → 1660.index.js} +2 -2
- package/dist/{700.index.js → 1700.index.js} +2 -2
- package/dist/{905.index.js → 1905.index.js} +3 -3
- package/dist/{920.index.js → 1920.index.js} +3 -3
- package/dist/{238.index.js → 2238.index.js} +3 -3
- package/dist/2271.index.js +165 -0
- package/dist/{985.index.js → 2376.index.js} +1260 -340
- package/dist/2432.index.js +793 -0
- package/dist/2659.index.js +93 -0
- package/dist/{826.index.js → 2826.index.js} +2 -2
- package/dist/{830.index.js → 2830.index.js} +2 -2
- package/dist/2923.index.js +298 -0
- package/dist/{1.index.js → 3001.index.js} +5 -5
- package/dist/{117.index.js → 3117.index.js} +3 -3
- package/dist/3180.index.js +307 -0
- package/dist/3276.index.js +117 -0
- package/dist/{415.index.js → 3415.index.js} +2 -2
- package/dist/{499.index.js → 3499.index.js} +2 -2
- package/dist/3518.index.js +450 -0
- package/dist/{526.index.js → 3526.index.js} +14 -6
- package/dist/{736.index.js → 3736.index.js} +4 -4
- package/dist/{839.index.js → 3839.index.js} +4 -4
- package/dist/{113.index.js → 4113.index.js} +14 -6
- package/dist/{265.index.js → 4265.index.js} +2 -2
- package/dist/{384.index.js → 4384.index.js} +3 -3
- package/dist/4547.index.js +268 -0
- package/dist/4863.index.js +422 -0
- package/dist/{970.index.js → 4970.index.js} +67 -3
- package/dist/5051.index.js +770 -0
- package/dist/{144.index.js → 5144.index.js} +5 -5
- package/dist/{333.index.js → 5333.index.js} +3 -3
- package/dist/5343.index.js +185 -0
- package/dist/5350.index.js +866 -0
- package/dist/5561.index.js +436 -0
- package/dist/{637.index.js → 5637.index.js} +29 -7
- package/dist/{449.index.js → 5830.index.js} +78 -14
- package/dist/6626.index.js +532 -0
- package/dist/6662.index.js +297 -0
- package/dist/{675.index.js → 6675.index.js} +5 -5
- package/dist/{730.index.js → 6730.index.js} +6 -6
- package/dist/6829.index.js +225 -0
- package/dist/6944.index.js +130 -0
- package/dist/{178.index.js → 7178.index.js} +26 -8
- package/dist/{227.index.js → 7227.index.js} +2 -2
- package/dist/7310.index.js +520 -0
- package/dist/{552.index.js → 7552.index.js} +4 -4
- package/dist/7709.index.js +78 -0
- package/dist/8218.index.js +160 -0
- package/dist/{476.index.js → 8476.index.js} +4 -4
- package/dist/{513.index.js → 8513.index.js} +5 -5
- package/dist/{520.index.js → 8520.index.js} +2 -2
- package/dist/{718.index.js → 8718.index.js} +2 -2
- package/dist/{752.index.js → 8752.index.js} +2 -2
- package/dist/8846.index.js +100 -0
- package/dist/{435.index.js → 9091.index.js} +580 -187
- package/dist/{207.index.js → 9207.index.js} +2 -2
- package/dist/{220.index.js → 9220.index.js} +2 -2
- package/dist/9390.index.js +163 -0
- package/dist/{503.index.js → 9503.index.js} +2 -2
- package/dist/{801.index.js → 9801.index.js} +2 -2
- package/dist/{824.index.js → 9824.index.js} +2 -2
- package/dist/agentic-security.mjs +16 -16
- package/dist/agentic-security.mjs.sha256 +1 -1
- package/dist/compliance-frameworks/hipaa-security-rule.json +3 -2
- package/package.json +23 -10
- package/src/compare.js +6 -1
- package/src/dataflow/CLAUDE.md +2 -2
- package/src/dataflow/catalog.js +42 -0
- package/src/dataflow/orm-write-catalog.js +175 -0
- package/src/engine.js +580 -30
- package/src/fix/apply-fix-service.js +1 -0
- package/src/history-scan.js +22 -5
- package/src/ir/CLAUDE.md +2 -1
- package/src/ir/chrome-probe.mjs +150 -0
- package/src/ir/parser-js.js +94 -7
- package/src/lineage/CLAUDE.md +1203 -0
- package/src/lineage/DESIGN_DESTINATION_RESOLVER.md +156 -0
- package/src/lineage/DESIGN_GRAPH_BUILDER.md +938 -0
- package/src/lineage/DESIGN_HANDLING_ANALYZER.md +355 -0
- package/src/lineage/DESIGN_INTRAPROCEDURAL.md +628 -0
- package/src/lineage/DESIGN_PATH_PROVENANCE.md +3451 -0
- package/src/lineage/DESIGN_QUEUE_DETAIL.md +120 -0
- package/src/lineage/DESIGN_REGISTRIES.md +880 -0
- package/src/lineage/DESIGN_STORE_DETAIL.md +143 -0
- package/src/lineage/DESIGN_TRANSIT_PROTECTION.md +245 -0
- package/src/lineage/classification.js +56 -0
- package/src/lineage/coverage.js +658 -0
- package/src/lineage/cross-repo-link.js +107 -0
- package/src/lineage/dataflow-graph.schema.json +184 -0
- package/src/lineage/decision-story.js +206 -0
- package/src/lineage/drift-policy.js +279 -0
- package/src/lineage/driver.js +135 -0
- package/src/lineage/engine.js +992 -0
- package/src/lineage/export-briefing.js +628 -0
- package/src/lineage/export-csv.js +62 -0
- package/src/lineage/export-json.js +238 -0
- package/src/lineage/export-privacy.js +258 -0
- package/src/lineage/federation-loader.js +111 -0
- package/src/lineage/field-identity.js +78 -0
- package/src/lineage/fixtures/build-flagship-fixture.mjs +272 -0
- package/src/lineage/fixtures/flagship-graph.json +1453 -0
- package/src/lineage/flow-grade.js +221 -0
- package/src/lineage/governance-edit.js +169 -0
- package/src/lineage/graph-builder.js +1114 -0
- package/src/lineage/graph-diff.js +431 -0
- package/src/lineage/graph-snapshot.js +180 -0
- package/src/lineage/handling-analyzer.js +168 -0
- package/src/lineage/ids.js +349 -0
- package/src/lineage/impact-assessment.js +76 -0
- package/src/lineage/impact-engine.js +268 -0
- package/src/lineage/index.js +281 -0
- package/src/lineage/language-coverage-tiers.js +58 -0
- package/src/lineage/obligation-mapping.js +126 -0
- package/src/lineage/obligation-predicates.js +235 -0
- package/src/lineage/observation-adapters.js +282 -0
- package/src/lineage/observation-correlation.js +622 -0
- package/src/lineage/observation-store.js +497 -0
- package/src/lineage/path-query.js +410 -0
- package/src/lineage/path-store.js +400 -0
- package/src/lineage/protection.js +53 -0
- package/src/lineage/recipient-profile.js +192 -0
- package/src/lineage/recipient-registry.js +394 -0
- package/src/lineage/redact-graph.js +224 -0
- package/src/lineage/remediation.js +417 -0
- package/src/lineage/resolve-destination.js +91 -0
- package/src/lineage/runtime-observation.js +464 -0
- package/src/lineage/scenario-diff.js +84 -0
- package/src/lineage/scenario-engine.js +251 -0
- package/src/lineage/scenario.js +101 -0
- package/src/lineage/schema.js +167 -0
- package/src/lineage/sink-registry.js +427 -0
- package/src/lineage/source-registry.js +357 -0
- package/src/lineage/source-seeding.js +212 -0
- package/src/lineage/summaries.js +590 -0
- package/src/lineage/transform-catalog.js +397 -0
- package/src/lineage/transit-protection.js +150 -0
- package/src/lineage/validate.js +285 -0
- package/src/lsp/server.js +49 -2
- package/src/mcp/CLAUDE.md +7 -1
- package/src/mcp/dataflow-tools.js +160 -0
- package/src/mcp/server.js +1 -1
- package/src/mcp/tools.js +22 -1
- package/src/pipeline/assurance-mode.js +64 -1
- package/src/pipeline/finding-schema.js +8 -1
- package/src/pipeline/scan-health.js +19 -1
- package/src/posture/CLAUDE.md +140 -0
- package/src/posture/accuracy-scorecard.js +60 -0
- package/src/posture/artifact-registry.js +76 -0
- package/src/posture/auditor-walkthrough.js +192 -13
- package/src/posture/compliance-frameworks/hipaa-security-rule.json +3 -2
- package/src/posture/compliance-policy.js +12 -2
- package/src/posture/cross-repo-memory.js +7 -2
- package/src/posture/fix-history.js +25 -2
- package/src/posture/fix-verify.js +9 -1
- package/src/posture/fleet.js +0 -0
- package/src/posture/git-history.js +13 -5
- package/src/posture/material-change.js +21 -2
- package/src/posture/mttr.js +75 -12
- package/src/posture/obligation-evidence-pack.js +202 -0
- package/src/posture/pre-incident-archaeology.js +39 -7
- package/src/posture/privacy-framework.js +14 -0
- package/src/posture/provenance/ai-authorship.js +68 -0
- package/src/posture/provenance/branch-entry.js +80 -0
- package/src/posture/provenance/cache.js +143 -0
- package/src/posture/provenance/confidence.js +36 -0
- package/src/posture/provenance/coordinator.js +786 -0
- package/src/posture/provenance/dag-walk.js +249 -0
- package/src/posture/provenance/evidence-attribution.js +59 -0
- package/src/posture/provenance/git-evidence.js +310 -0
- package/src/posture/provenance/lifecycle.js +208 -0
- package/src/posture/provenance/missing-control-resolver.js +137 -0
- package/src/posture/provenance/origin-resolver.js +342 -0
- package/src/posture/provenance/predicate-replay.js +133 -0
- package/src/posture/provenance/providers/config.js +39 -0
- package/src/posture/provenance/providers/github.js +62 -0
- package/src/posture/provenance/providers/gitlab.js +58 -0
- package/src/posture/provenance/repo-lineage.js +74 -0
- package/src/posture/provenance/sca-origin.js +139 -0
- package/src/posture/provenance/schema.js +255 -0
- package/src/posture/provenance/transitive-sca.js +147 -0
- package/src/posture/provenance/validate.js +30 -0
- package/src/posture/provenance-evidence-bundle.js +144 -0
- package/src/posture/remediation-ledger.js +337 -0
- package/src/posture/sbom-diff.js +15 -2
- package/src/posture/secret-history.js +10 -2
- package/src/posture/state-dir.js +38 -14
- package/src/posture/vuln-archaeology.js +8 -2
- package/src/pr-delta.js +25 -4
- package/src/report/index.js +197 -3
- package/src/runScan.js +34 -5
- package/src/sast/rate-limit.js +33 -3
- package/src/server/CLAUDE.md +47 -0
- package/src/server/graph-loader.js +141 -0
- package/src/server/http-server.js +325 -0
- package/src/server/routes.js +129 -0
- package/src/server/security.js +111 -0
- package/src/server/static-assets.js +139 -0
- package/src/util/git-hardening.js +128 -0
- package/dist/11.index.js +0 -353
- package/dist/259.index.js +0 -975
- package/dist/317.index.js +0 -300
- package/dist/609.index.js +0 -741
- 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
|
-
};
|