@clear-capabilities/agentic-security-scanner 0.150.1 → 0.150.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/bin/agentic-security.js +73 -10
  3. package/dist/1122.index.js +16 -16
  4. package/dist/1208.index.js +23 -0
  5. package/dist/1301.index.js +3 -3
  6. package/dist/1379.index.js +3 -3
  7. package/dist/1444.index.js +3 -3
  8. package/dist/1660.index.js +1 -1
  9. package/dist/1700.index.js +5 -5
  10. package/dist/1905.index.js +12 -12
  11. package/dist/1920.index.js +10 -10
  12. package/dist/2238.index.js +4 -4
  13. package/dist/2271.index.js +3 -3
  14. package/dist/2432.index.js +8 -8
  15. package/dist/2659.index.js +1 -1
  16. package/dist/2826.index.js +2 -2
  17. package/dist/2830.index.js +3 -3
  18. package/dist/2923.index.js +1 -1
  19. package/dist/3001.index.js +4 -4
  20. package/dist/3117.index.js +4 -4
  21. package/dist/3180.index.js +9 -9
  22. package/dist/3276.index.js +1 -1
  23. package/dist/3415.index.js +1 -1
  24. package/dist/3499.index.js +1 -1
  25. package/dist/3518.index.js +4 -4
  26. package/dist/3736.index.js +7 -7
  27. package/dist/3839.index.js +4 -4
  28. package/dist/4113.index.js +441 -418
  29. package/dist/4265.index.js +4 -4
  30. package/dist/4384.index.js +8 -3
  31. package/dist/4399.index.js +29 -3
  32. package/dist/4547.index.js +2 -2
  33. package/dist/4863.index.js +6 -6
  34. package/dist/4970.index.js +2 -2
  35. package/dist/5051.index.js +15 -15
  36. package/dist/5144.index.js +4 -4
  37. package/dist/5333.index.js +8 -8
  38. package/dist/5343.index.js +2 -2
  39. package/dist/5350.index.js +6 -6
  40. package/dist/5561.index.js +1 -1
  41. package/dist/5637.index.js +10 -5
  42. package/dist/5724.index.js +21642 -0
  43. package/dist/5756.index.js +99 -489
  44. package/dist/5830.index.js +3 -3
  45. package/dist/6257.index.js +21 -8
  46. package/dist/6626.index.js +5 -5
  47. package/dist/6662.index.js +1 -1
  48. package/dist/6675.index.js +4 -4
  49. package/dist/6730.index.js +10 -10
  50. package/dist/6829.index.js +4 -4
  51. package/dist/6944.index.js +2 -2
  52. package/dist/6994.index.js +5 -5
  53. package/dist/7039.index.js +83 -19
  54. package/dist/7178.index.js +11 -6
  55. package/dist/7227.index.js +3 -3
  56. package/dist/7552.index.js +2 -2
  57. package/dist/7709.index.js +2 -2
  58. package/dist/7838.index.js +1037 -0
  59. package/dist/8218.index.js +4 -4
  60. package/dist/8476.index.js +4 -4
  61. package/dist/8513.index.js +8 -8
  62. package/dist/8520.index.js +1 -1
  63. package/dist/8752.index.js +4 -4
  64. package/dist/9207.index.js +2 -2
  65. package/dist/9220.index.js +5 -5
  66. package/dist/9390.index.js +6 -6
  67. package/dist/9503.index.js +2 -2
  68. package/dist/9560.index.js +3221 -0
  69. package/dist/957.index.js +4 -4
  70. package/dist/9801.index.js +1 -1
  71. package/dist/9824.index.js +5 -5
  72. package/dist/agentic-security.mjs +23 -23
  73. package/dist/agentic-security.mjs.sha256 +1 -1
  74. package/package.json +3 -2
  75. package/src/egress/redact.js +1 -1
  76. package/src/engine.js +13 -2
  77. package/src/llm-validator/agent-loop.js +85 -5
  78. package/src/llm-validator/fix-proposal.js +16 -3
  79. package/src/llm-validator/model-capabilities.js +26 -1
  80. package/src/llm-validator/model-probe.js +46 -8
  81. package/src/llm-validator/ollama-provider.js +26 -1
  82. package/src/llm-validator/oom-feedback.js +69 -0
  83. package/src/llm-validator/providers.js +50 -0
  84. package/src/llm-validator/redact.js +177 -11
  85. package/src/report/index.js +14 -3
  86. package/src/sast/java-ast-folding.js +18 -2
