circle-ir 4.20.0 → 4.21.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 (170) hide show
  1. package/dist/analysis/config-loader.d.ts.map +1 -1
  2. package/dist/analysis/config-loader.js +17 -2
  3. package/dist/analysis/config-loader.js.map +1 -1
  4. package/dist/analysis/constant-propagation/patterns.d.ts.map +1 -1
  5. package/dist/analysis/constant-propagation/patterns.js +3 -0
  6. package/dist/analysis/constant-propagation/patterns.js.map +1 -1
  7. package/dist/analysis/constant-propagation/propagator.d.ts +46 -1
  8. package/dist/analysis/constant-propagation/propagator.d.ts.map +1 -1
  9. package/dist/analysis/constant-propagation/propagator.js +407 -56
  10. package/dist/analysis/constant-propagation/propagator.js.map +1 -1
  11. package/dist/analysis/findings.d.ts.map +1 -1
  12. package/dist/analysis/findings.js +7 -5
  13. package/dist/analysis/findings.js.map +1 -1
  14. package/dist/analysis/interprocedural.d.ts +16 -0
  15. package/dist/analysis/interprocedural.d.ts.map +1 -1
  16. package/dist/analysis/interprocedural.js +545 -197
  17. package/dist/analysis/interprocedural.js.map +1 -1
  18. package/dist/analysis/passes/csrf-samesite-none-session-pass.d.ts +58 -0
  19. package/dist/analysis/passes/csrf-samesite-none-session-pass.d.ts.map +1 -0
  20. package/dist/analysis/passes/csrf-samesite-none-session-pass.js +159 -0
  21. package/dist/analysis/passes/csrf-samesite-none-session-pass.js.map +1 -0
  22. package/dist/analysis/passes/interprocedural-pass.d.ts.map +1 -1
  23. package/dist/analysis/passes/interprocedural-pass.js +83 -10
  24. package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
  25. package/dist/analysis/passes/language-sources-pass.d.ts +0 -18
  26. package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
  27. package/dist/analysis/passes/language-sources-pass.js +439 -16
  28. package/dist/analysis/passes/language-sources-pass.js.map +1 -1
  29. package/dist/analysis/passes/param-source-flow-gate-pass.d.ts.map +1 -1
  30. package/dist/analysis/passes/param-source-flow-gate-pass.js +71 -1
  31. package/dist/analysis/passes/param-source-flow-gate-pass.js.map +1 -1
  32. package/dist/analysis/passes/prompt-injection-safety-gate-pass.js +1 -1
  33. package/dist/analysis/passes/prompt-injection-safety-gate-pass.js.map +1 -1
  34. package/dist/analysis/passes/scan-secrets-pass.js +2 -2
  35. package/dist/analysis/passes/scan-secrets-pass.js.map +1 -1
  36. package/dist/analysis/passes/sensitive-data-in-log-pass.d.ts +66 -0
  37. package/dist/analysis/passes/sensitive-data-in-log-pass.d.ts.map +1 -0
  38. package/dist/analysis/passes/sensitive-data-in-log-pass.js +462 -0
  39. package/dist/analysis/passes/sensitive-data-in-log-pass.js.map +1 -0
  40. package/dist/analysis/passes/sink-filter-pass.d.ts +7 -1
  41. package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
  42. package/dist/analysis/passes/sink-filter-pass.js +372 -14
  43. package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
  44. package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
  45. package/dist/analysis/passes/taint-propagation-pass.js +289 -13
  46. package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
  47. package/dist/analysis/project-callee-escape-gate.js +1 -1
  48. package/dist/analysis/project-callee-escape-gate.js.map +1 -1
  49. package/dist/analysis/rules.d.ts.map +1 -1
  50. package/dist/analysis/rules.js +9 -0
  51. package/dist/analysis/rules.js.map +1 -1
  52. package/dist/analysis/sbom.d.ts +49 -0
  53. package/dist/analysis/sbom.d.ts.map +1 -1
  54. package/dist/analysis/sbom.js +126 -1
  55. package/dist/analysis/sbom.js.map +1 -1
  56. package/dist/analysis/taint-matcher.d.ts.map +1 -1
  57. package/dist/analysis/taint-matcher.js +85 -16
  58. package/dist/analysis/taint-matcher.js.map +1 -1
  59. package/dist/analysis/taint-propagation.d.ts +1 -0
  60. package/dist/analysis/taint-propagation.d.ts.map +1 -1
  61. package/dist/analysis/taint-propagation.js +32 -0
  62. package/dist/analysis/taint-propagation.js.map +1 -1
  63. package/dist/analysis/test-to-production-taint-gate.d.ts +13 -0
  64. package/dist/analysis/test-to-production-taint-gate.d.ts.map +1 -0
  65. package/dist/analysis/test-to-production-taint-gate.js +30 -0
  66. package/dist/analysis/test-to-production-taint-gate.js.map +1 -0
  67. package/dist/analyzer.d.ts +15 -3
  68. package/dist/analyzer.d.ts.map +1 -1
  69. package/dist/analyzer.js +56 -2
  70. package/dist/analyzer.js.map +1 -1
  71. package/dist/browser/circle-ir.js +4972 -2470
  72. package/dist/core/circle-ir-core.cjs +2969 -2223
  73. package/dist/core/circle-ir-core.js +2969 -2219
  74. package/dist/core/extractors/calls.d.ts +10 -1
  75. package/dist/core/extractors/calls.d.ts.map +1 -1
  76. package/dist/core/extractors/calls.js +148 -6
  77. package/dist/core/extractors/calls.js.map +1 -1
  78. package/dist/core/extractors/cfg.d.ts.map +1 -1
  79. package/dist/core/extractors/cfg.js +12 -0
  80. package/dist/core/extractors/cfg.js.map +1 -1
  81. package/dist/core/extractors/dfg.d.ts.map +1 -1
  82. package/dist/core/extractors/dfg.js +151 -18
  83. package/dist/core/extractors/dfg.js.map +1 -1
  84. package/dist/core/extractors/types.d.ts +5 -0
  85. package/dist/core/extractors/types.d.ts.map +1 -1
  86. package/dist/core/extractors/types.js +149 -4
  87. package/dist/core/extractors/types.js.map +1 -1
  88. package/dist/core/parser.d.ts.map +1 -1
  89. package/dist/core/parser.js +3 -1
  90. package/dist/core/parser.js.map +1 -1
  91. package/dist/core/ts-grammar-workarounds.d.ts +18 -0
  92. package/dist/core/ts-grammar-workarounds.d.ts.map +1 -0
  93. package/dist/core/ts-grammar-workarounds.js +40 -0
  94. package/dist/core/ts-grammar-workarounds.js.map +1 -0
  95. package/dist/facts/facts2.d.ts +12 -3
  96. package/dist/facts/facts2.d.ts.map +1 -1
  97. package/dist/facts/facts2.js +24 -7
  98. package/dist/facts/facts2.js.map +1 -1
  99. package/dist/facts/index.d.ts +3 -1
  100. package/dist/facts/index.d.ts.map +1 -1
  101. package/dist/facts/index.js +2 -1
  102. package/dist/facts/index.js.map +1 -1
  103. package/dist/facts/schema2.d.ts +3 -3
  104. package/dist/facts/schema2.js +3 -3
  105. package/dist/facts/t6.d.ts +84 -0
  106. package/dist/facts/t6.d.ts.map +1 -0
  107. package/dist/facts/t6.js +226 -0
  108. package/dist/facts/t6.js.map +1 -0
  109. package/dist/graph-facts/dead-code.d.ts.map +1 -1
  110. package/dist/graph-facts/dead-code.js +3 -2
  111. package/dist/graph-facts/dead-code.js.map +1 -1
  112. package/dist/graph-facts/index.d.ts +1 -1
  113. package/dist/graph-facts/index.d.ts.map +1 -1
  114. package/dist/graph-facts/index.js +1 -1
  115. package/dist/graph-facts/index.js.map +1 -1
  116. package/dist/graph-facts/reach.d.ts +31 -4
  117. package/dist/graph-facts/reach.d.ts.map +1 -1
  118. package/dist/graph-facts/reach.js +120 -4
  119. package/dist/graph-facts/reach.js.map +1 -1
  120. package/dist/index.d.ts +8 -6
  121. package/dist/index.d.ts.map +1 -1
  122. package/dist/index.js +11 -7
  123. package/dist/index.js.map +1 -1
  124. package/dist/navigation/index.d.ts +1 -0
  125. package/dist/navigation/index.d.ts.map +1 -1
  126. package/dist/navigation/index.js +1 -0
  127. package/dist/navigation/index.js.map +1 -1
  128. package/dist/navigation/java-graph.d.ts +31 -9
  129. package/dist/navigation/java-graph.d.ts.map +1 -1
  130. package/dist/navigation/java-graph.js +174 -11
  131. package/dist/navigation/java-graph.js.map +1 -1
  132. package/dist/navigation/java-registrations.d.ts +93 -0
  133. package/dist/navigation/java-registrations.d.ts.map +1 -0
  134. package/dist/navigation/java-registrations.js +254 -0
  135. package/dist/navigation/java-registrations.js.map +1 -0
  136. package/dist/navigation/navigation-index.d.ts +65 -3
  137. package/dist/navigation/navigation-index.d.ts.map +1 -1
  138. package/dist/navigation/navigation-index.js +181 -11
  139. package/dist/navigation/navigation-index.js.map +1 -1
  140. package/dist/navigation/ts-call-edges.d.ts +6 -0
  141. package/dist/navigation/ts-call-edges.d.ts.map +1 -1
  142. package/dist/navigation/ts-call-edges.js.map +1 -1
  143. package/dist/navigation/ts-entry-tables.d.ts +1 -1
  144. package/dist/navigation/ts-entry-tables.d.ts.map +1 -1
  145. package/dist/navigation/ts-entry-tables.js.map +1 -1
  146. package/dist/navigation/xml-scan.d.ts +40 -0
  147. package/dist/navigation/xml-scan.d.ts.map +1 -0
  148. package/dist/navigation/xml-scan.js +269 -0
  149. package/dist/navigation/xml-scan.js.map +1 -0
  150. package/dist/stable-ids/index.d.ts +3 -3
  151. package/dist/stable-ids/index.d.ts.map +1 -1
  152. package/dist/stable-ids/index.js +16 -4
  153. package/dist/stable-ids/index.js.map +1 -1
  154. package/dist/stable-ids/nodes.d.ts +16 -6
  155. package/dist/stable-ids/nodes.d.ts.map +1 -1
  156. package/dist/stable-ids/nodes.js +17 -7
  157. package/dist/stable-ids/nodes.js.map +1 -1
  158. package/dist/stable-ids/ts-parse-errors.d.ts.map +1 -1
  159. package/dist/stable-ids/ts-parse-errors.js +21 -2
  160. package/dist/stable-ids/ts-parse-errors.js.map +1 -1
  161. package/dist/stable-ids/typescript.d.ts +5 -0
  162. package/dist/stable-ids/typescript.d.ts.map +1 -1
  163. package/dist/stable-ids/typescript.js +41 -8
  164. package/dist/stable-ids/typescript.js.map +1 -1
  165. package/dist/types/index.d.ts +21 -3
  166. package/dist/types/index.d.ts.map +1 -1
  167. package/dist/types/index.js +1 -0
  168. package/dist/types/index.js.map +1 -1
  169. package/docs/SPEC.md +9 -0
  170. package/package.json +3 -3
