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
|
@@ -107,6 +107,7 @@ export class CrossFileResolver {
|
|
|
107
107
|
typeHierarchy;
|
|
108
108
|
// Cache: file -> IR
|
|
109
109
|
fileIRs = new Map();
|
|
110
|
+
sourceLines;
|
|
110
111
|
// Cache: method FQN -> taint info
|
|
111
112
|
methodTaintInfo = new Map();
|
|
112
113
|
// Cache: `${typeFqn}.${fieldName}` -> field taint info
|
|
@@ -122,6 +123,14 @@ export class CrossFileResolver {
|
|
|
122
123
|
/**
|
|
123
124
|
* Add a file's IR for analysis
|
|
124
125
|
*/
|
|
126
|
+
/**
|
|
127
|
+
* Raw source lines per file. Optional: the JS/TS parameter-to-sink check reads a
|
|
128
|
+
* def's right-hand side from them (the DFG carries none) to stop at literal-only
|
|
129
|
+
* values; without them the check still runs, only less precisely.
|
|
130
|
+
*/
|
|
131
|
+
setSourceLines(lines) {
|
|
132
|
+
this.sourceLines = lines;
|
|
133
|
+
}
|
|
125
134
|
addFile(filePath, ir) {
|
|
126
135
|
this.fileIRs.set(filePath, ir);
|
|
127
136
|
this.symbolTable.addFromIR(ir, filePath);
|
|
@@ -614,13 +623,21 @@ export class CrossFileResolver {
|
|
|
614
623
|
if (name)
|
|
615
624
|
paramNameToIndex.set(name, i);
|
|
616
625
|
}
|
|
626
|
+
const isJs = ir.meta.language === 'javascript' || ir.meta.language === 'typescript';
|
|
617
627
|
for (const sink of ir.taint.sinks) {
|
|
618
628
|
if (sink.line < method.start_line || sink.line > method.end_line)
|
|
619
629
|
continue;
|
|
620
630
|
// Find the call(s) at the sink line — match by line number.
|
|
621
|
-
|
|
631
|
+
// JS/TS (#1120): only the sink call itself, at its dangerous positions —
|
|
632
|
+
// in `fs.writeFileSync(file, JSON.stringify(data))` the parameter `data`
|
|
633
|
+
// is written, not used as a path.
|
|
634
|
+
const callsAtSink = ir.calls.filter(c => c.location.line === sink.line
|
|
635
|
+
&& (!isJs || !sink.method || this.callMatchesSink(sink, c)));
|
|
622
636
|
for (const call of callsAtSink) {
|
|
623
637
|
for (const arg of call.arguments) {
|
|
638
|
+
if (isJs && sink.argPositions && sink.argPositions.length > 0
|
|
639
|
+
&& !sink.argPositions.includes(arg.position))
|
|
640
|
+
continue;
|
|
624
641
|
// Argument that's a direct variable reference.
|
|
625
642
|
const candidates = [];
|
|
626
643
|
if (arg.variable)
|
|
@@ -842,6 +859,15 @@ export class CrossFileResolver {
|
|
|
842
859
|
if (sinksInMethod.length === 0)
|
|
843
860
|
continue;
|
|
844
861
|
for (const sink of sinksInMethod) {
|
|
862
|
+
// JS/TS: the carried parameter must reach the sink's own arguments, not just
|
|
863
|
+
// any line of the callee (dogfood 2026-11-01: a route value bound as a `?`
|
|
864
|
+
// parameter was credited to `db.prepare(<constant SQL>)` in the same method).
|
|
865
|
+
// Every parameter is tried, not only `term.positions`: the caller-side carried
|
|
866
|
+
// positions can miss the real carrier (juice-shop `downloadToFile(imageUrl, dest)`
|
|
867
|
+
// reported [1] only), and this check must not lose a flow on that.
|
|
868
|
+
if ((targetIR.meta.language === 'javascript' || targetIR.meta.language === 'typescript')
|
|
869
|
+
&& !this.jsParamReachesSinkArgs(targetIR, targetMethod, targetMethod.parameters.map((_, i) => i), sink, term.file))
|
|
870
|
+
continue;
|
|
845
871
|
const key = `${filePath}:${source.line}→${term.file}:${sink.line}`;
|
|
846
872
|
if (seen.has(key))
|
|
847
873
|
continue;
|
|
@@ -864,6 +890,68 @@ export class CrossFileResolver {
|
|
|
864
890
|
}
|
|
865
891
|
return flows;
|
|
866
892
|
}
|
|
893
|
+
/**
|
|
894
|
+
* JS/TS: does a value in one of the parameters at `positions` of `method` reach the
|
|
895
|
+
* arguments of `sink`? Names derived from those parameters by def-use chains are matched
|
|
896
|
+
* against the sink call's dangerous arguments (`argPositions`, else all). Conservative:
|
|
897
|
+
* true when the sink call or the parameter defs cannot be found, so it only drops a
|
|
898
|
+
* flow whose sink call is present and mentions none of those names.
|
|
899
|
+
*/
|
|
900
|
+
jsParamReachesSinkArgs(ir, method, positions, sink, file) {
|
|
901
|
+
const params = positions.map(i => method.parameters[i]?.name).filter((n) => !!n);
|
|
902
|
+
if (params.length === 0)
|
|
903
|
+
return true;
|
|
904
|
+
const calls = (this.getFileIndex(ir).callsByLine.get(sink.line) ?? [])
|
|
905
|
+
.filter(c => c.method_name === sink.method
|
|
906
|
+
&& (sink.callColumn === undefined || c.location.column === undefined || c.location.column === sink.callColumn));
|
|
907
|
+
if (calls.length === 0)
|
|
908
|
+
return true;
|
|
909
|
+
const seeds = ir.dfg.defs
|
|
910
|
+
.filter(d => params.includes(d.variable) && d.line >= method.start_line && d.line <= method.end_line)
|
|
911
|
+
.map(d => d.id);
|
|
912
|
+
const names = new Set(params);
|
|
913
|
+
if (seeds.length > 0) {
|
|
914
|
+
// Def-use walk from the parameters that does not pass through a def whose value is
|
|
915
|
+
// literal-only (`const where = options.id ? 'WHERE id = ?' : ''`): the parameter
|
|
916
|
+
// decides which literal, but the value carries none of it.
|
|
917
|
+
const lines = this.sourceLines?.get(file);
|
|
918
|
+
const defById = new Map(ir.dfg.defs.map(d => [d.id, d]));
|
|
919
|
+
const visited = new Set(seeds);
|
|
920
|
+
const frontier = [...seeds];
|
|
921
|
+
while (frontier.length > 0) {
|
|
922
|
+
const cur = frontier.shift();
|
|
923
|
+
for (const ch of ir.dfg.chains ?? []) {
|
|
924
|
+
if (ch.from_def !== cur || visited.has(ch.to_def))
|
|
925
|
+
continue;
|
|
926
|
+
visited.add(ch.to_def);
|
|
927
|
+
const d = defById.get(ch.to_def);
|
|
928
|
+
if (!d || (lines && literalOnlyAssignment(lines[d.line - 1] ?? '', d.variable)))
|
|
929
|
+
continue;
|
|
930
|
+
if (d.variable)
|
|
931
|
+
names.add(d.variable);
|
|
932
|
+
frontier.push(ch.to_def);
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
const res = [...names].map(n => new RegExp(`(?<![\\w$.])${escapeRegExp(n)}(?![\\w$])`));
|
|
937
|
+
return calls.some(c => c.arguments
|
|
938
|
+
.filter(a => !sink.argPositions || sink.argPositions.length === 0 || sink.argPositions.includes(a.position))
|
|
939
|
+
.some(a => (a.variable && names.has(a.variable)) || res.some(re => re.test(a.expression ?? ''))));
|
|
940
|
+
}
|
|
941
|
+
/** Sink call on this line (method + optional column), same filter as `jsParamReachesSinkArgs`. */
|
|
942
|
+
callMatchesSink(sink, call) {
|
|
943
|
+
return call.method_name === sink.method
|
|
944
|
+
&& (sink.callColumn === undefined
|
|
945
|
+
|| call.location?.column === undefined
|
|
946
|
+
|| call.location.column === sink.callColumn);
|
|
947
|
+
}
|
|
948
|
+
/** Arguments the sink marks dangerous (`argPositions`, else all). */
|
|
949
|
+
dangerousSinkArguments(sink, call) {
|
|
950
|
+
const args = call.arguments ?? [];
|
|
951
|
+
if (!sink.argPositions || sink.argPositions.length === 0)
|
|
952
|
+
return args;
|
|
953
|
+
return args.filter(a => sink.argPositions.includes(a.position));
|
|
954
|
+
}
|
|
867
955
|
/**
|
|
868
956
|
* C# (cognium-dev#637): the methods a value ends in after a chain of pure
|
|
869
957
|
* forwarders. A callee that holds a sink is its own terminal. One that holds no
|
|
@@ -966,8 +1054,10 @@ export class CrossFileResolver {
|
|
|
966
1054
|
continue;
|
|
967
1055
|
// 2a. If callee returns a source and is NOT a sanitizer, mark every
|
|
968
1056
|
// local def on this caller line as tainted (the assignment LHS).
|
|
969
|
-
|
|
970
|
-
|
|
1057
|
+
const calleeNode0 = methodIndex.get(resolved.targetMethod);
|
|
1058
|
+
if (callee.returnsSource && !callee.sanitizes && callee.sourceType &&
|
|
1059
|
+
!(calleeNode0 && this.sourcesOnlySteerBranches(callee.file, calleeNode0.ir, calleeNode0.method))) {
|
|
1060
|
+
const calleeNode = calleeNode0;
|
|
971
1061
|
const calleeSourceLine = calleeNode
|
|
972
1062
|
? this.findRealSourceLineInMethod(calleeNode.ir, calleeNode.method)
|
|
973
1063
|
: undefined;
|
|
@@ -1000,7 +1090,7 @@ export class CrossFileResolver {
|
|
|
1000
1090
|
if (!callee.taintedParams.includes(argIdx))
|
|
1001
1091
|
continue;
|
|
1002
1092
|
const arg = call.arguments[argIdx];
|
|
1003
|
-
const matched = this.matchTaintedArg(arg, tainted);
|
|
1093
|
+
const matched = this.matchTaintedArg(arg, tainted, callerIR.meta.language === 'javascript' || callerIR.meta.language === 'typescript');
|
|
1004
1094
|
if (!matched)
|
|
1005
1095
|
continue;
|
|
1006
1096
|
// #266: skip when the matched var's value was reassigned away
|
|
@@ -1058,11 +1148,13 @@ export class CrossFileResolver {
|
|
|
1058
1148
|
// caller's file rather than in a cross-file callee.
|
|
1059
1149
|
if (tainted.size > 0) {
|
|
1060
1150
|
const sinksInCaller = callerIdx.sinksByMethod.get(method) ?? [];
|
|
1151
|
+
const isJs = callerIR.meta.language === 'javascript' || callerIR.meta.language === 'typescript';
|
|
1061
1152
|
for (const sink of sinksInCaller) {
|
|
1062
|
-
const callsAtSink = callerIdx.callsByLine.get(sink.line) ?? []
|
|
1153
|
+
const callsAtSink = (callerIdx.callsByLine.get(sink.line) ?? [])
|
|
1154
|
+
.filter(c => this.callMatchesSink(sink, c));
|
|
1063
1155
|
for (const sinkCall of callsAtSink) {
|
|
1064
|
-
for (const arg of
|
|
1065
|
-
const matched = this.matchTaintedArg(arg, tainted);
|
|
1156
|
+
for (const arg of this.dangerousSinkArguments(sink, sinkCall)) {
|
|
1157
|
+
const matched = this.matchTaintedArg(arg, tainted, isJs);
|
|
1066
1158
|
if (!matched)
|
|
1067
1159
|
continue;
|
|
1068
1160
|
const key = `${matched.origin.file}:${matched.origin.line}→${callerFile}:${sink.line}`;
|
|
@@ -1260,9 +1352,10 @@ export class CrossFileResolver {
|
|
|
1260
1352
|
// 3a. Caller-body sinks consuming a tainted local.
|
|
1261
1353
|
const sinksInCaller = callerIdx.sinksByMethod.get(method) ?? [];
|
|
1262
1354
|
for (const sink of sinksInCaller) {
|
|
1263
|
-
const callsAtSink = callerIdx.callsByLine.get(sink.line) ?? []
|
|
1355
|
+
const callsAtSink = (callerIdx.callsByLine.get(sink.line) ?? [])
|
|
1356
|
+
.filter(c => this.callMatchesSink(sink, c));
|
|
1264
1357
|
for (const sinkCall of callsAtSink) {
|
|
1265
|
-
for (const arg of
|
|
1358
|
+
for (const arg of this.dangerousSinkArguments(sink, sinkCall)) {
|
|
1266
1359
|
const matched = this.matchTaintedArg(arg, tainted);
|
|
1267
1360
|
if (!matched)
|
|
1268
1361
|
continue;
|
|
@@ -1542,18 +1635,29 @@ export class CrossFileResolver {
|
|
|
1542
1635
|
}
|
|
1543
1636
|
}
|
|
1544
1637
|
}
|
|
1545
|
-
matchTaintedArg(arg, tainted
|
|
1638
|
+
matchTaintedArg(arg, tainted,
|
|
1639
|
+
/** JS/TS: a name after a single `.` is a property (`args.output`), not the tainted local `output` (a spread `...output` still is). */
|
|
1640
|
+
jsMember = false) {
|
|
1546
1641
|
if (tainted.size === 0)
|
|
1547
1642
|
return null;
|
|
1643
|
+
// JS/TS (#1137): `name.length` is a number, so an argument that uses the
|
|
1644
|
+
// tainted name only as `name.length` carries no taint across the call.
|
|
1645
|
+
const lengthOnly = (tv) => arg.expression?.replace(new RegExp(`(?<![\\w$.])${escapeRegExp(tv)}\\s*\\??\\.\\s*length(?![\\w$(\\[])`, 'g'), '0');
|
|
1548
1646
|
// Direct variable reference
|
|
1549
1647
|
if (arg.variable && tainted.has(arg.variable)) {
|
|
1550
|
-
|
|
1648
|
+
const rest = jsMember ? lengthOnly(arg.variable) : undefined;
|
|
1649
|
+
if (rest === undefined || rest === arg.expression
|
|
1650
|
+
|| new RegExp(`(?<![\\w$])${escapeRegExp(arg.variable)}(?![\\w$])`).test(rest)) {
|
|
1651
|
+
return { var: arg.variable, origin: tainted.get(arg.variable) };
|
|
1652
|
+
}
|
|
1551
1653
|
}
|
|
1552
1654
|
// Whole-word scan inside the expression (handles `prefix + url`, `url.trim()`, etc.)
|
|
1553
1655
|
if (arg.expression) {
|
|
1554
1656
|
for (const [tv, origin] of tainted) {
|
|
1555
|
-
const re =
|
|
1556
|
-
|
|
1657
|
+
const re = jsMember
|
|
1658
|
+
? new RegExp(`(?<![\\w$])(?<!(?:^|[^.])\\.)${escapeRegExp(tv)}(?![\\w$])`)
|
|
1659
|
+
: new RegExp(`\\b${escapeRegExp(tv)}\\b`);
|
|
1660
|
+
if (re.test(jsMember ? lengthOnly(tv) : arg.expression))
|
|
1557
1661
|
return { var: tv, origin };
|
|
1558
1662
|
}
|
|
1559
1663
|
}
|
|
@@ -1707,6 +1811,102 @@ export class CrossFileResolver {
|
|
|
1707
1811
|
return false;
|
|
1708
1812
|
return !taintDefIds.has(use.def_id);
|
|
1709
1813
|
}
|
|
1814
|
+
/**
|
|
1815
|
+
* True when every real source inside `method` lands in a local that is only
|
|
1816
|
+
* ever read in a branch condition (`if (...)`, `while (...)`) after it is
|
|
1817
|
+
* assigned, so no source value can reach what the method returns (#914).
|
|
1818
|
+
*
|
|
1819
|
+
* OWASP `Utils.getOSCommandString(append)` reads
|
|
1820
|
+
* `String osName = System.getProperty("os.name");` only to choose between
|
|
1821
|
+
* `"cmd.exe /c " + append` and `append`. Without this, `returnsSource`
|
|
1822
|
+
* marks the method's return as `env_input` and every caller's
|
|
1823
|
+
* `exec(... getOSCommandString("ls ") ...)` became a command_injection path.
|
|
1824
|
+
*
|
|
1825
|
+
* Java / JS / TS when the source text is available; otherwise false
|
|
1826
|
+
* (the method keeps `returnsSource`).
|
|
1827
|
+
*/
|
|
1828
|
+
sourcesOnlySteerBranches(file, ir, method) {
|
|
1829
|
+
const lang = ir.meta.language;
|
|
1830
|
+
if (lang !== 'java' && lang !== 'javascript' && lang !== 'typescript')
|
|
1831
|
+
return false;
|
|
1832
|
+
const lines = this.sourceLines?.get(file);
|
|
1833
|
+
if (!lines)
|
|
1834
|
+
return false;
|
|
1835
|
+
const real = ir.taint.sources.filter(s => s.type !== 'interprocedural_param' && s.line >= method.start_line && s.line <= method.end_line);
|
|
1836
|
+
if (real.length === 0)
|
|
1837
|
+
return false;
|
|
1838
|
+
for (const src of real) {
|
|
1839
|
+
if (lang === 'java') {
|
|
1840
|
+
if (!this.javaSourceOnlySteersBranches(lines, method, src))
|
|
1841
|
+
return false;
|
|
1842
|
+
}
|
|
1843
|
+
else if (!this.jsTsSourceOnlySteersBranches(lines, method, src)) {
|
|
1844
|
+
return false;
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
return true;
|
|
1848
|
+
}
|
|
1849
|
+
/** #914 — local assigned from a source, then only read in branch conditions. */
|
|
1850
|
+
javaSourceOnlySteersBranches(lines, method, src) {
|
|
1851
|
+
const v = src.variable;
|
|
1852
|
+
if (!v || !/^[A-Za-z_$][\w$]*$/.test(v))
|
|
1853
|
+
return false;
|
|
1854
|
+
const decl = new RegExp(`^\\s*(?:final\\s+)?[\\w<>\\[\\].]+\\s+${v}\\s*=[^;]*;\\s*$`);
|
|
1855
|
+
if (!decl.test(stripJavaLiterals(lines[src.line - 1] ?? '')))
|
|
1856
|
+
return false;
|
|
1857
|
+
const mention = new RegExp(`(?<![\\w$.])${v.replace(/\$/g, '\\$')}(?![\\w$])`);
|
|
1858
|
+
for (let l = src.line + 1; l <= method.end_line; l++) {
|
|
1859
|
+
const text = withoutLeadingConditions(stripJavaLiterals(lines[l - 1] ?? ''));
|
|
1860
|
+
if (mention.test(text))
|
|
1861
|
+
return false;
|
|
1862
|
+
}
|
|
1863
|
+
return true;
|
|
1864
|
+
}
|
|
1865
|
+
/**
|
|
1866
|
+
* #1136 — JS/TS counterpart of #914: a read used only to steer a branch
|
|
1867
|
+
* (including inline `if (guard(read(...))) push(path)`) does not taint the
|
|
1868
|
+
* helper's return for cross-file chaining.
|
|
1869
|
+
*/
|
|
1870
|
+
jsTsSourceOnlySteersBranches(lines, method, src) {
|
|
1871
|
+
const v = src.variable;
|
|
1872
|
+
if (v && /^[A-Za-z_$][\w$]*$/.test(v)) {
|
|
1873
|
+
const decl = new RegExp(`^\\s*(?:const|let|var)\\s+${v.replace(/\$/g, '\\$')}\\s*=`);
|
|
1874
|
+
if (decl.test(stripJavaLiterals(lines[src.line - 1] ?? ''))) {
|
|
1875
|
+
const mention = new RegExp(`(?<![\\w$.])${v.replace(/\$/g, '\\$')}(?![\\w$])`);
|
|
1876
|
+
for (let l = src.line + 1; l <= method.end_line; l++) {
|
|
1877
|
+
const text = withoutLeadingConditions(stripJavaLiterals(lines[l - 1] ?? ''));
|
|
1878
|
+
if (mention.test(text))
|
|
1879
|
+
return false;
|
|
1880
|
+
}
|
|
1881
|
+
return true;
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
const anchor = this.jsTsBranchOnlyAnchor(lines, src);
|
|
1885
|
+
if (!anchor)
|
|
1886
|
+
return false;
|
|
1887
|
+
for (let l = method.start_line; l <= method.end_line; l++) {
|
|
1888
|
+
const text = stripJavaLiterals(lines[l - 1] ?? '');
|
|
1889
|
+
if (!text.includes(anchor))
|
|
1890
|
+
continue;
|
|
1891
|
+
const outsideCond = withoutLeadingConditions(text);
|
|
1892
|
+
if (outsideCond.includes(anchor))
|
|
1893
|
+
return false;
|
|
1894
|
+
}
|
|
1895
|
+
return true;
|
|
1896
|
+
}
|
|
1897
|
+
/** Stable substring for an inline read (e.g. `readFileSync`) on the source line. */
|
|
1898
|
+
jsTsBranchOnlyAnchor(lines, src) {
|
|
1899
|
+
const line = stripJavaLiterals(lines[src.line - 1] ?? '');
|
|
1900
|
+
const readCall = line.match(/\b(readFileSync|readFile|readSync)\s*\(/);
|
|
1901
|
+
if (readCall)
|
|
1902
|
+
return readCall[1];
|
|
1903
|
+
if (src.location) {
|
|
1904
|
+
const m = src.location.match(/\b(readFileSync|readFile|readSync)\b/);
|
|
1905
|
+
if (m)
|
|
1906
|
+
return m[1];
|
|
1907
|
+
}
|
|
1908
|
+
return undefined;
|
|
1909
|
+
}
|
|
1710
1910
|
findRealSourceLineInMethod(ir, method) {
|
|
1711
1911
|
for (const src of ir.taint.sources) {
|
|
1712
1912
|
if (src.type === 'interprocedural_param')
|
|
@@ -1776,6 +1976,41 @@ export class CrossFileResolver {
|
|
|
1776
1976
|
return this.fieldTaintInfo.get(`${typeFqn}.${fieldName}`);
|
|
1777
1977
|
}
|
|
1778
1978
|
}
|
|
1979
|
+
/** A Java line with comments and string / char literals blanked. */
|
|
1980
|
+
function stripJavaLiterals(text) {
|
|
1981
|
+
return text
|
|
1982
|
+
.replace(/"(?:[^"\\]|\\.)*"/g, '""')
|
|
1983
|
+
.replace(/'(?:[^'\\]|\\.)'/g, "''")
|
|
1984
|
+
.replace(/\/\/.*$/, '');
|
|
1985
|
+
}
|
|
1986
|
+
/**
|
|
1987
|
+
* The line with the parenthesised condition of every `if` / `else if` /
|
|
1988
|
+
* `while` it opens removed, so what remains is what the line does with
|
|
1989
|
+
* data. An unbalanced condition (it wraps to the next line) is left in
|
|
1990
|
+
* place, which only makes the caller more conservative.
|
|
1991
|
+
*/
|
|
1992
|
+
function withoutLeadingConditions(text) {
|
|
1993
|
+
let out = text;
|
|
1994
|
+
for (;;) {
|
|
1995
|
+
const m = /\b(?:if|while)\s*\(/.exec(out);
|
|
1996
|
+
if (!m)
|
|
1997
|
+
return out;
|
|
1998
|
+
const open = m.index + m[0].length - 1;
|
|
1999
|
+
let depth = 0;
|
|
2000
|
+
let close = -1;
|
|
2001
|
+
for (let i = open; i < out.length; i++) {
|
|
2002
|
+
if (out[i] === '(')
|
|
2003
|
+
depth++;
|
|
2004
|
+
else if (out[i] === ')' && --depth === 0) {
|
|
2005
|
+
close = i;
|
|
2006
|
+
break;
|
|
2007
|
+
}
|
|
2008
|
+
}
|
|
2009
|
+
if (close < 0)
|
|
2010
|
+
return out;
|
|
2011
|
+
out = out.slice(0, m.index) + out.slice(close + 1);
|
|
2012
|
+
}
|
|
2013
|
+
}
|
|
1779
2014
|
/**
|
|
1780
2015
|
* Build a cross-file resolver from multiple IR results
|
|
1781
2016
|
*/
|
|
@@ -1805,4 +2040,15 @@ function isJdkClassReceiver(receiver, language) {
|
|
|
1805
2040
|
return true;
|
|
1806
2041
|
return JAVA_LANG_CLASSES.has(receiver);
|
|
1807
2042
|
}
|
|
2043
|
+
// A JS literal: quoted string, a template literal without `${…}`, number, boolean, null, undefined.
|
|
2044
|
+
const JS_LITERAL = '(?:\'(?:[^\'\\\\]|\\\\.)*\'|"(?:[^"\\\\]|\\\\.)*"|`[^`$\\\\]*`|-?\\d+(?:\\.\\d+)?|true|false|null|undefined)';
|
|
2045
|
+
const LITERAL_RHS = new RegExp(`^(?:${JS_LITERAL}|[^?;]+\\?\\s*${JS_LITERAL}\\s*:\\s*${JS_LITERAL})$`);
|
|
2046
|
+
/**
|
|
2047
|
+
* True when the line assigns `variable` a literal-only value: a literal, or a
|
|
2048
|
+
* conditional whose two branches are literals (`x = cond ? 'a' : ''`).
|
|
2049
|
+
*/
|
|
2050
|
+
function literalOnlyAssignment(line, variable) {
|
|
2051
|
+
const m = new RegExp(`(?:^|[^\\w$.])${escapeRegExp(variable)}\\s*(?::[^=]+)?=(?!=)\\s*(.+?);?\\s*$`).exec(line);
|
|
2052
|
+
return m !== null && LITERAL_RHS.test(m[1].trim());
|
|
2053
|
+
}
|
|
1808
2054
|
//# sourceMappingURL=cross-file.js.map
|