@@ -21,28 +21,144 @@
21
21
 
22
22
  const REDACTED_PLACEHOLDER = '[REDACTED-SECRET]';
23
23
 
24
- // Case-insensitive names that, when assigned a quoted string, are treated as
25
- // carrying a credential. Exact identifiers only (word-boundary matched)
26
- // e.g. `password_field` does NOT match `password` because `_` is a word
27
- // character and blocks the trailing \b.
24
+ // Case-insensitive names that, when assigned a string, are treated as
25
+ // carrying a credential. `[_-]?` between compound words so a real .env/shell
26
+ // naming convention (`DB_PASSWORD`, `STRIPE_API_KEY`) matches those are
27
+ // two segments joined by `_`, not one identifier, so a plain `\b` (which
28
+ // treats `_` as a word character) would never see a boundary before
29
+ // `PASSWORD` in `DB_PASSWORD` at all. Handled below via lookaround, not \b.
28
30
  const SECRET_KEY_NAMES = [
29
- 'apiKey',
30
- 'api_key',
31
+ 'api[_-]?key',
31
32
  'secret',
32
33
  'token',
33
34
  'password',
34
35
  'passwd',
35
- 'client_secret',
36
- 'access_key',
37
- 'private_key',
36
+ 'client[_-]?secret',
37
+ 'access[_-]?key',
38
+ 'private[_-]?key',
38
39
  'authorization',
39
40
  ];
40
41
 
42
+ // Asymmetric boundary, deliberately not a plain `\b` on either side:
43
+ // BEFORE the name: anything non-alphanumeric counts as a boundary,
44
+ // INCLUDING `_`/`-` — this is what lets `DB_PASSWORD`/`stripe-api-key`
45
+ // match despite `_`/`-` being `\w` characters a real `\b` would treat
46
+ // as "still inside the same word."
47
+ // AFTER the name: only a non-alphanumeric, non-underscore char (or
48
+ // string end) counts — this is a real `\b`-equivalent on the suffix
49
+ // side, which is what keeps `password_field`/`tokenExpiry` from
50
+ // matching (a field ABOUT a secret, not a secret itself). Losing this
51
+ // asymmetry either direction reintroduces one of the two failure
52
+ // modes this module exists to avoid (see the module header).
53
+ const NAME_BOUNDARY = (name) => `(?<![A-Za-z0-9])(?:${name})(?![A-Za-z0-9_])`;
54
+ const KEY_NAME_ALT = SECRET_KEY_NAMES.map(NAME_BOUNDARY).join('|');
55
+
56
+ // The optional quote group right after the key name handles a JSON/YAML
57
+ // QUOTED key (`"password": "value"`) — the boundary lookaheads in
58
+ // NAME_BOUNDARY already treat the closing quote as a valid non-alphanumeric
59
+ // "after" boundary, but without this group the operator match immediately
60
+ // following would fail to consume that quote char before `[:=]`.
41
61
  const KEY_VALUE_RE = new RegExp(
42
- '(\\b(?:' + SECRET_KEY_NAMES.join('|') + ')\\b)(\\s*[:=]\\s*)([\'"`])([^\'"`]+)\\3',
62
+ '(' + KEY_NAME_ALT + ')([\'"`]?\\s*[:=]\\s*)([\'"`])([^\'"`]+)\\3',
63
+ 'gi'
64
+ );
65
+
66
+ // Split-string-concatenation (adversarial-review fix, 2026-09, second pass):
67
+ // `const secret = "Super" +\n "Secret123456";` used to redact only the
68
+ // FIRST segment — KEY_VALUE_RE matches one quoted literal, stops, and the
69
+ // second literal (joined by `+`, possibly on its own line) survives
70
+ // untouched, leaking the tail of the real value. Requires AT LEAST ONE `+`
71
+ // join (`+` one-or-more, not `*`) so this pass targets only the genuinely-
72
+ // concatenated case and never overlaps with — or double-processes — the
73
+ // plain single-literal case KEY_VALUE_RE already owns. The whole matched
74
+ // expression (every segment, every operator) is collapsed to ONE placeholder
75
+ // literal rather than trying to preserve per-segment structure: a
76
+ // concatenation is already an unusual enough shape that this codebase's
77
+ // "value gone, structure survives" ergonomic goal is secondary to just not
78
+ // leaking the tail half of a secret.
79
+ const CONCAT_KEY_VALUE_RE = new RegExp(
80
+ '(' + KEY_NAME_ALT + ')([\'"`]?\\s*[:=]\\s*)([\'"`][^\'"`]*[\'"`](?:\\s*\\+\\s*[\'"`][^\'"`]*[\'"`])+)',
43
81
  'gi'
44
82
  );