@@ -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;AAolBD,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,CAiyBhD;CACF;AA6rDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;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"}
@@ -13,7 +13,7 @@
13
13
  import { findJavaSpringReturnXSSSinks } from './language-sources-pass.js';
14
14
  import { expressionFullyWrappedBySanitizer, identifierOutsideSanitizerCalls, identifierOutsideSanitizerCallsInText, propagateTaint } from '../taint-propagation.js';
15
15
  import { isFalsePositive, isCorrelatedPredicateFP, constPropScopedVar } from '../constant-propagation.js';
16
- import { buildJavaTaintedVars, buildPythonTaintedVars, buildRustTaintedVars, findPythonTrustBoundaryViolations, findPythonReturnXSSSinks, findJavaWikiPluginReturnXSSSinks } from './language-sources-pass.js';
16
+ import { buildJavaTaintedVars, buildJavaScriptTaintedVars, buildPythonTaintedVars, buildRustTaintedVars, findPythonTrustBoundaryViolations, findPythonReturnXSSSinks, findJavaWikiPluginReturnXSSSinks } from './language-sources-pass.js';
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';
@@ -506,6 +506,15 @@ function makeConstPropVeto(constProp, graph, sources, code, language, sanitizers
506
506
  return use ? graph.defById.get(use.def_id) : undefined;
507
507
  };
