circle-ir 4.19.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.
- package/dist/analysis/advisories.d.ts +21 -3
- package/dist/analysis/advisories.d.ts.map +1 -1
- package/dist/analysis/advisories.js +26 -8
- package/dist/analysis/advisories.js.map +1 -1
- package/dist/analysis/arg-executing-programs.d.ts +16 -0
- package/dist/analysis/arg-executing-programs.d.ts.map +1 -0
- package/dist/analysis/arg-executing-programs.js +24 -0
- package/dist/analysis/arg-executing-programs.js.map +1 -0
- package/dist/analysis/config-loader.d.ts.map +1 -1
- package/dist/analysis/config-loader.js +27 -3
- package/dist/analysis/config-loader.js.map +1 -1
- package/dist/analysis/constant-caller-gate.d.ts +3 -1
- package/dist/analysis/constant-caller-gate.d.ts.map +1 -1
- package/dist/analysis/constant-caller-gate.js +108 -1
- package/dist/analysis/constant-caller-gate.js.map +1 -1
- package/dist/analysis/constant-propagation/index.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/index.js +1 -1
- package/dist/analysis/constant-propagation/index.js.map +1 -1
- package/dist/analysis/constant-propagation/patterns.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/patterns.js +8 -0
- package/dist/analysis/constant-propagation/patterns.js.map +1 -1
- package/dist/analysis/constant-propagation/propagator.d.ts +47 -2
- package/dist/analysis/constant-propagation/propagator.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/propagator.js +422 -57
- package/dist/analysis/constant-propagation/propagator.js.map +1 -1
- package/dist/analysis/constant-propagation/types.d.ts +2 -0
- package/dist/analysis/constant-propagation/types.d.ts.map +1 -1
- package/dist/analysis/dependency-versions.d.ts +33 -0
- package/dist/analysis/dependency-versions.d.ts.map +1 -1
- package/dist/analysis/dependency-versions.js +70 -0
- package/dist/analysis/dependency-versions.js.map +1 -1
- package/dist/analysis/findings.d.ts.map +1 -1
- package/dist/analysis/findings.js +7 -5
- package/dist/analysis/findings.js.map +1 -1
- package/dist/analysis/interprocedural.d.ts +16 -0
- package/dist/analysis/interprocedural.d.ts.map +1 -1
- package/dist/analysis/interprocedural.js +545 -197
- package/dist/analysis/interprocedural.js.map +1 -1
- package/dist/analysis/passes/constant-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/constant-propagation-pass.js +1 -0
- package/dist/analysis/passes/constant-propagation-pass.js.map +1 -1
- package/dist/analysis/passes/cross-file-pass.d.ts.map +1 -1
- package/dist/analysis/passes/cross-file-pass.js +61 -0
- package/dist/analysis/passes/cross-file-pass.js.map +1 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.d.ts.map +1 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.js +60 -3
- package/dist/analysis/passes/csharp-sanitizer-credit.js.map +1 -1
- package/dist/analysis/passes/csrf-samesite-none-session-pass.d.ts +58 -0
- package/dist/analysis/passes/csrf-samesite-none-session-pass.d.ts.map +1 -0
- package/dist/analysis/passes/csrf-samesite-none-session-pass.js +159 -0
- package/dist/analysis/passes/csrf-samesite-none-session-pass.js.map +1 -0
- package/dist/analysis/passes/deserialization-safety-gate-pass.d.ts +15 -0
- package/dist/analysis/passes/deserialization-safety-gate-pass.d.ts.map +1 -1
- package/dist/analysis/passes/deserialization-safety-gate-pass.js +60 -1
- package/dist/analysis/passes/deserialization-safety-gate-pass.js.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.d.ts +23 -1
- package/dist/analysis/passes/interprocedural-pass.d.ts.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.js +220 -7
- package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
- package/dist/analysis/passes/language-sources-pass.d.ts +0 -18
- package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
- package/dist/analysis/passes/language-sources-pass.js +549 -22
- package/dist/analysis/passes/language-sources-pass.js.map +1 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.d.ts.map +1 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.js +71 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.js.map +1 -1
- package/dist/analysis/passes/prompt-injection-safety-gate-pass.js +1 -1
- package/dist/analysis/passes/prompt-injection-safety-gate-pass.js.map +1 -1
- package/dist/analysis/passes/resource-leak-pass.d.ts.map +1 -1
- package/dist/analysis/passes/resource-leak-pass.js +15 -3
- package/dist/analysis/passes/resource-leak-pass.js.map +1 -1
- package/dist/analysis/passes/scan-secrets-pass.js +2 -2
- package/dist/analysis/passes/scan-secrets-pass.js.map +1 -1
- package/dist/analysis/passes/sensitive-data-in-log-pass.d.ts +66 -0
- package/dist/analysis/passes/sensitive-data-in-log-pass.d.ts.map +1 -0
- package/dist/analysis/passes/sensitive-data-in-log-pass.js +462 -0
- package/dist/analysis/passes/sensitive-data-in-log-pass.js.map +1 -0
- package/dist/analysis/passes/sink-filter-pass.d.ts +7 -1
- package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.js +564 -22
- package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.d.ts +7 -3
- package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.js +464 -27
- package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
- package/dist/analysis/passes/xml-entity-expansion-pass.d.ts.map +1 -1
- package/dist/analysis/passes/xml-entity-expansion-pass.js +50 -6
- package/dist/analysis/passes/xml-entity-expansion-pass.js.map +1 -1
- package/dist/analysis/pep440-version.d.ts +40 -0
- package/dist/analysis/pep440-version.d.ts.map +1 -0
- package/dist/analysis/pep440-version.js +149 -0
- package/dist/analysis/pep440-version.js.map +1 -0
- package/dist/analysis/project-callee-escape-gate.js +1 -1
- package/dist/analysis/project-callee-escape-gate.js.map +1 -1
- package/dist/analysis/rules.d.ts.map +1 -1
- package/dist/analysis/rules.js +15 -0
- package/dist/analysis/rules.js.map +1 -1
- package/dist/analysis/sbom.d.ts +92 -4
- package/dist/analysis/sbom.d.ts.map +1 -1
- package/dist/analysis/sbom.js +390 -33
- package/dist/analysis/sbom.js.map +1 -1
- package/dist/analysis/taint-matcher.d.ts.map +1 -1
- package/dist/analysis/taint-matcher.js +124 -19
- package/dist/analysis/taint-matcher.js.map +1 -1
- package/dist/analysis/taint-propagation.d.ts +1 -0
- package/dist/analysis/taint-propagation.d.ts.map +1 -1
- package/dist/analysis/taint-propagation.js +32 -0
- package/dist/analysis/taint-propagation.js.map +1 -1
- package/dist/analysis/test-to-production-taint-gate.d.ts +13 -0
- package/dist/analysis/test-to-production-taint-gate.d.ts.map +1 -0
- package/dist/analysis/test-to-production-taint-gate.js +30 -0
- package/dist/analysis/test-to-production-taint-gate.js.map +1 -0
- package/dist/analyzer.d.ts +21 -3
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +83 -3
- package/dist/analyzer.js.map +1 -1
- package/dist/browser/circle-ir.js +8118 -2526
- package/dist/core/circle-ir-core.cjs +3098 -2280
- package/dist/core/circle-ir-core.js +3036 -2214
- package/dist/core/extractors/calls.d.ts +10 -1
- package/dist/core/extractors/calls.d.ts.map +1 -1
- package/dist/core/extractors/calls.js +148 -6
- package/dist/core/extractors/calls.js.map +1 -1
- package/dist/core/extractors/cfg.d.ts.map +1 -1
- package/dist/core/extractors/cfg.js +12 -0
- package/dist/core/extractors/cfg.js.map +1 -1
- package/dist/core/extractors/dfg.d.ts.map +1 -1
- package/dist/core/extractors/dfg.js +151 -18
- package/dist/core/extractors/dfg.js.map +1 -1
- package/dist/core/extractors/ts-declaration-detail.d.ts +8 -0
- package/dist/core/extractors/ts-declaration-detail.d.ts.map +1 -1
- package/dist/core/extractors/ts-declaration-detail.js +22 -0
- package/dist/core/extractors/ts-declaration-detail.js.map +1 -1
- package/dist/core/extractors/types.d.ts +5 -0
- package/dist/core/extractors/types.d.ts.map +1 -1
- package/dist/core/extractors/types.js +149 -4
- package/dist/core/extractors/types.js.map +1 -1
- package/dist/core/parser.d.ts.map +1 -1
- package/dist/core/parser.js +3 -1
- package/dist/core/parser.js.map +1 -1
- package/dist/core/ts-grammar-workarounds.d.ts +18 -0
- package/dist/core/ts-grammar-workarounds.d.ts.map +1 -0
- package/dist/core/ts-grammar-workarounds.js +40 -0
- package/dist/core/ts-grammar-workarounds.js.map +1 -0
- package/dist/facts/arrow.d.ts +106 -0
- package/dist/facts/arrow.d.ts.map +1 -0
- package/dist/facts/arrow.js +196 -0
- package/dist/facts/arrow.js.map +1 -0
- package/dist/facts/facts2.d.ts +68 -0
- package/dist/facts/facts2.d.ts.map +1 -0
- package/dist/facts/facts2.js +379 -0
- package/dist/facts/facts2.js.map +1 -0
- package/dist/facts/index.d.ts +22 -0
- package/dist/facts/index.d.ts.map +1 -0
- package/dist/facts/index.js +15 -0
- package/dist/facts/index.js.map +1 -0
- package/dist/facts/java-facts.d.ts +56 -0
- package/dist/facts/java-facts.d.ts.map +1 -0
- package/dist/facts/java-facts.js +250 -0
- package/dist/facts/java-facts.js.map +1 -0
- package/dist/facts/order.d.ts +39 -0
- package/dist/facts/order.d.ts.map +1 -0
- package/dist/facts/order.js +120 -0
- package/dist/facts/order.js.map +1 -0
- package/dist/facts/schema.d.ts +60 -0
- package/dist/facts/schema.d.ts.map +1 -0
- package/dist/facts/schema.js +126 -0
- package/dist/facts/schema.js.map +1 -0
- package/dist/facts/schema2.d.ts +47 -0
- package/dist/facts/schema2.d.ts.map +1 -0
- package/dist/facts/schema2.js +194 -0
- package/dist/facts/schema2.js.map +1 -0
- package/dist/facts/t6.d.ts +84 -0
- package/dist/facts/t6.d.ts.map +1 -0
- package/dist/facts/t6.js +226 -0
- package/dist/facts/t6.js.map +1 -0
- package/dist/facts/table.d.ts +80 -0
- package/dist/facts/table.d.ts.map +1 -0
- package/dist/facts/table.js +548 -0
- package/dist/facts/table.js.map +1 -0
- package/dist/graph-facts/dead-code.d.ts +2 -0
- package/dist/graph-facts/dead-code.d.ts.map +1 -1
- package/dist/graph-facts/dead-code.js +4 -3
- package/dist/graph-facts/dead-code.js.map +1 -1
- package/dist/graph-facts/index.d.ts +1 -1
- package/dist/graph-facts/index.d.ts.map +1 -1
- package/dist/graph-facts/index.js +1 -1
- package/dist/graph-facts/index.js.map +1 -1
- package/dist/graph-facts/reach.d.ts +53 -8
- package/dist/graph-facts/reach.d.ts.map +1 -1
- package/dist/graph-facts/reach.js +172 -16
- package/dist/graph-facts/reach.js.map +1 -1
- package/dist/graph-facts/removal-reach.d.ts +2 -0
- package/dist/graph-facts/removal-reach.d.ts.map +1 -1
- package/dist/graph-facts/removal-reach.js +1 -1
- package/dist/graph-facts/removal-reach.js.map +1 -1
- package/dist/index.d.ts +15 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +19 -4
- package/dist/index.js.map +1 -1
- package/dist/navigation/index.d.ts +1 -0
- package/dist/navigation/index.d.ts.map +1 -1
- package/dist/navigation/index.js +1 -0
- package/dist/navigation/index.js.map +1 -1
- package/dist/navigation/java-graph.d.ts +47 -2
- package/dist/navigation/java-graph.d.ts.map +1 -1
- package/dist/navigation/java-graph.js +395 -18
- package/dist/navigation/java-graph.js.map +1 -1
- package/dist/navigation/java-registrations.d.ts +93 -0
- package/dist/navigation/java-registrations.d.ts.map +1 -0
- package/dist/navigation/java-registrations.js +254 -0
- package/dist/navigation/java-registrations.js.map +1 -0
- package/dist/navigation/navigation-index.d.ts +74 -3
- package/dist/navigation/navigation-index.d.ts.map +1 -1
- package/dist/navigation/navigation-index.js +206 -11
- package/dist/navigation/navigation-index.js.map +1 -1
- package/dist/navigation/ts-call-edges.d.ts +15 -0
- package/dist/navigation/ts-call-edges.d.ts.map +1 -1
- package/dist/navigation/ts-call-edges.js.map +1 -1
- package/dist/navigation/ts-entry-tables.d.ts +1 -1
- package/dist/navigation/ts-entry-tables.d.ts.map +1 -1
- package/dist/navigation/ts-entry-tables.js.map +1 -1
- package/dist/navigation/xml-scan.d.ts +40 -0
- package/dist/navigation/xml-scan.d.ts.map +1 -0
- package/dist/navigation/xml-scan.js +269 -0
- package/dist/navigation/xml-scan.js.map +1 -0
- package/dist/resolution/cross-file.d.ts +44 -0
- package/dist/resolution/cross-file.d.ts.map +1 -1
- package/dist/resolution/cross-file.js +259 -13
- package/dist/resolution/cross-file.js.map +1 -1
- package/dist/stable-ids/files.d.ts +22 -0
- package/dist/stable-ids/files.d.ts.map +1 -0
- package/dist/stable-ids/files.js +28 -0
- package/dist/stable-ids/files.js.map +1 -0
- package/dist/stable-ids/hash.d.ts +16 -4
- package/dist/stable-ids/hash.d.ts.map +1 -1
- package/dist/stable-ids/hash.js +266 -80
- package/dist/stable-ids/hash.js.map +1 -1
- package/dist/stable-ids/index.d.ts +6 -5
- package/dist/stable-ids/index.d.ts.map +1 -1
- package/dist/stable-ids/index.js +19 -6
- package/dist/stable-ids/index.js.map +1 -1
- package/dist/stable-ids/nodes.d.ts +61 -7
- package/dist/stable-ids/nodes.d.ts.map +1 -1
- package/dist/stable-ids/nodes.js +134 -21
- package/dist/stable-ids/nodes.js.map +1 -1
- package/dist/stable-ids/ts-parse-errors.d.ts +5 -1
- package/dist/stable-ids/ts-parse-errors.d.ts.map +1 -1
- package/dist/stable-ids/ts-parse-errors.js +55 -3
- package/dist/stable-ids/ts-parse-errors.js.map +1 -1
- package/dist/stable-ids/typescript.d.ts +5 -0
- package/dist/stable-ids/typescript.d.ts.map +1 -1
- package/dist/stable-ids/typescript.js +41 -8
- package/dist/stable-ids/typescript.js.map +1 -1
- package/dist/types/index.d.ts +21 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/docs/SPEC.md +9 -0
- package/package.json +9 -5
- package/schemas/facts@1.json +134 -0
- package/schemas/facts@2.json +216 -0
|
@@ -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,13 +114,21 @@ 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
|
*/
|
|
118
|
-
analyze(tree, sourceCode, additionalTaintPatterns = [], sanitizerMethods = [], taintedParameters = []) {
|
|
127
|
+
analyze(tree, sourceCode, additionalTaintPatterns = [], sanitizerMethods = [], taintedParameters = [], language) {
|
|
119
128
|
this.source = sourceCode;
|
|
120
129
|
this.additionalTaintPatterns = additionalTaintPatterns;
|
|
121
130
|
this.taintedParametersList = taintedParameters;
|
|
131
|
+
const omitJavaUnscopedTaintAliases = language === 'java';
|
|
122
132
|
this.symbols.clear();
|
|
123
133
|
this.tainted.clear();
|
|
124
134
|
this.unreachableLines.clear();
|
|
@@ -135,6 +145,7 @@ export class ConstantPropagator {
|
|
|
135
145
|
this.methodReturnsParameter.clear();
|
|
136
146
|
this.methodReturnsSafeValue.clear();
|
|
137
147
|
this.listElements.clear();
|
|
148
|
+
this.listAddAllFromTainted.clear();
|
|
138
149
|
this.loopVariables.clear();
|
|
139
150
|
this.taintedArrayElements.clear();
|
|
140
151
|
this.sanitizedVars.clear();
|
|
@@ -157,6 +168,7 @@ export class ConstantPropagator {
|
|
|
157
168
|
this.constructorParamPositions.clear();
|
|
158
169
|
this.safePatternFieldsCache = null;
|
|
159
170
|
this.isTaintedExpressionCache = null;
|
|
171
|
+
this.javaCalleeParameterOverlay = undefined;
|
|
160
172
|
// Pre-pass: single tree walk that collects class fields (previously
|
|
161
173
|
// `collectClassFields`) AND method nodes (previously `findAllMethods`,
|
|
162
174
|
// called from `analyzeMethodReturns`). Both prior walks did a full
|
|
@@ -179,10 +191,43 @@ export class ConstantPropagator {
|
|
|
179
191
|
// recursion hazards of dispatching the full `handleAssignment` path
|
|
180
192
|
// on Python ASTs.
|
|
181
193
|
this.seedPythonModuleConstants(tree.rootNode);
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
+
}
|
|
186
231
|
// Build result with both scoped and unscoped names for backward compatibility
|
|
187
232
|
// Unscoped names are needed for legacy code and tests
|
|
188
233
|
const resultTainted = new Set(this.tainted);
|
|
@@ -194,10 +239,23 @@ export class ConstantPropagator {
|
|
|
194
239
|
if (/^[^:]+:b\d+:/.test(name)) {
|
|
195
240
|
continue;
|
|
196
241
|
}
|
|
242
|
+
if (omitJavaUnscopedTaintAliases) {
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
197
245
|
const unscoped = name.substring(name.indexOf(':') + 1);
|
|
198
246
|
resultTainted.add(unscoped);
|
|
199
247
|
}
|
|
200
248
|
}
|
|
249
|
+
if (omitJavaUnscopedTaintAliases) {
|
|
250
|
+
for (const name of this.tainted) {
|
|
251
|
+
if (!name.includes(':') || /^[^:]+:b\d+:/.test(name))
|
|
252
|
+
continue;
|
|
253
|
+
const local = name.substring(name.indexOf(':') + 1);
|
|
254
|
+
if (this.classFields.has(local)) {
|
|
255
|
+
resultTainted.add(local);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
201
259
|
// #589 review: do NOT copy sanitizedVarUncovered onto the bare name.
|
|
202
260
|
// The unscoped sanitizedVars alias stays for legacy readers, but uncovered
|
|
203
261
|
// sink types are decided from the scoped `method:var` key only — otherwise
|
|
@@ -244,6 +302,137 @@ export class ConstantPropagator {
|
|
|
244
302
|
constantReturningMethods: new Set(this.methodReturnsConstant),
|
|
245
303
|
};
|
|
246
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
|
+
}
|
|
247
436
|
/**
|
|
248
437
|
* Evaluate an expression to determine its constant value.
|
|
249
438
|
*/
|
|
@@ -328,13 +517,8 @@ export class ConstantPropagator {
|
|
|
328
517
|
allReturnsSafe = false; // void return or unknown - not safe
|
|
329
518
|
continue;
|
|
330
519
|
}
|
|
331
|
-
// #589: `return
|
|
332
|
-
|
|
333
|
-
? valueNode.childForFieldName('arguments')?.children.filter((c) => c.type !== '(' && c.type !== ')' && c.type !== ',')
|
|
334
|
-
: undefined;
|
|
335
|
-
if (!(valueNode.type === 'method_invocation' &&
|
|
336
|
-
HTML_CONTEXT_ENCODER_METHODS.has(getNodeText(valueNode.childForFieldName('name') ?? valueNode, this.source)) &&
|
|
337
|
-
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)) {
|
|
338
522
|
allReturnsHtmlEncoder = false;
|
|
339
523
|
}
|
|
340
524
|
const value = tempPropagator.evaluateExpression(valueNode);
|
|
@@ -550,12 +734,9 @@ export class ConstantPropagator {
|
|
|
550
734
|
}
|
|
551
735
|
isSanitizerCall(node, methodBody) {
|
|
552
736
|
if (node.type === 'method_invocation') {
|
|
553
|
-
const
|
|
554
|
-
if (
|
|
555
|
-
|
|
556
|
-
if (SANITIZER_METHODS.has(methodName) && !this.localNonSanitizing.has(methodName)) {
|
|
557
|
-
return true;
|
|
558
|
-
}
|
|
737
|
+
const methodName = this.extractJavaCalleeSimpleName(node);
|
|
738
|
+
if (methodName && SANITIZER_METHODS.has(methodName) && !this.localNonSanitizing.has(methodName)) {
|
|
739
|
+
return true;
|
|
559
740
|
}
|
|
560
741
|
}
|
|
561
742
|
if (node.type === 'identifier' && methodBody) {
|
|
@@ -566,6 +747,75 @@ export class ConstantPropagator {
|
|
|
566
747
|
}
|
|
567
748
|
return false;
|
|
568
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
|
+
}
|
|
569
819
|
variableIsAssignedFromSanitizer(varName, methodBody) {
|
|
570
820
|
const findAssignments = (n) => {
|
|
571
821
|
if (n.type === 'local_variable_declaration') {
|
|
@@ -1090,6 +1340,15 @@ export class ConstantPropagator {
|
|
|
1090
1340
|
this.tainted.add(paramName); // Also add unscoped for flexibility
|
|
1091
1341
|
}
|
|
1092
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
|
+
}
|
|
1093
1352
|
}
|
|
1094
1353
|
paramPosition++;
|
|
1095
1354
|
}
|
|
@@ -1434,6 +1693,9 @@ export class ConstantPropagator {
|
|
|
1434
1693
|
this.sanitizedVars.add(scopedName);
|
|
1435
1694
|
this.recordSanitizerScope(scopedName, valueNode);
|
|
1436
1695
|
}
|
|
1696
|
+
else if (this.noteHtmlEncoderHelperAssignment(scopedName, valueNode)) {
|
|
1697
|
+
/* encoder-only helper return: uncovered trust_boundary */
|
|
1698
|
+
}
|
|
1437
1699
|
else {
|
|
1438
1700
|
this.sanitizedVars.delete(scopedName);
|
|
1439
1701
|
this.sanitizedVarUncovered.delete(scopedName);
|
|
@@ -1695,6 +1957,9 @@ export class ConstantPropagator {
|
|
|
1695
1957
|
this.sanitizedVars.add(scopedName);
|
|
1696
1958
|
this.recordSanitizerScope(scopedName, right);
|
|
1697
1959
|
}
|
|
1960
|
+
else if (this.noteHtmlEncoderHelperAssignment(scopedName, right)) {
|
|
1961
|
+
/* encoder-only helper return */
|
|
1962
|
+
}
|
|
1698
1963
|
else {
|
|
1699
1964
|
this.sanitizedVars.delete(scopedName);
|
|
1700
1965
|
this.sanitizedVarUncovered.delete(scopedName);
|
|
@@ -1716,6 +1981,39 @@ export class ConstantPropagator {
|
|
|
1716
1981
|
const { arrayName, indexKey } = this.arrayElementStorageKey(chain);
|
|
1717
1982
|
const isTainted = this.isTaintedExpression(right);
|
|
1718
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;
|
|
1719
2017
|
}
|
|
1720
2018
|
/** cognium-dev#476: `grid[0][0]` and deeper element paths. */
|
|
1721
2019
|
parseArrayAccessChain(node) {
|
|
@@ -2260,18 +2558,36 @@ export class ConstantPropagator {
|
|
|
2260
2558
|
return (SANITIZER_METHODS.has(methodName) && !this.localNonSanitizing.has(methodName))
|
|
2261
2559
|
|| this.methodReturnsSanitized.has(methodName);
|
|
2262
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
|
+
}
|
|
2263
2579
|
/**
|
|
2264
2580
|
* Extract the trailing method/function name from any call node shape:
|
|
2265
|
-
* Java `method_invocation` — name field
|
|
2581
|
+
* Java `method_invocation` — name field (identifier or field_access)
|
|
2266
2582
|
* Go/JS `call_expression` — function field (identifier or selector/member)
|
|
2267
2583
|
* Python `call` — function field (identifier or attribute)
|
|
2268
2584
|
*/
|
|
2269
2585
|
extractCallName(node) {
|
|
2270
|
-
let fnNode = null;
|
|
2271
2586
|
if (node.type === 'method_invocation') {
|
|
2272
|
-
|
|
2587
|
+
return this.extractJavaCalleeSimpleName(node);
|
|
2273
2588
|
}
|
|
2274
|
-
|
|
2589
|
+
let fnNode = null;
|
|
2590
|
+
if (node.type === 'call_expression' || node.type === 'call') {
|
|
2275
2591
|
fnNode = node.childForFieldName('function');
|
|
2276
2592
|
}
|
|
2277
2593
|
if (!fnNode)
|
|
@@ -2298,11 +2614,10 @@ export class ConstantPropagator {
|
|
|
2298
2614
|
if (node.type !== 'method_invocation') {
|
|
2299
2615
|
return false;
|
|
2300
2616
|
}
|
|
2301
|
-
const
|
|
2302
|
-
if (!
|
|
2617
|
+
const methodName = this.extractJavaCalleeSimpleName(node);
|
|
2618
|
+
if (!methodName) {
|
|
2303
2619
|
return false;
|
|
2304
2620
|
}
|
|
2305
|
-
const methodName = getNodeText(nameNode, this.source);
|
|
2306
2621
|
return ANTI_SANITIZER_METHODS.has(methodName);
|
|
2307
2622
|
}
|
|
2308
2623
|
/**
|
|
@@ -2377,33 +2692,52 @@ export class ConstantPropagator {
|
|
|
2377
2692
|
this.iteratorSources.set(varName, collectionName);
|
|
2378
2693
|
}
|
|
2379
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
|
+
}
|
|
2380
2715
|
/**
|
|
2381
2716
|
* Check if a collection is tainted (has any tainted elements).
|
|
2382
2717
|
*/
|
|
2383
2718
|
isCollectionTainted(collectionName) {
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
return true;
|
|
2390
|
-
if (elem !== null) {
|
|
2391
|
-
const scopedElem = this.currentMethod ? `${this.currentMethod}:${elem}` : elem;
|
|
2392
|
-
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__')
|
|
2393
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
|
+
}
|
|
2394
2730
|
}
|
|
2395
2731
|
}
|
|
2396
2732
|
}
|
|
2397
|
-
|
|
2398
|
-
|
|
2399
|
-
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
if (this.tainted.has(collectionName) || this.tainted.has(scopedCollection)) {
|
|
2406
|
-
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
|
+
}
|
|
2407
2741
|
}
|
|
2408
2742
|
return false;
|
|
2409
2743
|
}
|
|
@@ -2589,8 +2923,11 @@ export class ConstantPropagator {
|
|
|
2589
2923
|
if (index >= 0 && index < listElems.length) {
|
|
2590
2924
|
const elem = listElems[index];
|
|
2591
2925
|
if (elem === null) {
|
|
2592
|
-
//
|
|
2593
|
-
//
|
|
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
|
+
}
|
|
2594
2931
|
return false;
|
|
2595
2932
|
}
|
|
2596
2933
|
if (elem === '__TAINTED__') {
|
|
@@ -2715,6 +3052,20 @@ export class ConstantPropagator {
|
|
|
2715
3052
|
}
|
|
2716
3053
|
}
|
|
2717
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
|
+
}
|
|
2718
3069
|
}
|
|
2719
3070
|
}
|
|
2720
3071
|
if (node.type === 'array_access' || node.type === 'subscript_expression') {
|
|
@@ -2935,10 +3286,8 @@ export class ConstantPropagator {
|
|
|
2935
3286
|
else {
|
|
2936
3287
|
list.push(null);
|
|
2937
3288
|
}
|
|
2938
|
-
// Also mark the collection variable itself as tainted if it contains tainted elements
|
|
2939
3289
|
if (isTainted) {
|
|
2940
|
-
|
|
2941
|
-
this.tainted.add(scopedCollection);
|
|
3290
|
+
this.markJavaCollectionTainted(collectionName);
|
|
2942
3291
|
}
|
|
2943
3292
|
}
|
|
2944
3293
|
}
|
|
@@ -2949,16 +3298,32 @@ export class ConstantPropagator {
|
|
|
2949
3298
|
const sourceArg = args[0];
|
|
2950
3299
|
if (sourceArg.type === 'identifier') {
|
|
2951
3300
|
const sourceName = getNodeText(sourceArg, this.source);
|
|
2952
|
-
|
|
2953
|
-
if (
|
|
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)) {
|
|
2954
3321
|
if (!this.listElements.has(collectionName)) {
|
|
2955
3322
|
this.listElements.set(collectionName, []);
|
|
2956
3323
|
}
|
|
2957
|
-
// Add a tainted marker to indicate the collection now has tainted elements
|
|
2958
3324
|
this.listElements.get(collectionName).push('__TAINTED__');
|
|
2959
|
-
|
|
2960
|
-
|
|
2961
|
-
this.tainted.add(scopedCollection);
|
|
3325
|
+
this.markJavaCollectionTainted(collectionName);
|
|
3326
|
+
this.listAddAllFromTainted.add(collectionName);
|
|
2962
3327
|
}
|
|
2963
3328
|
}
|
|
2964
3329
|
else if (this.isTaintedExpression(sourceArg)) {
|
|
@@ -2966,8 +3331,8 @@ export class ConstantPropagator {
|
|
|
2966
3331
|
this.listElements.set(collectionName, []);
|
|
2967
3332
|
}
|
|
2968
3333
|
this.listElements.get(collectionName).push('__TAINTED__');
|
|
2969
|
-
|
|
2970
|
-
this.
|
|
3334
|
+
this.markJavaCollectionTainted(collectionName);
|
|
3335
|
+
this.listAddAllFromTainted.add(collectionName);
|
|
2971
3336
|
}
|
|
2972
3337
|
}
|
|
2973
3338
|
}
|