45
83
 
84
+ // camelCase compound identifiers (adversarial-review fix, 2026-09):
85
+ // `authToken`, `apiSecret`, `userPassword` all leaked through the original
86
+ // fix, which only generalized the `_`/`-`-delimited compound case
87
+ // (`DB_PASSWORD`). A plain `i` flag doesn't help here — case-insensitivity
88
+ // makes "Token" and "token" match the same NAME, but the boundary problem is
89
+ // separate: `(?<![A-Za-z0-9])` still fails when "Token" is preceded by the
90
+ // letters "auth", regardless of case. This is a SEPARATE, case-SENSITIVE
91
+ // regex specifically for "a capitalized key-name segment immediately
92
+ // preceded by a lowercase letter or digit" (the actual camelCase join
93
+ // point), run as its own pass — mixing this into the case-insensitive
94
+ // KEY_VALUE_RE would make it fire on the ALL-CAPS compound case too
95
+ // (`DB_PASSWORD`), which is already handled and correctly rejects the
96
+ // suffix-side `password_field` case using the case-insensitive boundary.
97
+ //
98
+ // Deliberately narrower than the full SECRET_KEY_NAMES list: "Key" alone
99
+ // (for `apiKey`/`accessKey`/`privateKey`) is too generic a camelCase suffix
100
+ // on its own (`primaryKey`, `cacheKey`, `sortKey` are not secrets) — those
101
+ // three stay as their full compound word here, matched case-flexibly on the
102
+ // FIRST letter of each segment only (`[Aa]pi[Kk]ey`, not full case-
103
+ // insensitivity, to keep this pass's own boundary logic exact).
104
+ const CAMEL_CASE_NAMES = [
105
+ 'Token', 'Secret', 'Password', 'Passwd', 'Authorization',
106
+ '[Aa]pi[Kk]ey', '[Aa]ccess[Kk]ey', '[Pp]rivate[Kk]ey', '[Cc]lient[Ss]ecret',
107
+ ];
108
+ const CAMEL_NAME_ALT = CAMEL_CASE_NAMES
109
+ .map((name) => `(?<=[a-z0-9])(?:${name})(?![A-Za-z0-9_])`)
110
+ .join('|');
111
+ const CAMEL_KEY_VALUE_RE = new RegExp(
112
+ '(' + CAMEL_NAME_ALT + ')([\'"`]?\\s*[:=]\\s*)([\'"`])([^\'"`]+)\\3',
113
+ 'g' // NOT case-insensitive — the lowercase-then-uppercase transition IS the signal
114
+ );
115
+ // Same split-string-concatenation fix as CONCAT_KEY_VALUE_RE, for the
116
+ // camelCase name set.
117
+ const CONCAT_CAMEL_KEY_VALUE_RE = new RegExp(
118
+ '(' + CAMEL_NAME_ALT + ')([\'"`]?\\s*[:=]\\s*)([\'"`][^\'"`]*[\'"`](?:\\s*\\+\\s*[\'"`][^\'"`]*[\'"`])+)',
119
+ 'g'
120
+ );
121
+
122
+ // `.env`/shell-export syntax: `KEY=value` with NO surrounding quotes at all
123
+ // — the shape secret-redaction.test.js already documented as evading
124
+ // KEY_VALUE_RE above (that test's own comment: "Standard .env syntax...
125
+ // evades the... catch-all, which requires a quoted value"). Anchored to
126
+ // the start of a line (optional leading whitespace/`export `) rather than
127
+ // matched anywhere, specifically so an ordinary code expression like
128
+ // `if (password == expected)` or `token = someFn()` embedded mid-statement
129
+ // is never a candidate — only a line whose FIRST token is the secret name
130
+ // itself, exactly the shape a real `.env` file or shell script uses. `(?!=)`
131
+ // after the operator blocks `==`/`===` from being read as `=` plus a
132
+ // leftover comparison; a bare `!=`/`<=`/`>=` already can't match because the
133
+ // operator class only accepts a literal `=`, not the character before it.
134
+ // The optional third group is a non-greedy compound-identifier prefix
135
+ // (`AWS_SECRET_` before `ACCESS_KEY`, `STRIPE_` before `API_KEY`) — the SAME
136
+ // compound-name problem NAME_BOUNDARY solves for a single leading segment,
137
+ // generalized to arbitrarily many, since real .env names commonly stack a
138
+ // vendor/namespace prefix ahead of the sensitive word.
139
+ const ENV_STYLE_RE = new RegExp(
140
+ '^([ \\t]*(?:export\\s+)?)([A-Za-z0-9_-]*?[_-])?(' + KEY_NAME_ALT + ')(\\s*=(?!=)\\s*)([^\\r\\n]+)$',
141
+ 'gim'
142
+ );
143
+
144
+ // YAML `key: value` (adversarial-review fix, 2026-09): the SAME unquoted
145
+ // shape as .env, but YAML's operator is `:`, which ENV_STYLE_RE never
146
+ // accepted. Deliberately NOT just added to ENV_STYLE_RE's operator class —
147
+ // `:` collides with two extremely common non-secret shapes this codebase
148
+ // already has a pinned regression test for: a TypeScript type annotation
149
+ // (`password: string;`) and a JS object-literal key
150
+ // (`{ password: getSecret() }`). Neither of those is YAML, so this pattern
151
+ // is applied ONLY when the file extension says so (see redactSecrets'
152
+ // `filePath` option below) rather than unconditionally — the risk of the
153
+ // blanket approach is a regression in exactly the case this module's own
154
+ // header calls out ("redact too aggressively and the validator loses the
155
+ // context it needs").
156
+ const YAML_STYLE_RE = new RegExp(
157
+ '^([ \\t]*(?:- )?)([A-Za-z0-9_-]*?[_-])?(' + KEY_NAME_ALT + ')(\\s*:\\s*)([^\\r\\n]+)$',
158
+ 'gim'
159
+ );
160
+ const YAML_EXT_RE = /\.ya?ml$/i;
161
+
46
162
  // `Authorization: Bearer <blob>` — the blob only, scheme word survives.