508
508
  return (step, sourceLine, sinkLine, sinkType) => {
509
+ // cognium-dev#1198 — heap-field stamped sources are not in constProp.tainted.
510
+ if (step.variable.includes('.') &&
511
+ sources.some((s) => s.variable === step.variable &&
512
+ s.line >= sourceLine &&
513
+ s.line <= sinkLine &&
514
+ typeof s.location === 'string' &&
515
+ s.location.includes('heap field read'))) {
516
+ return false;
517
+ }
509
518
  const method = methodAtLine(graph, step.line);
510
519
  const blockLine = defLineForUse(graph, step.variable, step.line);
511
520
  const fpLookup = constPropFlowLookup(language, method, step.variable, blockLine, constProp);
@@ -919,7 +928,7 @@ export class TaintPropagationPass {
919
928
  pushIfNew(f);
920
929
  }
921
930
  // Supplement: collection/iterator flows — with FP filtering
922
- const collectionFlows = detectCollectionFlows(calls, sources, sinks, constProp, ctx.code, types, graph) ?? [];
931
+ const collectionFlows = detectCollectionFlows(calls, sources, sinks, constProp, ctx.code, types, graph, ctx.language) ?? [];
923
932
  for (const f of collectionFlows) {
924
933
  if (flowKeys.has(flowKey(f)))
925
934
  continue;
@@ -1329,6 +1338,25 @@ export class TaintPropagationPass {
1329
1338
  return false;
1330
1339
  });
1331
1340
  }
