circle-ir 4.20.0 → 4.21.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.
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 +21 -19
  26. package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
  27. package/dist/analysis/passes/language-sources-pass.js +703 -25
  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 +5149 -2477
  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
@@ -57,6 +57,8 @@ export class ConstantPropagator {
57
57
  additionalTaintPatterns = [];
58
58
  // Track list elements by index for precise list taint tracking
59
59
  listElements = new Map();
60
+ /** Lists that received taint via addAll (SecuriBench Collections8 get(0) recall). */
61
+ listAddAllFromTainted = new Set();
60
62
  // Track loop variables (should not be overwritten with constant values)
61
63
  loopVariables = new Set();
62
64
  // Track tainted array elements: array name → set of tainted indices (or '*' for whole array)
@@ -112,6 +114,13 @@ export class ConstantPropagator {
112
114
  // would never hit between the explicit recursion at line 2245 and the
113
115
  // wrapper's iterative child descent.
114
116
  isTaintedExpressionCache = null;
117
+ /**
118
+ * cognium-dev#814 S2: per-iteration overlay of callee parameter names that
119
+ * received tainted actuals at same-file call sites. Filled by a fixpoint
120
+ * loop so callee bodies are analyzed with correct param taint regardless of
121
+ * method declaration order.
122
+ */
123
+ javaCalleeParameterOverlay;
115
124
  /**
116
125
  * Analyze source code and build constant propagation state.
117
126
  */
@@ -136,6 +145,7 @@ export class ConstantPropagator {
136
145
  this.methodReturnsParameter.clear();
137
146
  this.methodReturnsSafeValue.clear();
138
147
  this.listElements.clear();
148
+ this.listAddAllFromTainted.clear();
139
149
  this.loopVariables.clear();
140
150
  this.taintedArrayElements.clear();
141
151
  this.sanitizedVars.clear();
@@ -158,6 +168,7 @@ export class ConstantPropagator {
158
168
  this.constructorParamPositions.clear();
159
169
  this.safePatternFieldsCache = null;
160
170
  this.isTaintedExpressionCache = null;
171
+ this.javaCalleeParameterOverlay = undefined;
161
172
  // Pre-pass: single tree walk that collects class fields (previously
162
173
  // `collectClassFields`) AND method nodes (previously `findAllMethods`,
163
174
  // called from `analyzeMethodReturns`). Both prior walks did a full
@@ -180,10 +191,43 @@ export class ConstantPropagator {
180
191
  // recursion hazards of dispatching the full `handleAssignment` path
181
192
  // on Python ASTs.
182
193
  this.seedPythonModuleConstants(tree.rootNode);
183
- // First pass: collect symbols, taint, and unreachable lines
184
- this.visit(tree.rootNode);
185
- // Second pass: refine taint for variables derived from constants
186
- this.refineTaintFromConstants();
194
+ const javaMethodParamIndex = this.buildJavaMethodParameterIndex(prePassMethods);
195
+ const javaCalleeOverlay = new Map();
196
+ if (omitJavaUnscopedTaintAliases && javaMethodParamIndex.arityKeyToParams.size > 0) {
197
+ // Fixpoint: same-file calls pass taint into callees; const-prop order
198
+ // follows declaration order, so seed params from call sites iteratively.
199
+ let prevSig = '';
200
+ for (let round = 0; round < 16; round++) {
201
+ this.resetStateForJavaFixpointRound();
202
+ this.javaCalleeParameterOverlay = javaCalleeOverlay;
203
+ this.visit(tree.rootNode);
204
+ this.refineTaintFromConstants();
205
+ this.javaCalleeParameterOverlay = undefined;
206
+ const discovered = this.collectJavaCalleeParameterSeedsFromCalls(tree.rootNode, javaMethodParamIndex);
207
+ let sig = '';
208
+ for (const [m, ps] of [...discovered.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {
209
+ sig += `${m}:[${[...ps].sort().join(',')}];`;
210
+ }
211
+ if (sig === prevSig) {
212
+ break;
213
+ }
214
+ prevSig = sig;
215
+ for (const [m, ps] of discovered) {
216
+ let acc = javaCalleeOverlay.get(m);
217
+ if (!acc) {
218
+ acc = new Set();
219
+ javaCalleeOverlay.set(m, acc);
220
+ }
221
+ for (const p of ps) {
222
+ acc.add(p);
223
+ }
224
+ }
225
+ }
226
+ }
227
+ else {
228
+ this.visit(tree.rootNode);
229
+ this.refineTaintFromConstants();
230
+ }
187
231
  // Build result with both scoped and unscoped names for backward compatibility
188
232
  // Unscoped names are needed for legacy code and tests
189
233
  const resultTainted = new Set(this.tainted);
@@ -258,6 +302,137 @@ export class ConstantPropagator {
258
302
  constantReturningMethods: new Set(this.methodReturnsConstant),
259
303
  };
260
304
  }
305
+ /**
306
+ * Clear per-visit const-prop state between Java fixpoint rounds. Keeps
307
+ * `classFields` from the one-time collection pass.
308
+ */
309
+ resetStateForJavaFixpointRound() {
310
+ this.symbols.clear();
311
+ this.tainted.clear();
312
+ this.unreachableLines.clear();
313
+ this.taintedCollections.clear();
314
+ this.definitionNodes.clear();
315
+ this.inConditionalBranch = false;
316
+ this.goUnknownVars.clear();
317
+ this.goScopedNames.clear();
318
+ this.listElements.clear();
319
+ this.listAddAllFromTainted.clear();
320
+ this.loopVariables.clear();
321
+ this.taintedArrayElements.clear();
322
+ this.sanitizedVars.clear();
323
+ this.sanitizedVarUncovered.clear();
324
+ this.currentMethod = null;
325
+ this.blockScopeStack = [];
326
+ this.lineBlockScopes.clear();
327
+ this.skipMethodBodyBlockScope = false;
328
+ this.conditionalTaints.clear();
329
+ this.conditionStack = [];
330
+ this.lineConditions.clear();
331
+ this.synchronizedLines.clear();
332
+ this.inSynchronizedBlock = false;
333
+ this.iteratorSources.clear();
334
+ this.taintedFromIteratorNext.clear();
335
+ this.instanceFieldTaint.clear();
336
+ this.currentClassName = null;
337
+ this.inConstructor = false;
338
+ this.constructorParamPositions.clear();
339
+ this.isTaintedExpressionCache = null;
340
+ }
341
+ /**
342
+ * Index same-file Java callables by `simpleName#argCount` with arity-only
343
+ * keys. If two overloads share the same simple name and parameter count,
344
+ * that key is marked ambiguous and callee-param seeding skips it (avoids
345
+ * wiring the wrong formal list).
346
+ */
347
+ buildJavaMethodParameterIndex(methods) {
348
+ const byKey = new Map();
349
+ for (const m of methods) {
350
+ const nameNode = m.childForFieldName('name');
351
+ const methodName = nameNode ? getNodeText(nameNode, this.source) : null;
352
+ if (!methodName)
353
+ continue;
354
+ const params = this.getMethodParameters(m);
355
+ if (params.length === 0)
356
+ continue;
357
+ const key = `${methodName}#${params.length}`;
358
+ let list = byKey.get(key);
359
+ if (!list) {
360
+ list = [];
361
+ byKey.set(key, list);
362
+ }
363
+ list.push(params);
364
+ }
365
+ const arityKeyToParams = new Map();
366
+ const ambiguousArityKeys = new Set();
367
+ for (const [key, lists] of byKey) {
368
+ if (lists.length > 1) {
369
+ const first = lists[0];
370
+ const namesMatch = lists.every((p) => p.length === first.length && p.every((name, i) => name === first[i]));
371
+ if (!namesMatch) {
372
+ ambiguousArityKeys.add(key);
373
+ continue;
374
+ }
375
+ }
376
+ arityKeyToParams.set(key, lists[0]);
377
+ }
378
+ return { arityKeyToParams, ambiguousArityKeys };
379
+ }
380
+ /**
381
+ * After a fixpoint round, find simple same-file `foo(arg)` calls where the
382
+ * callee `foo` is declared in this compilation unit and an argument is
383
+ * tainted; record those formal parameter names for the next overlay.
384
+ */
385
+ collectJavaCalleeParameterSeedsFromCalls(root, index) {
386
+ const out = new Map();
387
+ const walk = (node) => {
388
+ if (node.type === 'method_declaration' ||
389
+ node.type === 'function_declaration' ||
390
+ node.type === 'constructor_declaration') {
391
+ const nameNode = node.childForFieldName('name');
392
+ const mName = nameNode ? getNodeText(nameNode, this.source) : null;
393
+ const prev = this.currentMethod;
394
+ this.currentMethod = mName;
395
+ for (const c of node.children) {
396
+ walk(c);
397
+ }
398
+ this.currentMethod = prev;
399
+ return;
400
+ }
401
+ if (node.type === 'method_invocation') {
402
+ const calleeName = this.extractJavaCalleeSimpleName(node);
403
+ if (calleeName) {
404
+ const argsNode = node.childForFieldName('arguments');
405
+ if (argsNode) {
406
+ const args = argsNode.children.filter((c) => c.type !== '(' && c.type !== ')' && c.type !== ',');
407
+ const arityKey = `${calleeName}#${args.length}`;
408
+ if (!index.ambiguousArityKeys.has(arityKey)) {
409
+ const formalList = index.arityKeyToParams.get(arityKey);
410
+ if (formalList && formalList.length > 0) {
411
+ for (let i = 0; i < args.length && i < formalList.length; i++) {
412
+ const formal = formalList[i];
413
+ if (!formal)
414
+ continue;
415
+ if (!this.isTaintedExpression(args[i]))
416
+ continue;
417
+ let acc = out.get(calleeName);
418
+ if (!acc) {
419
+ acc = new Set();
420
+ out.set(calleeName, acc);
421
+ }
422
+ acc.add(formal);
423
+ }
424
+ }
425
+ }
426
+ }
427
+ }
428
+ }
429
+ for (const c of node.children) {
430
+ walk(c);
431
+ }
432
+ };
433
+ walk(root);
434
+ return out;
435
+ }
261
436
  /**
262
437
  * Evaluate an expression to determine its constant value.
263
438
  */
@@ -342,13 +517,8 @@ export class ConstantPropagator {
342
517
  allReturnsSafe = false; // void return or unknown - not safe
343
518
  continue;
344
519
  }
345
- // #589: `return <Encoder>.<encode>(<the only parameter>)`.
346
- const encoderArgs = valueNode.type === 'method_invocation'
347
- ? valueNode.childForFieldName('arguments')?.children.filter((c) => c.type !== '(' && c.type !== ')' && c.type !== ',')
348
- : undefined;
349
- if (!(valueNode.type === 'method_invocation' &&
350
- HTML_CONTEXT_ENCODER_METHODS.has(getNodeText(valueNode.childForFieldName('name') ?? valueNode, this.source)) &&
351
- params.length === 1 && encoderArgs?.length === 1 && getNodeText(encoderArgs[0], this.source) === params[0])) {
520
+ // #589: direct encoder return, or `String bar = escapeHtml(param); return bar;` (#589 S4).
521
+ if (!this.returnExpressionIsHtmlEncoderOnly(valueNode, body, params)) {
352
522
  allReturnsHtmlEncoder = false;
353
523
  }
354
524
  const value = tempPropagator.evaluateExpression(valueNode);
@@ -564,12 +734,9 @@ export class ConstantPropagator {
564
734
  }
565
735
  isSanitizerCall(node, methodBody) {
566
736
  if (node.type === 'method_invocation') {
567
- const nameNode = node.childForFieldName('name');
568
- if (nameNode) {
569
- const methodName = getNodeText(nameNode, this.source);
570
- if (SANITIZER_METHODS.has(methodName) && !this.localNonSanitizing.has(methodName)) {
571
- return true;
572
- }
737
+ const methodName = this.extractJavaCalleeSimpleName(node);
738
+ if (methodName && SANITIZER_METHODS.has(methodName) && !this.localNonSanitizing.has(methodName)) {
739
+ return true;
573
740
  }
574
741
  }
575
742
  if (node.type === 'identifier' && methodBody) {
@@ -580,6 +747,75 @@ export class ConstantPropagator {
580
747
  }
581
748
  return false;
582
749
  }
750
+ /** #589 S4: `return escapeHtml(param)` or `bar = escapeHtml(param); return bar;`. */
751
+ returnExpressionIsHtmlEncoderOnly(valueNode, methodBody, params) {
752
+ if (valueNode.type === 'method_invocation') {
753
+ return this.htmlEncoderCallUsesDeclaredParam(valueNode, params);
754
+ }
755
+ if (valueNode.type === 'identifier') {
756
+ const varName = getNodeText(valueNode, this.source);
757
+ return this.variableIsAssignedFromHtmlEncoderOnParam(varName, methodBody, params);
758
+ }
759
+ return false;
760
+ }
761
+ htmlEncoderCallUsesDeclaredParam(node, params) {
762
+ if (node.type !== 'method_invocation')
763
+ return false;
764
+ const methodName = this.extractJavaCalleeSimpleName(node);
765
+ if (!methodName || !HTML_CONTEXT_ENCODER_METHODS.has(methodName))
766
+ return false;
767
+ const argsNode = node.childForFieldName('arguments');
768
+ if (!argsNode)
769
+ return false;
770
+ const args = argsNode.children.filter((c) => c.type !== '(' && c.type !== ')' && c.type !== ',');
771
+ if (args.length !== 1)
772
+ return false;
773
+ const argText = getNodeText(args[0], this.source);
774
+ return params.includes(argText);
775
+ }
776
+ variableIsAssignedFromHtmlEncoderOnParam(varName, methodBody, params) {
777
+ const findAssignments = (n) => {
778
+ if (n.type === 'local_variable_declaration') {
779
+ const declarator = n.children.find(c => c.type === 'variable_declarator');
780
+ if (declarator) {
781
+ const nameNode = declarator.childForFieldName('name');
782
+ const valueNode = declarator.childForFieldName('value');
783
+ if (nameNode && valueNode) {
784
+ const name = getNodeText(nameNode, this.source);
785
+ if (name === varName) {
786
+ return this.htmlEncoderCallUsesDeclaredParam(valueNode, params);
787
+ }
788
+ }
789
+ }
790
+ }
791
+ if (n.type === 'assignment_expression') {
792
+ const leftNode = n.childForFieldName('left');
793
+ const rightNode = n.childForFieldName('right');
794
+ if (leftNode && rightNode) {
795
+ const name = getNodeText(leftNode, this.source);
796
+ if (name === varName) {
797
+ return this.htmlEncoderCallUsesDeclaredParam(rightNode, params);
798
+ }
799
+ }
800
+ }
801
+ for (const child of n.children) {
802
+ if (findAssignments(child))
803
+ return true;
804
+ }
805
+ return false;
806
+ };
807
+ return findAssignments(methodBody);
808
+ }
809
+ noteHtmlEncoderHelperAssignment(scopedName, valueNode) {
810
+ if (valueNode.type !== 'method_invocation')
811
+ return false;
812
+ const callee = this.extractJavaCalleeSimpleName(valueNode);
813
+ if (!callee || !this.methodReturnsHtmlEncoderOnly.has(callee))
814
+ return false;
815
+ this.sanitizedVars.add(scopedName);
816
+ this.sanitizedVarUncovered.set(scopedName, HTML_CONTEXT_ENCODER_UNCOVERED_SINKS);
817
+ return true;
818
+ }
583
819
  variableIsAssignedFromSanitizer(varName, methodBody) {
584
820
  const findAssignments = (n) => {
585
821
  if (n.type === 'local_variable_declaration') {
@@ -1104,6 +1340,15 @@ export class ConstantPropagator {
1104
1340
  this.tainted.add(paramName); // Also add unscoped for flexibility
1105
1341
  }
1106
1342
  }
1343
+ // #814 S2: callee formals that received tainted actuals at a same-file
1344
+ // call site (fixpoint overlay; arity-resolved; same-name+arity overload
1345
+ // conflicts skip seeding).
1346
+ const overlay = this.javaCalleeParameterOverlay?.get(methodName);
1347
+ if (overlay?.has(paramName)) {
1348
+ const scopedName = this.getScopedName(paramName);
1349
+ this.tainted.add(scopedName);
1350
+ this.tainted.add(paramName);
1351
+ }
1107
1352
  }
1108
1353
  paramPosition++;
1109
1354
  }
@@ -1448,6 +1693,9 @@ export class ConstantPropagator {
1448
1693
  this.sanitizedVars.add(scopedName);
1449
1694
  this.recordSanitizerScope(scopedName, valueNode);
1450
1695
  }
1696
+ else if (this.noteHtmlEncoderHelperAssignment(scopedName, valueNode)) {
1697
+ /* encoder-only helper return: uncovered trust_boundary */
1698
+ }
1451
1699
  else {
1452
1700
  this.sanitizedVars.delete(scopedName);
1453
1701
  this.sanitizedVarUncovered.delete(scopedName);
@@ -1709,6 +1957,9 @@ export class ConstantPropagator {
1709
1957
  this.sanitizedVars.add(scopedName);
1710
1958
  this.recordSanitizerScope(scopedName, right);
1711
1959
  }
1960
+ else if (this.noteHtmlEncoderHelperAssignment(scopedName, right)) {
1961
+ /* encoder-only helper return */
1962
+ }
1712
1963
  else {
1713
1964
  this.sanitizedVars.delete(scopedName);
1714
1965
  this.sanitizedVarUncovered.delete(scopedName);
@@ -1730,6 +1981,39 @@ export class ConstantPropagator {
1730
1981
  const { arrayName, indexKey } = this.arrayElementStorageKey(chain);
1731
1982
  const isTainted = this.isTaintedExpression(right);
1732
1983
  this.setArrayElementTaint(arrayName, indexKey, isTainted);
1984
+ this.propagateJavaRowArrayInitializerElementTaint(chain, right);
1985
+ }
1986
+ /**
1987
+ * cognium-dev#476 / SecuriBench Arrays10 — `matrix[0] = new String[] { tainted, "ok" }`
1988
+ * stores taint in row cells (`matrix@0` index `0`), not only on the row slot.
1989
+ */
1990
+ propagateJavaRowArrayInitializerElementTaint(rowChain, right) {
1991
+ if (rowChain.indices.length !== 1 || rowChain.indices[0] === '*')
1992
+ return;
1993
+ const initializer = this.findJavaArrayLiteralInitializer(right);
1994
+ if (!initializer)
1995
+ return;
1996
+ const rowArrayName = `${rowChain.base}@${rowChain.indices[0]}`;
1997
+ let position = 0;
1998
+ for (const child of initializer.children) {
1999
+ if (child.type === ',' || child.type === '{' || child.type === '}')
2000
+ continue;
2001
+ if (this.isTaintedExpression(child)) {
2002
+ this.setArrayElementTaint(rowArrayName, String(position), true);
2003
+ }
2004
+ position++;
2005
+ }
2006
+ }
2007
+ findJavaArrayLiteralInitializer(node) {
2008
+ if (node.type === 'array_initializer')
2009
+ return node;
2010
+ if (node.type === 'array_creation_expression') {
2011
+ for (const child of node.children) {
2012
+ if (child.type === 'array_initializer')
2013
+ return child;
2014
+ }
2015
+ }
2016
+ return null;
1733
2017
  }
1734
2018
  /** cognium-dev#476: `grid[0][0]` and deeper element paths. */
1735
2019
  parseArrayAccessChain(node) {
@@ -2274,18 +2558,36 @@ export class ConstantPropagator {
2274
2558
  return (SANITIZER_METHODS.has(methodName) && !this.localNonSanitizing.has(methodName))
2275
2559
  || this.methodReturnsSanitized.has(methodName);
2276
2560
  }
2561
+ /**
2562
+ * Trailing simple name for a Java `method_invocation` (`sink`, `this.sink`, …).
2563
+ */
2564
+ extractJavaCalleeSimpleName(node) {
2565
+ if (node.type !== 'method_invocation')
2566
+ return null;
2567
+ const nameNode = node.childForFieldName('name');
2568
+ if (!nameNode)
2569
+ return null;
2570
+ if (nameNode.type === 'identifier') {
2571
+ return getNodeText(nameNode, this.source);
2572
+ }
2573
+ if (nameNode.type === 'field_access') {
2574
+ const field = nameNode.childForFieldName('name') ?? nameNode.childForFieldName('field');
2575
+ return field ? getNodeText(field, this.source) : null;
2576
+ }
2577
+ return null;
2578
+ }
2277
2579
  /**
2278
2580
  * Extract the trailing method/function name from any call node shape:
2279
- * Java `method_invocation` — name field
2581
+ * Java `method_invocation` — name field (identifier or field_access)
2280
2582
  * Go/JS `call_expression` — function field (identifier or selector/member)
2281
2583
  * Python `call` — function field (identifier or attribute)
2282
2584
  */
2283
2585
  extractCallName(node) {
2284
- let fnNode = null;
2285
2586
  if (node.type === 'method_invocation') {
2286
- fnNode = node.childForFieldName('name');
2587
+ return this.extractJavaCalleeSimpleName(node);
2287
2588
  }
2288
- else if (node.type === 'call_expression' || node.type === 'call') {
2589
+ let fnNode = null;
2590
+ if (node.type === 'call_expression' || node.type === 'call') {
2289
2591
  fnNode = node.childForFieldName('function');
2290
2592
  }
2291
2593
  if (!fnNode)
@@ -2312,11 +2614,10 @@ export class ConstantPropagator {
2312
2614
  if (node.type !== 'method_invocation') {
2313
2615
  return false;
2314
2616
  }
2315
- const nameNode = node.childForFieldName('name');
2316
- if (!nameNode) {
2617
+ const methodName = this.extractJavaCalleeSimpleName(node);
2618
+ if (!methodName) {
2317
2619
  return false;
2318
2620
  }
2319
- const methodName = getNodeText(nameNode, this.source);
2320
2621
  return ANTI_SANITIZER_METHODS.has(methodName);
2321
2622
  }
2322
2623
  /**
@@ -2391,33 +2692,52 @@ export class ConstantPropagator {
2391
2692
  this.iteratorSources.set(varName, collectionName);
2392
2693
  }
2393
2694
  }
2695
+ /** Instance field list/collection names: `arguments` ↔ `this.arguments` (cognium-dev#1199). */
2696
+ javaCollectionLookupNames(collectionName) {
2697
+ const names = [collectionName];
2698
+ if (collectionName.startsWith('this.')) {
2699
+ const field = collectionName.slice(5);
2700
+ if (this.classFields.has(field))
2701
+ names.push(field);
2702
+ }
2703
+ else if (this.classFields.has(collectionName)) {
2704
+ names.push(`this.${collectionName}`);
2705
+ }
2706
+ return names;
2707
+ }
2708
+ markJavaCollectionTainted(collectionName) {
2709
+ for (const name of this.javaCollectionLookupNames(collectionName)) {
2710
+ const scopedCollection = this.currentMethod ? `${this.currentMethod}:${name}` : name;
2711
+ this.tainted.add(name);
2712
+ this.tainted.add(scopedCollection);
2713
+ }
2714
+ }
2394
2715
  /**
2395
2716
  * Check if a collection is tainted (has any tainted elements).
2396
2717
  */
2397
2718
  isCollectionTainted(collectionName) {
2398
- // Check if the collection has tainted elements via list tracking
2399
- const listElems = this.listElements.get(collectionName);
2400
- if (listElems) {
2401
- for (const elem of listElems) {
2402
- if (elem === '__TAINTED__')
2403
- return true;
2404
- if (elem !== null) {
2405
- const scopedElem = this.currentMethod ? `${this.currentMethod}:${elem}` : elem;
2406
- if (this.tainted.has(elem) || this.tainted.has(scopedElem)) {
2719
+ for (const lookup of this.javaCollectionLookupNames(collectionName)) {
2720
+ const listElems = this.listElements.get(lookup);
2721
+ if (listElems) {
2722
+ for (const elem of listElems) {
2723
+ if (elem === '__TAINTED__')
2407
2724
  return true;
2725
+ if (elem !== null) {
2726
+ const scopedElem = this.currentMethod ? `${this.currentMethod}:${elem}` : elem;
2727
+ if (this.tainted.has(elem) || this.tainted.has(scopedElem)) {
2728
+ return true;
2729
+ }
2408
2730
  }
2409
2731
  }
2410
2732
  }
2411
- }
2412
- // Check if the collection has tainted keys (for maps)
2413
- const taintedKeys = this.taintedCollections.get(collectionName);
2414
- if (taintedKeys && taintedKeys.size > 0) {
2415
- return true;
2416
- }
2417
- // Check if the collection variable itself is tainted
2418
- const scopedCollection = this.currentMethod ? `${this.currentMethod}:${collectionName}` : collectionName;
2419
- if (this.tainted.has(collectionName) || this.tainted.has(scopedCollection)) {
2420
- return true;
2733
+ const taintedKeys = this.taintedCollections.get(lookup);
2734
+ if (taintedKeys && taintedKeys.size > 0) {
2735
+ return true;
2736
+ }
2737
+ const scopedCollection = this.currentMethod ? `${this.currentMethod}:${lookup}` : lookup;
2738
+ if (this.tainted.has(lookup) || this.tainted.has(scopedCollection)) {
2739
+ return true;
2740
+ }
2421
2741
  }
2422
2742
  return false;
2423
2743
  }
@@ -2603,8 +2923,11 @@ export class ConstantPropagator {
2603
2923
  if (index >= 0 && index < listElems.length) {
2604
2924
  const elem = listElems[index];
2605
2925
  if (elem === null) {
2606
- // Index points to a literal value (like "safe" or "moresafe")
2607
- // which was added directly, not via a variable - this is clean
2926
+ // Literal slot: stay clean unless addAll merged taint into this list
2927
+ // (Collections8: add("abc") then addAll(tainted) then get(0) → sink).
2928
+ if (hasAnyTainted && this.listAddAllFromTainted.has(collectionName)) {
2929
+ return true;
2930
+ }
2608
2931
  return false;
2609
2932
  }
2610
2933
  if (elem === '__TAINTED__') {
@@ -2729,6 +3052,20 @@ export class ConstantPropagator {
2729
3052
  }
2730
3053
  }
2731
3054
  }
3055
+ // JSON.parse — propagate taint from input only (#1149 IL-22).
3056
+ if (methodName === 'parse') {
3057
+ const callee = node.childForFieldName('function');
3058
+ const calleeText = callee ? getNodeText(callee, this.source) : '';
3059
+ if (/\bJSON\.parse\b/.test(calleeText)) {
3060
+ const argsNode = node.childForFieldName('arguments');
3061
+ if (argsNode) {
3062
+ const args = argsNode.children.filter((c) => c.type !== '(' && c.type !== ')' && c.type !== ',');
3063
+ if (args.length > 0 && this.isTaintedExpression(args[0])) {
3064
+ return true;
3065
+ }
3066
+ }
3067
+ }
3068
+ }
2732
3069
  }
2733
3070
  }
2734
3071
  if (node.type === 'array_access' || node.type === 'subscript_expression') {
@@ -2949,10 +3286,8 @@ export class ConstantPropagator {
2949
3286
  else {
2950
3287
  list.push(null);
2951
3288
  }
2952
- // Also mark the collection variable itself as tainted if it contains tainted elements
2953
3289
  if (isTainted) {
2954
- const scopedCollection = this.currentMethod ? `${this.currentMethod}:${collectionName}` : collectionName;
2955
- this.tainted.add(scopedCollection);
3290
+ this.markJavaCollectionTainted(collectionName);
2956
3291
  }
2957
3292
  }
2958
3293
  }
@@ -2963,16 +3298,32 @@ export class ConstantPropagator {
2963
3298
  const sourceArg = args[0];
2964
3299
  if (sourceArg.type === 'identifier') {
2965
3300
  const sourceName = getNodeText(sourceArg, this.source);
2966
- // Check if the source collection is tainted
2967
- if (this.isCollectionTainted(sourceName)) {
3301
+ const sourceList = this.listElements.get(sourceName);
3302
+ if (sourceList && sourceList.length > 0) {
3303
+ if (!this.listElements.has(collectionName)) {
3304
+ this.listElements.set(collectionName, []);
3305
+ }
3306
+ const targetList = this.listElements.get(collectionName);
3307
+ targetList.push(...sourceList);
3308
+ if (sourceList.some(e => {
3309
+ if (e === null)
3310
+ return false;
3311
+ if (e === '__TAINTED__')
3312
+ return true;
3313
+ const scopedE = this.currentMethod ? `${this.currentMethod}:${e}` : e;
3314
+ return this.tainted.has(e) || this.tainted.has(scopedE);
3315
+ })) {
3316
+ this.markJavaCollectionTainted(collectionName);
3317
+ this.listAddAllFromTainted.add(collectionName);
3318
+ }
3319
+ }
3320
+ else if (this.isCollectionTainted(sourceName)) {
2968
3321
  if (!this.listElements.has(collectionName)) {
2969
3322
  this.listElements.set(collectionName, []);
2970
3323
  }
2971
- // Add a tainted marker to indicate the collection now has tainted elements
2972
3324
  this.listElements.get(collectionName).push('__TAINTED__');
2973
- // Also mark the target collection as tainted
2974
- const scopedCollection = this.currentMethod ? `${this.currentMethod}:${collectionName}` : collectionName;
2975
- this.tainted.add(scopedCollection);
3325
+ this.markJavaCollectionTainted(collectionName);
3326
+ this.listAddAllFromTainted.add(collectionName);
2976
3327
  }
2977
3328
  }
2978
3329
  else if (this.isTaintedExpression(sourceArg)) {
@@ -2980,8 +3331,8 @@ export class ConstantPropagator {
2980
3331
  this.listElements.set(collectionName, []);
2981
3332
  }
2982
3333
  this.listElements.get(collectionName).push('__TAINTED__');
2983
- const scopedCollection = this.currentMethod ? `${this.currentMethod}:${collectionName}` : collectionName;
2984
- this.tainted.add(scopedCollection);
3334
+ this.markJavaCollectionTainted(collectionName);
3335
+ this.listAddAllFromTainted.add(collectionName);
2985
3336
  }
2986
3337
  }
2987
3338
  }