circle-ir 4.22.0 → 4.24.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.
Files changed (183) hide show
  1. package/configs/sink-semantics.json +6 -0
  2. package/dist/analysis/config-loader.d.ts.map +1 -1
  3. package/dist/analysis/config-loader.js +24 -5
  4. package/dist/analysis/config-loader.js.map +1 -1
  5. package/dist/analysis/constant-propagation/patterns.d.ts +16 -8
  6. package/dist/analysis/constant-propagation/patterns.d.ts.map +1 -1
  7. package/dist/analysis/constant-propagation/patterns.js +18 -9
  8. package/dist/analysis/constant-propagation/patterns.js.map +1 -1
  9. package/dist/analysis/findings.d.ts +8 -1
  10. package/dist/analysis/findings.d.ts.map +1 -1
  11. package/dist/analysis/findings.js +67 -5
  12. package/dist/analysis/findings.js.map +1 -1
  13. package/dist/analysis/hono-env.d.ts +24 -0
  14. package/dist/analysis/hono-env.d.ts.map +1 -0
  15. package/dist/analysis/hono-env.js +105 -0
  16. package/dist/analysis/hono-env.js.map +1 -0
  17. package/dist/analysis/html/html-extractor.d.ts +6 -0
  18. package/dist/analysis/html/html-extractor.d.ts.map +1 -1
  19. package/dist/analysis/html/html-extractor.js +16 -0
  20. package/dist/analysis/html/html-extractor.js.map +1 -1
  21. package/dist/analysis/interprocedural.d.ts.map +1 -1
  22. package/dist/analysis/interprocedural.js +51 -2
  23. package/dist/analysis/interprocedural.js.map +1 -1
  24. package/dist/analysis/js-helper-return.d.ts +7 -0
  25. package/dist/analysis/js-helper-return.d.ts.map +1 -1
  26. package/dist/analysis/js-helper-return.js +165 -0
  27. package/dist/analysis/js-helper-return.js.map +1 -1
  28. package/dist/analysis/js-spawn-argv.d.ts +34 -0
  29. package/dist/analysis/js-spawn-argv.d.ts.map +1 -0
  30. package/dist/analysis/js-spawn-argv.js +156 -0
  31. package/dist/analysis/js-spawn-argv.js.map +1 -0
  32. package/dist/analysis/maven-declared.d.ts.map +1 -1
  33. package/dist/analysis/maven-declared.js +5 -1
  34. package/dist/analysis/maven-declared.js.map +1 -1
  35. package/dist/analysis/passes/cli-main-reflection-suppress-pass.d.ts +1 -1
  36. package/dist/analysis/passes/cli-main-reflection-suppress-pass.d.ts.map +1 -1
  37. package/dist/analysis/passes/cli-main-reflection-suppress-pass.js +3 -1
  38. package/dist/analysis/passes/cli-main-reflection-suppress-pass.js.map +1 -1
  39. package/dist/analysis/passes/cross-file-pass.d.ts.map +1 -1
  40. package/dist/analysis/passes/cross-file-pass.js +2 -1
  41. package/dist/analysis/passes/cross-file-pass.js.map +1 -1
  42. package/dist/analysis/passes/interprocedural-pass.d.ts.map +1 -1
  43. package/dist/analysis/passes/interprocedural-pass.js +113 -2
  44. package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
  45. package/dist/analysis/passes/language-sources-pass.d.ts +15 -0
  46. package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
  47. package/dist/analysis/passes/language-sources-pass.js +1551 -119
  48. package/dist/analysis/passes/language-sources-pass.js.map +1 -1
  49. package/dist/analysis/passes/module-side-effect-pass.d.ts +9 -0
  50. package/dist/analysis/passes/module-side-effect-pass.d.ts.map +1 -1
  51. package/dist/analysis/passes/module-side-effect-pass.js +30 -3
  52. package/dist/analysis/passes/module-side-effect-pass.js.map +1 -1
  53. package/dist/analysis/passes/orphan-module-pass.d.ts +6 -1
  54. package/dist/analysis/passes/orphan-module-pass.d.ts.map +1 -1
  55. package/dist/analysis/passes/orphan-module-pass.js +6 -1
  56. package/dist/analysis/passes/orphan-module-pass.js.map +1 -1
  57. package/dist/analysis/passes/param-source-flow-gate-pass.d.ts.map +1 -1
  58. package/dist/analysis/passes/param-source-flow-gate-pass.js +2 -1
  59. package/dist/analysis/passes/param-source-flow-gate-pass.js.map +1 -1
  60. package/dist/analysis/passes/scan-secrets-pass.d.ts +8 -0
  61. package/dist/analysis/passes/scan-secrets-pass.d.ts.map +1 -1
  62. package/dist/analysis/passes/scan-secrets-pass.js +78 -10
  63. package/dist/analysis/passes/scan-secrets-pass.js.map +1 -1
  64. package/dist/analysis/passes/sink-filter-pass.d.ts +17 -0
  65. package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
  66. package/dist/analysis/passes/sink-filter-pass.js +691 -7
  67. package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
  68. package/dist/analysis/passes/taint-propagation-pass.d.ts +19 -0
  69. package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
  70. package/dist/analysis/passes/taint-propagation-pass.js +116 -12
  71. package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
  72. package/dist/analysis/require-entry-path.d.ts +4 -1
  73. package/dist/analysis/require-entry-path.d.ts.map +1 -1
  74. package/dist/analysis/require-entry-path.js +150 -7
  75. package/dist/analysis/require-entry-path.js.map +1 -1
  76. package/dist/analysis/rules.d.ts +7 -0
  77. package/dist/analysis/rules.d.ts.map +1 -1
  78. package/dist/analysis/rules.js +65 -0
  79. package/dist/analysis/rules.js.map +1 -1
  80. package/dist/analysis/sbom.d.ts +32 -4
  81. package/dist/analysis/sbom.d.ts.map +1 -1
  82. package/dist/analysis/sbom.js +57 -19
  83. package/dist/analysis/sbom.js.map +1 -1
  84. package/dist/analysis/taint-matcher.d.ts.map +1 -1
  85. package/dist/analysis/taint-matcher.js +85 -8
  86. package/dist/analysis/taint-matcher.js.map +1 -1
  87. package/dist/analysis/taint-propagation.d.ts +7 -0
  88. package/dist/analysis/taint-propagation.d.ts.map +1 -1
  89. package/dist/analysis/taint-propagation.js +84 -0
  90. package/dist/analysis/taint-propagation.js.map +1 -1
  91. package/dist/analysis/test-to-production-taint-gate.d.ts.map +1 -1
  92. package/dist/analysis/test-to-production-taint-gate.js +6 -2
  93. package/dist/analysis/test-to-production-taint-gate.js.map +1 -1
  94. package/dist/analyzer.d.ts +30 -5
  95. package/dist/analyzer.d.ts.map +1 -1
  96. package/dist/analyzer.js +93 -13
  97. package/dist/analyzer.js.map +1 -1
  98. package/dist/browser/circle-ir.js +11477 -8820
  99. package/dist/core/circle-ir-core.cjs +351 -28
  100. package/dist/core/circle-ir-core.js +351 -28
  101. package/dist/core/extractors/calls.d.ts.map +1 -1
  102. package/dist/core/extractors/calls.js +83 -1
  103. package/dist/core/extractors/calls.js.map +1 -1
  104. package/dist/core/extractors/meta.d.ts +3 -2
  105. package/dist/core/extractors/meta.d.ts.map +1 -1
  106. package/dist/core/extractors/meta.js +3 -2
  107. package/dist/core/extractors/meta.js.map +1 -1
  108. package/dist/core/extractors/runtime-registrations.js +5 -2
  109. package/dist/core/extractors/runtime-registrations.js.map +1 -1
  110. package/dist/core/extractors/types.d.ts +3 -2
  111. package/dist/core/extractors/types.d.ts.map +1 -1
  112. package/dist/core/extractors/types.js +22 -20
  113. package/dist/core/extractors/types.js.map +1 -1
  114. package/dist/core/index.d.ts +1 -1
  115. package/dist/core/index.d.ts.map +1 -1
  116. package/dist/core/index.js +1 -1
  117. package/dist/core/index.js.map +1 -1
  118. package/dist/core/parser.d.ts +11 -6
  119. package/dist/core/parser.d.ts.map +1 -1
  120. package/dist/core/parser.js +29 -5
  121. package/dist/core/parser.js.map +1 -1
  122. package/dist/core/partial-parse-recovery.d.ts +26 -0
  123. package/dist/core/partial-parse-recovery.d.ts.map +1 -0
  124. package/dist/core/partial-parse-recovery.js +129 -0
  125. package/dist/core/partial-parse-recovery.js.map +1 -0
  126. package/dist/graph/code-graph.d.ts +1 -0
  127. package/dist/graph/code-graph.d.ts.map +1 -1
  128. package/dist/graph/code-graph.js +1 -0
  129. package/dist/graph/code-graph.js.map +1 -1
  130. package/dist/graph/import-graph.d.ts +14 -4
  131. package/dist/graph/import-graph.d.ts.map +1 -1
  132. package/dist/graph/import-graph.js +72 -9
  133. package/dist/graph/import-graph.js.map +1 -1
  134. package/dist/graph-facts/dead-code.d.ts +2 -0
  135. package/dist/graph-facts/dead-code.d.ts.map +1 -1
  136. package/dist/graph-facts/dead-code.js +126 -1
  137. package/dist/graph-facts/dead-code.js.map +1 -1
  138. package/dist/graph-facts/index.d.ts +1 -1
  139. package/dist/graph-facts/index.d.ts.map +1 -1
  140. package/dist/graph-facts/index.js +1 -1
  141. package/dist/graph-facts/index.js.map +1 -1
  142. package/dist/index.d.ts +3 -2
  143. package/dist/index.d.ts.map +1 -1
  144. package/dist/index.js +2 -1
  145. package/dist/index.js.map +1 -1
  146. package/dist/languages/plugins/javascript.d.ts.map +1 -1
  147. package/dist/languages/plugins/javascript.js +1 -1
  148. package/dist/languages/plugins/javascript.js.map +1 -1
  149. package/dist/languages/registry.d.ts.map +1 -1
  150. package/dist/languages/registry.js +12 -0
  151. package/dist/languages/registry.js.map +1 -1
  152. package/dist/navigation/index.d.ts +1 -1
  153. package/dist/navigation/index.d.ts.map +1 -1
  154. package/dist/navigation/index.js.map +1 -1
  155. package/dist/navigation/navigation-index.js +3 -1
  156. package/dist/navigation/navigation-index.js.map +1 -1
  157. package/dist/navigation/python-graph.d.ts +3 -1
  158. package/dist/navigation/python-graph.d.ts.map +1 -1
  159. package/dist/navigation/python-graph.js +236 -23
  160. package/dist/navigation/python-graph.js.map +1 -1
  161. package/dist/navigation/ts-call-edges.d.ts +18 -0
  162. package/dist/navigation/ts-call-edges.d.ts.map +1 -1
  163. package/dist/navigation/ts-call-edges.js +207 -18
  164. package/dist/navigation/ts-call-edges.js.map +1 -1
  165. package/dist/path-set/path-set.d.ts +5 -2
  166. package/dist/path-set/path-set.d.ts.map +1 -1
  167. package/dist/path-set/path-set.js +4 -1
  168. package/dist/path-set/path-set.js.map +1 -1
  169. package/dist/resolution/cross-file.d.ts +12 -0
  170. package/dist/resolution/cross-file.d.ts.map +1 -1
  171. package/dist/resolution/cross-file.js +357 -3
  172. package/dist/resolution/cross-file.js.map +1 -1
  173. package/dist/stable-ids/ts-parse-errors.d.ts +2 -0
  174. package/dist/stable-ids/ts-parse-errors.d.ts.map +1 -1
  175. package/dist/stable-ids/ts-parse-errors.js +43 -1
  176. package/dist/stable-ids/ts-parse-errors.js.map +1 -1
  177. package/dist/types/config.d.ts +2 -1
  178. package/dist/types/config.d.ts.map +1 -1
  179. package/dist/types/index.d.ts +74 -5
  180. package/dist/types/index.d.ts.map +1 -1
  181. package/dist/types/index.js.map +1 -1
  182. package/docs/SPEC.md +1 -1
  183. package/package.json +2 -2