1341
+ // cognium-dev #1152 / #1247 — Java `new Cookie(…, value)` trust_boundary only
1342
+ // when `value` is HTTP-sourced in the same method. Method parameters such as
1343
+ // `InsecureCookieTp.set(..., String sid)` are not CWE-501 session-trust writes.
1344
+ const javaCookieTrustSinkLines = new Set();
1345
+ for (const s of sinks) {
1346
+ if (s.type === 'trust_boundary' &&
1347
+ (s.method === 'Cookie' || s.method === 'setValue')) {
1348
+ javaCookieTrustSinkLines.add(s.line);
1349
+ }
1350
+ }
1351
+ if (javaCookieTrustSinkLines.size > 0) {
1352
+ finalFlows = finalFlows.filter(f => {
1353
+ if (f.sink_type !== 'trust_boundary')
1354
+ return true;
1355
+ if (!javaCookieTrustSinkLines.has(f.sink_line))
1356
+ return true;
1357
+ return typeof f.source_type === 'string' && f.source_type.startsWith('http_');
1358
+ });
1359
+ }
1332
1360
  // cognium-dev #49 — final dedup on (source_line, sink_line, sink_type).
1333
1361
  // The DFG propagator and the four supplementary detectors each emit
1334
1362
  // independently; merge-time dedup at the supplement seams is partial
@@ -1411,6 +1439,21 @@ export class TaintPropagationPass {
1411
1439
  return true;
1412
1440
  });
1413
1441
  }
1442
+ // cognium-dev #1156: `parser.parse(fs.readFileSync(abs))`. When every sink
1443
+ // of the flow's type on the line is a call nested inside the arguments of a
1444
+ // source call of the flow's source type, the sink runs first and the
1445
+ // source's result never reaches it. Applied to the flows of every emitter;
1446
+ // JavaScript and TypeScript only for now.
1447
+ if (ctx.language === 'javascript' || ctx.language === 'typescript')
1448
+ finalFlows = finalFlows.filter(f => {
1449
+ if (f.source_line !== f.sink_line)
1450
+ return true;
1451
+ const lineSinks = sinks.filter(k => k.line === f.sink_line && k.type === f.sink_type);
1452
+ const lineSources = sources.filter(x => x.line === f.source_line && x.type === f.source_type);
1453
+ if (lineSinks.length === 0 || lineSources.length === 0)
1454
+ return true;
1455
+ return !lineSinks.every(k => lineSources.some(x => sinkNestedInSourceCall(x, k)));
1456
+ });
1414
1457
  return { flows: finalFlows };
1415
1458
  }
1416
1459
  }
