@clear-capabilities/agentic-security-scanner 0.153.2 → 0.154.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 +34 -0
- package/bin/agentic-security.js +123 -19
- package/dist/1444.index.js +64 -19
- package/dist/1905.index.js +46 -3
- package/dist/2862.index.js +325 -0
- package/dist/3499.index.js +5 -1
- package/dist/3531.index.js +261 -0
- package/dist/3596.index.js +103 -0
- package/dist/4113.index.js +15 -3
- package/dist/4171.index.js +319 -0
- package/dist/5637.index.js +10 -4
- package/dist/6359.index.js +433 -0
- package/dist/7838.index.js +15 -3
- package/dist/8551.index.js +1164 -0
- package/dist/8587.index.js +410 -0
- package/dist/8714.index.js +98 -0
- package/dist/8798.index.js +218 -0
- package/dist/9220.index.js +35 -3
- package/dist/9560.index.js +26 -3
- package/dist/agentic-security.mjs +51 -51
- package/dist/agentic-security.mjs.sha256 +1 -1
- package/package.json +17 -2
- package/src/dataflow/CLAUDE.md +9 -0
- package/src/dataflow/catalog-haskell.js +37 -0
- package/src/dataflow/catalog.js +4 -0
- package/src/dataflow/engine.js +33 -3
- package/src/dataflow/privacy-catalog-haskell.js +50 -0
- package/src/dataflow/privacy-catalog.js +5 -1
- package/src/discovery/CLAUDE.md +6 -0
- package/src/discovery/index.js +12 -3
- package/src/discovery/lenses.js +4 -1
- package/src/discovery/partition.js +28 -0
- package/src/egress/redact.js +8 -0
- package/src/engine.js +125 -14
- package/src/ir/index.js +39 -2
- package/src/language/CLAUDE.md +74 -0
- package/src/language/accuracy.js +90 -0
- package/src/language/aibom.js +307 -0
- package/src/language/assurance.js +193 -0
- package/src/language/bom-validate.js +227 -0
- package/src/language/bom.js +236 -0
- package/src/language/bridges.js +392 -0
- package/src/language/compliance-map.js +61 -0
- package/src/language/context.js +199 -0
- package/src/language/contracts.js +339 -0
- package/src/language/discovery.js +359 -0
- package/src/language/engine-pass.js +120 -0
- package/src/language/fix-lifecycle.js +120 -0
- package/src/language/haskell-adapter.js +51 -0
- package/src/language/haskell-disclosure.js +170 -0
- package/src/language/haskell-findings.js +44 -0
- package/src/language/haskell-fix.js +409 -0
- package/src/language/haskell-grammar.js +78 -0
- package/src/language/haskell-guards.js +382 -0
- package/src/language/haskell-ir.js +1377 -0
- package/src/language/haskell-llm.js +128 -0
- package/src/language/haskell-manifests.js +1290 -0
- package/src/language/haskell-models.js +278 -0
- package/src/language/haskell-parser.js +1073 -0
- package/src/language/haskell-resolved-graph.js +414 -0
- package/src/language/haskell-sca.js +387 -0
- package/src/language/haskell-security-rules.js +332 -0
- package/src/language/haskell-supply.js +140 -0
- package/src/language/haskell-sweep.js +85 -0
- package/src/language/haskell-syntax.js +895 -0
- package/src/language/haskell-web.js +749 -0
- package/src/language/nix-adapter.js +42 -0
- package/src/language/nix-agents.js +155 -0
- package/src/language/nix-build-trust.js +790 -0
- package/src/language/nix-closure.js +331 -0
- package/src/language/nix-eval-isolation.js +274 -0
- package/src/language/nix-fix.js +268 -0
- package/src/language/nix-grammar.js +97 -0
- package/src/language/nix-inventory.js +379 -0
- package/src/language/nix-ir.js +642 -0
- package/src/language/nix-parser.js +908 -0
- package/src/language/nix-privacy.js +114 -0
- package/src/language/nix-sca.js +358 -0
- package/src/language/nix-script-taint.js +885 -0
- package/src/language/nix-secrets.js +396 -0
- package/src/language/nixos-hardening.js +564 -0
- package/src/language/nixos-module-resolver.js +595 -0
- package/src/language/nixos-option-catalog.js +96 -0
- package/src/language/pragma.js +150 -0
- package/src/language/resolved-pass.js +146 -0
- package/src/language/secrets.js +323 -0
- package/src/language/state-artifacts.js +78 -0
- package/src/language/support-registry.js +224 -0
- package/src/language/witness.js +185 -0
- package/src/lineage/CLAUDE.md +8 -0
- package/src/lineage/coverage.js +2 -0
- package/src/lineage/cross-repo-link.js +22 -0
- package/src/lineage/graph-builder.js +5 -1
- package/src/lineage/haskell-view.js +319 -0
- package/src/lineage/index.js +8 -1
- package/src/lineage/nix-view.js +198 -0
- package/src/lineage/sink-registry.js +10 -1
- package/src/lineage/source-registry.js +3 -0
- package/src/lineage/transform-catalog.js +12 -0
- package/src/llm-validator/index.js +16 -2
- package/src/lsp/server.js +69 -9
- package/src/mcp/CLAUDE.md +7 -0
- package/src/mcp/tools.js +26 -3
- package/src/pipeline/coverage-ledger.js +0 -0
- package/src/pipeline/scan-health.js +19 -1
- package/src/posture/accuracy-scorecard.js +51 -0
- package/src/posture/aibom.js +61 -3
- package/src/posture/artifact-registry.js +12 -0
- package/src/posture/auditor-walkthrough.js +41 -0
- package/src/posture/clustering.js +2 -2
- package/src/posture/evidence-bundle.js +7 -1
- package/src/posture/execution-proof.js +15 -0
- package/src/posture/falsification.js +7 -0
- package/src/posture/family-resolve.js +7 -0
- package/src/posture/fix-history.js +40 -0
- package/src/posture/fix-verify.js +15 -3
- package/src/posture/provenance/git-evidence.js +24 -0
- package/src/posture/provenance/origin-resolver.js +14 -2
- package/src/posture/provenance/predicate-replay.js +11 -2
- package/src/posture/provenance/sca-origin.js +20 -3
- package/src/posture/sbom-diff.js +7 -6
- package/src/posture/sbom.js +85 -32
- package/src/posture/sca-policy.js +10 -1
- package/src/posture/sca-verdict.js +8 -1
- package/src/posture/secret-history.js +62 -18
- package/src/posture/stable-id.js +21 -2
- package/src/posture/state-dir.js +21 -0
- package/src/posture/threat-model-auto.js +4 -4
- package/src/posture/triage.js +18 -1
- package/src/posture/watch-mode.js +34 -3
- package/src/pr-delta.js +9 -4
- package/src/report/index.js +35 -9
- package/src/runScan.js +56 -5
- package/src/sast/pipeline.js +34 -1
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
export const id = 8798;
|
|
2
|
+
export const ids = [8798];
|
|
3
|
+
export const modules = {
|
|
4
|
+
|
|
5
|
+
/***/ 18798:
|
|
6
|
+
/***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
|
|
7
|
+
|
|
8
|
+
__webpack_require__.r(__webpack_exports__);
|
|
9
|
+
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
10
|
+
/* harmony export */ PROOF_MARKER: () => (/* binding */ PROOF_MARKER),
|
|
11
|
+
/* harmony export */ WITNESS_STATUS: () => (/* binding */ WITNESS_STATUS),
|
|
12
|
+
/* harmony export */ WITNESS_VERSION: () => (/* binding */ WITNESS_VERSION),
|
|
13
|
+
/* harmony export */ buildNixScriptWitness: () => (/* binding */ buildNixScriptWitness),
|
|
14
|
+
/* harmony export */ haskellRunner: () => (/* binding */ haskellRunner),
|
|
15
|
+
/* harmony export */ judgeFixWitness: () => (/* binding */ judgeFixWitness),
|
|
16
|
+
/* harmony export */ nixFixWitness: () => (/* binding */ nixFixWitness),
|
|
17
|
+
/* harmony export */ nixFlowTarget: () => (/* binding */ nixFlowTarget),
|
|
18
|
+
/* harmony export */ runHaskellWitness: () => (/* binding */ runHaskellWitness),
|
|
19
|
+
/* harmony export */ runNixScriptWitness: () => (/* binding */ runNixScriptWitness),
|
|
20
|
+
/* harmony export */ witnessNixFlow: () => (/* binding */ witnessNixFlow),
|
|
21
|
+
/* harmony export */ witnessPayload: () => (/* binding */ witnessPayload)
|
|
22
|
+
/* harmony export */ });
|
|
23
|
+
/* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(73024);
|
|
24
|
+
/* harmony import */ var node_os__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(48161);
|
|
25
|
+
/* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(76760);
|
|
26
|
+
/* harmony import */ var node_child_process__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(31421);
|
|
27
|
+
/* harmony import */ var _sandbox_index_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(65398);
|
|
28
|
+
/* harmony import */ var _nix_script_taint_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(11793);
|
|
29
|
+
// Controlled proof witnesses for Haskell and Nix findings (X-009).
|
|
30
|
+
//
|
|
31
|
+
// A witness is a small, bounded program that DEMONSTRATES the predicted effect inside the confinement sandbox
|
|
32
|
+
// (src/sandbox: writes confined to a temporary root, no network, wall-clock and resource limits, fail-closed when no
|
|
33
|
+
// primitive is available). The effect is always the same observable: the witness payload creates the marker file
|
|
34
|
+
// `PROVEN` in its working directory. Nothing else counts.
|
|
35
|
+
//
|
|
36
|
+
// Supported witnesses, stated explicitly:
|
|
37
|
+
//
|
|
38
|
+
// nix-shell A shell script a Nix expression generates (systemd script, build phase). The generated script text is
|
|
39
|
+
// taken from the NIX-003 analysis, the interpolation the finding concerns is replaced by an attacker
|
|
40
|
+
// payload shaped for its shell context and passed through the SAME escaping the Nix code applies
|
|
41
|
+
// (lib.escapeShellArg), and the script is run for real by the host shell. The payload is only shell
|
|
42
|
+
// text: it runs only inside the sandbox, and only `touch PROVEN` is ever asked of it.
|
|
43
|
+
// haskell Needs a Haskell toolchain (runghc). Without one the result is `unavailable`, which is neither proof
|
|
44
|
+
// nor refutation. This module never installs or downloads a toolchain.
|
|
45
|
+
//
|
|
46
|
+
// What is NOT proof, ever: a syntax error in the witness, a missing executable, a sandbox that could not start or was
|
|
47
|
+
// refused, a timeout or resource limit, or an output cap. Each is reported as `invalid` with its reason and leaves
|
|
48
|
+
// the finding's static proof tier unchanged. Only the marker proves; its absence after a clean run is
|
|
49
|
+
// `not-reproduced`, which is evidence about THIS witness, not a proof that the code is safe.
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
const WITNESS_VERSION = 'language-witness/1';
|
|
59
|
+
const PROOF_MARKER = 'PROVEN';
|
|
60
|
+
const WITNESS_STATUS = Object.freeze(['reproduced', 'not-reproduced', 'invalid', 'unavailable', 'unsupported']);
|
|
61
|
+
const SHELLS = new Set(['bash', 'sh', 'dash', 'ash', 'ksh', 'mksh']);
|
|
62
|
+
const DEFAULT_TIMEOUT_MS = 20_000;
|
|
63
|
+
const MAX_SCRIPT_BYTES = 256 * 1024;
|
|
64
|
+
|
|
65
|
+
const shEscape = (s) => `'${String(s).replace(/'/g, `'\\''`)}'`;
|
|
66
|
+
|
|
67
|
+
/** The text one placeholder takes in the generated script, given the Nix-side protection and the shell context. */
|
|
68
|
+
function witnessPayload(context, protection) {
|
|
69
|
+
const cmd = `touch ${PROOF_MARKER}`;
|
|
70
|
+
let raw;
|
|
71
|
+
if (context === 'single') raw = `'; ${cmd}; echo '`;
|
|
72
|
+
else if (context === 'double') raw = `$(${cmd})`;
|
|
73
|
+
else raw = `$(${cmd})`;
|
|
74
|
+
// escapeShellArg(s) wraps in single quotes at EVALUATION time, before the shell ever sees the text. The shell then
|
|
75
|
+
// reads that result inside whatever quote context the script put it in, which is exactly the wrong-context case.
|
|
76
|
+
if (protection === 'escapeShellArg') return shEscape(raw);
|
|
77
|
+
if (protection === 'escapeShellArgs') return shEscape(raw);
|
|
78
|
+
return raw;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const placeholderIndexes = (text) => { const out = []; for (let i = 0; i < text.length; i++) if (text[i] === _nix_script_taint_js__WEBPACK_IMPORTED_MODULE_5__/* .SHELL_PLACEHOLDER */ .v0) out.push(i); return out; };
|
|
82
|
+
const indexOfPosition = (text, line, col) => { let l = 1; let i = 0; while (i < text.length && l < line) { if (text[i] === '\n') l++; i++; } return i + col; };
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Builds a witness for one flow of one generated script.
|
|
86
|
+
* @param {{script:{generated:string, shell:string|null, attrPath:string, file:string}, flow:{generatedLocation:{line:number,startColumn:number}, context:string, protection:string|null}}} t
|
|
87
|
+
*/
|
|
88
|
+
function buildNixScriptWitness({ script, flow }) {
|
|
89
|
+
if (!script || typeof script.generated !== 'string' || !flow || !flow.generatedLocation) return { status: 'unsupported', reason: 'the flow has no generated-script location' };
|
|
90
|
+
const shell = script.shell || 'bash';
|
|
91
|
+
if (!SHELLS.has(shell)) return { status: 'unsupported', reason: `shell "${shell}" is not supported by the witness runner` };
|
|
92
|
+
if (Buffer.byteLength(script.generated) > MAX_SCRIPT_BYTES) return { status: 'unsupported', reason: 'the generated script exceeds the witness size limit' };
|
|
93
|
+
const all = placeholderIndexes(script.generated);
|
|
94
|
+
const at = indexOfPosition(script.generated, flow.generatedLocation.line, flow.generatedLocation.startColumn);
|
|
95
|
+
const ordinal = all.indexOf(at);
|
|
96
|
+
if (ordinal < 0) return { status: 'unsupported', reason: 'the flow location does not match an interpolation in the generated script' };
|
|
97
|
+
const payload = witnessPayload(flow.context, flow.protection);
|
|
98
|
+
let out = ''; let n = 0;
|
|
99
|
+
for (const ch of script.generated) { if (ch === _nix_script_taint_js__WEBPACK_IMPORTED_MODULE_5__/* .SHELL_PLACEHOLDER */ .v0) { out += n === ordinal ? payload : 'benign'; n++; } else out += ch; }
|
|
100
|
+
const body = out.replace(/^#!.*\n/, '');
|
|
101
|
+
return { status: 'ready', lang: 'nix-shell', shell, ordinal, attrPath: script.attrPath, file: script.file, payload, code: `${body}\n`, context: flow.context, protection: flow.protection || null };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function which(name) {
|
|
105
|
+
for (const d of String(process.env.PATH || '').split(node_path__WEBPACK_IMPORTED_MODULE_2__.delimiter)) { const p = node_path__WEBPACK_IMPORTED_MODULE_2__.join(d, name); try { node_fs__WEBPACK_IMPORTED_MODULE_0__.accessSync(p, node_fs__WEBPACK_IMPORTED_MODULE_0__.constants.X_OK); return p; } catch { /* next */ } }
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** Runs a witness built by buildNixScriptWitness inside the confinement sandbox. Never throws. */
|
|
110
|
+
function runNixScriptWitness(w, { timeoutMs = DEFAULT_TIMEOUT_MS, force } = {}) {
|
|
111
|
+
const base = { witness: WITNESS_VERSION, lang: 'nix-shell', ran: false, backend: null, marker: PROOF_MARKER };
|
|
112
|
+
if (!w || w.status !== 'ready') return { ...base, status: w && w.status === 'unsupported' ? 'unsupported' : 'invalid', reason: (w && w.reason) || 'no witness' };
|
|
113
|
+
const shellBin = which(w.shell);
|
|
114
|
+
if (!shellBin) return { ...base, status: 'invalid', reason: `executable not found: ${w.shell}` };
|
|
115
|
+
if (!(0,_sandbox_index_js__WEBPACK_IMPORTED_MODULE_4__/* .sandboxAvailable */ .$G)()) return { ...base, status: 'invalid', reason: 'no confinement primitive available; refusing to execute' };
|
|
116
|
+
let root;
|
|
117
|
+
try {
|
|
118
|
+
root = node_fs__WEBPACK_IMPORTED_MODULE_0__.realpathSync(node_fs__WEBPACK_IMPORTED_MODULE_0__.mkdtempSync(node_path__WEBPACK_IMPORTED_MODULE_2__.join(node_os__WEBPACK_IMPORTED_MODULE_1__.tmpdir(), 'witness-')));
|
|
119
|
+
node_fs__WEBPACK_IMPORTED_MODULE_0__.writeFileSync(node_path__WEBPACK_IMPORTED_MODULE_2__.join(root, 'witness.sh'), w.code, 'utf8');
|
|
120
|
+
// 1. a witness that does not parse proves nothing in either direction
|
|
121
|
+
const syn = (0,_sandbox_index_js__WEBPACK_IMPORTED_MODULE_4__/* .runConfined */ .id)([shellBin, '-n', 'witness.sh'], { root, timeoutMs, force });
|
|
122
|
+
if (syn.status === 'disabled' || syn.status === 'error') return { ...base, backend: syn.backend, status: 'invalid', reason: `the sandbox could not run the syntax check (${syn.backend}): ${String(syn.stderr || '').trim() || 'no detail'}` };
|
|
123
|
+
if (syn.timedOut) return { ...base, backend: syn.backend, status: 'invalid', reason: 'the syntax check exceeded its time budget' };
|
|
124
|
+
if (syn.exitCode !== 0) return { ...base, backend: syn.backend, status: 'invalid', reason: `syntax error in the generated witness: ${String(syn.stderr || '').trim().split('\n')[0] || 'shell rejected it'}` };
|
|
125
|
+
// 2. the real run
|
|
126
|
+
const r = (0,_sandbox_index_js__WEBPACK_IMPORTED_MODULE_4__/* .runConfined */ .id)([shellBin, 'witness.sh'], { root, timeoutMs, force });
|
|
127
|
+
const ran = !r.timedOut && r.status !== 'disabled' && r.status !== 'error';
|
|
128
|
+
if (!ran) return { ...base, backend: r.backend, status: 'invalid', reason: r.timedOut ? 'the witness exceeded its time budget' : `the sandbox could not execute it (${r.backend}): ${String(r.stderr || '').trim() || r.status}`, timedOut: !!r.timedOut };
|
|
129
|
+
const proven = node_fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(node_path__WEBPACK_IMPORTED_MODULE_2__.join(root, PROOF_MARKER));
|
|
130
|
+
return { ...base, ran: true, backend: r.backend, status: proven ? 'reproduced' : 'not-reproduced', exitCode: r.exitCode,
|
|
131
|
+
observed: proven ? `the payload created '${PROOF_MARKER}' by running inside the generated script` : null,
|
|
132
|
+
reason: proven ? null : 'the script ran and the marker was not created: this witness did not reproduce the effect' };
|
|
133
|
+
} catch (e) {
|
|
134
|
+
return { ...base, status: 'invalid', reason: `witness harness error: ${String((e && e.message) || e)}` };
|
|
135
|
+
} finally { if (root) node_fs__WEBPACK_IMPORTED_MODULE_0__.rmSync(root, { recursive: true, force: true }); }
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** Finds the flow for (attrPath, ordinal) in a fresh analysis of `files`, and builds+runs its witness. */
|
|
139
|
+
function witnessNixFlow(files, target, opts = {}) {
|
|
140
|
+
const a = (0,_nix_script_taint_js__WEBPACK_IMPORTED_MODULE_5__/* .analyzeNixScripts */ .S3)({ files });
|
|
141
|
+
const script = a.scripts.find((s) => s.attrPath === target.attrPath && (!target.file || s.file === target.file));
|
|
142
|
+
if (!script) return { status: 'unsupported', ran: false, reason: `no generated script ${target.attrPath}` };
|
|
143
|
+
const idx = placeholderIndexes(script.generated);
|
|
144
|
+
const flow = a.flows.find((f) => f.attrPath === script.attrPath && f.generatedLocation && idx.indexOf(indexOfPosition(script.generated, f.generatedLocation.line, f.generatedLocation.startColumn)) === target.ordinal);
|
|
145
|
+
if (!flow) return { status: 'unsupported', ran: false, reason: `no interpolation #${target.ordinal} in ${target.attrPath}` };
|
|
146
|
+
return runNixScriptWitness(buildNixScriptWitness({ script, flow }), opts);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** The (attrPath, ordinal) of the flow a finding describes, taken from a fresh analysis. */
|
|
150
|
+
function nixFlowTarget(files, finding) {
|
|
151
|
+
const a = (0,_nix_script_taint_js__WEBPACK_IMPORTED_MODULE_5__/* .analyzeNixScripts */ .S3)({ files });
|
|
152
|
+
const flow = a.flows.find((f) => f.file === finding.file && f.line === finding.line && f.attrPath && f.generatedLocation)
|
|
153
|
+
|| a.flows.find((f) => f.file === finding.file && f.attrPath === finding.attrPath && f.generatedLocation);
|
|
154
|
+
if (!flow) return null;
|
|
155
|
+
const script = a.scripts.find((s) => s.attrPath === flow.attrPath && s.file === (flow.generatedLocation.file || finding.file));
|
|
156
|
+
if (!script) return null;
|
|
157
|
+
const ordinal = placeholderIndexes(script.generated).indexOf(indexOfPosition(script.generated, flow.generatedLocation.line, flow.generatedLocation.startColumn));
|
|
158
|
+
return ordinal < 0 ? null : { attrPath: script.attrPath, file: script.file, ordinal };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Before/after judgement for a fix. A fix is witness-verified only when the ORIGINAL reproduced and the PATCHED code
|
|
163
|
+
* ran cleanly without reproducing. Anything invalid on either side verifies nothing.
|
|
164
|
+
*/
|
|
165
|
+
function judgeFixWitness(before, after) {
|
|
166
|
+
if (!before || before.status !== 'reproduced') return { ok: false, verified: false, reason: `the original code did not reproduce (${(before && before.status) || 'no witness'}${before && before.reason ? `: ${before.reason}` : ''}), so the fix cannot be witness-verified` };
|
|
167
|
+
if (!after || after.status === 'invalid' || after.status === 'unavailable' || after.status === 'unsupported') return { ok: false, verified: false, reason: `the patched witness could not be judged (${(after && after.status) || 'no witness'}${after && after.reason ? `: ${after.reason}` : ''})` };
|
|
168
|
+
if (after.status === 'reproduced') return { ok: false, verified: false, stillReproduces: true, reason: 'the patched code still reproduces the effect' };
|
|
169
|
+
return { ok: true, verified: true, reason: null, note: 'the witness reproduced before the patch and not after; this is evidence about this witness, not a proof of safety' };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// ── Haskell: optional, toolchain-gated ───────────────────────────────────────
|
|
173
|
+
/** Whether a Haskell runner exists. Never installs anything. */
|
|
174
|
+
function haskellRunner() {
|
|
175
|
+
const p = which('runghc') || which('runhaskell');
|
|
176
|
+
if (!p) return { available: false, reason: 'no Haskell toolchain (runghc) on PATH; witnesses for Haskell findings are unavailable here' };
|
|
177
|
+
const v = (0,node_child_process__WEBPACK_IMPORTED_MODULE_3__.spawnSync)(p, ['--version'], { encoding: 'utf8', timeout: 10_000 });
|
|
178
|
+
return v.status === 0 ? { available: true, path: p, version: String(v.stdout || v.stderr).trim() } : { available: false, reason: 'the Haskell runner did not start' };
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Runs a Haskell program text as a witness. `main` must create PROVEN in its working directory when the effect is
|
|
183
|
+
* reproduced. Without a toolchain the answer is `unavailable`: not proof, not refutation.
|
|
184
|
+
*/
|
|
185
|
+
function runHaskellWitness(source, { timeoutMs = 60_000, force } = {}) {
|
|
186
|
+
const base = { witness: WITNESS_VERSION, lang: 'haskell', ran: false, backend: null, marker: PROOF_MARKER };
|
|
187
|
+
const hr = haskellRunner();
|
|
188
|
+
if (!hr.available) return { ...base, status: 'unavailable', reason: hr.reason };
|
|
189
|
+
if (!(0,_sandbox_index_js__WEBPACK_IMPORTED_MODULE_4__/* .sandboxAvailable */ .$G)()) return { ...base, status: 'invalid', reason: 'no confinement primitive available; refusing to execute' };
|
|
190
|
+
let root;
|
|
191
|
+
try {
|
|
192
|
+
root = node_fs__WEBPACK_IMPORTED_MODULE_0__.realpathSync(node_fs__WEBPACK_IMPORTED_MODULE_0__.mkdtempSync(node_path__WEBPACK_IMPORTED_MODULE_2__.join(node_os__WEBPACK_IMPORTED_MODULE_1__.tmpdir(), 'witness-hs-')));
|
|
193
|
+
node_fs__WEBPACK_IMPORTED_MODULE_0__.writeFileSync(node_path__WEBPACK_IMPORTED_MODULE_2__.join(root, 'Witness.hs'), source, 'utf8');
|
|
194
|
+
const r = (0,_sandbox_index_js__WEBPACK_IMPORTED_MODULE_4__/* .runConfined */ .id)([hr.path, 'Witness.hs'], { root, timeoutMs, force });
|
|
195
|
+
if (r.status === 'disabled' || r.status === 'error') return { ...base, backend: r.backend, status: 'invalid', reason: `the sandbox could not execute it: ${String(r.stderr || '').trim() || r.status}` };
|
|
196
|
+
if (r.timedOut) return { ...base, backend: r.backend, status: 'invalid', reason: 'the witness exceeded its time budget', timedOut: true };
|
|
197
|
+
if (/error|parse error|Could not find module/i.test(String(r.stderr || '')) && r.exitCode !== 0) return { ...base, backend: r.backend, status: 'invalid', reason: `the program did not compile or run: ${String(r.stderr).trim().split('\n')[0]}` };
|
|
198
|
+
const proven = node_fs__WEBPACK_IMPORTED_MODULE_0__.existsSync(node_path__WEBPACK_IMPORTED_MODULE_2__.join(root, PROOF_MARKER));
|
|
199
|
+
return { ...base, ran: true, backend: r.backend, status: proven ? 'reproduced' : 'not-reproduced', exitCode: r.exitCode, reason: proven ? null : 'the program ran and the marker was not created' };
|
|
200
|
+
} catch (e) {
|
|
201
|
+
return { ...base, status: 'invalid', reason: `witness harness error: ${String((e && e.message) || e)}` };
|
|
202
|
+
} finally { if (root) node_fs__WEBPACK_IMPORTED_MODULE_0__.rmSync(root, { recursive: true, force: true }); }
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/** A `witness` hook for runFixLifecycle over a Nix generated-script finding: runs the original and the patched tree. */
|
|
206
|
+
function nixFixWitness(finding, opts = {}) {
|
|
207
|
+
return (plan, files, patched) => {
|
|
208
|
+
const nixOnly = (t) => Object.fromEntries(Object.entries(t).filter(([p, x]) => /\.nix$/i.test(p) && typeof x === 'string'));
|
|
209
|
+
const target = nixFlowTarget(nixOnly(files), finding);
|
|
210
|
+
if (!target) return { ok: false, verified: false, reason: 'the finding is not a generated-script interpolation, so no witness applies' };
|
|
211
|
+
return judgeFixWitness(witnessNixFlow(nixOnly(files), target, opts), witnessNixFlow(nixOnly(patched), target, opts));
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
/***/ })
|
|
217
|
+
|
|
218
|
+
};
|
package/dist/9220.index.js
CHANGED
|
@@ -16,6 +16,7 @@ export const modules = {
|
|
|
16
16
|
/* harmony import */ var node_fs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(73024);
|
|
17
17
|
/* harmony import */ var node_path__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(76760);
|
|
18
18
|
/* harmony import */ var _state_dir_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(31174);
|
|
19
|
+
/* harmony import */ var _language_discovery_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(30951);
|
|
19
20
|
// Watch mode — continuous incremental scan as the developer edits.
|
|
20
21
|
//
|
|
21
22
|
// Spawns a long-running scan watcher that:
|
|
@@ -42,6 +43,7 @@ export const modules = {
|
|
|
42
43
|
|
|
43
44
|
|
|
44
45
|
|
|
46
|
+
|
|
45
47
|
const STATUS_MD = 'watch-status.md';
|
|
46
48
|
const STATUS_JSON = 'watch-status.json';
|
|
47
49
|
const DEBOUNCE_MS = 350;
|
|
@@ -51,10 +53,35 @@ const SCAN_EXT_RE = /\.(?:[jt]sx?|mjs|cjs|py|java|kt|go|rb|php|cs|c|cc|cpp|h|hpp
|
|
|
51
53
|
const IGNORE_DIR_RE = /(?:^|\/)(?:\.git|node_modules|\.bench-cache|dist|build|\.next|coverage|\.agentic-security)(?:$|\/)/;
|
|
52
54
|
|
|
53
55
|
function _isScanable(rel) {
|
|
54
|
-
if (!rel
|
|
56
|
+
if (!rel) return false;
|
|
57
|
+
// An explicit export is evidence even though it lives in a build directory.
|
|
58
|
+
if ((0,_language_discovery_js__WEBPACK_IMPORTED_MODULE_4__/* .isExplicitExport */ .Zh)(rel)) return true;
|
|
59
|
+
if (IGNORE_DIR_RE.test(rel)) return false;
|
|
60
|
+
if ((0,_language_discovery_js__WEBPACK_IMPORTED_MODULE_4__/* .isLanguageSource */ .Sv)(rel) || (0,_language_discovery_js__WEBPACK_IMPORTED_MODULE_4__/* .isLanguageManifest */ .mD)(rel)) return !(0,_language_discovery_js__WEBPACK_IMPORTED_MODULE_4__/* .isLanguageExcludedPath */ .EG)(rel);
|
|
55
61
|
return SCAN_EXT_RE.test(rel);
|
|
56
62
|
}
|
|
57
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Widen a batch of changed absolute paths to every file whose results the
|
|
66
|
+
* change can stale: dependents through imports, and all Haskell/Nix sources for
|
|
67
|
+
* a manifest, lockfile or export change. Batches with no Haskell/Nix path are
|
|
68
|
+
* returned untouched, so other languages never pay for a tree read.
|
|
69
|
+
*/
|
|
70
|
+
async function expandChangedBatch(scanRoot, batch) {
|
|
71
|
+
const rels = batch.map((p) => node_path__WEBPACK_IMPORTED_MODULE_2__.relative(scanRoot, p).split(node_path__WEBPACK_IMPORTED_MODULE_2__.sep).join('/'));
|
|
72
|
+
if (!rels.some((r) => (0,_language_discovery_js__WEBPACK_IMPORTED_MODULE_4__/* .isLanguageSource */ .Sv)(r) || (0,_language_discovery_js__WEBPACK_IMPORTED_MODULE_4__/* .isLanguageManifest */ .mD)(r) || (0,_language_discovery_js__WEBPACK_IMPORTED_MODULE_4__/* .isExplicitExport */ .Zh)(r))) return batch;
|
|
73
|
+
try {
|
|
74
|
+
const { readTree } = await Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 45950));
|
|
75
|
+
const { fileContents, depFileContents } = await readTree(scanRoot);
|
|
76
|
+
const hit = (0,_language_discovery_js__WEBPACK_IMPORTED_MODULE_4__/* .impactedFiles */ .nn)(fileContents, depFileContents, rels);
|
|
77
|
+
const out = new Set(batch);
|
|
78
|
+
for (const r of hit) out.add(node_path__WEBPACK_IMPORTED_MODULE_2__.join(scanRoot, r));
|
|
79
|
+
return [...out];
|
|
80
|
+
} catch {
|
|
81
|
+
return batch;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
58
85
|
function _readJsonSafe(fp) {
|
|
59
86
|
try { return JSON.parse(fsSync.readFileSync(fp, 'utf8')); } catch { return null; }
|
|
60
87
|
}
|
|
@@ -162,7 +189,12 @@ async function watchProject(scanRoot, onChange, opts = {}) {
|
|
|
162
189
|
if (pending.size > MAX_BURST) { pending.clear(); return; }
|
|
163
190
|
const batch = Array.from(pending);
|
|
164
191
|
pending.clear();
|
|
165
|
-
|
|
192
|
+
const needsExpansion = batch.some((p) => {
|
|
193
|
+
const r = node_path__WEBPACK_IMPORTED_MODULE_2__.relative(scanRoot, p).split(node_path__WEBPACK_IMPORTED_MODULE_2__.sep).join('/');
|
|
194
|
+
return (0,_language_discovery_js__WEBPACK_IMPORTED_MODULE_4__/* .isLanguageSource */ .Sv)(r) || (0,_language_discovery_js__WEBPACK_IMPORTED_MODULE_4__/* .isLanguageManifest */ .mD)(r) || (0,_language_discovery_js__WEBPACK_IMPORTED_MODULE_4__/* .isExplicitExport */ .Zh)(r);
|
|
195
|
+
});
|
|
196
|
+
if (!needsExpansion) { try { onChange(batch); } catch {} return; }
|
|
197
|
+
expandChangedBatch(scanRoot, batch).then((b) => { try { onChange(b); } catch {} });
|
|
166
198
|
};
|
|
167
199
|
let stopped = false;
|
|
168
200
|
(async () => {
|
|
@@ -187,7 +219,7 @@ async function watchProject(scanRoot, onChange, opts = {}) {
|
|
|
187
219
|
};
|
|
188
220
|
}
|
|
189
221
|
|
|
190
|
-
const _internals = { _isScanable, SCAN_EXT_RE, IGNORE_DIR_RE };
|
|
222
|
+
const _internals = { _isScanable, expandChangedBatch, SCAN_EXT_RE, IGNORE_DIR_RE };
|
|
191
223
|
|
|
192
224
|
|
|
193
225
|
/***/ })
|
package/dist/9560.index.js
CHANGED
|
@@ -1018,6 +1018,10 @@ const scan_diff = {
|
|
|
1018
1018
|
const abs = files.map(f => _confine(sessionRoot, f, 'files[]'));
|
|
1019
1019
|
|
|
1020
1020
|
const fileContents = {};
|
|
1021
|
+
// `_confine` returns real paths; the session root may itself be a symlink (macOS /tmp, /var), so keys are made
|
|
1022
|
+
// relative to the REAL root. A key built from the unresolved root climbs out of the tree and no finding ever
|
|
1023
|
+
// matches the file it was asked about.
|
|
1024
|
+
const rootReal = node_fs__WEBPACK_IMPORTED_MODULE_0__.realpathSync(node_path__WEBPACK_IMPORTED_MODULE_2__.resolve(sessionRoot));
|
|
1021
1025
|
let totalBytes = 0;
|
|
1022
1026
|
for (const a of abs) {
|
|
1023
1027
|
let stat;
|
|
@@ -1030,7 +1034,7 @@ const scan_diff = {
|
|
|
1030
1034
|
}
|
|
1031
1035
|
let content;
|
|
1032
1036
|
try { content = node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync(a, 'utf8'); } catch { continue; }
|
|
1033
|
-
const rel = node_path__WEBPACK_IMPORTED_MODULE_2__.relative(
|
|
1037
|
+
const rel = node_path__WEBPACK_IMPORTED_MODULE_2__.relative(rootReal, a).replace(/\\/g, '/');
|
|
1034
1038
|
fileContents[rel] = content;
|
|
1035
1039
|
}
|
|
1036
1040
|
|
|
@@ -1050,9 +1054,13 @@ const scan_diff = {
|
|
|
1050
1054
|
// user's real project on every pre-write self-correction scan. Confirmed
|
|
1051
1055
|
// by direct execution before this fix (11 state artifacts written by a
|
|
1052
1056
|
// single scan_diff-shaped call).
|
|
1053
|
-
|
|
1054
|
-
|
|
1057
|
+
// Haskell and Nix results depend on imported modules and manifests, so the files asked about are scanned together
|
|
1058
|
+
// with their import closure (read from disk, bounded). Findings are still reported only for the requested files.
|
|
1055
1059
|
const wantSet = new Set(Object.keys(fileContents));
|
|
1060
|
+
const { withLanguageContext } = await Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 15911));
|
|
1061
|
+
const lc = withLanguageContext(sessionRoot, fileContents, {});
|
|
1062
|
+
const result = await (0,_posture_state_dir_js__WEBPACK_IMPORTED_MODULE_10__/* .withStateWritesDisabled */ .Ao)(() =>
|
|
1063
|
+
runScan(sessionRoot, { network: false, fileContents: lc.fileContents, depFileContents: lc.depFileContents, deep: true, deepInCi: true }));
|
|
1056
1064
|
const sevRank = { info: 0, low: 1, medium: 2, high: 3, critical: 4 };
|
|
1057
1065
|
const min = sevRank[severity] ?? 0;
|
|
1058
1066
|
// Stage 6 correctness audit (historical): this used to only read
|
|
@@ -1702,12 +1710,26 @@ const synthesize_fix = {
|
|
|
1702
1710
|
// even a mis-attributed swap can't land a bad edit. No stored replacement,
|
|
1703
1711
|
// no per-finding bloat in last-scan.json.
|
|
1704
1712
|
let autofix = null;
|
|
1713
|
+
let languageFix = null;
|
|
1705
1714
|
if (!hasReplacement) {
|
|
1706
1715
|
try {
|
|
1707
1716
|
const abs = _confine(ctx.sessionRoot, f.file, 'finding.file');
|
|
1708
1717
|
const det = (0,_posture_deterministic_fix_js__WEBPACK_IMPORTED_MODULE_8__/* .synthesizeDeterministicPatch */ .X)(f, node_fs__WEBPACK_IMPORTED_MODULE_0__.readFileSync(abs, 'utf8'));
|
|
1709
1718
|
if (det) autofix = { deterministic: true, ruleId: det.ruleId, patch: det.patch };
|
|
1710
1719
|
} catch { /* best-effort — no file / no rule → no autofix */ }
|
|
1720
|
+
// Haskell and Nix: a read-only preview from the language fixer, with the verification gates' verdict and the
|
|
1721
|
+
// FULL / MITIGATION / WORKAROUND tier. It writes nothing; apply_fix re-verifies before anything lands.
|
|
1722
|
+
if (!autofix) {
|
|
1723
|
+
try {
|
|
1724
|
+
const lc = await Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 15911));
|
|
1725
|
+
if (lc.languageOfFinding(f)) {
|
|
1726
|
+
const proj = lc.loadLanguageProject(ctx.sessionRoot);
|
|
1727
|
+
const prev = await lc.languageFixPreview(f, proj.files);
|
|
1728
|
+
languageFix = { status: prev.status, ok: prev.ok, label: prev.label || null, tier: prev.tier || null, reason: prev.reason || null, diff: prev.diff || null, explanation: prev.explanation || null, consequences: prev.consequences || [] };
|
|
1729
|
+
if (prev.ok) autofix = { deterministic: true, ruleId: f.rule || f.family || null, patch: prev.after, file: prev.file, label: prev.label || null, verified: true };
|
|
1730
|
+
}
|
|
1731
|
+
} catch { /* best-effort: the preview is advisory */ }
|
|
1732
|
+
}
|
|
1711
1733
|
}
|
|
1712
1734
|
// Premortem #2: `replacement` is a *patch* (the code we'll write to disk),
|
|
1713
1735
|
// not a finding excerpt. Running it through redactString silently corrupts
|
|
@@ -1726,6 +1748,7 @@ const synthesize_fix = {
|
|
|
1726
1748
|
replacement: hasReplacement ? fix.replacement : null,
|
|
1727
1749
|
template: fix.code || null,
|
|
1728
1750
|
autofix,
|
|
1751
|
+
languageFix,
|
|
1729
1752
|
// #15 — the regression test the scan annotator already generated for this
|
|
1730
1753
|
// finding (present when a PoC was built). Surfaced here so the fix flow
|
|
1731
1754
|
// writes the test alongside the patch; fix-verify-loop then runs it, so an
|