@clear-capabilities/agentic-security-scanner 0.127.0 → 0.128.1

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 CHANGED
@@ -1,5 +1,65 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.128.1 — patch dependency vulnerabilities (11 Dependabot alerts → 0)
4
+
5
+ Security maintenance. Cleared all 11 open Dependabot alerts by updating the two lockfiles to
6
+ patched versions (all within-major bumps, no breakage):
7
+
8
+ - **`scanner/`** — `js-yaml` 4.1 → 4.3.0 (GHSA-h67p-54hq-rp68, quadratic-complexity DoS via merge
9
+ keys). `js-yaml` is inlined into the shipped bundle, so `dist/agentic-security.mjs` was rebuilt;
10
+ full gate re-run green (`npm test` 1695/0, cve-replay 185/185).
11
+ - **`ide/vscode/`** — `undici` → 7.28.0 (incl. one high), `form-data` → 4.0.6 (high),
12
+ `markdown-it` → 14.3.0, `esbuild` → 0.28.1, `js-yaml` → 4.3.0. All transitive under
13
+ `@vscode/vsce`/`esbuild`; lockfile-only, `npm audit` now reports 0.
14
+
15
+ `npm audit` is clean (0 vulnerabilities) in both packages.
16
+
17
+ ## 0.128.0 — the agentic methodology layer + a simpler command surface
18
+
19
+ Two things landed together this release: a set of default-on **methodology annotators** that
20
+ layer agentic-hunter discipline on top of the deterministic engine, and a **consolidation** of
21
+ the command and skill surface so there's less to remember.
22
+
23
+ **Methodology layer (7 additions, all v1, all tested — see `docs/AGENTIC_METHODOLOGY_PRD.md`):**
24
+
25
+ - **Default falsification pass** (`posture/falsification.js`) — for each taint finding it tries
26
+ to *disprove* the finding by locating a context-matched control on the path, and demotes +
27
+ quarantines the ones it can block. Recall-preserving (never removes a finding, never touches
28
+ severity — like the proof gate); genuine cve-replay `pre` vulns still fire (0 false blocks,
29
+ corpus 185/185 intact). Opt out with `AGENTIC_SECURITY_NO_FALSIFICATION=1`.
30
+ - **Attack-surface completeness inventory** (`posture/entrypoint-inventory.js`) — enumerates
31
+ every entry point (HTTP / queue / cron / CLI / env / upload / webhook) with a disposition
32
+ each, on `scan.entrypointInventory`.
33
+ - **Root-cause sweep** (`posture/root-cause-sweep.js`) — from a confirmed finding, searches the
34
+ repo for sibling instances detectors missed, with a `found = candidates + mitigated`
35
+ accounting invariant, on `scan.rootCauseSweep`.
36
+ - **Meta-security hardening** (`util/untrusted.js` + `docs/AGENT_THREAT_MODEL.md`) — a tested
37
+ threat model treating attacker-authored finding text as untrusted input; escaping wired into
38
+ the PR/issue/ticket render paths.
39
+ - **Capability-based model routing** (`posture/model-routing.js`) — stamps `finding.dispatchModel`
40
+ (strongest for crypto/auth/critical, mid for injection, cheapest for low-sev hardening) for
41
+ cost-sensitive subagent dispatch.
42
+ - **Self-improving recall harness** (`bench/realworld-recall/`) — LLM-judged (offline-degrading)
43
+ recall on real repos + a miss-analyzer that names the pipeline stage that dropped a finding
44
+ and proposes the fix. Bench-only; never in the product scan path.
45
+ - **Deterministic fix-honesty gates** (`posture/fix-honesty-gate.js`) — a residual-risk
46
+ hand-wave guard, a cited-file:line requirement for FP/safe verdicts, and FULL/MITIGATION/
47
+ WORKAROUND completeness tiers; the previously-orphaned test loop is now wired into
48
+ `apply_fix` behind `AGENTIC_SECURITY_FIX_RUN_TESTS=1`.
49
+
50
+ **Simpler surface (no functionality removed — everything folds to a mode + alias):**
51
+
52
+ - Commands **12 → 10**: `/ci` folded into `/setup --ci` (+ new `/setup --predeploy`), and
53
+ `/three-agent-review` into `/triage --deep`. Old names still resolve via the
54
+ legacy-alias-redirect hook.
55
+ - Skills **11 → 7**: the four write-time guards merged into `secure-coding-guard`, and the two
56
+ explainers into `security-explain`.
57
+
58
+ **Docs:** README + ARCHITECTURE + HARNESS_COMPATIBILITY refreshed with accurate surface counts
59
+ (17 MCP tools, 10 commands, 7 skills, 5 hook events, 9 sub-agents); the SAST/SCA improvement PRD
60
+ audited and marked (16 of 25 shipped, 9 partial). Full `npm test` green (1695 tests); cve-replay
61
+ corpus 185/185, no drift.
62
+
3
63
  ## 0.127.0 — cost advisor: an actual choice, not just a tip