@@ -11,6 +11,7 @@
11
11
  * Depends on: sink-filter, constant-propagation
12
12
  */
13
13
  import type { TaintFlowInfo } from '../../types/index.js';
14
+ import type { CircleIR } from '../../types/index.js';
14
15
  import type { AnalysisPass, PassContext } from '../../graph/analysis-pass.js';
15
16
  export interface TaintPropagationPassResult {
16
17
  flows: TaintFlowInfo[];
@@ -20,6 +21,24 @@ export declare class TaintPropagationPass implements AnalysisPass<TaintPropagati
20
21
  readonly category: 'security';
21
22
  run(ctx: PassContext): TaintPropagationPassResult;
22
23
  }
24
+ /**
25
+ * cognium-dev #101 (Sprint 14 Phase C/D). Detect Java method-level sanitizer
26
+ * idioms that protect the entire method body from a given sink type.
27
+ *
28
+ * `path_traversal` — canonical-path-startsWith-throw guard. Used in OWASP
29
+ * path-traversal cheatsheet examples and is the standard Java idiom for
30
+ * confining a derived `new File(base, userInput)` to a known root.
31
+ * `xxe` — DocumentBuilderFactory hardening via `setFeature`. The OWASP XXE
32
+ * cheatsheet lists `disallow-doctype-decl=true` and the two
33
+ * external-entity features as the canonical fix; presence of any of them
34
+ * on the factory in the method suffices.
35
+ *
36
+ * The check is method-scoped (using `types[].methods[]` start/end lines) and
37
+ * conservative — it does NOT verify that the guarded factory is the one used
38
+ * by the sink call. False-negatives are preferred over false-positives in
39
+ * the FP corpus regression context the issue is about.
40
+ */
41
+ export declare function isInJavaSanitizedMethod(code: string, types: CircleIR['types'] | undefined, sinkLine: number, sinkType: string): boolean;
23
42
  /**
24
43
  * Blank the *text* of string literals in a sink-argument expression before it
25
44
  * is tokenised into identifiers, while preserving interpolated expressions.
@@ -1 +1 @@
1
- {"version":3,"file":"taint-propagation-pass.d.ts","sourceRoot":"","sources":["../../../src/analysis/passes/taint-propagation-pass.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAe9E,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB;AAkmBD,qBAAa,oBAAqB,YAAW,YAAY,CAAC,0BAA0B,CAAC;IACnF,QAAQ,CAAC,IAAI,uBAAuB;IACpC,QAAQ,CAAC,QAAQ,EAAG,UAAU,CAAU;IAExC,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,0BAA0B,CAm0BhD;CACF;AA2vDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA6FnE"}
1
+ {"version":3,"file":"taint-propagation-pass.d.ts","sourceRoot":"","sources":["../../../src/analysis/passes/taint-propagation-pass.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAgB9E,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB;AA+nBD,qBAAa,oBAAqB,YAAW,YAAY,CAAC,0BAA0B,CAAC;IACnF,QAAQ,CAAC,IAAI,uBAAuB;IACpC,QAAQ,CAAC,QAAQ,EAAG,UAAU,CAAU;IAExC,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,0BAA0B,CAw2BhD;CACF;AA6FD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,SAAS,EACpC,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACf,OAAO,CAgCT;AAgpDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA6FnE"}
@@ -17,6 +17,7 @@ import { buildJavaTaintedVars, buildJavaScriptTaintedVars, buildPythonTaintedVar
17
17
  import { parseJavaArrayAccessExpression } from '../java-array-element-keys.js';
18
18
  import { canSourceReachSink, sourceSemanticsAllowed } from '../findings.js';
19
19
  import { walkBackwardDefs } from '../dfg-walk.js';
20
+ import { ARGV_NO_SHELL_TAG, JS_SPAWN_METHODS, classifyJsSpawnTaint, stripInMethodSuffix } from '../js-spawn-argv.js';
20
21
  import { sanitizerCoversSink } from '../sanitizer-index.js';
21
22
  import { HTML_CONTEXT_ENCODER_METHODS } from '../constant-propagation/patterns.js';
22
23
  import { javaCanonicalStartsWithAllBare } from '../java-canonical-prefix.js';
@@ -473,6 +474,20 @@ function goConstantHelperCalleeFromLines(lines, lineNumber) {
473
474
  }
474
475
  return null;
475
476
  }
477
+ /**
478
+ * Whether `step` is a variable produced by an HTML-context encoder
479
+ * that does not clean `sinkType` (#589 `sanitizedVarUncovered`, scoped
480
+ * `method:var`; a bare name looks up only its own method).
481
+ */
482
+ function encoderLeavesSinkUncovered(constProp, graph, step, sinkType) {
483
+ const unc = constProp.sanitizedVarUncovered;
484
+ if (!unc || unc.size === 0)
485
+ return false;
486
+ if (step.variable.includes(':'))
487
+ return !!unc.get(step.variable)?.has(sinkType);
488
+ const method = methodAtLine(graph, step.line);
489
+ return !!unc.get(method ? `${method}:${step.variable}` : step.variable)?.has(sinkType);
490
+ }
476
491
  function makeConstPropVeto(constProp, graph, sources, code, language, sanitizers) {
477
492
  const lines = typeof code === 'string' ? code.split('\n') : [];
478
493
  const selfReassign = new Map();
@@ -505,7 +520,7 @@ function makeConstPropVeto(constProp, graph, sources, code, language, sanitizers
505
520
  const use = (graph.usesByLine.get(line) ?? []).find(u => u.variable === v && u.def_id != null);
506
521
  return use ? graph.defById.get(use.def_id) : undefined;
507
522
  };
508
- return (step, sourceLine, sinkLine, sinkType) => {
523
+ return (step, sourceLine, sinkLine, sinkType, encodedUpstream) => {
509
524
  // cognium-dev#1198 — heap-field stamped sources are not in constProp.tainted.
510
525
  if (step.variable.includes('.') &&
511
526
  sources.some((s) => s.variable === step.variable &&
@@ -523,6 +538,12 @@ function makeConstPropVeto(constProp, graph, sources, code, language, sanitizers
523
538
  return false;
524
539
  if (r.reason !== 'variable_not_tainted')
525
540
  return true;
541
+ // An earlier step is the output of an HTML-context encoder
542
+ // that does not clean this sink type (`sql = "…" + encodeForHTML(p)`).
543
+ // const-prop's "not tainted" for a value derived from it is that encoder's
544
+ // credit, which does not apply here.
545
+ if (encodedUpstream)
546
+ return false;
526
547
  if (r.reason === 'variable_not_tainted' &&
527
548
  language === 'java' &&
528
549
  method &&
@@ -699,9 +720,15 @@ export class TaintPropagationPass {
699
720
  const verifiedFlows = propagationResult.flows.filter(flow => {
700
721
  if (constProp.unreachableLines.has(flow.sink.line))
701
722
  return false;
723
+ // Once the path passes a variable whose HTML-context encoder
724
+ // leaves this sink type uncovered, later steps are not vetoed as
725
+ // "not tainted" (see `encodedUpstream` in makeConstPropVeto).
726
+ let encodedUpstream = false;
702
727
  for (const step of flow.path) {
703
- if (isVetoed(step, flow.source.line, flow.sink.line, flow.sink.type))
728
+ if (isVetoed(step, flow.source.line, flow.sink.line, flow.sink.type, encodedUpstream))
704
729
  return false;
730
+ if (!encodedUpstream)
731
+ encodedUpstream = encoderLeavesSinkUncovered(constProp, graph, step, flow.sink.type);
705
732
  }
706
733
  if (isCorrelatedPredicateFP(constProp, flow))
707
734
  return false;
@@ -1454,6 +1481,44 @@ export class TaintPropagationPass {
1454
1481
  return true;
1455
1482
  return !lineSinks.every(k => lineSources.some(x => sinkNestedInSourceCall(x, k)));
1456
1483
  });
1484
+ // cognium-devE2/E6 — spawn / spawnSync / execFile / execFileSync.
1485
+ // Taint that reaches only the options object (`env: { ...process.env, X: v }`,
1486
+ // `cwd`) is not command injection: drop the flow. With an argument array and
1487
+ // no shell, tainted argv (or a program taken from the process environment)
1488
+ // is argument injection at most: tag the flow so it reports at medium.
1489
+ if ((ctx.language === 'javascript' || ctx.language === 'typescript') && typeof ctx.code === 'string') {
1490
+ const code = ctx.code;
1491
+ const spawnSinks = sinks.filter(k => k.type === 'command_injection' && JS_SPAWN_METHODS.has(k.method ?? ''));
1492
+ if (spawnSinks.length > 0) {
1493
+ finalFlows = finalFlows.filter(f => {
1494
+ if (f.sink_type !== 'command_injection')
1495
+ return true;
1496
+ const sink = spawnSinks.find(k => k.line === f.sink_line);
1497
+ if (!sink)
1498
+ return true;
1499
+ const carriers = new Set();
1500
+ for (const step of f.path) {
1501
+ if (step.variable && !step.variable.startsWith('<'))
1502
+ carriers.add(step.variable);
1503
+ }
1504
+ for (const src of sources) {
1505
+ if (src.line !== f.source_line || src.type !== f.source_type)
1506
+ continue;
1507
+ if (src.variable)
1508
+ carriers.add(src.variable);
1509
+ else if (src.location)
1510
+ carriers.add(stripInMethodSuffix(src.location));
1511
+ }
1512
+ const shape = classifyJsSpawnTaint(code, sink.line, sink.method, [...carriers], f.source_type === 'env_input');
1513
+ if (shape === 'options-only')
1514
+ return false;
1515
+ if (shape === 'argv-no-shell' && !f.tags?.includes(ARGV_NO_SHELL_TAG)) {
1516
+ f.tags = [...(f.tags ?? []), ARGV_NO_SHELL_TAG];
1517
+ }
1518
+ return true;
1519
+ });
1520
+ }
1521
+ }
1457
1522
  return { flows: finalFlows };
1458
1523
  }
1459
1524
  }
@@ -1591,7 +1656,7 @@ function isMongoValueBoundFilter(sinkCode, sinkMethod, sourceVar) {
1591
1656
  * by the sink call. False-negatives are preferred over false-positives in
1592
1657
  * the FP corpus regression context the issue is about.
1593
1658
  */
1594
- function isInJavaSanitizedMethod(code, types, sinkLine, sinkType) {
1659
+ export function isInJavaSanitizedMethod(code, types, sinkLine, sinkType) {
1595
1660
  if (!types || types.length === 0)
1596
1661
  return false;
1597
1662
  let methodStart = -1;
@@ -1627,18 +1692,57 @@ function isInJavaSanitizedMethod(code, types, sinkLine, sinkType) {
1627
1692
  return true;
1628
1693
  }
1629
1694
  if (sinkType === 'xxe') {
1630
- // DocumentBuilderFactory / SAXParserFactory / XMLInputFactory hardening.
1631
- // Any one of these features suffices per the OWASP XXE cheatsheet.
1632
- const setFeatureRe = /\.setFeature\s*\(\s*"(?:[^"]*disallow-doctype-decl|[^"]*external-general-entities|[^"]*external-parameter-entities|[^"]*load-external-dtd)"/;
1633
- if (setFeatureRe.test(body))
1634
- return true;
1635
- // setProperty variant for XMLInputFactory: `XMLInputFactory.SUPPORT_DTD`.
1636
- if (/\.setProperty\s*\([^,]*SUPPORT_DTD[^,]*,\s*false\s*\)/.test(body))
1637
- return true;
1638
- return false;
1695
+ return isHardenedXmlFactory(body);
1639
1696
  }
1640
1697
  return false;
1641
1698
  }
1699
+ /**
1700
+ * cognium-dev#1291 / #1293 follow-up — does this Java method body harden an XML
1701
+ * factory against XXE? One table shared by every factory kind (DocumentBuilder,
1702
+ * SAXParser, XMLInputFactory, TransformerFactory, SchemaFactory, XMLReader).
1703
+ *
1704
+ * Hardened when ANY of these appears in the body:
1705
+ * 1. setFeature("…disallow-doctype-decl | external-general-entities |
1706
+ * external-parameter-entities | load-external-dtd", …) — a string literal.
1707
+ * 2. setProperty(…SUPPORT_DTD…, false) — XMLInputFactory.
1708
+ * 3. set{Attribute,Property}(…ACCESS_EXTERNAL_{DTD,STYLESHEET,SCHEMA}…, "")
1709
+ * or the literal "http://javax.xml.XMLConstants/property/accessExternal…"
1710
+ * URI, with the value argument checked to be the EMPTY STRING. Covers both
1711
+ * the direct `tf.setAttribute(NAME, "")` form and a wrapper call such as
1712
+ * angus-mail's `setAttribute(tf, NAME, "")`.
1713
+ *
1714
+ * FEATURE_SECURE_PROCESSING is deliberately NOT accepted: on its own it does not
1715
+ * stop external entity or DTD resolution (JAXP). A non-empty access value such
1716
+ * as "all" or "file" is NOT hardening and must not match (#1293 regression: it
1717
+ * cleared `ACCESS_EXTERNAL_DTD="all"` because it never checked the value).
1718
+ *
1719
+ * Limits (unchanged from the prior recognizer): matching is textual and
1720
+ * method-scoped — it does not verify the hardened factory is the one used at the
1721
+ * sink, and an occurrence inside a comment or a log string is not excluded (the
1722
+ * accessExternal* URI itself contains "//", so cheap comment-stripping would
1723
+ * corrupt it).
1724
+ */
1725
+ function isHardenedXmlFactory(body) {
1726
+ // (1) Feature flags that disable DTD / external-entity processing.
1727
+ const setFeatureRe = /\.setFeature\s*\(\s*"(?:[^"]*disallow-doctype-decl|[^"]*external-general-entities|[^"]*external-parameter-entities|[^"]*load-external-dtd)"/;
1728
+ if (setFeatureRe.test(body))
1729
+ return true;
1730
+ // (2) XMLInputFactory SUPPORT_DTD = false.
1731
+ if (/\.setProperty\s*\([^,]*SUPPORT_DTD[^,]*,\s*false\s*\)/.test(body))
1732
+ return true;
1733
+ // (3) External-access lockdown set to the empty string. The name (XMLConstants
1734
+ // constant or literal property URI) is matched only when the value argument is
1735
+ // the empty string, so a non-empty value like "all"/"file" is not credited.
1736
+ // A permissive value on ANY external-access attribute (e.g. ACCESS_EXTERNAL_DTD
1737
+ // = "all" alongside ACCESS_EXTERNAL_STYLESHEET = "") vetoes the credit — the
1738
+ // open vector is still exploitable, so the method is not treated as hardened.
1739
+ const accessName = '(?:ACCESS_EXTERNAL_(?:DTD|STYLESHEET|SCHEMA)\\b|"https?:\\/\\/javax\\.xml\\.XMLConstants\\/property\\/accessExternal(?:DTD|Stylesheet|Schema)")';
1740
+ const emptyExternalAccessRe = new RegExp(`${accessName}\\s*,\\s*""`);
1741
+ const permissiveExternalAccessRe = new RegExp(`${accessName}\\s*,\\s*"[^"]+"`);
1742
+ if (emptyExternalAccessRe.test(body) && !permissiveExternalAccessRe.test(body))
1743
+ return true;
1744
+ return false;
1745
+ }
1642
1746
  // ---------------------------------------------------------------------------
1643
1747
  // Helpers (moved verbatim from analyzer.ts)
1644
1748
  // ---------------------------------------------------------------------------