@@ -1506,7 +1549,7 @@ function isMongoValueBoundFilter(sinkCode, sinkMethod, sourceVar) {
1506
1549
  if (!body)
1507
1550
  return false;
1508
1551
  // Strip string literals so `$` inside string values doesn't false-trip.
1509
- const stripped = body.replace(/(['"`])(?:\\.|(?!\1).)*\1/g, '""');
1552
+ const stripped = body.replace(/(['"`])(?:\\.|(?!\1)[^\\\n\r\u2028\u2029])*\1/g, '""');
1510
1553
  // Spread / rest disqualifies (opaque subset).
1511
1554
  if (/\.\.\./.test(stripped))
1512
1555
  return false;
@@ -1752,13 +1795,16 @@ function detectJsModuleScopeFlows(code, sources, sinks, unreachableLines) {
1752
1795
  return flows;
1753
1796
  const lines = code.split('\n');
1754
1797
  const moduleVars = new Set();
1798
+ const moduleDeclRe = /(?:^|;)\s*(?:export\s+)?(?:let|var|const)\s+([A-Za-z_$][\w$]*)\b/g;
1755
1799
  for (const line of lines) {
1756
1800
  const stripped = line.replace(/\s+$/, '');
1757
1801
  if (!stripped || /^[ \t]/.test(line))
1758
1802
  continue;
1759
- const m = stripped.match(/^(?:export\s+)?(?:let|var|const)\s+([A-Za-z_$][\w$]*)\b/);
1760
- if (m)
1803
+ let m;
1804
+ moduleDeclRe.lastIndex = 0;
1805
+ while ((m = moduleDeclRe.exec(stripped)) !== null) {
1761
1806
  moduleVars.add(m[1]);
1807
+ }
1762
1808
  }
1763
1809
  if (moduleVars.size === 0)
1764
1810
  return flows;
@@ -1956,7 +2002,7 @@ function isMapLiteralKeyTainted(constProp, mapName, key, inMethod) {
1956
2002
  return false;
1957
2003
  return keys.has(key) || keys.has('*');
1958
2004
  }
1959
- function detectCollectionFlows(calls, sources, sinks, constProp, code, types, graph) {
2005
+ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, graph, language) {
1960
2006
  const taintedVars = constProp.tainted;
1961
2007
  const unreachableLines = constProp.unreachableLines;
1962
2008
  const flows = [];
@@ -1970,9 +2016,20 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
1970
2016
  existing.push(call);
1971
2017
  callsByLine.set(call.location.line, existing);
1972
2018
  }
1973
- const javaDerivedVars = typeof code === 'string'
2019
+ const javaDerivedVars = language === 'java' && typeof code === 'string'
1974
2020
  ? buildJavaTaintedVars(code, new Set(sources.map(s => s.variable).filter((v) => Boolean(v))))
1975
2021
  : undefined;
2022
+ // Stamp qualified sources (#1198 heap-field reads) — seeds are not
2023
+ // present in the derived-only map returned by `buildJavaTaintedVars`.
2024
+ if (javaDerivedVars) {
2025
+ for (const s of sources) {
2026
+ if (s.variable?.includes('.') &&
2027
+ typeof s.location === 'string' &&
2028
+ s.location.includes('heap field read')) {
2029
+ javaDerivedVars.set(s.variable, s.line);
2030
+ }
2031
+ }
2032
+ }
1976
2033
  for (const sink of sinks) {
1977
2034
  if (unreachableLines.has(sink.line))
1978
2035
  continue;
@@ -1985,9 +2042,22 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
1985
2042
  continue;
1986
2043
  }
1987
2044
  if (arg.variable) {
1988
- const varName = arg.variable;
2045
+ const expr = arg.expression ?? '';
2046
+ let varName = arg.variable;
2047
+ // cognium-dev#1198 — Tree-sitter sink args carry the innermost
2048
+ // identifier (`value` in `next.value`); `buildJavaTaintedVars` keys
2049
+ // the qualified field path instead.
2050
+ if (language === 'java' &&
2051
+ expr.includes('.') &&
2052
+ !expr.startsWith('this.') &&
2053
+ (javaDerivedVars?.has(expr) ||
2054
+ sources.some((s) => s.variable === expr &&
2055
+ typeof s.location === 'string' &&
2056
+ s.location.includes('heap field read')))) {
2057
+ varName = expr;
2058
+ }
1989
2059
  let scopedName = varName;
1990
- if (call.in_method) {
2060
+ if (call.in_method && !varName.includes('.')) {
1991
2061
  const blockLine = graph
1992
2062
  ? defLineForUse(graph, varName, call.location.line)
1993
2063
  : call.location.line;
@@ -1996,7 +2066,6 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
1996
2066
  // Bare `name` that is a field read (no local of that name in this
1997
2067
  // method) still counts as a field use — Inter4-style. A shadowing
1998
2068
  // local declaration in the method does not.
1999
- const expr = arg.expression ?? '';
2000
2069
  const explicitField = isFieldUseExpression(expr, varName, enclosingTypeNamesAt(types, call.location.line));
2001
2070
  const bareFieldRead = fieldNames.has(varName)
2002
2071
  && expr === varName
@@ -2004,6 +2073,14 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
2004
2073
  const isFieldUse = explicitField || bareFieldRead;
2005
2074
  const mapKeyRead = mapGetLiteralKeyFromExpr(expr);
2006
2075
  let argTainted = isTaintedInMethod(taintedVars, varName, scopedName, fieldNames, isFieldUse);
2076
+ if (language === 'java' &&
2077
+ !argTainted &&
2078
+ javaDerivedVars?.has(varName) &&
2079
+ sources.some((s) => s.variable === varName &&
2080
+ typeof s.location === 'string' &&
2081
+ s.location.includes('heap field read'))) {
2082
+ argTainted = true;
2083
+ }
2007
2084
  if (mapKeyRead && mapKeyRead.map === varName) {
2008
2085
  argTainted = isMapLiteralKeyTainted(constProp, varName, mapKeyRead.key, call.in_method);
2009
2086
  }
@@ -2113,6 +2190,16 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
2113
2190
  }
2114
2191
  return flows;
2115
2192
  }
2193
+ /** cognium-dev#476 — `array[n-n]` in SecuriBench stores index as `0` but sink arg is `n-n`. */
2194
+ function normalizeJavaArrayIndexKey(indexKey) {
2195
+ const trimmed = indexKey.trim();
2196
+ if (/^\d+$/.test(trimmed))
2197
+ return trimmed;
2198
+ const sameVarDiff = trimmed.match(/^([A-Za-z_]\w*)\s*-\s*\1$/);
2199
+ if (sameVarDiff)
2200
+ return '0';
2201
+ return trimmed;
2202
+ }
2116
2203
  function detectArrayElementFlows(calls, sources, sinks, taintedArrayElements, unreachableLines, types) {
2117
2204
  const flows = [];
2118
2205
  const callsByLine = new Map();
@@ -2135,9 +2222,12 @@ function detectArrayElementFlows(calls, sources, sinks, taintedArrayElements, un
2135
2222
  const arrayAccess = parseJavaArrayAccessExpression(arg.expression);
2136
2223
  if (arrayAccess) {
2137
2224
  const { base, arrayName, indexKey, displayVar } = arrayAccess;
2225
+ const resolvedIndex = normalizeJavaArrayIndexKey(indexKey);
2138
2226
  const taintedIndices = taintedArrayElements.get(arrayName);
2139
2227
  if (taintedIndices) {
2140
- const isTainted = taintedIndices.has(indexKey) || taintedIndices.has('*');
2228
+ const isTainted = taintedIndices.has(resolvedIndex) ||
2229
+ taintedIndices.has(indexKey) ||
2230
+ taintedIndices.has('*');
2141
2231
  if (isTainted) {
2142
2232
  // Sprint 13 #70 — method-scoped source picker (see detectCollectionFlows).
2143
2233
  const source = pickScopedSource(sources, sink.line, call.in_method ?? null, types, base);
@@ -2196,7 +2286,7 @@ function shouldGateCSharpPatPermsLibraryParamFlow(flow, sources, sinks, types, c
2196
2286
  }
2197
2287
  /** Parameter names referenced as identifiers inside a compound sink argument (#685). */
2198
2288
  function compoundArgParamNames(expression, paramNames) {
2199
- const stripped = expression.replace(/(['"`])(?:\\.|(?!\1).)*\1/g, (m) => ' '.repeat(m.length));
2289
+ const stripped = expression.replace(/(['"`])(?:\\.|(?!\1)[^\\\n\r\u2028\u2029])*\1/g, (m) => ' '.repeat(m.length));
2200
2290
  const matched = [];
2201
2291
  for (const raw of paramNames) {
2202
2292
  const name = raw.startsWith('*') ? raw.slice(1) : raw;
@@ -3246,6 +3336,65 @@ function matchingCloseParen(lineText, openParenIndex) {
3246
3336
  }
3247
3337
  return -1;
3248
3338
  }
3339
+ /**
3340
+ * cognium-dev#1223 — `req.query.url` contains the token `query`, which must not
3341
+ * pair with a tainted local named `query` in another function. True when every
3342
+ * occurrence of `ident` in `expr` is only as `(req|request|ctx).ident`.
3343
+ */
3344
+ function jsBareIdentOnlyAsRequestProxy(expr, ident) {
3345
+ const escaped = ident.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
3346
+ const re = new RegExp(`\\b${escaped}\\b`, 'gu');
3347
+ let hits = 0;
3348
+ let m;
3349
+ while ((m = re.exec(expr)) !== null) {
3350
+ hits++;
3351
+ const before = expr.slice(0, m.index);
3352
+ if (!/(?:\breq|\brequest|\bctx)\.\s*$/.test(before))
3353
+ return false;
3354
+ }
3355
+ return hits > 0;
3356
+ }
3357
+ /**
3358
+ * cognium-dev#1223 — when `types[].methods` is empty (common for
3359
+ * `module.exports.foo = function` handlers), derive function line ranges from
3360
+ * the source so the #472-style same-function gate still applies.
3361
+ */
3362
+ function buildJsTsFunctionRangesFromSource(code) {
3363
+ const lines = code.split('\n');
3364
+ const ranges = [];
3365
+ const startPatterns = [
3366
+ /\bfunction\b/,
3367
+ /(?:^|\s)(?:module\.)?exports\.\w+\s*=\s*(?:async\s+)?function\b/,
3368
+ /(?:^|\s)(?:module\.)?exports\.\w+\s*=\s*(?:async\s+)?\([^)]*\)\s*=>/,
3369
+ /(?:^|\s)(?:const|let|var)\s+\w+\s*=\s*(?:async\s+)?function\b/,
3370
+ /(?:^|\s)(?:const|let|var)\s+\w+\s*=\s*(?:async\s+)?\([^)]*\)\s*=>/,
3371
+ ];
3372
+ for (let i = 0; i < lines.length; i++) {
3373
+ const line = lines[i];
3374
+ if (line.trimStart().startsWith('//'))
3375
+ continue;
3376
+ if (!startPatterns.some((re) => re.test(line)))
3377
+ continue;
3378
+ const startLine = i + 1;
3379
+ let depth = 0;
3380
+ let started = false;
3381
+ for (let j = i; j < lines.length; j++) {
3382
+ for (const ch of lines[j]) {
3383
+ if (ch === '{') {
3384
+ depth++;
3385
+ started = true;
3386
+ }
3387
+ else if (ch === '}')
3388
+ depth--;
3389
+ }
3390
+ if (started && depth === 0) {
3391
+ ranges.push([startLine, j + 1]);
3392
+ break;
3393
+ }
3394
+ }
3395
+ }
3396
+ return ranges;
3397
+ }
3249
3398
  /**
3250
3399
  * cognium-dev#1156 — `io_input` at `*.parse(...)` has no `method` tag; `location` is
3251
3400
  * like `parser.parse() in m`. When `path_traversal` (`readFileSync`, …) appears only
@@ -3314,7 +3463,12 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
3314
3463
  // is every Juliet C# file.
3315
3464
  const csFnRanges = methodRanges(['csharp']);
3316
3465
  const csFnStart = (line) => enclosingStart(csFnRanges, line);
3317
- const jsFnRanges = methodRanges(['javascript', 'typescript']);
3466
+ let jsFnRanges = methodRanges(['javascript', 'typescript']);
3467
+ if (jsFnRanges.length === 0 &&
3468
+ typeof code === 'string' &&
3469
+ (language === 'javascript' || language === 'typescript')) {
3470
+ jsFnRanges = buildJsTsFunctionRangesFromSource(code);
3471
+ }
3318
3472
  const jsFnStart = (line) => enclosingStart(jsFnRanges, line);
3319
3473
  // cognium-dev#548 — names declared as class fields. A field is the one kind
3320
3474
  // of variable whose value legitimately crosses from one method to another, so
@@ -3532,6 +3686,64 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
3532
3686
  }
3533
3687
  }
3534
3688
  }
3689
+ // JS/TS body-parse chains (#1149 IL-22): virtual sources for variables
3690
+ // derived from `JSON.parse(req.body)` without widening to all jsTaintedVars.
3691
+ if ((language === 'javascript' || language === 'typescript') &&
3692
+ typeof code === 'string') {
3693
+ const httpTypes = new Set([
3694
+ 'http_body',
3695
+ 'http_query',
3696
+ 'http_param',
3697
+ 'http_header',
3698
+ 'http_cookie',
3699
+ ]);
3700
+ const httpAnchor = sourcesWithVar.find((s) => httpTypes.has(s.type));
3701
+ if (httpAnchor) {
3702
+ const lines = code.split('\n');
3703
+ const chainVars = new Set();
3704
+ for (let i = 0; i < lines.length; i++) {
3705
+ const line = lines[i];
3706
+ if (/\bJSON\.parse\b/.test(line) && /\b(?:req|request)\.body\b/.test(line)) {
3707
+ const bind = line.match(/(?:const|let|var)\s+(\w+)\s*=/);
3708
+ if (bind?.[1])
3709
+ chainVars.add(bind[1]);
3710
+ }
3711
+ }
3712
+ let expanded = true;
3713
+ while (expanded) {
3714
+ expanded = false;
3715
+ for (let i = 0; i < lines.length; i++) {
3716
+ const line = lines[i];
3717
+ for (const seed of chainVars) {
3718
+ const prop = line.match(new RegExp(`(?:const|let|var)\\s+(\\w+)\\s*=\\s*${seed}\\.`));
3719
+ const alias = line.match(new RegExp(`(?:const|let|var)\\s+(\\w+)\\s*=\\s*\\b${seed}\\b`));
3720
+ const lhs = prop?.[1] ?? alias?.[1];
3721
+ if (lhs && !chainVars.has(lhs)) {
3722
+ chainVars.add(lhs);
3723
+ expanded = true;
3724
+ }
3725
+ }
3726
+ }
3727
+ }
3728
+ if (chainVars.size > 0) {
3729
+ const derivedLines = buildJavaScriptTaintedVars(code, language);
3730
+ const existingVars = new Set(sourcesWithVar.map((s) => s.variable));
3731
+ for (const varName of chainVars) {
3732
+ if (!varName || existingVars.has(varName))
3733
+ continue;
3734
+ const originLine = derivedLines.get(varName);
3735
+ if (originLine === undefined)
3736
+ continue;
3737
+ sourcesWithVar.push({
3738
+ ...httpAnchor,
3739
+ variable: varName,
3740
+ line: originLine,
3741
+ });
3742
+ existingVars.add(varName);
3743
+ }
3744
+ }
3745
+ }
3746
+ }
3535
3747
  // Rust alias expansion (#71): mirror the Python branch above so that
3536
3748
  // multi-level extractor chains like
3537
3749
  // let form = f.into_inner();
@@ -4410,6 +4622,20 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
4410
4622
  if (srcFn !== -1 && sinkFn !== -1 && srcFn !== sinkFn)
4411
4623
  continue;
4412
4624
  }
4625
+ // cognium-dev#1223 — cross-function name collision on request proxies:
4626
+ // `req.query` must not match a local `query` in another handler.
4627
+ if (jsFnRanges.length > 0 &&
4628
+ source.variable &&
4629
+ !complex) {
4630
+ const srcFn = jsFnStart(source.line);
4631
+ const sinkFn = jsFnStart(sink.line);
4632
+ if (srcFn !== -1 &&
4633
+ sinkFn !== -1 &&
4634
+ srcFn !== sinkFn &&
4635
+ jsBareIdentOnlyAsRequestProxy(expr, source.variable)) {
4636
+ continue;
4637
+ }
4638
+ }
4413
4639
  // cognium-dev#752: GraphQL resolver args are seeded by name only; scope
4414
4640
  // them to the resolver (or factory) they came from so a same-named
4415
4641
  // local in another recorded function does not inherit the seed.
@@ -4782,6 +5008,14 @@ strictUnrelatedSourceGuard = false, javaDerivedVars) {
4782
5008
  }
4783
5009
  return null;
4784
5010
  };
5011
+ // cognium-dev#1198 — stamped heap-field sources (`next.value`) must win over
5012
+ // RHS-derived anchor resolution (#515), which would otherwise credit `name`.
5013
+ if (language === 'java' && taintedVar?.includes('.')) {
5014
+ const byQualified = sources.filter((s) => s.variable === taintedVar);
5015
+ const pickQualified = closestPreceding(byQualified);
5016
+ if (pickQualified)
5017
+ return pickQualified;
5018
+ }
4785
5019
  // cognium-dev#515 — derived locals must credit the RHS read, not an earlier
4786
5020
  // decoy source in the same method (alias entries can still carry a stale anchor).
4787
5021
  if (taintedVar &&
@@ -4856,4 +5090,46 @@ strictUnrelatedSourceGuard = false, javaDerivedVars) {
4856
5090
  return undefined;
4857
5091
  return sources[0];
4858
5092
  }
5093
+ /**
5094
+ * cognium-dev #1156: true when every call to the sink's method on the sink line
5095
+ * sits inside the argument list of a call to the source's method on that line,
5096
+ * as in `parser.parse(fs.readFileSync(abs))`. The inner call runs first and the
5097
+ * outer call consumes its result, so the source's value cannot reach the sink.
5098
+ * When the source text or a sink call outside every source call can't be
5099
+ * found, it returns false and the flow is kept.
5100
+ */
5101
+ function sinkNestedInSourceCall(source, sink) {
5102
+ if (source.line !== sink.line || !sink.method || !sink.code)
5103
+ return false;
5104
+ const srcMethod = /([A-Za-z_$][\w$]*)\s*\(\)\s+in\b/.exec(source.location ?? '')?.[1];
5105
+ if (!srcMethod || srcMethod === sink.method)
5106
+ return false;
5107
+ // Blank string literals so parentheses inside them don't count.
5108
+ const text = sink.code.replace(/(["'`])(?:\\.|(?!\1)[^\\])*\1/g, m => m[0] + ' '.repeat(m.length - 2) + m[0]);
5109
+ const callStarts = (name) => {
5110
+ const re = new RegExp(`(?<![\\w$])${name.replace(/\$/g, '\\$')}\\s*\\(`, 'g');
5111
+ const out = [];
5112
+ for (let m = re.exec(text); m; m = re.exec(text))
5113
+ out.push(m.index + m[0].length - 1);
5114
+ return out;
5115
+ };
5116
+ const ranges = [];
5117
+ for (const open of callStarts(srcMethod)) {
5118
+ let depth = 0;
5119
+ for (let i = open; i < text.length; i++) {
5120
+ if (text[i] === '(')
5121
+ depth++;
5122
+ else if (text[i] === ')' && --depth === 0) {
5123
+ ranges.push([open, i]);
5124
+ break;
5125
+ }
5126
+ }
5127
+ }
5128
+ if (ranges.length === 0)
5129
+ return false;
5130
+ const sinks = callStarts(sink.method);
5131
+ if (sinks.length === 0)
5132
+ return false;
5133
+ return sinks.every(pos => ranges.some(([a, b]) => pos > a && pos < b));
5134
+ }
4859
5135
  //# sourceMappingURL=taint-propagation-pass.js.map