4
64
 
5
65
  The model-cost advisor (`hooks/model-cost-advisor.js`) has always been advisory
@@ -0,0 +1,353 @@
1
+ export const id = 11;
2
+ export const ids = [11];
3
+ export const modules = {
4
+
5
+ /***/ 11:
6
+ /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => {
7
+
8
+ // ESM COMPAT FLAG
9
+ __webpack_require__.r(__webpack_exports__);
10
+
11
+ // EXPORTS
12
+ __webpack_require__.d(__webpack_exports__, {
13
+ runProjectLinter: () => (/* binding */ runProjectLinter),
14
+ verifyFix: () => (/* binding */ verifyFix),
15
+ verifyPatch: () => (/* binding */ verifyPatch)
16
+ });
17
+
18
+ // EXTERNAL MODULE: external "node:child_process"
19
+ var external_node_child_process_ = __webpack_require__(1421);
20
+ // EXTERNAL MODULE: external "node:fs"
21
+ var external_node_fs_ = __webpack_require__(3024);
22
+ // EXTERNAL MODULE: external "node:path"
23
+ var external_node_path_ = __webpack_require__(6760);
24
+ // EXTERNAL MODULE: ./src/engine.js + 524 modules
25
+ var engine = __webpack_require__(8215);
26
+ ;// CONCATENATED MODULE: ./src/posture/fix-honesty-gate.js
27
+ // Deterministic honesty gates on fix / finding output (#7).
28
+ //
29
+ // The project's verification discipline (scanner/CLAUDE.md) exists because
30
+ // several releases shipped broken or false because work was reported as done
31
+ // without confirming the artifact changed. Two of those failure modes are
32
+ // *textual* — they live in the prose an agent emits alongside a fix — and can
33
+ // be caught deterministically, with no LLM and no network:
34
+ //
35
+ // 1. Hand-wave residual-risk prose. "The input is adequately handled",
36
+ // "future work", "tbd", "later" — vague assurances that claim safety
37
+ // without naming a concrete remaining vector. A residual you can't name
38
+ // is a residual you're guessing about; reject the guess.
39
+ //
40
+ // 2. An unbacked "this is a false positive / provably safe" verdict. Marking
41
+ // a finding safe is a coverage *reduction* — it must cite a `file:line`
42
+ // that shows why, exactly like the rules-override gate refuses to silently
43
+ // shrink coverage.
44
+ //
45
+ // Plus a conservative fix-tier classifier so a partial remediation can never be
46
+ // labelled FULL: any workaround-only signal (rate-limit, docs, log-without-
47
+ // reject) is WORKAROUND; anything short of (sink signature changed + all callers
48
+ // routed + a discriminating test) is at most MITIGATION; only the full set with
49
+ // no partial-sanitization caveat earns FULL.
50
+ //
51
+ // Pure functions, no side effects, no throwing — safe to call from a command,
52
+ // a hook, or the MCP verify_fix path.
53
+
54
+ // Vague-assurance phrases that a real residual must never hide behind. Matched
55
+ // case-insensitively with word boundaries so "later" doesn't trip on
56
+ // "collateral" and "tbd" doesn't trip on a longer token.
57
+ const BANNED_RESIDUAL_PHRASES = Object.freeze([
58
+ 'adequately handled',
59
+ 'adequately handles',
60
+ 'properly validated',
61
+ 'properly handled',
62
+ 'handled properly',
63
+ 'handled safely',
64
+ 'future work',
65
+ 'more work needed',
66
+ 'to be done',
67
+ 'tbd',
68
+ 'later',
69
+ ]);
70
+
71
+ // A citation shaped like `file:line` — one or more non-space, non-colon chars,
72
+ // a colon, then digits. Unanchored: it need only appear somewhere in the item.
73
+ const CITATION_RE = /[^\s:]+:\d+/;
74
+
75
+ // Verdicts that assert the finding is not real and therefore demand a citation.
76
+ // Compared after normalizing separators (`_`/space → `-`) and lowercasing, so
77
+ // FALSE_POSITIVE, false-positive, and "provably safe" all land here.
78
+ const FP_VERDICTS = Object.freeze(new Set(['false-positive', 'provably-safe', 'safe']));
79
+
80
+ function _escapeRe(s) {
81
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
82
+ }
83
+
84
+ /**
85
+ * Reject vague-assurance / hand-wave residual-risk prose.
86
+ *
87
+ * An empty or whitespace-only residual is ok — there is no residual to lie
88
+ * about. A non-empty residual is rejected when it contains any banned phrase;
89
+ * each match yields one violation naming the offending phrase.
90
+ *
91
+ * @param {string} residualText
92
+ * @returns {{ ok: boolean, violations: string[] }}
93
+ */
94
+ function checkResidualHonesty(residualText) {
95
+ const text = typeof residualText === 'string' ? residualText : '';
96
+ if (text.trim() === '') return { ok: true, violations: [] };
97
+
98
+ const violations = [];
99
+ for (const phrase of BANNED_RESIDUAL_PHRASES) {
100
+ const re = new RegExp(`\\b${_escapeRe(phrase)}\\b`, 'i');
101
+ if (re.test(text)) {
102
+ violations.push(`vague-assurance phrase: "${phrase}"`);
103
+ }
104
+ }
105
+ return { ok: violations.length === 0, violations };
106
+ }
107
+
108
+ function _isCitation(item) {
109
+ if (typeof item === 'string') return CITATION_RE.test(item);
110
+ if (item && typeof item === 'object' && typeof item.location === 'string') {
111
+ return CITATION_RE.test(item.location);
112
+ }
113
+ return false;
114
+ }
115
+
116
+ function _normalizeVerdict(verdict) {
117
+ return String(verdict).trim().toLowerCase().replace(/[_\s]+/g, '-');
118
+ }
119
+
120
+ /**
121
+ * Require a file:line citation behind a "this is not real" verdict.
122
+ *
123
+ * For a false-positive / provably-safe / safe verdict (case-insensitive; also
124
+ * accepts FALSE_POSITIVE), at least one evidence item must be a `file:line`
125
+ * citation — either a string matching /[^\s:]+:\d+/ or an object
126
+ * `{ location: "file:line" }`. Any other verdict passes unconditionally.
127
+ *
128
+ * @param {string} verdict
129
+ * @param {Array|string|object} evidence
130
+ * @returns {{ ok: boolean, violations: string[] }}
131
+ */
132
+ function requireCitedEvidence(verdict, evidence) {
133
+ if (typeof verdict !== 'string' || !FP_VERDICTS.has(_normalizeVerdict(verdict))) {
134
+ return { ok: true, violations: [] };
135
+ }
136
+ const items = Array.isArray(evidence)
137
+ ? evidence
138
+ : evidence == null
139
+ ? []
140
+ : [evidence];
141
+ if (items.some(_isCitation)) return { ok: true, violations: [] };
142
+ return {
143
+ ok: false,
144
+ violations: ['false-positive/safe verdict requires a file:line citation'],
145
+ };
146
+ }
147
+
148
+ /**
149
+ * Classify a fix into FULL | MITIGATION | WORKAROUND, conservative-first.
150
+ *
151
+ * @param {object} signals
152
+ * @param {boolean} signals.sinkSignatureChanged
153
+ * @param {boolean} signals.allCallersRouted
154
+ * @param {boolean} signals.testDiscriminates - a test that fails pre-fix, passes post-fix
155
+ * @param {boolean} [signals.rateLimitOnly]
156
+ * @param {boolean} [signals.docsOnly]
157
+ * @param {boolean} [signals.logOnlyNoReject]
158
+ * @param {boolean} [signals.partialSanitization]
159
+ * @returns {'FULL'|'MITIGATION'|'WORKAROUND'}
160
+ */
161
+ function computeFixTier(signals) {
162
+ const s = signals && typeof signals === 'object' ? signals : {};
163
+ if (s.rateLimitOnly || s.docsOnly || s.logOnlyNoReject) return 'WORKAROUND';
164
+ const complete = s.sinkSignatureChanged && s.allCallersRouted && s.testDiscriminates;
165
+ if (s.partialSanitization || !complete) return 'MITIGATION';
166
+ return 'FULL';
167
+ }
168
+
169
+ /**
170
+ * Compose the three gates for a single fix's output.
171
+ *
172
+ * ok = residual-honesty ok AND evidence-citation ok, further constrained by the
173
+ * tier/residual consistency invariant:
174
+ * - a FULL tier must NOT carry a residual (a full fix has nothing left);
175
+ * - a non-FULL tier MUST document a residual (say what's still open).
176
+ *
177
+ * @param {{ residual?: string, verdict?: string, evidence?: any, signals?: object }} input
178
+ * @returns {{ ok: boolean, tier: string, violations: string[] }}
179
+ */
180
+ function gateFixOutput({ residual, verdict, evidence, signals } = {}) {
181
+ const tier = computeFixTier(signals);
182
+ const residualCheck = checkResidualHonesty(residual);
183
+ const evidenceCheck = requireCitedEvidence(verdict, evidence);
184
+
185
+ const violations = [...residualCheck.violations, ...evidenceCheck.violations];
186
+ let ok = residualCheck.ok && evidenceCheck.ok;
187
+
188
+ const residualEmpty = typeof residual !== 'string' || residual.trim() === '';
189
+ if (tier === 'FULL' && !residualEmpty) {
190
+ violations.push('FULL tier cannot carry a residual');
191
+ ok = false;
192
+ }
193
+ if (tier !== 'FULL' && residualEmpty) {
194
+ violations.push('non-FULL tier must document a residual');
195
+ ok = false;
196
+ }
197
+
198
+ return { ok, tier, violations };
199
+ }
200
+
201
+ const _internals = Object.freeze({ BANNED_RESIDUAL_PHRASES, CITATION_RE, FP_VERDICTS });
202
+
203
+ ;// CONCATENATED MODULE: ./src/posture/fix-verify.js
204
+ // Closed-loop /fix verification (Sentinel-parity FR-L4-4, FR-L4-5).
205
+ //
206
+ // Given a candidate patch (the new file content + the finding stableId being
207
+ // fixed), verify it:
208
+ //
209
+ // 1. The original finding's stableId no longer fires on the patched file.
210
+ // 2. No new findings at severity ≥ medium were introduced by the patch.
211
+ // 3. The project's existing linter (when present) passes on the patched file.
212
+ //
213
+ // If any of those fail, the caller is expected to NOT apply the patch and
214
+ // instead surface a "fix plan" — a numbered list of steps the engineer can
215
+ // follow — rather than dump a broken patch on the user.
216
+
217
+
218
+
219
+
220
+
221
+
222
+
223
+ const SEVERITY_RANK = { critical: 0, high: 1, medium: 2, low: 3, info: 4 };
224
+
225
+ // Run a focused re-scan over just the patched file(s) using the in-memory
226
+ // engine. No filesystem write needed — we hand the new content in via the
227
+ // fileContents map.
228
+ async function verifyPatch({
229
+ scanRoot,
230
+ originalFindingStableId,
231
+ files, // { [relPath]: newContent }
232
+ depFileContents = {},
233
+ } = {}) {
234
+ if (!files || typeof files !== 'object') return { ok: false, reason: 'no-files-provided' };
235
+ const fileContents = { ...files };
236
+ let scan;
237
+ try {
238
+ scan = await (0,engine/* runFullScan */.wW)({ fileContents, depFileContents, scanRoot }, () => {});
239
+ } catch (e) {
240
+ return { ok: false, reason: 'rescan-failed', error: e.message };
241
+ }
242
+ const findings = (scan && scan.findings) || [];
243
+ const stillHasOriginal = !!originalFindingStableId &&
244
+ findings.some(f => f.stableId === originalFindingStableId);
245
+ if (stillHasOriginal) {
246
+ return { ok: false, reason: 'original-finding-still-present', stableId: originalFindingStableId };
247
+ }
248
+ const introducedHighOrAbove = findings.filter(f =>
249
+ (SEVERITY_RANK[f.severity] ?? 9) <= SEVERITY_RANK.medium);
250
+ // Don't count findings on lines outside the patched files — but our
251
+ // fileContents map IS the patched files, so every finding is in-scope.
252
+ return {
253
+ ok: introducedHighOrAbove.length === 0,
254
+ reason: introducedHighOrAbove.length === 0 ? 'verified' : 'introduced-new-findings',
255
+ introduced: introducedHighOrAbove.map(f => ({
256
+ vuln: f.vuln, file: f.file, line: f.line, severity: f.severity,
257
+ stableId: f.stableId,
258
+ })),
259
+ };
260
+ }
261
+
262
+ // Detect which linter the project uses and run it on the patched files.
263
+ // Returns { ok, runner, output } or { ok: true, runner: 'none' } when no
264
+ // linter is configured (silent pass).
265
+ function runProjectLinter(scanRoot, filePaths) {
266
+ if (!scanRoot || !Array.isArray(filePaths) || filePaths.length === 0) {
267
+ return { ok: true, runner: 'none' };
268
+ }
269
+ const has = (p) => { try { return external_node_fs_.existsSync(external_node_path_.join(scanRoot, p)); } catch { return false; } };
270
+ // Pick the linter by config file present in the repo root.
271
+ const jsFiles = filePaths.filter(f => /\.(?:js|jsx|ts|tsx|mjs|cjs)$/i.test(f));
272
+ const pyFiles = filePaths.filter(f => /\.py$/i.test(f));
273
+ const goFiles = filePaths.filter(f => /\.go$/i.test(f));
274
+ const javaFiles = filePaths.filter(f => /\.java$/i.test(f));
275
+
276
+ if (jsFiles.length && (has('.eslintrc') || has('.eslintrc.json') || has('.eslintrc.js') || has('eslint.config.js') || has('eslint.config.mjs'))) {
277
+ return runLinter(scanRoot, 'eslint', ['--no-error-on-unmatched-pattern', ...jsFiles]);
278
+ }
279
+ if (pyFiles.length && (has('pyproject.toml') || has('ruff.toml') || has('.ruff.toml'))) {
280
+ return runLinter(scanRoot, 'ruff', ['check', ...pyFiles]);
281
+ }
282
+ if (pyFiles.length && has('.flake8')) {
283
+ return runLinter(scanRoot, 'flake8', pyFiles);
284
+ }
285
+ if (goFiles.length && (has('.golangci.yml') || has('.golangci.yaml'))) {
286
+ return runLinter(scanRoot, 'golangci-lint', ['run', ...goFiles]);
287
+ }
288
+ if (javaFiles.length && has('checkstyle.xml')) {
289
+ return runLinter(scanRoot, 'checkstyle', ['-c', 'checkstyle.xml', ...javaFiles]);
290
+ }
291
+ return { ok: true, runner: 'none' };
292
+ }
293
+
294
+ function runLinter(cwd, cmd, args) {
295
+ let r;
296
+ try {
297
+ r = (0,external_node_child_process_.spawnSync)(cmd, args, { cwd, encoding: 'utf8', timeout: 60_000 });
298
+ } catch (e) {
299
+ return { ok: true, runner: cmd, skipped: true, reason: 'binary-missing', error: e.message };
300
+ }
301
+ if (r.error && r.error.code === 'ENOENT') {
302
+ return { ok: true, runner: cmd, skipped: true, reason: 'binary-missing' };
303
+ }
304
+ if (r.status === null) {
305
+ return { ok: false, runner: cmd, reason: 'timed-out', output: (r.stderr || r.stdout || '').slice(-2000) };
306
+ }
307
+ return {
308
+ ok: r.status === 0,
309
+ runner: cmd,
310
+ exitCode: r.status,
311
+ output: ((r.stderr || '') + (r.stdout || '')).slice(-2000),
312
+ };
313
+ }
314
+
315
+ // Top-level verify: re-scan + lint. Returns the combined verdict + a
316
+ // human-readable summary string suitable for surfacing to the user.
317
+ // Addition #7 — deterministic honesty gates on fix output. When the caller
318
+ // supplies `fixMeta` ({ residual, verdict, evidence, signals }) — e.g. the
319
+ // security-fixer agent's residual-risk text + completeness signals — the fix's
320
+ // claims are checked mechanically (no hand-wave residual prose, a cited
321
+ // file:line for any FP/safe verdict, and a FULL/MITIGATION/WORKAROUND tier). A
322
+ // dishonest or over-claiming fix fails the gate. When `fixMeta` is absent
323
+ // (the deterministic MCP write path, which has no claims to check) the honesty
324
+ // gate is skipped and behavior is unchanged.
325
+ async function verifyFix({
326
+ scanRoot,
327
+ originalFindingStableId,
328
+ files,
329
+ depFileContents,
330
+ fixMeta,
331
+ } = {}) {
332
+ const rescan = await verifyPatch({ scanRoot, originalFindingStableId, files, depFileContents });
333
+ const lint = runProjectLinter(scanRoot, Object.keys(files || {}));
334
+ let honesty = null;
335
+ if (fixMeta && typeof fixMeta === 'object') {
336
+ try { honesty = gateFixOutput(fixMeta); } catch { honesty = null; }
337
+ }
338
+ const ok = rescan.ok && (lint.ok || lint.skipped) && (honesty ? honesty.ok : true);
339
+ const summary = [
340
+ `re-scan: ${rescan.ok ? 'PASS' : 'FAIL — ' + rescan.reason}`,
341
+ `linter: ${lint.runner === 'none' ? 'skipped (no linter config)'
342
+ : lint.skipped ? `${lint.runner} not installed`
343
+ : lint.ok ? `${lint.runner} PASS`
344
+ : `${lint.runner} FAIL (exit ${lint.exitCode})`}`,
345
+ honesty ? `honesty: ${honesty.ok ? `PASS (${honesty.tier})` : 'FAIL — ' + honesty.violations.join('; ')}` : null,
346
+ ].filter(Boolean).join('\n');
347
+ return { ok, rescan, lint, honesty, summary };
348
+ }
349
+
350
+
351
+ /***/ })
352
+
353
+ };