@clear-capabilities/agentic-security-scanner 0.186.2 → 0.187.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 +11 -0
- package/dist/1602.index.js +275 -19
- package/dist/9560.index.js +61 -4
- package/dist/agentic-security.mjs +2 -2
- package/dist/agentic-security.mjs.sha256 +1 -1
- package/dist/{4d06c8944ae121d7085c.json → deabc47d0e27e21bf99b.json} +4 -4
- package/package.json +4 -4
- package/src/capabilities/decide.js +7 -1
- package/src/dataflow/CLAUDE.md +2 -0
- package/src/dataflow/catalog-haskell.js +7 -1
- package/src/dataflow/engine.js +16 -0
- package/src/dataflow/privacy-catalog-haskell.js +2 -1
- package/src/language/CLAUDE.md +19 -0
- package/src/language/compliance-map.js +6 -0
- package/src/language/context.js +20 -0
- package/src/language/haskell-disclosure.js +16 -4
- package/src/language/haskell-guards.js +130 -3
- package/src/language/haskell-ir.js +182 -10
- package/src/language/haskell-models.js +93 -4
- package/src/language/haskell-security-rules.js +112 -34
- package/src/language/haskell-syntax.js +10 -1
- package/src/language/haskell-web.js +44 -8
- package/src/language/support-registry.js +3 -2
- package/src/mcp/tools.js +54 -3
- package/src/posture/attack-taxonomy.js +10 -0
- package/src/posture/entrypoint-inventory.js +6 -2
- package/src/posture/proof-fabric/generate-haskell.js +266 -17
- package/src/posture/proof-fabric/generate.js +10 -3
- package/src/posture/proof-fabric/oracles.js +21 -0
- package/src/posture/stable-id.js +2 -1
- package/src/report/index.js +3 -0
- package/dist/2066.index.js +0 -851
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,17 @@
|
|
|
9
9
|
> make the history less accurate, not more.
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
## 0.187.0 - Haskell parity work: wider exploit proof, broader SAST and taint, new unseen measurement sets
|
|
13
|
+
|
|
14
|
+
- **Haskell SAST and taint, generalised beyond the shapes they were written against.** New sources and sinks (Scotty, Yesod, WAI, Servant, Req, conduit, http-client), guards recognised by what they do rather than by name (host allow-lists, hand-written HTML escapers, `sh -c` scripts), SSRF reported at the send instead of the parse, and Haskell-scoped engine fixes for branches handed to combinators, `words`, `>>=` and common lowering forms. On unseen-v3, now a development set, SAST and taint reach 100%; that is a regression result, not a generalisation claim.
|
|
15
|
+
- **Honest unseen measurement.** A new set, unseen-v4 (78 forms, 13 families, measured once before this release's engine work), gives SAST recall 45.8% to 54.2% and taint precision 73.3% to 84.6%; taint recall is unchanged at 73.3%. Several families remain at 0 to 33% recall.
|
|
16
|
+
- **Real-code precision did not move.** On four pinned real Haskell projects (`bench/dag/independent-haskell/`, one LLM labeler, 60 of the flagged sites), default-scan precision is 2.3% (95% interval 0.4% to 12.1%), against 2.0% before. The new engine flags additional sites that are unlabeled and are not counted.
|
|
17
|
+
- **Alias fix.** A point-free alias of a library function (`tidy = takeFileName`, `run = callCommand`) was treated as an unresolved call, so a sanitizer alias left a flow unsanitized and a sink alias went undetected. Aliases of library functions are now expanded; a local binding with the same name disables the expansion.
|
|
18
|
+
- **Exploit proof.** Widened Haskell reproducer coverage and oracles.
|
|
19
|
+
- **Gates.** 56 Haskell mutation cases and 8 synthetic corpus entries (verdict-flip 460 of 460, corpus 228 of 228); layer-recall maps `.hs` and `.lhs`, taint attribution 126 to 134.
|
|
20
|
+
- **Parity outside the engine.** Haskell on the MCP `query_taint`, context, compliance mapping, capability decisions, attack taxonomy, entrypoint inventory and reports, with `docs/language-parity-haskell.md` listing what remains open.
|
|
21
|
+
- **Not done.** The container proof path is untested, `prove_finding` and `prove_fix` have no `.hs` harness builder, and `haskell-web-auth` route fixtures need a host with scotty, wai, servant and yesod to compile.
|
|
22
|
+
|
|
12
23
|
## 0.186.2 - Haskell exploit proof, a default-scan drift gate, and the measurements behind earlier claims
|
|
13
24
|
|
|
14
25
|
- **Haskell in the exploit proof fabric (GA capability, new language).** `proof doctor` now lists `haskell` and `proof generate` builds reproducers for Haskell findings. Reproducers run in GHC's interpreter (`ghc -e`), so there is no build step. Command injection and path-traversal writes are proven; server-side request forgery is refused because no HTTP client ships with GHC; SQL, argument injection and deserialization are refused by name. Only `base` and the packages that ship with GHC are allowed (read from the installed GHC); a handler that needs a web framework is refused with the package named. Template Haskell, quasi-quotes, CPP, the foreign function interface and plugin options are refused as load-time code execution. 45 of 45 fixture reproductions across 15 classes, 0 false confirmations. Limits: exercised under local confinement on macOS with GHC 9.14.1 only; the container image is wired but was not run against a real engine, and Linux was not exercised.
|
package/dist/1602.index.js
CHANGED
|
@@ -194,9 +194,19 @@ var haskell_parser = __webpack_require__(99864);
|
|
|
194
194
|
// or any Hackage package is refused with the package named where it is known. Template Haskell, quasi-quotes, CPP, the foreign
|
|
195
195
|
// function interface and compiler-plugin options are refused too: they run code at load time, before the payload is involved.
|
|
196
196
|
//
|
|
197
|
-
// Classes
|
|
198
|
-
//
|
|
199
|
-
//
|
|
197
|
+
// Classes, each with an oracle that sees its effect and nothing else:
|
|
198
|
+
// command injection (CWE-78) a nonce-named canary file the injected command alone could create;
|
|
199
|
+
// path traversal by a WRITE a file created or changed outside the directory the program writes to (CWE-22);
|
|
200
|
+
// path traversal by a READ a per-run secret, planted in a file one directory above the program's base directory, appears in the
|
|
201
|
+
// program's output (stdout, stderr or, for a function, its printed result). A read whose content never
|
|
202
|
+
// reaches the output leaves nothing to see and stays unproven;
|
|
203
|
+
// argument injection (CWE-88) the called program is replaced by a harness stand-in that acts on one planted option, but only when that
|
|
204
|
+
// option is its FIRST argument; the canary exists only if attacker data reached the first position of the
|
|
205
|
+
// argument vector. It shows the option position is attacker-controlled, not that the real program has a
|
|
206
|
+
// dangerous option, and the generated reproducer says so in its assumptions.
|
|
207
|
+
// Refused on purpose, with the construct named and the way to supply a hand-written reproducer: SSRF (no HTTP client ships with GHC), SQL
|
|
208
|
+
// (no database binding ships with GHC), deserialization, XSS, code injection, argument injection past the first argument, reads and writes
|
|
209
|
+
// whose base directory the file does not state, and any function the proof cannot fill or call. Nothing is executed on a refusal.
|
|
200
210
|
|
|
201
211
|
|
|
202
212
|
|
|
@@ -281,20 +291,189 @@ function classify(mod, pkg, boot) {
|
|
|
281
291
|
return { ok: false, name: mod };
|
|
282
292
|
}
|
|
283
293
|
|
|
294
|
+
// ---------------------------------------------------------------------------------------------------------------- parameter types
|
|
295
|
+
|
|
296
|
+
const STRING_TYPES = /^(?:String|Prelude\.String|FilePath|System\.IO\.FilePath|\[Char\])$/;
|
|
297
|
+
const unparen = (t) => { let x = t.trim(); while (x.startsWith('(') && x.endsWith(')') && splitArrows(x.slice(1, -1)).length === 1 && !x.slice(1, -1).includes(',')) x = x.slice(1, -1).trim(); return x; };
|
|
298
|
+
|
|
299
|
+
/** What the file means by `Text` and `ByteString` (an import of the real module, not a local type of the same name) and its one-line `type` aliases. */
|
|
300
|
+
function typeResolver(info, text) {
|
|
301
|
+
const textQ = new Set(); const bytesQ = new Set(); let textBare = false; let bytesBare = false;
|
|
302
|
+
for (const imp of info.imports ?? []) {
|
|
303
|
+
const isText = /^Data\.Text(?:\.Lazy)?$/.test(imp.module);
|
|
304
|
+
const isBytes = /^Data\.ByteString(?:\.(?:Char8|Lazy|Lazy\.Char8))?$/.test(imp.module);
|
|
305
|
+
if (!isText && !isBytes) continue;
|
|
306
|
+
const bare = !imp.qualified && !imp.hiding && (imp.items == null || imp.items.some((i) => /^(?:Text|ByteString)\b/.test(i)));
|
|
307
|
+
if (isText) { textQ.add(imp.as ?? imp.module); textBare ||= bare; } else { bytesQ.add(imp.as ?? imp.module); bytesBare ||= bare; }
|
|
308
|
+
}
|
|
309
|
+
const localDef = (n) => new RegExp(`^(?:data|newtype)\\s+${n}\\b`, 'm').test(text);
|
|
310
|
+
if (localDef('Text')) textBare = false;
|
|
311
|
+
if (localDef('ByteString')) bytesBare = false;
|
|
312
|
+
const aliases = new Map();
|
|
313
|
+
for (const m of text.matchAll(/^type\s+([A-Z][\w']*)\s*=\s*([^\n=]+?)\s*(?:--.*)?$/gm)) aliases.set(m[1], m[2]);
|
|
314
|
+
const resolve = (t, depth = 0) => {
|
|
315
|
+
const x = unparen(t);
|
|
316
|
+
if (depth < 4 && aliases.has(x)) return resolve(aliases.get(x), depth + 1);
|
|
317
|
+
return x;
|
|
318
|
+
};
|
|
319
|
+
const stringish = (t) => {
|
|
320
|
+
const x = resolve(t);
|
|
321
|
+
if (STRING_TYPES.test(x)) return 'string';
|
|
322
|
+
const q = /^(?:([A-Z][\w.]*)\.)?(Text|ByteString)$/.exec(x);
|
|
323
|
+
if (!q) return null;
|
|
324
|
+
if (q[2] === 'Text') return q[1] ? (textQ.has(q[1]) ? 'overloaded' : null) : (textBare ? 'overloaded' : null);
|
|
325
|
+
return q[1] ? (bytesQ.has(q[1]) ? 'overloaded' : null) : (bytesBare ? 'overloaded' : null);
|
|
326
|
+
};
|
|
327
|
+
/** `{lit}` is the Haskell expression for a value of this type holding `value`, `{needsOverloaded}` whether it relies on OverloadedStrings. */
|
|
328
|
+
const fill = (t, value) => {
|
|
329
|
+
const x = resolve(t);
|
|
330
|
+
const one = stringish(x);
|
|
331
|
+
if (one) return { expr: value, overloaded: one === 'overloaded' };
|
|
332
|
+
const list = /^\[\s*(.+?)\s*\]$/.exec(x);
|
|
333
|
+
if (list) { const e = stringish(list[1]); if (e) return { expr: `[${value}]`, overloaded: e === 'overloaded' }; }
|
|
334
|
+
const maybe = /^Maybe\s+(.+)$/.exec(x);
|
|
335
|
+
if (maybe) { const e = stringish(maybe[1]); if (e) return { expr: `(Just ${value})`, overloaded: e === 'overloaded' }; }
|
|
336
|
+
return null;
|
|
337
|
+
};
|
|
338
|
+
/** The result can be shown by `print` and carries the content a read returned (String, Text, ByteString, lists and Maybe of them). */
|
|
339
|
+
const printable = (t) => {
|
|
340
|
+
const x = resolve(t);
|
|
341
|
+
return !!(stringish(x) || (/^\[\s*(.+?)\s*\]$/.exec(x) && stringish(/^\[\s*(.+?)\s*\]$/.exec(x)[1])) || (/^Maybe\s+(.+)$/.exec(x) && stringish(/^Maybe\s+(.+)$/.exec(x)[1])));
|
|
342
|
+
};
|
|
343
|
+
return { fill, printable, resolve };
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// ---------------------------------------------------------------------------------------------------------------- path traversal: write or read
|
|
347
|
+
|
|
348
|
+
const READ_SINK = /\b(?:readFile'?|readFileBinary)\b|\b(?:openFile|withFile|openBinaryFile|withBinaryFile)\b[^\n]*\bReadMode\b/;
|
|
349
|
+
const READ_PAYLOAD = '../agentic-proof-secret.txt';
|
|
350
|
+
const READ_SECRET_FILE = 'agentic-proof-secret.txt';
|
|
351
|
+
const READ_ORACLE = { type: 'file_disclosure', params: { secret: 'file' } };
|
|
352
|
+
const WRITE_CONSTRUCTS = 'writeFile, appendFile, copyFile, renameFile, or openFile/withFile in WriteMode/AppendMode';
|
|
353
|
+
const READ_CONSTRUCTS = 'readFile, or openFile/withFile in ReadMode';
|
|
354
|
+
|
|
355
|
+
/** Which path operation the flagged line is: its own line first, then the lines around it. */
|
|
356
|
+
function pathKind(sinkLine, around, writeRe) {
|
|
357
|
+
if (writeRe.test(sinkLine)) return 'write';
|
|
358
|
+
if (READ_SINK.test(sinkLine)) return 'read';
|
|
359
|
+
if (writeRe.test(around)) return 'write';
|
|
360
|
+
if (READ_SINK.test(around)) return 'read';
|
|
361
|
+
return null;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* The directories a read is meant to stay under, as far as the source says: a literal that ends in a slash, or sits next to `</>`, or is
|
|
366
|
+
* bound to a name that says directory. The proof creates them (empty) so that `dir/../secret` resolves; a program whose base is not a
|
|
367
|
+
* relative literal cannot be modelled and is refused rather than guessed.
|
|
368
|
+
*/
|
|
369
|
+
function readBaseDirs(text) {
|
|
370
|
+
const found = [];
|
|
371
|
+
const add = (lit) => {
|
|
372
|
+
if (!lit || lit.startsWith('/') || lit.includes('..') || lit.includes('\\') || /[{}\s:*?"<>|]/.test(lit)) return;
|
|
373
|
+
const seg = lit.split('/').filter(Boolean)[0];
|
|
374
|
+
if (!seg || seg === '.' || ['canary', 'tmp'].includes(seg) || !/^[A-Za-z0-9._-]{1,32}$/.test(seg) || seg.startsWith('__oracle_')) return;
|
|
375
|
+
if (!found.includes(seg)) found.push(seg);
|
|
376
|
+
};
|
|
377
|
+
for (const m of text.matchAll(/"([^"\\\n]+\/)"/g)) add(m[1]);
|
|
378
|
+
for (const m of text.matchAll(/"([^"\\\n]+)"\s*<\/>/g)) add(m[1]);
|
|
379
|
+
for (const m of text.matchAll(/<\/>\s*"([^"\\\n]+)"/g)) add(m[1]);
|
|
380
|
+
for (const m of text.matchAll(/\b[a-z]\w*(?:Dir|Base|Root|Folder|Path|Directory)\w*'?\s*=\s*"([^"\\\n]+)"/gi)) add(m[1]);
|
|
381
|
+
return found.slice(0, 4);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// ---------------------------------------------------------------------------------------------------------------- argument injection
|
|
385
|
+
|
|
386
|
+
// Shells and the tools the proof itself runs are never stood in for: an argument to a shell is command injection (CWE-78), and shadowing
|
|
387
|
+
// a toolchain program on PATH would break the proof rather than test the finding.
|
|
388
|
+
const NEVER_STAND_IN = new Set(['sh', 'bash', 'dash', 'zsh', 'csh', 'tcsh', 'ksh', 'fish', 'env', 'ghc', 'runghc', 'ghci', 'cc', 'gcc', 'clang', 'c++', 'g++', 'ld', 'as', 'ar', 'make', 'cabal', 'stack', 'nix', 'sudo', 'su', 'ssh', 'xargs', 'chmod', 'touch', 'node', 'python', 'python3']);
|
|
389
|
+
const PROCESS_CALL = /\b(callProcess|readProcess|readProcessWithExitCode|spawnProcess|rawSystem|proc)\s+(?:\$\s*)?"([^"\\\s]+)"\s*/;
|
|
390
|
+
const STAND_IN = `#!/bin/sh
|
|
391
|
+
# Stand-in for the program the code under test calls. It is planted by the proof runner, never by the target.
|
|
392
|
+
# It acts on exactly one option, and only when that option is its FIRST argument, by creating the file the option names.
|
|
393
|
+
case "$1" in
|
|
394
|
+
--agentic-proof-write=*) : > "\${1#--agentic-proof-write=}" ;;
|
|
395
|
+
esac
|
|
396
|
+
exit 0
|
|
397
|
+
`;
|
|
398
|
+
// PATH puts the stand-in directory first and keeps the system and toolchain directories after it
|
|
399
|
+
const STAND_IN_PATH = '{{ROOT}}/bin:/opt/ghc/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/homebrew/bin';
|
|
400
|
+
|
|
401
|
+
/** What stands in first position of the argument vector at the call: a named element, a whole list, a fixed string, or something else. */
|
|
402
|
+
function firstArgument(rest) {
|
|
403
|
+
if (rest.startsWith('[')) {
|
|
404
|
+
const inner = rest.slice(1).trimStart();
|
|
405
|
+
if (inner.startsWith('"')) return { kind: 'literal' };
|
|
406
|
+
if (inner.startsWith(']')) return { kind: 'empty' };
|
|
407
|
+
const m = /^([a-z_][\w']*)\s*(?:,|\])/.exec(inner);
|
|
408
|
+
return m ? { kind: 'element', name: m[1] } : { kind: 'complex' };
|
|
409
|
+
}
|
|
410
|
+
if (rest.startsWith('(')) {
|
|
411
|
+
const m = /^\(\s*([a-z_][\w']*)\s*:/.exec(rest);
|
|
412
|
+
return m ? { kind: 'element', name: m[1] } : { kind: 'complex' };
|
|
413
|
+
}
|
|
414
|
+
const m = /^([a-z_][\w']*)\s*(?:$|\)|"|--)/.exec(rest);
|
|
415
|
+
return m ? { kind: 'list', name: m[1] } : { kind: 'complex' };
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
const HINT = 'To prove it anyway, write a reproducer for lang "haskell" (run: ["{{GHC}}", "-ignore-dot-ghci", "-e", "<expression that calls the code>", "<File>.hs"], with an oracle such as command_execution, filesystem_mutation or file_disclosure) and pass it with --reproducer <file>; see the Haskell section of the exploit proof guide. Nothing was executed.';
|
|
419
|
+
|
|
420
|
+
/** What the flagged line is, in words, for a refusal message. */
|
|
421
|
+
function describeLine(finding, root) {
|
|
422
|
+
const src = (() => { try { return generate_haskell_readInside(root, String(finding.file)); } catch { return null; } })();
|
|
423
|
+
const line = src ? (src.text.split('\n')[finding.line - 1] ?? '').trim().replace(/\s+/g, ' ').slice(0, 90) : '';
|
|
424
|
+
return line ? `the flagged line \`${line}\`` : 'the flagged code';
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const REFUSALS = {
|
|
428
|
+
'CWE-89': (what) => `sql-injection: ${what} reaches a database, and GHC ships no database binding, so a program that queries one imports a package outside the proof environment; a program that shells out to the sqlite3 command-line tool depends on a schema, a table and a column count the proof cannot know and a sqlite3 binary this host may not have. A SQL injection is not proven for Haskell.`,
|
|
429
|
+
'CWE-502': (what) => `deserialization: ${what} decodes data, and nothing observable happens when a decoder reads hostile bytes unless a gadget exists in the program; the decoders in common use (aeson, yaml, cereal) are packages outside GHC's own. A deserialization flaw is not proven for Haskell.`,
|
|
430
|
+
'CWE-79': (what) => `cross-site scripting: ${what} builds markup, and the effect is in a browser's DOM, which a command-line run cannot observe. XSS is not proven for Haskell.`,
|
|
431
|
+
'CWE-94': (what) => `code injection: ${what} evaluates code at run time through an interpreter package (hint, plugins) that does not ship with GHC. Code injection is not proven for Haskell.`,
|
|
432
|
+
'CWE-918': (what) => `ssrf: ${what} makes a request, and no HTTP client ships with GHC, so any program that makes one imports a package outside the proof environment. SSRF is not proven for Haskell.`,
|
|
433
|
+
'CWE-1427': (what) => `prompt injection: ${what} builds a model prompt, whose effect needs a model endpoint the proof does not have. Not proven for Haskell.`,
|
|
434
|
+
};
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* The reason a Haskell finding of a class this generator does not cover is refused, naming the construct and the way out.
|
|
438
|
+
* @param {{finding: object, root: string, cwe: string|null}} o
|
|
439
|
+
*/
|
|
440
|
+
function haskellRefusal({ finding, root, cwe }) {
|
|
441
|
+
const what = describeLine(finding, root);
|
|
442
|
+
const body = REFUSALS[cwe]?.(what) ?? `${cwe ?? 'this class'}: no payload and oracle exist for ${cwe ?? 'it'} in Haskell (${what}). Generated reproducers cover command injection (CWE-78), path traversal by a write or a read (CWE-22) and argument injection into a process call (CWE-88).`;
|
|
443
|
+
return generate_haskell_fail(`${body} ${HINT}`);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
// ---------------------------------------------------------------------------------------------------------------- generation
|
|
447
|
+
|
|
284
448
|
/** @param {{finding: object, root: string, cls: {name: string, payload: string, oracle: object, network?: string, watch?: object, needsHs?: RegExp}, bootModules?: Set<string>}} o */
|
|
285
|
-
function generateHaskellReproducer(
|
|
449
|
+
function generateHaskellReproducer(o) {
|
|
450
|
+
const r = generateInner(o);
|
|
451
|
+
if (r.ok || r.reason.includes('Nothing was executed.')) return r;
|
|
452
|
+
return { ...r, reason: `${r.reason.replace(/\.$/, '')}. ${HINT}` };
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
function generateInner({ finding, root, cls, bootModules }) {
|
|
286
456
|
const rel = String(finding.file);
|
|
287
|
-
if (cls.name === 'ssrf') return
|
|
457
|
+
if (cls.name === 'ssrf') return haskellRefusal({ finding, root, cwe: 'CWE-918' });
|
|
288
458
|
const src = generate_haskell_readInside(root, rel);
|
|
289
459
|
if (!src) return generate_haskell_fail('the flagged file is missing, outside the repository, or too large');
|
|
290
460
|
const hazard = loadTimeHazard(src.text);
|
|
291
461
|
if (hazard) return generate_haskell_fail(`the flagged file is refused: ${hazard}`);
|
|
462
|
+
if (/\{\{[A-Z_]+(?::[a-z0-9_-]{1,32})?\}\}/.test(src.text)) return generate_haskell_fail('the flagged file contains text shaped like a proof placeholder ({{NAME}}), which the runner would substitute inside the program');
|
|
292
463
|
const info = (0,haskell_parser/* parseHaskell */.cX)(src.text);
|
|
293
464
|
if (!info || info.status !== 'parsed') return generate_haskell_fail('the flagged file could not be parsed as Haskell');
|
|
294
465
|
const lines = src.text.split('\n');
|
|
295
466
|
const sinkLine = lines[finding.line - 1] ?? '';
|
|
296
467
|
const around = lines.slice(Math.max(0, finding.line - 3), finding.line + 2).join('\n');
|
|
297
|
-
|
|
468
|
+
|
|
469
|
+
// the class decides what is planted and what is watched; for a path operation the flagged line decides which of two it is
|
|
470
|
+
let spec = cls;
|
|
471
|
+
let kind = cls.name;
|
|
472
|
+
if (cls.name === 'path-traversal') {
|
|
473
|
+
const k = pathKind(sinkLine, around, cls.needsHs);
|
|
474
|
+
if (!k) return generate_haskell_fail(`path-traversal: ${describeLine(finding, root)} is not a write (${WRITE_CONSTRUCTS}) or a read (${READ_CONSTRUCTS}); other file operations (removeFile, createDirectory, listDirectory, doesFileExist, and the like) leave nothing the oracle can observe`);
|
|
475
|
+
if (k === 'read') { kind = 'path-traversal-read'; spec = { name: 'path-traversal-read', payload: READ_PAYLOAD, oracle: READ_ORACLE }; }
|
|
476
|
+
}
|
|
298
477
|
|
|
299
478
|
const tools = (0,runner/* hostTools */.qV)();
|
|
300
479
|
const boot = bootModules ?? (tools.ghc ? bootModuleSet(tools.ghc) : null);
|
|
@@ -322,6 +501,7 @@ function generateHaskellReproducer({ finding, root, cls, bootModules }) {
|
|
|
322
501
|
const dep = (0,haskell_parser/* parseHaskell */.cX)(local.text);
|
|
323
502
|
if (!dep || dep.status !== 'parsed') return generate_haskell_fail(`the module ${mod} could not be parsed as Haskell`);
|
|
324
503
|
const h = loadTimeHazard(local.text); if (h) return generate_haskell_fail(`the module ${mod} is refused: ${h}`);
|
|
504
|
+
if (/\{\{[A-Z_]+(?::[a-z0-9_-]{1,32})?\}\}/.test(local.text)) return generate_haskell_fail(`the module ${mod} contains text shaped like a proof placeholder ({{NAME}})`);
|
|
325
505
|
sources[`${mod.replaceAll('.', '/')}.hs`] = external_node_path_.relative(rootReal, local.real);
|
|
326
506
|
const r = visit(dep.imports ?? []); if (r) return r;
|
|
327
507
|
continue;
|
|
@@ -337,18 +517,35 @@ function generateHaskellReproducer({ finding, root, cls, bootModules }) {
|
|
|
337
517
|
sources[entry] = rel;
|
|
338
518
|
|
|
339
519
|
const assumptions = [];
|
|
340
|
-
const base = { schema: 'agentic-security/reproducer', version: 1, findingId: String(finding.stableId ?? finding.id ?? 'generated'), lang: 'haskell', oracle:
|
|
341
|
-
if (
|
|
342
|
-
const ghcRun = (expr) => ['{{GHC}}', '-ignore-dot-ghci', '-e', expr, entry];
|
|
520
|
+
const base = { schema: 'agentic-security/reproducer', version: 1, findingId: String(finding.stableId ?? finding.id ?? 'generated'), lang: 'haskell', oracle: spec.oracle, network: spec.network ?? 'none', ...(spec.watch ? { watch: spec.watch } : {}) };
|
|
521
|
+
if (spec.watch) assumptions.push('the write target is assumed to be one directory below the working directory (the payload is ../escaped.txt); if the code uses another base, the proof will not confirm it');
|
|
522
|
+
const ghcRun = (expr, overloaded = false) => ['{{GHC}}', '-ignore-dot-ghci', ...(overloaded ? ['-e', ':set -XOverloadedStrings'] : []), '-e', expr, entry];
|
|
343
523
|
const literal = (s) => JSON.stringify(s); // payloads are fixed strings with no quote or backslash; this is a plain Haskell string literal
|
|
524
|
+
const resolver = typeResolver(info, src.text);
|
|
525
|
+
|
|
526
|
+
// what the class plants beside the program
|
|
527
|
+
const extras = { files: {}, build: undefined, env: undefined };
|
|
528
|
+
if (kind === 'path-traversal-read') {
|
|
529
|
+
const dirs = readBaseDirs(src.text);
|
|
530
|
+
if (!dirs.length) return generate_haskell_fail(`path-traversal: ${describeLine(finding, root)} reads a path whose base directory is not a relative literal in the file (a path built from getCurrentDirectory, an environment variable, an absolute directory or a configuration value), so the proof cannot plant the file it would escape to`);
|
|
531
|
+
extras.files = { [READ_SECRET_FILE]: '{{SECRET:file}}', ...Object.fromEntries(dirs.map((d) => [`${d}/.keep`, ''])) };
|
|
532
|
+
assumptions.push(`the read is assumed to be confined under ${dirs.map((d) => `"${d}"`).join(' or ')}, one directory below the working directory; the proof plants a file one level up (${READ_PAYLOAD}) and sees it only if it reaches the program's output (stdout, stderr or, for a function, its printed result)`);
|
|
533
|
+
}
|
|
344
534
|
|
|
345
535
|
// shape 1: a program that reads its payload from the command line
|
|
346
536
|
const hasMain = (info.functions ?? []).some((f) => f.scope === 'top' && f.name === 'main');
|
|
347
537
|
if (/\bgetArgs\b/.test(src.text) && hasMain) {
|
|
538
|
+
if (kind === 'argument-injection') {
|
|
539
|
+
const call = argumentCall(lines, finding);
|
|
540
|
+
if (!call.ok) return call;
|
|
541
|
+
if (call.first.kind !== 'list' || !new RegExp(`\\b${call.first.name}\\s*<-\\s*getArgs\\b`).test(src.text)) return generate_haskell_fail(`argument-injection: the first argument of the call to ${call.exe} is ${describeFirst(call.first)}, and the proof can place the payload only where the whole argument vector comes straight from getArgs (\`args <- getArgs\` then the call with \`args\`)`);
|
|
542
|
+
Object.assign(extras, standIn(call.exe));
|
|
543
|
+
assumptions.push(...standInAssumptions(call.exe));
|
|
544
|
+
}
|
|
348
545
|
assumptions.push('the payload is passed as the first and only command-line argument; a program that expects other arguments will not reach the flagged line');
|
|
349
|
-
const reproducer = { ...base, sources, run: ghcRun(`:main ${literal(
|
|
546
|
+
const reproducer = { ...base, sources, ...(Object.keys(extras.files).length ? { files: extras.files } : {}), ...(extras.build ? { build: extras.build } : {}), ...(extras.env ? { env: extras.env } : {}), run: ghcRun(`:main ${literal(spec.payload)}`) };
|
|
350
547
|
const errs = (0,proof_fabric_reproducer/* validateReproducer */.mC)(reproducer);
|
|
351
|
-
return errs.length ? generate_haskell_fail(`the generated reproducer is invalid: ${errs[0]}`) : { ok: true, reproducer, basis: { shape: 'script', class:
|
|
548
|
+
return errs.length ? generate_haskell_fail(`the generated reproducer is invalid: ${errs[0]}`) : { ok: true, reproducer, basis: { shape: 'script', class: spec.name, entry: rel, line: finding.line, assumptions } };
|
|
352
549
|
}
|
|
353
550
|
|
|
354
551
|
// shape 2: a top-level function around the flagged line
|
|
@@ -368,14 +565,66 @@ function generateHaskellReproducer({ finding, root, cls, bootModules }) {
|
|
|
368
565
|
const result = parts[parts.length - 1]; const params = parts.slice(0, -1);
|
|
369
566
|
if (!/^IO\b/.test(result)) return generate_haskell_fail(`${fn.name} returns ${result.slice(0, 40)}, not IO, so calling it would not perform the flagged operation`);
|
|
370
567
|
if (!params.length) return generate_haskell_fail(`${fn.name} takes no parameters, so the payload has no way in`);
|
|
371
|
-
const
|
|
372
|
-
if (
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
568
|
+
const resultInner = result.replace(/^IO\s*/, '').trim();
|
|
569
|
+
if (kind === 'path-traversal-read' && resultInner !== '()' && !resolver.printable(resultInner)) return generate_haskell_fail(`${fn.name} returns IO ${resultInner.slice(0, 40)}, whose content the proof cannot print; a read is observed only in the output, so the result must be (), String, Text, ByteString or a list or Maybe of them`);
|
|
570
|
+
|
|
571
|
+
let payloadFor = () => spec.payload; // which parameters get the payload (all, unless the class says which)
|
|
572
|
+
if (kind === 'argument-injection') {
|
|
573
|
+
const call = argumentCall(lines, finding);
|
|
574
|
+
if (!call.ok) return call;
|
|
575
|
+
const headLine = lines[fn.span.startLine - 1] ?? '';
|
|
576
|
+
const head = new RegExp(`^${fn.name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}((?:\\s+[a-z_][\\w']*)*)\\s*(?:=|\\|)`).exec(headLine);
|
|
577
|
+
const names = head ? head[1].trim().split(/\s+/).filter(Boolean) : null;
|
|
578
|
+
if (!names || names.length !== params.length) return generate_haskell_fail(`argument-injection: the parameters of ${fn.name} are patterns or the definition is point-free, so the proof cannot tell which parameter reaches the call`);
|
|
579
|
+
if (call.first.kind !== 'element' && call.first.kind !== 'list') return generate_haskell_fail(`argument-injection: the first argument of the call to ${call.exe} is ${describeFirst(call.first)}, and the proof can place the payload only where a plain parameter of ${fn.name} stands first in the argument vector`);
|
|
580
|
+
const at = names.indexOf(call.first.name);
|
|
581
|
+
if (at < 0) return generate_haskell_fail(`argument-injection: the first argument of the call to ${call.exe} is \`${call.first.name}\`, which is not a parameter of ${fn.name}, so the proof cannot place the payload there`);
|
|
582
|
+
const shape = resolver.fill(params[at], 'x');
|
|
583
|
+
if (!shape) return generate_haskell_fail(`${fn.name} takes a parameter of type ${params[at].slice(0, 40)}; only String, FilePath, Text, ByteString and lists or Maybe of them can be filled with a payload`);
|
|
584
|
+
if (call.first.kind === 'list' && !/^\[/.test(shape.expr)) return generate_haskell_fail(`argument-injection: ${call.first.name} is passed as the whole argument vector but has type ${params[at].slice(0, 40)}, not a list of strings`);
|
|
585
|
+
if (call.first.kind === 'element' && /^\[/.test(shape.expr)) return generate_haskell_fail(`argument-injection: ${call.first.name} is a list but stands as one element of the argument vector`);
|
|
586
|
+
payloadFor = (i) => (i === at ? spec.payload : 'benign');
|
|
587
|
+
Object.assign(extras, standIn(call.exe));
|
|
588
|
+
assumptions.push(...standInAssumptions(call.exe), `the payload is placed in the parameter \`${call.first.name}\` only; the other parameters get the value "benign"`);
|
|
589
|
+
} else assumptions.push('the payload is passed in every parameter (a String has no request-like stand-in), which is an approximation of how the function is really called');
|
|
590
|
+
|
|
591
|
+
const filled = [];
|
|
592
|
+
let overloaded = false;
|
|
593
|
+
for (let i = 0; i < params.length; i++) {
|
|
594
|
+
const f = resolver.fill(params[i], literal(payloadFor(i)));
|
|
595
|
+
if (!f) return generate_haskell_fail(`${fn.name} takes a parameter of type ${params[i].slice(0, 40)}; only String, FilePath, Text, ByteString and lists or Maybe of them can be filled with a payload`);
|
|
596
|
+
filled.push(f.expr); overloaded ||= f.overloaded;
|
|
597
|
+
}
|
|
598
|
+
if (overloaded) assumptions.push('Text and ByteString arguments are written as string literals under OverloadedStrings, set for the call only, not for the program');
|
|
599
|
+
const tail = kind === 'path-traversal-read' && resultInner !== '()' ? '>>= print' : '>>= \\_ -> return ()';
|
|
600
|
+
const call = `${fn.name} ${filled.join(' ')} ${tail}`;
|
|
601
|
+
const reproducer = { ...base, sources, ...(Object.keys(extras.files).length ? { files: extras.files } : {}), ...(extras.build ? { build: extras.build } : {}), ...(extras.env ? { env: extras.env } : {}), run: ghcRun(call, overloaded) };
|
|
376
602
|
const errs = (0,proof_fabric_reproducer/* validateReproducer */.mC)(reproducer);
|
|
377
|
-
return errs.length ? generate_haskell_fail(`the generated reproducer is invalid: ${errs[0]}`) : { ok: true, reproducer, basis: { shape: 'function', class:
|
|
603
|
+
return errs.length ? generate_haskell_fail(`the generated reproducer is invalid: ${errs[0]}`) : { ok: true, reproducer, basis: { shape: 'function', class: spec.name, entry: rel, line: finding.line, function: `${fn.name}(${params.length} ${params.every((p) => STRING_TYPES.test(p.trim())) ? 'String' : params.length === 1 ? 'parameter' : 'parameters'})`, assumptions } };
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
function describeFirst(first) {
|
|
607
|
+
return { literal: 'a fixed string', empty: 'absent (an empty list)', complex: 'an expression the proof cannot read as a plain parameter', element: 'a parameter', list: 'a list' }[first.kind] ?? 'unreadable';
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
/** Find the process call at the flagged line and what stands first in its argument vector. */
|
|
611
|
+
function argumentCall(lines, finding) {
|
|
612
|
+
const window = lines.slice(Math.max(0, finding.line - 1), finding.line + 2).join(' ').replace(/\s+/g, ' ');
|
|
613
|
+
const m = PROCESS_CALL.exec(window);
|
|
614
|
+
if (!m) return generate_haskell_fail('argument-injection: the flagged line is not a call to callProcess, readProcess, readProcessWithExitCode, spawnProcess, rawSystem or proc with the program named by a string literal, so the proof cannot tell which program receives the arguments');
|
|
615
|
+
const exe = m[2];
|
|
616
|
+
if (NEVER_STAND_IN.has(exe) || !/^[A-Za-z0-9][A-Za-z0-9._+-]{0,31}$/.test(exe)) return generate_haskell_fail(`argument-injection: the program is \`${exe}\`, which the proof does not stand in for (a shell, an interpreter or a toolchain program; an argument to a shell is command injection, CWE-78)`);
|
|
617
|
+
const rest = window.slice(m.index + m[0].length).trimStart();
|
|
618
|
+
const first = firstArgument(rest);
|
|
619
|
+
if (first.kind === 'literal' || first.kind === 'empty') return generate_haskell_fail(`argument-injection: the first argument of the call to ${exe} is ${describeFirst(first)}, and the proof covers only attacker data in the FIRST position, where every conventional option parser reads a leading dash as an option; later positions depend on the program's own grammar (an option such as -f takes the next word as its value)`);
|
|
620
|
+
return { ok: true, exe, first };
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/** The stand-in program, its permission and the PATH that finds it. */
|
|
624
|
+
function standIn(exe) {
|
|
625
|
+
return { files: { [`bin/${exe}`]: STAND_IN }, build: ['/bin/chmod', '755', `bin/${exe}`], env: { PATH: STAND_IN_PATH } };
|
|
378
626
|
}
|
|
627
|
+
const standInAssumptions = (exe) => [`the program \`${exe}\` is replaced by a harness stand-in that acts on one planted option when it is the FIRST argument; a confirmation shows attacker data reaches the first argument unseparated and unvalidated, not that the real ${exe} has a dangerous option`];
|
|
379
628
|
|
|
380
629
|
;// CONCATENATED MODULE: ./src/posture/proof-fabric/generate.js
|
|
381
630
|
// Reproducer generation from a finding's own evidence (PRD 1: `triage exploit --prove` with no hand-written reproducer).
|
|
@@ -397,6 +646,8 @@ function generateHaskellReproducer({ finding, root, cls, bootModules }) {
|
|
|
397
646
|
// loads it and calls it, filling the tainted parameter with the payload. A parameter that is a request-like object
|
|
398
647
|
// (`req`) gets a stand-in whose `body`/`query`/`params` answer every property with the payload.
|
|
399
648
|
//
|
|
649
|
+
// Haskell additionally proves path-traversal READS (a planted secret appears in the output) and argument injection into the first argument
|
|
650
|
+
// of a process call (a stand-in for the called program); see `generate-haskell.js` for what each shows and does not show.
|
|
400
651
|
// Weakness classes with a payload and an oracle that can SEE the effect: CWE-78 (a canary file created by the injected command),
|
|
401
652
|
// CWE-22 (a write that lands outside the working directory, only for write sinks), CWE-918 (a request reaching the runner's loopback
|
|
402
653
|
// listener). Others (injection into a database, deserialization, memory safety) need an environment or a native harness this does not
|
|
@@ -414,6 +665,10 @@ const CLASSES = {
|
|
|
414
665
|
'CWE-22': { needsPy: /\bopen\s*\([^)]*['"][wax]b?\+?['"]|\.write_(?:text|bytes)\s*\(|\bshutil\.(?:copy|move)/, name: 'path-traversal', payload: '../escaped.txt', oracle: { type: 'filesystem_mutation', params: { canary: 'fs' } }, watch: { fs: 'escaped.txt' }, needsHs: /\b(?:writeFile|appendFile|copyFile|copyFileWithMetadata|renameFile|openBinaryFile)\b|\b(?:openFile|withFile|withBinaryFile)\b[^\n]*\b(?:WriteMode|AppendMode|ReadWriteMode)\b/, needs: /\b(?:writeFile|writeFileSync|appendFile|appendFileSync|createWriteStream)\b/ },
|
|
415
666
|
'CWE-918': { name: 'ssrf', payload: '{{CALLBACK_URL}}', oracle: { type: 'outbound_callback' }, network: 'callback' },
|
|
416
667
|
};
|
|
668
|
+
// classes only the Haskell generator builds (the other languages refuse them): argument injection needs a stand-in for the called program
|
|
669
|
+
const HASKELL_ONLY = {
|
|
670
|
+
'CWE-88': { name: 'argument-injection', payload: '--agentic-proof-write={{CANARY:arg}}', oracle: { type: 'argument_injection', params: { canary: 'arg' } } },
|
|
671
|
+
};
|
|
417
672
|
const generate_MAX_SOURCE = 256 * 1024;
|
|
418
673
|
const generate_MAX_FILES = 8;
|
|
419
674
|
const EXTS = ['', '.js', '.mjs', '.cjs', '/index.js'];
|
|
@@ -515,11 +770,12 @@ clearTimeout(timer);
|
|
|
515
770
|
|
|
516
771
|
function generateReproducer({ finding, root }) {
|
|
517
772
|
const cwe = normCwe(finding?.cwe);
|
|
518
|
-
const cls = CLASSES[cwe];
|
|
519
|
-
if (!cls) return generate_fail(`no payload and oracle exist for ${cwe ?? 'this finding'}; supported: ${Object.keys(CLASSES).join(', ')} (others need a database, a deserializer or a native harness)`);
|
|
520
773
|
const rel = String(finding?.file ?? '');
|
|
521
774
|
const isPy = /\.py$/i.test(rel);
|
|
522
775
|
const isHs = /\.hs$/i.test(rel);
|
|
776
|
+
const cls = CLASSES[cwe] ?? (isHs ? HASKELL_ONLY[cwe] : undefined);
|
|
777
|
+
if (isHs && !cls && Number.isInteger(finding?.line)) return haskellRefusal({ finding, root, cwe });
|
|
778
|
+
if (!cls) return generate_fail(`no payload and oracle exist for ${cwe ?? 'this finding'}; supported: ${Object.keys(CLASSES).join(', ')} (others need a database, a deserializer or a native harness)`);
|
|
523
779
|
if (!isPy && !isHs && !/\.(?:js|mjs|cjs)$/i.test(rel)) return generate_fail(`no harness builder for ${external_node_path_.extname(rel) || 'this file type'}; JavaScript, Python and Haskell only`);
|
|
524
780
|
if (!Number.isInteger(finding?.line)) return generate_fail('the finding has no line number');
|
|
525
781
|
if (isPy) return generatePythonReproducer({ finding, root, cls });
|
package/dist/9560.index.js
CHANGED
|
@@ -721,8 +721,14 @@ const INTERPRETER_NAMES = new Set([
|
|
|
721
721
|
'time', 'timeout', 'sudo', 'doas', 'su', 'ssh', 'osascript', 'launchctl', 'script', 'expect', 'tclsh', 'wish',
|
|
722
722
|
'awk', 'gawk', 'mawk', 'nawk', 'java', 'jshell', 'deno', 'bun', 'nodejs', 'swift', 'make', 'gmake',
|
|
723
723
|
'npm', 'npx', 'yarn', 'pnpm', 'pip', 'pip3', 'pipx', 'gem', 'bundle', 'cargo', 'go', 'gradle', 'mvn', 'watch',
|
|
724
|
+
// Haskell and Nix toolchains run code supplied by the project: GHC and cabal execute Template Haskell splices and a
|
|
725
|
+
// custom Setup.hs at build time, runghc/ghci interpret a source file, and the Nix evaluators run the expressions they
|
|
726
|
+
// are given (builders run the derivation's build script).
|
|
727
|
+
'ghc', 'ghci', 'runghc', 'runhaskell', 'cabal', 'stack',
|
|
728
|
+
'nix', 'nix-build', 'nix-shell', 'nix-instantiate', 'nix-env', 'nix-store',
|
|
724
729
|
]);
|
|
725
|
-
|
|
730
|
+
// Versioned toolchain binaries (`ghc-9.14.1`, `runghc-9.14.1`, `cabal-3.14`) are the same executables under another name.
|
|
731
|
+
const INTERPRETER_FAMILY = /^(?:python|pypy|ruby|perl|php|lua|luajit|node|tclsh)[0-9.]*$|^(?:ghc|ghci|runghc|runhaskell|cabal|stack)-[0-9][0-9.]*$/;
|
|
726
732
|
|
|
727
733
|
/**
|
|
728
734
|
* What kind of executable this is. `interpreter` is true for a known shell or
|
|
@@ -3578,6 +3584,22 @@ const scan_diff = {
|
|
|
3578
3584
|
},
|
|
3579
3585
|
};
|
|
3580
3586
|
|
|
3587
|
+
// The ordered source-to-sink steps of a finding: its `trace` when the detector wrote one, else the `chain` the IR taint
|
|
3588
|
+
// engine records (file, line, label, kind, provenance). Null when the finding carries neither.
|
|
3589
|
+
function _flowSteps(f) {
|
|
3590
|
+
if (Array.isArray(f.trace) && f.trace.length) return f.trace;
|
|
3591
|
+
if (f.trace && !Array.isArray(f.trace)) return f.trace;
|
|
3592
|
+
if (Array.isArray(f.chain) && f.chain.length) {
|
|
3593
|
+
return f.chain.map((s) => ({ file: s.file ?? null, line: s.line ?? null, label: s.label ?? null, kind: s.kind || (s.provenance ? 'source' : 'step'), provenance: s.provenance ?? null }));
|
|
3594
|
+
}
|
|
3595
|
+
return null;
|
|
3596
|
+
}
|
|
3597
|
+
// Labels of the structured source, sink and rule, for matching only.
|
|
3598
|
+
function _flowEnds(f) {
|
|
3599
|
+
const lab = (x) => (x && typeof x === 'object' ? [x.label, x.family, x.kind].filter((v) => typeof v === 'string').join(' ') : '');
|
|
3600
|
+
return [lab(f.source), lab(f.sink), typeof f.rule === 'string' ? f.rule : ''].join(' ');
|
|
3601
|
+
}
|
|
3602
|
+
|
|
3581
3603
|
// ─── query_taint ─────────────────────────────────────────────────────────────
|
|
3582
3604
|
const query_taint = {
|
|
3583
3605
|
name: 'query_taint',
|
|
@@ -3608,13 +3630,16 @@ const query_taint = {
|
|
|
3608
3630
|
// dilutes its reasoning; the agent receives a bounded slice plus the
|
|
3609
3631
|
// cursor to fetch the rest if it wants.
|
|
3610
3632
|
const all = (scan.findings || []).filter(f => {
|
|
3611
|
-
|
|
3633
|
+
// The structured flow counts too: an IR taint finding (Haskell included) records its path as `source`, `sink`, `rule`
|
|
3634
|
+
// and `chain`, and carries no free-text description or `trace`, so matching only the text fields would answer
|
|
3635
|
+
// "no path" for a path the scan did find.
|
|
3636
|
+
const hay = [f.description, f.title, f.vuln, f.snippet, JSON.stringify(_flowSteps(f) || ''), _flowEnds(f)].join(' ').toLowerCase();
|
|
3612
3637
|
return hay.includes(srcL) && hay.includes(sinkL);
|
|
3613
3638
|
});
|
|
3614
3639
|
const page = all.slice(off, off + lim).map(f => (0,_redact_js__WEBPACK_IMPORTED_MODULE_21__/* .redactFinding */ .lE)({
|
|
3615
3640
|
id: f.id, severity: f.severity, file: f.file, line: f.line,
|
|
3616
3641
|
title: f.title || f.vuln, description: f.description,
|
|
3617
|
-
trace: f
|
|
3642
|
+
trace: _flowSteps(f),
|
|
3618
3643
|
}));
|
|
3619
3644
|
return {
|
|
3620
3645
|
_meta: META,
|
|
@@ -3654,7 +3679,7 @@ const explain_finding = {
|
|
|
3654
3679
|
title: f.title || f.vuln, cwe: f.cwe,
|
|
3655
3680
|
description: f.description, remediation: f.remediation,
|
|
3656
3681
|
snippet: f.snippet || null,
|
|
3657
|
-
trace: f
|
|
3682
|
+
trace: _flowSteps(f),
|
|
3658
3683
|
});
|
|
3659
3684
|
// Harness-anatomy #1: explain_finding's trace is the most-likely-large
|
|
3660
3685
|
// field on a single finding. Offload when it crosses the threshold so
|
|
@@ -4314,6 +4339,9 @@ const synthesize_fix = {
|
|
|
4314
4339
|
languageFix.applyWith = { finding_id: f.id, confirm: true, plan_digest: languageFix.planDigest };
|
|
4315
4340
|
}
|
|
4316
4341
|
else if (prev.ok) autofix = { deterministic: true, ruleId: f.rule || f.family || null, patch: prev.after, file: prev.file, label: prev.label || null, verified: true };
|
|
4342
|
+
} else if (lc.isLanguageDependencyFinding(f)) {
|
|
4343
|
+
// Named, not silent: a Hackage or flake dependency is fixed by raising a constraint, which has its own tool.
|
|
4344
|
+
languageFix = { status: 'use-sca-upgrade', ok: false, label: null, tier: null, reason: 'this is a dependency finding: use synthesize_sca_upgrade for the constraint edit (apply_sca_upgrade writes it)', diff: null, explanation: null, consequences: [] };
|
|
4317
4345
|
}
|
|
4318
4346
|
} catch { /* best-effort: the preview is advisory */ }
|
|
4319
4347
|
}
|
|
@@ -4728,6 +4756,22 @@ const query_cache_telemetry = {
|
|
|
4728
4756
|
},
|
|
4729
4757
|
};
|
|
4730
4758
|
|
|
4759
|
+
async function _languageUpgrade(lc, f, ctx, apply) {
|
|
4760
|
+
const proj = lc.loadLanguageProject(ctx.sessionRoot);
|
|
4761
|
+
return lc.languageUpgradePreview(f, { ...proj.files, ...proj.manifests }, { apply, root: ctx.sessionRoot });
|
|
4762
|
+
}
|
|
4763
|
+
// The result shape both SCA upgrade tools return for a Hackage or flake dependency. `verified` is never true: the edit
|
|
4764
|
+
// changes a declared constraint or a ref, not the resolved version.
|
|
4765
|
+
function _languageUpgradeResult(f, r) {
|
|
4766
|
+
return {
|
|
4767
|
+
ok: true, mode: r.ok ? 'source-edit' : 'blocked', ecosystem: f.ecosystem, package: f.package || null,
|
|
4768
|
+
currentVersion: f.version || null, targetVersion: null, command: null,
|
|
4769
|
+
reason: r.ok ? null : (r.reason || 'no upgrade could be planned'),
|
|
4770
|
+
languageUpgrade: { status: r.status || null, tier: r.tier || null, label: r.label || null, file: r.file || null, diff: r.diff || null, explanation: r.explanation || null, consequences: r.consequences || [], backup: r.backup ? r.backup.id || null : null },
|
|
4771
|
+
verified: false,
|
|
4772
|
+
};
|
|
4773
|
+
}
|
|
4774
|
+
|
|
4731
4775
|
// ─── synthesize_sca_upgrade ───────────────────────────────────────────────
|
|
4732
4776
|
// Phase 3 / Item 5 of the SCA improvement plan. Read-only counterpart to
|
|
4733
4777
|
// apply_sca_upgrade — produces a structured upgrade plan via the
|
|
@@ -4756,6 +4800,10 @@ const synthesize_sca_upgrade = {
|
|
|
4756
4800
|
if (f.type !== 'vulnerable_dep') {
|
|
4757
4801
|
return { _meta: META, ok: false, reason: 'finding is not an SCA vulnerable_dep — use synthesize_fix for SAST findings' };
|
|
4758
4802
|
}
|
|
4803
|
+
// Hackage constraints and flake inputs are source edits the language planner owns; without this the generic planner
|
|
4804
|
+
// answers "no automated upgrade" for a dependency the CLI can fix. Read-only: nothing is written or run.
|
|
4805
|
+
const lc = await Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 52603));
|
|
4806
|
+
if (lc.isLanguageDependencyFinding(f)) return { _meta: META, ..._languageUpgradeResult(f, await _languageUpgrade(lc, f, ctx, false)) };
|
|
4759
4807
|
const { planScaUpgrade } = await _getScaUpgrade();
|
|
4760
4808
|
const plan = await planScaUpgrade({ scanRoot: ctx.sessionRoot, finding: f });
|
|
4761
4809
|
return { _meta: META, ...plan };
|
|
@@ -4796,6 +4844,15 @@ const apply_sca_upgrade = {
|
|
|
4796
4844
|
if (f.type !== 'vulnerable_dep') {
|
|
4797
4845
|
return { _meta: META, applied: false, reason: 'finding is not an SCA vulnerable_dep — use apply_fix for SAST findings' };
|
|
4798
4846
|
}
|
|
4847
|
+
const lc = await Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 52603));
|
|
4848
|
+
if (lc.isLanguageDependencyFinding(f)) {
|
|
4849
|
+
// Plan first, confine the one file it names, then write it with a backup and a history entry (`undo` reverts it).
|
|
4850
|
+
const plan = await _languageUpgrade(lc, f, ctx, false);
|
|
4851
|
+
if (!plan.ok) return { _meta: META, applied: false, ..._languageUpgradeResult(f, plan) };
|
|
4852
|
+
try { _confine(ctx.sessionRoot, plan.file, 'upgrade.file'); } catch (e) { return { _meta: META, applied: false, reason: String((e && e.message) || e) }; }
|
|
4853
|
+
const done = await _languageUpgrade(lc, f, ctx, true);
|
|
4854
|
+
return { _meta: META, applied: done.applied === true, ..._languageUpgradeResult(f, done), testsRun: false, testsNote: 'a constraint edit is not re-resolved or re-tested by this tool; resolve (for example `cabal build --dry-run`), rescan and run the project tests before relying on it' };
|
|
4855
|
+
}
|
|
4799
4856
|
const { applyScaUpgrade } = await _getScaUpgrade();
|
|
4800
4857
|
const result = await applyScaUpgrade({ scanRoot: ctx.sessionRoot, finding: f, runTests: run_tests });
|
|
4801
4858
|
return { _meta: META, ...result };
|