47
163
  const BEARER_RE = /\bBearer\s+[A-Za-z0-9._~+/=-]+/gi;
48
164
 
@@ -104,7 +220,7 @@ function looksLikeHighEntropySecret(inner) {
104
220
  // overlap on an already-redacted span is harmless (the value is still gone
105
221
  // exactly once; see KEY_VALUE_RE + BEARER_RE interaction for the one case
106
222
  // where both can fire on the same literal).
107
- export function redactSecrets(text) {
223
+ export function redactSecrets(text, { filePath } = {}) {
108
224
  if (typeof text !== 'string' || text.length === 0) {
109
225
  return { text: typeof text === 'string' ? text : '', redactions: 0 };
110
226
  }
@@ -132,6 +248,16 @@ export function redactSecrets(text) {
132
248
  return `Bearer ${REDACTED_PLACEHOLDER}`;
133
249
  });
134
250
 
251
+ // 3.5. Split-string-concatenation values — MUST run before pass 4:
252
+ // KEY_VALUE_RE matches the first quoted segment of a concatenation too
253
+ // (it's a valid, if incomplete, match on its own), so if pass 4 ran first
254
+ // it would already have consumed and "fixed" the first segment, leaving
255
+ // this pass nothing to find and the second segment still exposed.
256
+ out = out.replace(CONCAT_KEY_VALUE_RE, (_m, keyName, opWs) => {
257
+ redactions++;
258
+ return `${keyName}${opWs}"${REDACTED_PLACEHOLDER}"`;
259
+ });
260
+
135
261
  // 4. `secretName = "value"` / `secretName: "value"` assignments.
136
262
  //
137
263
  // Special case: `authorization: "Bearer <blob>"` — keep the `Bearer `
@@ -144,6 +270,46 @@ export function redactSecrets(text) {
144
270
  return `${keyName}${opWs}${quote}${REDACTED_PLACEHOLDER}${quote}`;
145
271
  });
146
272
 
273
+ // 3.6. Split-string-concatenation, camelCase name set — same ordering
274
+ // requirement as 3.5 (must run before 4a).
275
+ out = out.replace(CONCAT_CAMEL_KEY_VALUE_RE, (_m, keyName, opWs) => {
276
+ redactions++;
277
+ return `${keyName}${opWs}"${REDACTED_PLACEHOLDER}"`;
278
+ });
279
+
280
+ // 4a. camelCase compound identifiers (`authToken = "..."`, `apiSecret: "..."`)
281
+ // — a case-SENSITIVE pass, separate from pass 4's case-insensitive one for
282
+ // exactly the reason CAMEL_KEY_VALUE_RE's own comment explains.
283
+ out = out.replace(CAMEL_KEY_VALUE_RE, (_m, keyName, opWs, quote, value) => {
284
+ redactions++;
285
+ const bearer = /^(Bearer\s+)(.+)$/i.exec(value);
286
+ if (bearer) return `${keyName}${opWs}${quote}${bearer[1]}${REDACTED_PLACEHOLDER}${quote}`;
287
+ return `${keyName}${opWs}${quote}${REDACTED_PLACEHOLDER}${quote}`;
288
+ });
289
+
290
+ // 4.5. `.env`/shell-export syntax: `KEY=value`, no quotes at all. Must run
291
+ // AFTER pass 4 (KEY_VALUE_RE): pass 4 already consumed every quoted
292
+ // occurrence, so anything ENV_STYLE_RE still finds on a candidate line is,
293
+ // by construction, unquoted — there is no double-redaction risk between
294
+ // the two passes even though their key-name sets are identical.
295
+ out = out.replace(ENV_STYLE_RE, (_m, lead, prefix, keyName, opWs, value) => {
296
+ redactions++;
297
+ const bearer = /^(Bearer\s+)(.+)$/i.exec(value);
298
+ if (bearer) return `${lead}${prefix || ''}${keyName}${opWs}${bearer[1]}${REDACTED_PLACEHOLDER}`;
299
+ return `${lead}${prefix || ''}${keyName}${opWs}${REDACTED_PLACEHOLDER}`;
300
+ });
301
+
302
+ // 4.6. YAML `key: value` — ONLY for a file the caller identifies as YAML
303
+ // (see YAML_STYLE_RE's own comment for why this isn't unconditional).
304
+ if (typeof filePath === 'string' && YAML_EXT_RE.test(filePath)) {
305
+ out = out.replace(YAML_STYLE_RE, (_m, lead, prefix, keyName, opWs, value) => {
306
+ redactions++;
307
+ const bearer = /^(Bearer\s+)(.+)$/i.exec(value);
308
+ if (bearer) return `${lead}${prefix || ''}${keyName}${opWs}${bearer[1]}${REDACTED_PLACEHOLDER}`;
309
+ return `${lead}${prefix || ''}${keyName}${opWs}${REDACTED_PLACEHOLDER}`;
310
+ });
311
+ }
312
+
147
313
  // 5. Long high-entropy string literals not caught by a more specific rule.
148
314
  out = out.replace(QUOTED_STRING_RE, (m) => {
149
315
  const q = m[0];
@@ -1606,19 +1606,30 @@ export function toShipVerdict(scan, options = {}) {
1606
1606
  // requirement) — this line describes the model calls, not deterministic
1607
1607
  // network access elsewhere in the scan (OSV/KEV/EPSS), which is a
1608
1608
  // different claim this block must not blur.
1609
+ //
1610
+ // Adversarial-review finding (2026-09): the header used to carry no scope
1611
+ // qualifier and "Cloud fallback: disabled" was a hardcoded string, not
1612
+ // read from `_ai` at all — both fixed here. The header now names the ONE
1613
+ // role this block actually measured (`scopeRole`), and a role that
1614
+ // resolves to a remote/cloud provider is called out explicitly rather than
1615
+ // left for the reader to wrongly generalize the loopback claim onto.
1609
1616
  const _ai = scan.aiAssistance;
1610
1617
  if (_ai) {
1611
1618
  lines.push('');
1612
- lines.push(c(' AI Assistance', BOLD));
1619
+ lines.push(c(` AI Assistance (${_ai.scopeRole || 'validate'} role only)`, BOLD));
1613
1620
  lines.push(c(` Provider: ${_ai.provider || 'unknown'} Model: ${_ai.model || 'unknown'}`, DIM));
1614
- lines.push(c(` LLM egress: ${_ai.egress || 'unknown'} Cloud fallback: disabled`, DIM));
1621
+ lines.push(c(` LLM egress: ${_ai.egress || 'unknown'} Cloud fallback: ${_ai.cloudFallback ? 'enabled' : 'disabled'}`, DIM));
1615
1622
  for (const [stage, s] of Object.entries(_ai.stages || {})) {
1616
1623
  const parts = [`${s.calls} call${s.calls === 1 ? '' : 's'}`, `success ${s.success}`];
1617
1624
  if (s.refused) parts.push(`refused ${s.refused}`);
1618
1625
  if (s.failed) parts.push(`failed ${s.failed}`);
1619
1626
  lines.push(c(` ${stage.padEnd(10)} ${parts.join(' ')}`, DIM));
1620
1627
  }
1621
- lines.push(c(` ${_ai.egress === 'loopback-only' ? 'LLM inference was loopback-only.' : 'LLM inference used a remote endpoint.'}`, DIM));
1628
+ lines.push(c(` ${_ai.egress === 'loopback-only' ? `LLM inference for the ${_ai.scopeRole || 'validate'} role was loopback-only.` : `LLM inference for the ${_ai.scopeRole || 'validate'} role used a remote endpoint.`}`, DIM));
1629
+ if (Array.isArray(_ai.otherRolesRemote) && _ai.otherRolesRemote.length > 0) {
1630
+ const named = _ai.otherRolesRemote.map((r) => `${r.role} (${r.provider})`).join(', ');
1631
+ lines.push(c(` ⚠ other role(s) configured for a remote provider, NOT covered above: ${named}`, DIM));
1632
+ }
1622
1633
  }
1623
1634
  // Coverage-honesty line (#5/#6): show the scan's blind spots — which
1624
1635
  // languages got flow analysis vs pattern-only, what was skipped, and how
@@ -19,7 +19,23 @@
19
19
  // - Floating-point arithmetic
20
20
  // - long / short / byte coercion edge cases (we treat all as Number)
21
21
 
22
- import { parse } from '#java-parser';
22
+ // Dynamic + try/caught, not a plain static import: java-ast-folding.js is
23
+ // pulled in by engine.js, which every CLI invocation imports regardless of
24
+ // language — a static import made a transient failure to resolve the
25
+ // vendored '#java-parser' subpath (observed under heavy concurrent test
26
+ // load: many processes resolving the same large vendored tree at once) a
27
+ // module-LINK-time crash of the entire CLI, for every user, for every scan,
28
+ // not just Java ones. This file already treats a `parse()` call failure as
29
+ // non-fatal ("On parse error returns []; callers should fall back to
30
+ // non-AST behavior" — see deadBranchRanges below); extending that same
31
+ // degrade-to-empty philosophy to a load-time failure, instead of letting it
32
+ // crash the process, is the fix.
33
+ let parse = null;
34
+ try {
35
+ ({ parse } = await import('#java-parser'));
36
+ } catch {
37
+ parse = null;
38
+ }
23
39
 
24
40
  // ─── CST helpers ──────────────────────────────────────────────────────────
25
41
 
@@ -518,7 +534,7 @@ function walkInterfaceDeclaration(id, out) {
518
534
  /** Parse a Java source file and return dead-branch line ranges.
519
535
  * On parse error returns []; callers should fall back to non-AST behavior. */
520
536
  export function deadBranchRanges(source) {
521
- if (!source || source.length === 0 || source.length > 800_000) return [];
537
+ if (!parse || !source || source.length === 0 || source.length > 800_000) return [];
522
538
  let cst;
523
539
  try {
524
540
  cst = parse(source);