circle-ir 4.18.1 → 4.20.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 +32 -23
- 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 +5 -0
- package/dist/analysis/constant-propagation/patterns.js.map +1 -1
- package/dist/analysis/constant-propagation/propagator.d.ts +1 -1
- package/dist/analysis/constant-propagation/propagator.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/propagator.js +15 -1
- 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/interprocedural.d.ts +6 -0
- package/dist/analysis/interprocedural.d.ts.map +1 -1
- package/dist/analysis/interprocedural.js +53 -6
- package/dist/analysis/interprocedural.js.map +1 -1
- package/dist/analysis/js-helper-return.d.ts +12 -0
- package/dist/analysis/js-helper-return.d.ts.map +1 -0
- package/dist/analysis/js-helper-return.js +64 -0
- package/dist/analysis/js-helper-return.js.map +1 -0
- 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/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 +148 -6
- package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
- package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
- package/dist/analysis/passes/language-sources-pass.js +150 -7
- package/dist/analysis/passes/language-sources-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 +20 -4
- package/dist/analysis/passes/resource-leak-pass.js.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.js +229 -8
- 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 +176 -15
- 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/rules.d.ts.map +1 -1
- package/dist/analysis/rules.js +6 -0
- package/dist/analysis/rules.js.map +1 -1
- package/dist/analysis/sbom.d.ts +43 -4
- package/dist/analysis/sbom.d.ts.map +1 -1
- package/dist/analysis/sbom.js +265 -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 +107 -5
- package/dist/analysis/taint-matcher.js.map +1 -1
- package/dist/analyzer.d.ts +6 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +27 -1
- package/dist/analyzer.js.map +1 -1
- package/dist/browser/circle-ir.js +3379 -101
- package/dist/core/circle-ir-core.cjs +218 -35
- package/dist/core/circle-ir-core.js +218 -35
- package/dist/core/extractors/dfg.js +46 -7
- 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/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 +59 -0
- package/dist/facts/facts2.d.ts.map +1 -0
- package/dist/facts/facts2.js +362 -0
- package/dist/facts/facts2.js.map +1 -0
- package/dist/facts/index.d.ts +20 -0
- package/dist/facts/index.d.ts.map +1 -0
- package/dist/facts/index.js +14 -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/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 +1 -1
- package/dist/graph-facts/dead-code.js.map +1 -1
- package/dist/graph-facts/reach.d.ts +24 -6
- package/dist/graph-facts/reach.d.ts.map +1 -1
- package/dist/graph-facts/reach.js +52 -12
- 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 +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -2
- package/dist/index.js.map +1 -1
- package/dist/navigation/java-graph.d.ts +23 -0
- package/dist/navigation/java-graph.d.ts.map +1 -1
- package/dist/navigation/java-graph.js +222 -8
- package/dist/navigation/java-graph.js.map +1 -1
- package/dist/navigation/navigation-index.d.ts +9 -0
- package/dist/navigation/navigation-index.d.ts.map +1 -1
- package/dist/navigation/navigation-index.js +25 -0
- package/dist/navigation/navigation-index.js.map +1 -1
- package/dist/navigation/ts-call-edges.d.ts +9 -0
- package/dist/navigation/ts-call-edges.d.ts.map +1 -1
- package/dist/navigation/ts-call-edges.js.map +1 -1
- package/dist/resolution/cross-file.d.ts +46 -0
- package/dist/resolution/cross-file.d.ts.map +1 -1
- package/dist/resolution/cross-file.js +281 -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 +3 -2
- package/dist/stable-ids/index.d.ts.map +1 -1
- package/dist/stable-ids/index.js +3 -2
- package/dist/stable-ids/index.js.map +1 -1
- package/dist/stable-ids/nodes.d.ts +45 -1
- package/dist/stable-ids/nodes.d.ts.map +1 -1
- package/dist/stable-ids/nodes.js +118 -15
- 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 +35 -2
- package/dist/stable-ids/ts-parse-errors.js.map +1 -1
- package/package.json +8 -4
- package/schemas/facts@1.json +134 -0
- package/schemas/facts@2.json +216 -0
|
@@ -7226,7 +7226,7 @@ function extractCallInfo(node, context, typed = false) {
|
|
|
7226
7226
|
const receiver = objectNode ? getNodeText(objectNode) : null;
|
|
7227
7227
|
const argsNode = node.childForFieldName("arguments");
|
|
7228
7228
|
const args2 = argsNode ? extractArguments(argsNode, typed) : [];
|
|
7229
|
-
const
|
|
7229
|
+
const enclosingMethod3 = findEnclosingMethod(node);
|
|
7230
7230
|
const { resolved, resolution } = resolveMethodCall(methodName, receiver, context);
|
|
7231
7231
|
let { simpleName, fqn } = resolveReceiverType(receiver, context);
|
|
7232
7232
|
if (typed && objectNode?.type === "identifier") {
|
|
@@ -7244,7 +7244,7 @@ function extractCallInfo(node, context, typed = false) {
|
|
|
7244
7244
|
line: node.startPosition.row + 1,
|
|
7245
7245
|
column: node.startPosition.column
|
|
7246
7246
|
},
|
|
7247
|
-
in_method:
|
|
7247
|
+
in_method: enclosingMethod3,
|
|
7248
7248
|
resolved,
|
|
7249
7249
|
resolution
|
|
7250
7250
|
};
|
|
@@ -7255,7 +7255,7 @@ function extractObjectCreation(node, context, typed = false) {
|
|
|
7255
7255
|
const typeName = getNodeText(typeNode);
|
|
7256
7256
|
const argsNode = node.childForFieldName("arguments");
|
|
7257
7257
|
const args2 = argsNode ? extractArguments(argsNode, typed) : [];
|
|
7258
|
-
const
|
|
7258
|
+
const enclosingMethod3 = findEnclosingMethod(node);
|
|
7259
7259
|
const resolution = {
|
|
7260
7260
|
status: "resolved",
|
|
7261
7261
|
target: `${typeName}.<init>`
|
|
@@ -7273,7 +7273,7 @@ function extractObjectCreation(node, context, typed = false) {
|
|
|
7273
7273
|
line: node.startPosition.row + 1,
|
|
7274
7274
|
column: node.startPosition.column
|
|
7275
7275
|
},
|
|
7276
|
-
in_method:
|
|
7276
|
+
in_method: enclosingMethod3,
|
|
7277
7277
|
resolved: true,
|
|
7278
7278
|
resolution
|
|
7279
7279
|
};
|
|
@@ -10413,9 +10413,46 @@ function processStatement2(stmt, startDefId, startUseId, scopeStack, isJavaScrip
|
|
|
10413
10413
|
case "try_statement":
|
|
10414
10414
|
case "try_with_resources_statement": {
|
|
10415
10415
|
if (isJavaScript) {
|
|
10416
|
-
const
|
|
10417
|
-
|
|
10418
|
-
|
|
10416
|
+
const tryBody = stmt.childForFieldName("body");
|
|
10417
|
+
if (tryBody) {
|
|
10418
|
+
const r = processStatement2(tryBody, defId, useId, scopeStack, isJavaScript);
|
|
10419
|
+
defs.push(...r.defs);
|
|
10420
|
+
uses.push(...r.uses);
|
|
10421
|
+
defId = r.nextDefId;
|
|
10422
|
+
useId = r.nextUseId;
|
|
10423
|
+
}
|
|
10424
|
+
const handler = stmt.childForFieldName("handler");
|
|
10425
|
+
if (handler) {
|
|
10426
|
+
scopeStack.push(/* @__PURE__ */ new Map());
|
|
10427
|
+
const param = handler.childForFieldName("parameter");
|
|
10428
|
+
if (param) {
|
|
10429
|
+
const paramDefs = param.type === "identifier" ? [{ id: defId, variable: getNodeText(param), line: param.startPosition.row + 1, column: param.startPosition.column, kind: "local" }] : extractDestructuringDefs(param, defId);
|
|
10430
|
+
for (const def of paramDefs) {
|
|
10431
|
+
defs.push(def);
|
|
10432
|
+
currentScope(scopeStack).set(def.variable, def.id);
|
|
10433
|
+
markDeclared(currentScope(scopeStack), def.variable);
|
|
10434
|
+
defId++;
|
|
10435
|
+
}
|
|
10436
|
+
}
|
|
10437
|
+
const handlerBody = handler.childForFieldName("body");
|
|
10438
|
+
if (handlerBody) {
|
|
10439
|
+
const r = processStatement2(handlerBody, defId, useId, scopeStack, isJavaScript);
|
|
10440
|
+
defs.push(...r.defs);
|
|
10441
|
+
uses.push(...r.uses);
|
|
10442
|
+
defId = r.nextDefId;
|
|
10443
|
+
useId = r.nextUseId;
|
|
10444
|
+
}
|
|
10445
|
+
carryBranchDefsOut(scopeStack.pop(), scopeStack, false);
|
|
10446
|
+
}
|
|
10447
|
+
const finalizer6 = stmt.childForFieldName("finalizer");
|
|
10448
|
+
const finallyBody = finalizer6?.childForFieldName("body");
|
|
10449
|
+
if (finallyBody) {
|
|
10450
|
+
const r = processStatement2(finallyBody, defId, useId, scopeStack, isJavaScript);
|
|
10451
|
+
defs.push(...r.defs);
|
|
10452
|
+
uses.push(...r.uses);
|
|
10453
|
+
defId = r.nextDefId;
|
|
10454
|
+
useId = r.nextUseId;
|
|
10455
|
+
}
|
|
10419
10456
|
break;
|
|
10420
10457
|
}
|
|
10421
10458
|
scopeStack.push(/* @__PURE__ */ new Map());
|
|
@@ -12751,6 +12788,11 @@ var DEFAULT_SOURCES = [
|
|
|
12751
12788
|
{ method: "getMethod", class: "HttpServletRequest", type: "http_header", severity: "low", return_tainted: true },
|
|
12752
12789
|
{ method: "getContentType", class: "HttpServletRequest", type: "http_header", severity: "medium", return_tainted: true },
|
|
12753
12790
|
{ method: "getCharacterEncoding", class: "HttpServletRequest", type: "http_header", severity: "low", return_tainted: true },
|
|
12791
|
+
// OWASP Benchmark helpers — wrap HttpServletRequest accessors (configs/sources/http_sources.yaml).
|
|
12792
|
+
// Omit getTheValue: OWASP returns a constant (#914 S4); interprocedural gates handle it.
|
|
12793
|
+
{ method: "getTheParameter", class: "SeparateClassRequest", type: "http_param", severity: "high", return_tainted: true, languages: ["java"] },
|
|
12794
|
+
{ method: "getTheHeaders", class: "SeparateClassRequest", type: "http_header", severity: "high", return_tainted: true, languages: ["java"] },
|
|
12795
|
+
{ method: "getTheCookies", class: "SeparateClassRequest", type: "http_cookie", severity: "high", return_tainted: true, languages: ["java"] },
|
|
12754
12796
|
// Enumeration/Iterator sources (from request.getHeaders(), etc.)
|
|
12755
12797
|
{ method: "nextElement", class: "Enumeration", type: "http_header", severity: "high", return_tainted: true },
|
|
12756
12798
|
{ method: "nextElement", type: "http_header", severity: "high", return_tainted: true },
|
|
@@ -13105,7 +13147,7 @@ var DEFAULT_SOURCES = [
|
|
|
13105
13147
|
{ method: "getenv", class: "os", type: "env_input", severity: "medium", return_tainted: true },
|
|
13106
13148
|
{ method: "get", class: "environ", type: "env_input", severity: "medium", return_tainted: true },
|
|
13107
13149
|
{ method: "input", type: "io_input", severity: "high", return_tainted: true },
|
|
13108
|
-
{ method: "read", type: "file_input", severity: "medium", return_tainted: true },
|
|
13150
|
+
{ method: "read", type: "file_input", severity: "medium", return_tainted: true, languages: ["python"] },
|
|
13109
13151
|
{ method: "readline", type: "file_input", severity: "medium", return_tainted: true },
|
|
13110
13152
|
{ method: "readlines", type: "file_input", severity: "medium", return_tainted: true },
|
|
13111
13153
|
// Python database sources
|
|
@@ -14022,7 +14064,7 @@ var DEFAULT_SINKS = [
|
|
|
14022
14064
|
{ method: "renderHTML", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14023
14065
|
{ method: "parseHTML", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14024
14066
|
// HTML sanitizer/validator sinks (AntiSamy, OWASP HTML Sanitizer, etc.)
|
|
14025
|
-
{ method: "scan", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14067
|
+
{ method: "scan", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
|
|
14026
14068
|
{ method: "isValid", class: "SafeHtmlValidator", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14027
14069
|
{ method: "sanitize", class: "PolicyFactory", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14028
14070
|
{ method: "validate", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0] },
|
|
@@ -14038,8 +14080,8 @@ var DEFAULT_SINKS = [
|
|
|
14038
14080
|
{ method: "writeAttribute", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0, 1] },
|
|
14039
14081
|
// AntiSamy specific (SAX filters)
|
|
14040
14082
|
{ method: "startElement", class: "MagicSAXFilter", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0, 1, 2] },
|
|
14041
|
-
{ method: "scan", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14042
|
-
{ method: "scan", class: "AntiSamySAXScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14083
|
+
{ method: "scan", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
|
|
14084
|
+
{ method: "scan", class: "AntiSamySAXScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
|
|
14043
14085
|
// Hibernate Validator
|
|
14044
14086
|
{ method: "getFragmentAsDocument", class: "SafeHtmlValidator", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14045
14087
|
// JSPWiki specific
|
|
@@ -14089,15 +14131,15 @@ var DEFAULT_SINKS = [
|
|
|
14089
14131
|
{ method: "getValidListItem", class: "DefaultValidator", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0, 1] },
|
|
14090
14132
|
{ method: "isValidURI", class: "DefaultValidator", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0, 1] },
|
|
14091
14133
|
// AntiSamy test/processing methods
|
|
14092
|
-
{ method: "scriptAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
14093
|
-
{ method: "imgAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
14094
|
-
{ method: "hrefAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
14095
|
-
{ method: "cssAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
14096
|
-
{ method: "IllegalXML", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
14097
|
-
{ method: "testIssue2", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
14098
|
-
{ method: "issue41", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
14099
|
-
{ method: "testGithubIssue151", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
14100
|
-
{ method: "processStyleTag", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14134
|
+
{ method: "scriptAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14135
|
+
{ method: "imgAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14136
|
+
{ method: "hrefAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14137
|
+
{ method: "cssAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14138
|
+
{ method: "IllegalXML", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14139
|
+
{ method: "testIssue2", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14140
|
+
{ method: "issue41", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14141
|
+
{ method: "testGithubIssue151", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14142
|
+
{ method: "processStyleTag", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
|
|
14101
14143
|
// JSON Sanitizer
|
|
14102
14144
|
{ method: "sanitizeString", class: "JsonSanitizer", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14103
14145
|
{ method: "testIssue13", class: "JsonSanitizerTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
@@ -14624,6 +14666,10 @@ var DEFAULT_SINKS = [
|
|
|
14624
14666
|
// not reach it.
|
|
14625
14667
|
{ method: "run", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["@duckdb/node-api", "duckdb", "duckdb-async"] },
|
|
14626
14668
|
{ method: "prepare", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["@duckdb/node-api", "duckdb", "duckdb-async", "react-native-duckdb"] },
|
|
14669
|
+
// #1073 — better-sqlite3 / sqlite3: `db.prepare(sql)` takes the SQL text (arg 0); the statement's
|
|
14670
|
+
// `get` / `all` / `run` take bound parameters (sink-filter Stage 15f3). Without this row a tainted
|
|
14671
|
+
// query built into `prepare` was no sink in either library.
|
|
14672
|
+
{ method: "prepare", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["better-sqlite3", "sqlite3"] },
|
|
14627
14673
|
{ method: "stream", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["@duckdb/node-api", "duckdb", "duckdb-async", "react-native-duckdb"] },
|
|
14628
14674
|
{ method: "runAndRead", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["@duckdb/node-api"] },
|
|
14629
14675
|
{ method: "runAndReadAll", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["@duckdb/node-api"] },
|
|
@@ -14923,16 +14969,16 @@ var DEFAULT_SINKS = [
|
|
|
14923
14969
|
{ method: "parse", class: "sax", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0] },
|
|
14924
14970
|
{ method: "XMLParser", class: "lxml", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0] },
|
|
14925
14971
|
// Python LDAP Injection
|
|
14926
|
-
{ method: "search", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
|
|
14927
|
-
{ method: "search_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
|
|
14928
|
-
{ method: "search_ext", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
|
|
14929
|
-
{ method: "search_ext_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
|
|
14972
|
+
{ method: "search", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
|
|
14973
|
+
{ method: "search_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
|
|
14974
|
+
{ method: "search_ext", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
|
|
14975
|
+
{ method: "search_ext_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
|
|
14930
14976
|
// ldap3 library (different API from python-ldap)
|
|
14931
|
-
{ method: "search", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 1] },
|
|
14932
|
-
{ method: "extend", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
|
|
14933
|
-
{ method: "modify", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
|
|
14934
|
-
{ method: "add", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
|
|
14935
|
-
{ method: "delete", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
|
|
14977
|
+
{ method: "search", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 1], languages: ["python"] },
|
|
14978
|
+
{ method: "extend", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
|
|
14979
|
+
{ method: "modify", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
|
|
14980
|
+
{ method: "add", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
|
|
14981
|
+
{ method: "delete", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
|
|
14936
14982
|
// Python Trust Boundary (CWE-501)
|
|
14937
14983
|
// The vulnerability is storing untrusted data in session that gets trusted later
|
|
14938
14984
|
{ method: "__setitem__", class: "session", type: "trust_boundary", cwe: "CWE-501", severity: "medium", arg_positions: [1] },
|
|
@@ -15023,7 +15069,7 @@ var DEFAULT_SINKS = [
|
|
|
15023
15069
|
{ method: "put", class: "VelocityContext", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [1] },
|
|
15024
15070
|
{ method: "setVariable", class: "Context", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [1] },
|
|
15025
15071
|
// HTML sanitizer bypass markers (known CVE patterns)
|
|
15026
|
-
{ method: "clean", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0] },
|
|
15072
|
+
{ method: "clean", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0], languages: ["java"] },
|
|
15027
15073
|
{ method: "getValidSafeHTML", class: "ESAPI", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0] },
|
|
15028
15074
|
// NOTE (cognium-dev#270): `HttpServletRequest`/`HttpSession.getAttribute()`
|
|
15029
15075
|
// were registered here as xss sinks to model "attribute reflection XSS", but
|
|
@@ -16415,6 +16461,77 @@ var DEFAULT_HEADER_RULES = [
|
|
|
16415
16461
|
}
|
|
16416
16462
|
];
|
|
16417
16463
|
|
|
16464
|
+
// src/analysis/arg-executing-programs.ts
|
|
16465
|
+
var ARG_EXECUTING_PROGRAMS = /* @__PURE__ */ new Set([
|
|
16466
|
+
"ssh",
|
|
16467
|
+
"sudo",
|
|
16468
|
+
"doas",
|
|
16469
|
+
"su",
|
|
16470
|
+
"runuser",
|
|
16471
|
+
"pkexec",
|
|
16472
|
+
"docker",
|
|
16473
|
+
"podman",
|
|
16474
|
+
"nerdctl",
|
|
16475
|
+
"kubectl",
|
|
16476
|
+
"oc",
|
|
16477
|
+
"xargs",
|
|
16478
|
+
"parallel",
|
|
16479
|
+
"env",
|
|
16480
|
+
"nohup",
|
|
16481
|
+
"timeout",
|
|
16482
|
+
"nice",
|
|
16483
|
+
"ionice",
|
|
16484
|
+
"stdbuf",
|
|
16485
|
+
"setsid",
|
|
16486
|
+
"chroot",
|
|
16487
|
+
"flock",
|
|
16488
|
+
"watch"
|
|
16489
|
+
]);
|
|
16490
|
+
function runsArgvAsCommand(program) {
|
|
16491
|
+
const base = (program.split(/[\\/]/).pop() ?? program).toLowerCase().replace(/\.exe$/, "");
|
|
16492
|
+
return ARG_EXECUTING_PROGRAMS.has(base);
|
|
16493
|
+
}
|
|
16494
|
+
|
|
16495
|
+
// src/analysis/js-helper-return.ts
|
|
16496
|
+
function jsHelperReturnsNoParam(sourceCode, rawName) {
|
|
16497
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(rawName)) return false;
|
|
16498
|
+
const name2 = rawName.replace(/\$/g, "\\$");
|
|
16499
|
+
const decls = [...sourceCode.matchAll(new RegExp(`\\bfunction\\s+${name2}\\s*\\(([^)]*)\\)\\s*\\{`, "g"))];
|
|
16500
|
+
if (decls.length !== 1) return false;
|
|
16501
|
+
if (new RegExp(`(?:const|let|var)\\s+${name2}\\s*=`).test(sourceCode)) return false;
|
|
16502
|
+
const open = (decls[0].index ?? 0) + decls[0][0].length - 1;
|
|
16503
|
+
let depth = 0;
|
|
16504
|
+
let close = -1;
|
|
16505
|
+
for (let i2 = open; i2 < sourceCode.length; i2++) {
|
|
16506
|
+
const ch = sourceCode[i2];
|
|
16507
|
+
if (ch === "{") depth++;
|
|
16508
|
+
else if (ch === "}" && --depth === 0) {
|
|
16509
|
+
close = i2;
|
|
16510
|
+
break;
|
|
16511
|
+
}
|
|
16512
|
+
}
|
|
16513
|
+
if (close < 0) return false;
|
|
16514
|
+
const body2 = sourceCode.slice(open + 1, close).replace(/\/\/.*$/gm, "");
|
|
16515
|
+
if (/\bfunction\b|=>/.test(body2)) return false;
|
|
16516
|
+
const literal = /^(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`[^`$]*`|-?\d+(?:\.\d+)?|true|false|null)$/;
|
|
16517
|
+
const returns = [...body2.matchAll(/\breturn\b\s*([^;]*);?/g)].map((m) => m[1].trim());
|
|
16518
|
+
if (returns.length === 0) return false;
|
|
16519
|
+
for (const expr of returns) {
|
|
16520
|
+
if (literal.test(expr)) continue;
|
|
16521
|
+
const slot = /^([A-Za-z_$][\w$]*)\s*\[\s*(\d+)\s*\]$/.exec(expr);
|
|
16522
|
+
if (!slot) return false;
|
|
16523
|
+
const arr = slot[1].replace(/\$/g, "\\$");
|
|
16524
|
+
const declRe = new RegExp(`(?:const|let|var)\\s+${arr}\\s*=\\s*\\[([^\\]]*)\\]\\s*;?`);
|
|
16525
|
+
const d = declRe.exec(body2);
|
|
16526
|
+
if (!d) return false;
|
|
16527
|
+
if (new RegExp(`\\b${arr}\\s*(?:\\[[^\\]]*\\]\\s*=(?!=)|\\.\\s*(?:push|unshift|splice|shift|pop|reverse|sort|fill|copyWithin)\\s*\\()`).test(body2)) return false;
|
|
16528
|
+
const elems = d[1].split(",").map((e) => e.trim());
|
|
16529
|
+
const el = elems[Number(slot[2])];
|
|
16530
|
+
if (el === void 0 || !literal.test(el)) return false;
|
|
16531
|
+
}
|
|
16532
|
+
return true;
|
|
16533
|
+
}
|
|
16534
|
+
|
|
16418
16535
|
// src/analysis/literal-expression.ts
|
|
16419
16536
|
function isProvablyLiteralExpression(expr) {
|
|
16420
16537
|
let e = (expr ?? "").trim();
|
|
@@ -18137,6 +18254,9 @@ var LanguageSourcesPass = class {
|
|
|
18137
18254
|
additionalSanitizers.push(
|
|
18138
18255
|
...findJsPathResolveStartsWithGuardSanitizers(code)
|
|
18139
18256
|
);
|
|
18257
|
+
additionalSanitizers.push(
|
|
18258
|
+
...findJsPathAllowlistHelperSanitizers(code)
|
|
18259
|
+
);
|
|
18140
18260
|
additionalSanitizers.push(
|
|
18141
18261
|
...findJsCommandAllowlistGuardSanitizers(code)
|
|
18142
18262
|
);
|
|
@@ -19208,12 +19328,37 @@ function classifyCSharpLambdaParam(raw) {
|
|
|
19208
19328
|
if (baseType === "string") return { type: "http_param", name: name2, via: "string param" };
|
|
19209
19329
|
return null;
|
|
19210
19330
|
}
|
|
19331
|
+
var REQUEST_FIELD_TYPES = {
|
|
19332
|
+
query: "http_param",
|
|
19333
|
+
params: "http_param",
|
|
19334
|
+
body: "http_body",
|
|
19335
|
+
headers: "http_header",
|
|
19336
|
+
cookies: "http_cookie"
|
|
19337
|
+
};
|
|
19338
|
+
function destructuredRequestPatterns(sourceCode) {
|
|
19339
|
+
const out2 = [];
|
|
19340
|
+
const seen = /* @__PURE__ */ new Set();
|
|
19341
|
+
for (const m of sourceCode.matchAll(/[(,]\s*\{([^{}]*)\}\s*:\s*(?:express\.)?Request\b/g)) {
|
|
19342
|
+
for (const part of m[1].split(",")) {
|
|
19343
|
+
const bind = /^\s*(\w+)\s*(?::\s*(\w+))?\s*(?:=[^,]*)?$/.exec(part);
|
|
19344
|
+
if (!bind) continue;
|
|
19345
|
+
const field = bind[1];
|
|
19346
|
+
const local = bind[2] ?? bind[1];
|
|
19347
|
+
const type = REQUEST_FIELD_TYPES[field];
|
|
19348
|
+
if (!type || seen.has(local)) continue;
|
|
19349
|
+
seen.add(local);
|
|
19350
|
+
out2.push({ pattern: new RegExp(`(?<![\\w.])${local}\\s*[.[]`), type });
|
|
19351
|
+
}
|
|
19352
|
+
}
|
|
19353
|
+
return out2;
|
|
19354
|
+
}
|
|
19211
19355
|
function findJavaScriptAssignmentSources(sourceCode, language) {
|
|
19212
19356
|
if (!["javascript", "typescript"].includes(language)) return [];
|
|
19213
19357
|
const sources = [];
|
|
19214
19358
|
const lines = sourceCode.split("\n");
|
|
19215
19359
|
const isRouteHandler2 = /export\s+(?:async\s+)?(?:function\s+(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|loader|action)\b|const\s+(?:GET|POST|PUT|PATCH|DELETE|loader|action)\b)/.test(sourceCode) && /\{[^}]*\bparams\b[^}]*\}/.test(sourceCode);
|
|
19216
|
-
const patterns = isRouteHandler2 ? [...JS_TAINTED_PATTERNS, { pattern: /\bparams\s*[.[]/, type: "http_path" }] : JS_TAINTED_PATTERNS;
|
|
19360
|
+
const patterns = isRouteHandler2 ? [...JS_TAINTED_PATTERNS, { pattern: /\bparams\s*[.[]/, type: "http_path" }] : [...JS_TAINTED_PATTERNS];
|
|
19361
|
+
patterns.push(...destructuredRequestPatterns(sourceCode));
|
|
19217
19362
|
const lookupTables = constLookupTables(sourceCode, language);
|
|
19218
19363
|
const assignmentRe2 = /(?:(?:var|let|const)\s+(\w+)\s*:\s*[^=;]+?\s*=(?![>=])|(?:(?:var|let|const)\s+)?(\w+)\s*=)\s*/g;
|
|
19219
19364
|
const rhsOwnStmt = /^(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`|[^;}"'`])*/;
|
|
@@ -19231,6 +19376,8 @@ function findJavaScriptAssignmentSources(sourceCode, language) {
|
|
|
19231
19376
|
rhs = rhsOwnStmt.exec(rhs)?.[0] ?? rhs;
|
|
19232
19377
|
}
|
|
19233
19378
|
if (isConstTableLookup(rhs, lookupTables)) continue;
|
|
19379
|
+
const wholeCall = /^\s*([A-Za-z_$][\w$]*)\s*\(.*\)\s*;?\s*$/.exec(rhs);
|
|
19380
|
+
if (wholeCall && jsHelperReturnsNoParam(sourceCode, wholeCall[1])) continue;
|
|
19234
19381
|
for (const { pattern, type } of patterns) {
|
|
19235
19382
|
if (pattern.test(rhs)) {
|
|
19236
19383
|
const alreadyExists = sources.some((s) => s.line === lineNumber && s.type === type && s.variable === varName);
|
|
@@ -20654,7 +20801,7 @@ function buildJavaTaintedVars(sourceCode, seedVars, deadBranchLines, options) {
|
|
|
20654
20801
|
const derived = /* @__PURE__ */ new Map();
|
|
20655
20802
|
const knownTainted = new Set(seedVars);
|
|
20656
20803
|
const trackSlots = options?.trackSlots === true;
|
|
20657
|
-
const lines =
|
|
20804
|
+
const lines = sourceCode.split("\n").map(stripJavaTrailingLineComment);
|
|
20658
20805
|
const dead = deadBranchLines ?? /* @__PURE__ */ new Set();
|
|
20659
20806
|
const listElems = /* @__PURE__ */ new Map();
|
|
20660
20807
|
const mapSlots = /* @__PURE__ */ new Map();
|
|
@@ -22684,6 +22831,8 @@ function findJsArgvFormExecSanitizers(code) {
|
|
|
22684
22831
|
const text = lines[i2];
|
|
22685
22832
|
if (!argvExecRe.test(text)) continue;
|
|
22686
22833
|
if (shellArgvRe.test(text)) continue;
|
|
22834
|
+
const prog = /\b(?:execFile|spawn)(?:Sync)?\s*\(\s*(['"`])([^'"`]*)\1/.exec(text);
|
|
22835
|
+
if (prog && runsArgvAsCommand(prog[2])) continue;
|
|
22687
22836
|
sanitizers.push({
|
|
22688
22837
|
type: "js_argv_form_exec",
|
|
22689
22838
|
method: "execFile",
|
|
@@ -22769,6 +22918,86 @@ function findJsPathResolveStartsWithGuardSanitizers(code) {
|
|
|
22769
22918
|
}
|
|
22770
22919
|
return sanitizers;
|
|
22771
22920
|
}
|
|
22921
|
+
function jsBracedBlockLines(lines, startLineIdx) {
|
|
22922
|
+
let depth = 0;
|
|
22923
|
+
let started = false;
|
|
22924
|
+
const out2 = [];
|
|
22925
|
+
for (let i2 = startLineIdx; i2 < lines.length; i2++) {
|
|
22926
|
+
const l = lines[i2];
|
|
22927
|
+
for (const c of l) {
|
|
22928
|
+
if (c === "{") {
|
|
22929
|
+
depth++;
|
|
22930
|
+
started = true;
|
|
22931
|
+
} else if (c === "}") {
|
|
22932
|
+
depth--;
|
|
22933
|
+
}
|
|
22934
|
+
}
|
|
22935
|
+
out2.push(l);
|
|
22936
|
+
if (started && depth === 0) return out2;
|
|
22937
|
+
}
|
|
22938
|
+
return null;
|
|
22939
|
+
}
|
|
22940
|
+
function jsPathCanonicalAllowlistGuardRejects(bodyLines, canon, terminatorRe) {
|
|
22941
|
+
const esc = canon.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
22942
|
+
const singleRoot = new RegExp(
|
|
22943
|
+
`if\\s*\\(\\s*!\\s*${esc}\\s*\\.\\s*startsWith\\s*\\(`
|
|
22944
|
+
);
|
|
22945
|
+
const multiRootLine = (line) => /if\s*\(\s*!\s*[A-Za-z_\w]*\.some\s*\(/.test(line) && new RegExp(`\\b${esc}\\b\\s*===\\s*\\w+\\s*\\|\\|\\s*\\b${esc}\\b\\.startsWith\\s*\\(`).test(line);
|
|
22946
|
+
for (let j = 0; j < bodyLines.length; j++) {
|
|
22947
|
+
const line = bodyLines[j];
|
|
22948
|
+
if (!singleRoot.test(line) && !multiRootLine(line)) continue;
|
|
22949
|
+
if (guardRejects(bodyLines, j, terminatorRe, 2)) return true;
|
|
22950
|
+
}
|
|
22951
|
+
return false;
|
|
22952
|
+
}
|
|
22953
|
+
function findJsPathAllowlistHelperSanitizers(code) {
|
|
22954
|
+
const sanitizers = [];
|
|
22955
|
+
const lines = code.split("\n");
|
|
22956
|
+
const terminatorRe = /\b(?:throw|return)\b/;
|
|
22957
|
+
const qualified = /* @__PURE__ */ new Set();
|
|
22958
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
22959
|
+
const fnStart = lines[i2].match(
|
|
22960
|
+
/\bfunction\s+([A-Za-z_]\w*)\s*\(\s*([A-Za-z_]\w*)\s*\)\s*\{/
|
|
22961
|
+
);
|
|
22962
|
+
if (!fnStart) continue;
|
|
22963
|
+
const fnName = fnStart[1];
|
|
22964
|
+
const param = fnStart[2];
|
|
22965
|
+
const bodyLines = jsBracedBlockLines(lines, i2);
|
|
22966
|
+
if (!bodyLines) continue;
|
|
22967
|
+
const bodyText = bodyLines.join("\n");
|
|
22968
|
+
const resolveRe = new RegExp(
|
|
22969
|
+
`\\b(?:const|let|var)\\s+([A-Za-z_\\w]*)\\s*=\\s*(?:(?:node:)?path|nodePath|Path)\\s*\\.\\s*(?:resolve|normalize)\\s*\\(\\s*${param}\\s*\\)`
|
|
22970
|
+
);
|
|
22971
|
+
const resolveM = resolveRe.exec(bodyText);
|
|
22972
|
+
if (!resolveM) continue;
|
|
22973
|
+
const canon = resolveM[1];
|
|
22974
|
+
if (!jsPathCanonicalAllowlistGuardRejects(bodyLines, canon, terminatorRe)) continue;
|
|
22975
|
+
if (!new RegExp(`\\breturn\\s+${canon}\\b`).test(bodyText)) continue;
|
|
22976
|
+
qualified.add(fnName);
|
|
22977
|
+
}
|
|
22978
|
+
for (const fnName of qualified) {
|
|
22979
|
+
const escFn = fnName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
22980
|
+
const callAssign = new RegExp(
|
|
22981
|
+
`\\b(?:const|let|var)\\s+([A-Za-z_\\w]*)\\s*=\\s*${escFn}\\s*\\(`
|
|
22982
|
+
);
|
|
22983
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
22984
|
+
const m = callAssign.exec(lines[i2]);
|
|
22985
|
+
if (!m) continue;
|
|
22986
|
+
const outVar = m[1];
|
|
22987
|
+
const varRef = new RegExp(`\\b${outVar}\\b`);
|
|
22988
|
+
for (let l = i2; l < lines.length; l++) {
|
|
22989
|
+
if (!varRef.test(lines[l])) continue;
|
|
22990
|
+
sanitizers.push({
|
|
22991
|
+
type: "js_path_allowlist_helper",
|
|
22992
|
+
method: fnName,
|
|
22993
|
+
line: l + 1,
|
|
22994
|
+
sanitizes: ["path_traversal", "external_taint_escape"]
|
|
22995
|
+
});
|
|
22996
|
+
}
|
|
22997
|
+
}
|
|
22998
|
+
}
|
|
22999
|
+
return sanitizers;
|
|
23000
|
+
}
|
|
22772
23001
|
function findJsCommandAllowlistGuardSanitizers(code) {
|
|
22773
23002
|
const sanitizers = [];
|
|
22774
23003
|
const lines = code.split("\n");
|
|
@@ -26942,6 +27171,11 @@ var TAINT_PATTERNS = [
|
|
|
26942
27171
|
".getParameterMap(",
|
|
26943
27172
|
".getHeader(",
|
|
26944
27173
|
".getHeaders(",
|
|
27174
|
+
// OWASP Benchmark SeparateClassRequest wrappers (cognium-dev #1107).
|
|
27175
|
+
// Do not add getTheValue — its body is a constant return (#914 S4).
|
|
27176
|
+
".getTheParameter(",
|
|
27177
|
+
".getTheHeaders(",
|
|
27178
|
+
".getTheCookies(",
|
|
26945
27179
|
".getValue(",
|
|
26946
27180
|
// Cookie.getValue()
|
|
26947
27181
|
".getCookies(",
|
|
@@ -27454,7 +27688,9 @@ function findSources(calls, types, patterns, sourceLines, language, imports) {
|
|
|
27454
27688
|
(p) => !p.languages || p.languages.length === 0 || p.languages.includes(language)
|
|
27455
27689
|
);
|
|
27456
27690
|
for (const call of calls) {
|
|
27691
|
+
const inMemoryMapGet = call.method_name === "get" && (language === "javascript" || language === "typescript") && isInMemoryMapGetReceiver(call.receiver, sourceLines);
|
|
27457
27692
|
for (const pattern of patternsForLanguage) {
|
|
27693
|
+
if (inMemoryMapGet && pattern.type === "db_input") continue;
|
|
27458
27694
|
if (matchesSourcePattern(call, pattern, language, types, imports)) {
|
|
27459
27695
|
sources.push({
|
|
27460
27696
|
type: pattern.type,
|
|
@@ -27575,7 +27811,14 @@ function findSources(calls, types, patterns, sourceLines, language, imports) {
|
|
|
27575
27811
|
}
|
|
27576
27812
|
const propertyPatterns = patterns.filter((p) => p.property && p.object && p.property_tainted);
|
|
27577
27813
|
const hasPropertyPatterns = propertyPatterns.length > 0;
|
|
27814
|
+
const jsCode = (language === "javascript" || language === "typescript") && sourceLines ? sourceLines.join("\n") : void 0;
|
|
27815
|
+
const noParamHelper = /* @__PURE__ */ new Map();
|
|
27578
27816
|
for (const call of calls) {
|
|
27817
|
+
if (jsCode !== void 0 && !call.receiver) {
|
|
27818
|
+
let drop = noParamHelper.get(call.method_name);
|
|
27819
|
+
if (drop === void 0) noParamHelper.set(call.method_name, drop = jsHelperReturnsNoParam(jsCode, call.method_name));
|
|
27820
|
+
if (drop) continue;
|
|
27821
|
+
}
|
|
27579
27822
|
for (const arg of call.arguments) {
|
|
27580
27823
|
if (arg.expression) {
|
|
27581
27824
|
const taintCheck = isJavaScriptTaintedArgument(arg.expression, hasPropertyPatterns ? patterns : void 0);
|
|
@@ -27855,8 +28098,16 @@ function isSafePythonSubprocessCall(call, pattern, language) {
|
|
|
27855
28098
|
const e = (a.expression ?? "").trim();
|
|
27856
28099
|
if (/^shell\s*=\s*True\b/.test(e)) return false;
|
|
27857
28100
|
}
|
|
28101
|
+
const first = /^\[\s*(?:[rbuRBU]{0,2})(['"])([^'"]*)\1\s*(?:,|\])/.exec(expr0);
|
|
28102
|
+
if (first) {
|
|
28103
|
+
const program = (first[2].split(/[\\/]/).pop() ?? first[2]).toLowerCase().replace(/\.exe$/, "");
|
|
28104
|
+
if (PYTHON_LIST_SHELLS.has(program) || runsArgvAsCommand(program)) return false;
|
|
28105
|
+
if (PYTHON_LIST_INTERPRETERS.test(program) && /,\s*(?:[rbuRBU]{0,2})(['"])-(?:c|e|-eval|-command)\1/.test(expr0)) return false;
|
|
28106
|
+
}
|
|
27858
28107
|
return true;
|
|
27859
28108
|
}
|
|
28109
|
+
var PYTHON_LIST_SHELLS = /* @__PURE__ */ new Set(["sh", "bash", "zsh", "dash", "ash", "ksh", "csh", "tcsh", "fish", "cmd", "powershell", "pwsh"]);
|
|
28110
|
+
var PYTHON_LIST_INTERPRETERS = /^(?:python[\d.]*|pypy[\d.]*|perl|ruby|node|nodejs|php|lua|osascript)$/;
|
|
27860
28111
|
function isSafeGoExecCommandCall(call, pattern, language) {
|
|
27861
28112
|
if (language !== "go") return false;
|
|
27862
28113
|
if (pattern.type !== "command_injection") return false;
|
|
@@ -27891,6 +28142,7 @@ function isSafeGoExecCommandCall(call, pattern, language) {
|
|
|
27891
28142
|
"pwsh.exe"
|
|
27892
28143
|
]);
|
|
27893
28144
|
if (SHELL_PROGRAMS2.has(program)) return false;
|
|
28145
|
+
if (runsArgvAsCommand(program)) return false;
|
|
27894
28146
|
const PACKAGE_MANAGER_EXEC_SUBCOMMANDS = {
|
|
27895
28147
|
go: /* @__PURE__ */ new Set(["install", "run", "get"]),
|
|
27896
28148
|
npm: /* @__PURE__ */ new Set(["install", "i", "exec"]),
|
|
@@ -27981,6 +28233,7 @@ function isSafeJSChildProcessCall(call, pattern, language) {
|
|
|
27981
28233
|
"pwsh.exe"
|
|
27982
28234
|
]);
|
|
27983
28235
|
if (SHELL_PROGRAMS2.has(program)) return false;
|
|
28236
|
+
if (runsArgvAsCommand(program)) return false;
|
|
27984
28237
|
return true;
|
|
27985
28238
|
}
|
|
27986
28239
|
var CSHARP_SHELL_PROGRAMS = /* @__PURE__ */ new Set([
|
|
@@ -27999,7 +28252,7 @@ function isConstNonShellExe(raw) {
|
|
|
27999
28252
|
const t = raw.trim();
|
|
28000
28253
|
if (!/^@?"[^"]*"$/.test(t)) return false;
|
|
28001
28254
|
const program = (t.replace(/^@?"|"$/g, "").split(/[\\/]/).pop() ?? "").toLowerCase().replace(/\.exe$/, "");
|
|
28002
|
-
return !CSHARP_SHELL_PROGRAMS.has(program);
|
|
28255
|
+
return !CSHARP_SHELL_PROGRAMS.has(program) && !runsArgvAsCommand(program);
|
|
28003
28256
|
}
|
|
28004
28257
|
var PSI_CTOR_EXE_RE = /\bnew\s+ProcessStartInfo\s*(?:<[^>]*>)?\s*\(\s*(@?"[^"]*")/;
|
|
28005
28258
|
function processStartInfoExe(expr, sourceLines) {
|
|
@@ -28262,13 +28515,13 @@ function isSafeRustCommandCall(call, pattern, language) {
|
|
|
28262
28515
|
const stripped = expr.slice(1, -1);
|
|
28263
28516
|
program = stripped.split("/").pop() ?? stripped;
|
|
28264
28517
|
}
|
|
28265
|
-
return !SHELL_PROGRAMS2.has(program);
|
|
28518
|
+
return !SHELL_PROGRAMS2.has(program) && !runsArgvAsCommand(program);
|
|
28266
28519
|
}
|
|
28267
28520
|
if (pattern.method === "arg" || pattern.method === "args" || pattern.method === "spawn" || pattern.method === "output") {
|
|
28268
28521
|
const receiverText = call.receiver ?? "";
|
|
28269
28522
|
const program = extractProgram(receiverText);
|
|
28270
28523
|
if (program === null) return false;
|
|
28271
|
-
return !SHELL_PROGRAMS2.has(program);
|
|
28524
|
+
return !SHELL_PROGRAMS2.has(program) && !runsArgvAsCommand(program);
|
|
28272
28525
|
}
|
|
28273
28526
|
return false;
|
|
28274
28527
|
}
|
|
@@ -28346,8 +28599,29 @@ function isRegexReceiver(receiver, sourceLines) {
|
|
|
28346
28599
|
if (r.startsWith("/") && /\/[a-z]*$/.test(r)) return true;
|
|
28347
28600
|
if (/^(?:new\s+)?RegExp\s*\(/.test(r)) return true;
|
|
28348
28601
|
if (!/^[A-Za-z_$][\w$]*$/.test(r) || !sourceLines) return false;
|
|
28349
|
-
const
|
|
28350
|
-
|
|
28602
|
+
const n = escapeRe(r);
|
|
28603
|
+
const decl = new RegExp(`(?:const|let|var)\\s+${n}\\s*(?::\\s*RegExp\\s*)?=\\s*(?:/|(?:new\\s+)?RegExp\\s*\\()`);
|
|
28604
|
+
if (sourceLines.some((l) => decl.test(l))) return true;
|
|
28605
|
+
const wrapped = new RegExp(`(?:const|let|var)\\s+${n}\\s*(?::\\s*RegExp\\s*)?=\\s*$`);
|
|
28606
|
+
const typed = new RegExp(`\\b${n}\\s*[?!]?\\s*:\\s*RegExp\\b`);
|
|
28607
|
+
return sourceLines.some((l, i2) => typed.test(l) || wrapped.test(l) && /^\s*(?:\/|(?:new\s+)?RegExp\s*\()/.test(sourceLines[i2 + 1] ?? ""));
|
|
28608
|
+
}
|
|
28609
|
+
var DB_TYPE_NAME = /(?:connection|database|\bdb\b|db$|^db|pool|client|knex|sql|statement|prisma|sequelize|repository|transaction|query|store)/i;
|
|
28610
|
+
function isTypedNonDbReceiver(receiver, sourceLines) {
|
|
28611
|
+
const raw = (receiver ?? "").trim();
|
|
28612
|
+
if (!raw || !sourceLines) return false;
|
|
28613
|
+
const lastDot = raw.lastIndexOf(".");
|
|
28614
|
+
const name2 = (lastDot >= 0 ? raw.slice(lastDot + 1) : raw).trim();
|
|
28615
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(name2) || DB_TYPE_NAME.test(name2)) return false;
|
|
28616
|
+
const decl = raw.startsWith("this.") ? new RegExp(`^\\s*(?:(?:private|protected|public|readonly|static|declare)\\s+)+${escapeRe(name2)}\\s*[?!]?\\s*:\\s*([A-Za-z_$][\\w$]*)\\s*[;=]`) : new RegExp(`\\b${escapeRe(name2)}\\s*\\??\\s*:\\s*([A-Za-z_$][\\w$]*)\\s*[;,)=]`);
|
|
28617
|
+
let typed;
|
|
28618
|
+
for (const l of sourceLines) {
|
|
28619
|
+
const m = decl.exec(l);
|
|
28620
|
+
if (!m) continue;
|
|
28621
|
+
if (typed !== void 0 && typed !== m[1]) return false;
|
|
28622
|
+
typed = m[1];
|
|
28623
|
+
}
|
|
28624
|
+
return typed !== void 0 && !DB_TYPE_NAME.test(typed) && !/^(?:any|unknown|object)$/.test(typed);
|
|
28351
28625
|
}
|
|
28352
28626
|
function isNavigationReceiverName(receiver) {
|
|
28353
28627
|
const r = (receiver ?? "").trim();
|
|
@@ -28384,7 +28658,10 @@ function isDeclaredFunctionReference(arg, sourceLines) {
|
|
|
28384
28658
|
// const connect = () => / function / async () =>
|
|
28385
28659
|
new RegExp(
|
|
28386
28660
|
`\\b(?:const|let|var)\\s+${n}\\s*=\\s*(?:async\\s+)?(?:function\\b|\\(|[A-Za-z_$][\\w$]*\\s*=>)`
|
|
28387
|
-
)
|
|
28661
|
+
),
|
|
28662
|
+
// A Promise executor's resolve / reject: `new Promise((r) => setTimeout(r, ms))`,
|
|
28663
|
+
// the sleep idiom (dogfood 2026-10-31, controldeck harness).
|
|
28664
|
+
new RegExp(`\\bnew\\s+Promise\\s*(?:<[^>]*>)?\\s*\\(\\s*(?:async\\s+)?(?:\\(\\s*(?:[A-Za-z_$][\\w$]*\\s*,\\s*)?${n}\\s*[,)]|${n}\\s*=>|function\\s*\\(\\s*(?:[A-Za-z_$][\\w$]*\\s*,\\s*)?${n}\\s*[,)])`)
|
|
28388
28665
|
];
|
|
28389
28666
|
return sourceLines.some((l) => decls.some((re) => re.test(l)));
|
|
28390
28667
|
}
|
|
@@ -28645,7 +28922,10 @@ function findSinks(calls, patterns, typeHierarchy, language, sourceLines, types)
|
|
|
28645
28922
|
if ((pattern.type === "command_injection" || pattern.type === "sql_injection") && call.method_name === "exec" && (language === "javascript" || language === "typescript") && isRegexReceiver(call.receiver, sourceLines)) {
|
|
28646
28923
|
continue;
|
|
28647
28924
|
}
|
|
28648
|
-
if (pattern.type === "sql_injection" && call.method_name === "get" && pattern.class === "Connection" && (language === "javascript" || language === "typescript") && isInMemoryMapGetReceiver(call.receiver, sourceLines)) {
|
|
28925
|
+
if (pattern.type === "sql_injection" && call.method_name === "get" && pattern.class === "Connection" && (language === "javascript" || language === "typescript") && (isInMemoryMapGetReceiver(call.receiver, sourceLines) || isTypedNonDbReceiver(call.receiver, sourceLines))) {
|
|
28926
|
+
continue;
|
|
28927
|
+
}
|
|
28928
|
+
if (call.method_name === "get" && (language === "javascript" || language === "typescript") && isInMemoryMapGetReceiver(call.receiver, sourceLines)) {
|
|
28649
28929
|
continue;
|
|
28650
28930
|
}
|
|
28651
28931
|
if (pattern.type === "code_injection" && language === "python" && call.method_name === "compile" && call.receiver && call.receiver !== "builtins") {
|
|
@@ -28700,6 +28980,7 @@ function matchesSourcePattern(call, pattern, language, types, imports) {
|
|
|
28700
28980
|
}
|
|
28701
28981
|
if (pattern.class && pattern.class !== "constructor") {
|
|
28702
28982
|
if (call.receiver_type && call.receiver_type === pattern.class) {
|
|
28983
|
+
} else if (call.receiver_type && call.receiver_type.includes(".") && call.receiver_type.endsWith("." + pattern.class)) {
|
|
28703
28984
|
} else if (call.receiver_type_fqn && call.receiver_type_fqn.endsWith("." + pattern.class)) {
|
|
28704
28985
|
} else if (!call.receiver) {
|
|
28705
28986
|
const target = call.resolution?.target;
|
|
@@ -30775,12 +31056,12 @@ var TypeHierarchyResolver = class {
|
|
|
30775
31056
|
* Also handles interface-extends-interface relationships
|
|
30776
31057
|
*/
|
|
30777
31058
|
implementsInterface(typeName, interfaceName) {
|
|
30778
|
-
const
|
|
31059
|
+
const typeFqn2 = this.resolveFqn(typeName);
|
|
30779
31060
|
const ifaceFqn = this.resolveFqn(interfaceName);
|
|
30780
31061
|
const allImpls = this.getAllImplementations(ifaceFqn);
|
|
30781
|
-
if (allImpls.includes(
|
|
31062
|
+
if (allImpls.includes(typeFqn2)) return true;
|
|
30782
31063
|
const allSubtypes = this.getAllSubtypes(ifaceFqn);
|
|
30783
|
-
if (allSubtypes.includes(
|
|
31064
|
+
if (allSubtypes.includes(typeFqn2)) return true;
|
|
30784
31065
|
return false;
|
|
30785
31066
|
}
|
|
30786
31067
|
/**
|
|
@@ -31312,6 +31593,2047 @@ function registerCommonLibraries(resolver) {
|
|
|
31312
31593
|
);
|
|
31313
31594
|
}
|
|
31314
31595
|
|
|
31596
|
+
// src/resolution/symbol-table.ts
|
|
31597
|
+
var SymbolTable = class {
|
|
31598
|
+
// All exported symbols by FQN
|
|
31599
|
+
exports = /* @__PURE__ */ new Map();
|
|
31600
|
+
// Simple name -> FQNs (for ambiguous resolution)
|
|
31601
|
+
nameToFqns = /* @__PURE__ */ new Map();
|
|
31602
|
+
// File -> its imports
|
|
31603
|
+
fileImports = /* @__PURE__ */ new Map();
|
|
31604
|
+
// Package -> exported types in that package
|
|
31605
|
+
packageTypes = /* @__PURE__ */ new Map();
|
|
31606
|
+
// FQN -> file path
|
|
31607
|
+
fqnToFile = /* @__PURE__ */ new Map();
|
|
31608
|
+
/**
|
|
31609
|
+
* Add exports and imports from a CircleIR analysis result
|
|
31610
|
+
*/
|
|
31611
|
+
addFromIR(ir, filePath) {
|
|
31612
|
+
const pkg = ir.meta.package || "";
|
|
31613
|
+
for (const type of ir.types) {
|
|
31614
|
+
this.addTypeExports(type, filePath, pkg);
|
|
31615
|
+
}
|
|
31616
|
+
this.addFileImports(ir.imports, filePath);
|
|
31617
|
+
for (const exp of ir.exports) {
|
|
31618
|
+
this.addExplicitExport(exp, filePath, pkg);
|
|
31619
|
+
}
|
|
31620
|
+
}
|
|
31621
|
+
/**
|
|
31622
|
+
* Add type and its members as exports
|
|
31623
|
+
*/
|
|
31624
|
+
addTypeExports(type, filePath, pkg) {
|
|
31625
|
+
const fqn = pkg ? `${pkg}.${type.name}` : type.name;
|
|
31626
|
+
const visibility = this.getVisibility(type.annotations);
|
|
31627
|
+
const typeExport = {
|
|
31628
|
+
name: type.name,
|
|
31629
|
+
fqn,
|
|
31630
|
+
kind: type.kind,
|
|
31631
|
+
file: filePath,
|
|
31632
|
+
line: type.start_line,
|
|
31633
|
+
visibility
|
|
31634
|
+
};
|
|
31635
|
+
this.registerExport(typeExport);
|
|
31636
|
+
if (!this.packageTypes.has(pkg)) {
|
|
31637
|
+
this.packageTypes.set(pkg, /* @__PURE__ */ new Set());
|
|
31638
|
+
}
|
|
31639
|
+
this.packageTypes.get(pkg).add(fqn);
|
|
31640
|
+
for (const method of type.methods) {
|
|
31641
|
+
this.addMethodExport(method, fqn, filePath);
|
|
31642
|
+
}
|
|
31643
|
+
for (const field of type.fields) {
|
|
31644
|
+
this.addFieldExport(field, fqn, filePath);
|
|
31645
|
+
}
|
|
31646
|
+
}
|
|
31647
|
+
/**
|
|
31648
|
+
* Add a method as an export
|
|
31649
|
+
*/
|
|
31650
|
+
addMethodExport(method, parentFqn, filePath) {
|
|
31651
|
+
const methodFqn = `${parentFqn}.${method.name}`;
|
|
31652
|
+
const signature = method.parameters.map((p) => p.type || "Object").join(",");
|
|
31653
|
+
const visibility = this.getVisibilityFromModifiers(method.modifiers);
|
|
31654
|
+
const methodExport = {
|
|
31655
|
+
name: method.name,
|
|
31656
|
+
fqn: methodFqn,
|
|
31657
|
+
kind: "method",
|
|
31658
|
+
file: filePath,
|
|
31659
|
+
line: method.start_line,
|
|
31660
|
+
visibility,
|
|
31661
|
+
parentType: parentFqn,
|
|
31662
|
+
signature
|
|
31663
|
+
};
|
|
31664
|
+
this.registerExport(methodExport);
|
|
31665
|
+
}
|
|
31666
|
+
/**
|
|
31667
|
+
* Add a field as an export
|
|
31668
|
+
*/
|
|
31669
|
+
addFieldExport(field, parentFqn, filePath) {
|
|
31670
|
+
const fieldFqn = `${parentFqn}.${field.name}`;
|
|
31671
|
+
const visibility = this.getVisibilityFromModifiers(field.modifiers);
|
|
31672
|
+
const fieldExport = {
|
|
31673
|
+
name: field.name,
|
|
31674
|
+
fqn: fieldFqn,
|
|
31675
|
+
kind: "field",
|
|
31676
|
+
file: filePath,
|
|
31677
|
+
line: 0,
|
|
31678
|
+
// Fields don't have line numbers in current TypeInfo
|
|
31679
|
+
visibility,
|
|
31680
|
+
parentType: parentFqn
|
|
31681
|
+
};
|
|
31682
|
+
this.registerExport(fieldExport);
|
|
31683
|
+
}
|
|
31684
|
+
/**
|
|
31685
|
+
* Register an export in all indexes
|
|
31686
|
+
*/
|
|
31687
|
+
registerExport(symbol) {
|
|
31688
|
+
this.exports.set(symbol.fqn, symbol);
|
|
31689
|
+
this.fqnToFile.set(symbol.fqn, symbol.file);
|
|
31690
|
+
if (!this.nameToFqns.has(symbol.name)) {
|
|
31691
|
+
this.nameToFqns.set(symbol.name, /* @__PURE__ */ new Set());
|
|
31692
|
+
}
|
|
31693
|
+
this.nameToFqns.get(symbol.name).add(symbol.fqn);
|
|
31694
|
+
}
|
|
31695
|
+
/**
|
|
31696
|
+
* Add imports for a file
|
|
31697
|
+
*/
|
|
31698
|
+
addFileImports(imports, filePath) {
|
|
31699
|
+
const fileImport = {
|
|
31700
|
+
imports,
|
|
31701
|
+
resolved: /* @__PURE__ */ new Map(),
|
|
31702
|
+
wildcardPackages: []
|
|
31703
|
+
};
|
|
31704
|
+
for (const imp of imports) {
|
|
31705
|
+
if (imp.is_wildcard && imp.from_package) {
|
|
31706
|
+
fileImport.wildcardPackages.push(imp.from_package);
|
|
31707
|
+
} else if (imp.from_package && imp.imported_name !== "*") {
|
|
31708
|
+
const fqn = `${imp.from_package}.${imp.imported_name}`;
|
|
31709
|
+
fileImport.resolved.set(imp.imported_name, fqn);
|
|
31710
|
+
}
|
|
31711
|
+
}
|
|
31712
|
+
this.fileImports.set(filePath, fileImport);
|
|
31713
|
+
}
|
|
31714
|
+
/**
|
|
31715
|
+
* Add explicit export declaration
|
|
31716
|
+
*/
|
|
31717
|
+
addExplicitExport(exp, filePath, pkg) {
|
|
31718
|
+
const fqn = pkg ? `${pkg}.${exp.symbol}` : exp.symbol;
|
|
31719
|
+
if (!this.exports.has(fqn)) {
|
|
31720
|
+
const symbol = {
|
|
31721
|
+
name: exp.symbol,
|
|
31722
|
+
fqn,
|
|
31723
|
+
kind: exp.kind,
|
|
31724
|
+
file: filePath,
|
|
31725
|
+
line: 0,
|
|
31726
|
+
visibility: exp.visibility
|
|
31727
|
+
};
|
|
31728
|
+
this.registerExport(symbol);
|
|
31729
|
+
}
|
|
31730
|
+
}
|
|
31731
|
+
/**
|
|
31732
|
+
* Resolve a simple name to its FQN from a given file's context
|
|
31733
|
+
*/
|
|
31734
|
+
resolveSymbol(name2, fromFile) {
|
|
31735
|
+
if (this.exports.has(name2)) {
|
|
31736
|
+
return this.exports.get(name2);
|
|
31737
|
+
}
|
|
31738
|
+
const fileImport = this.fileImports.get(fromFile);
|
|
31739
|
+
if (fileImport) {
|
|
31740
|
+
const resolved = fileImport.resolved.get(name2);
|
|
31741
|
+
if (resolved && this.exports.has(resolved)) {
|
|
31742
|
+
return this.exports.get(resolved);
|
|
31743
|
+
}
|
|
31744
|
+
for (const pkg of fileImport.wildcardPackages) {
|
|
31745
|
+
const fqn = `${pkg}.${name2}`;
|
|
31746
|
+
if (this.exports.has(fqn)) {
|
|
31747
|
+
return this.exports.get(fqn);
|
|
31748
|
+
}
|
|
31749
|
+
}
|
|
31750
|
+
}
|
|
31751
|
+
const fqns = this.nameToFqns.get(name2);
|
|
31752
|
+
if (fqns && fqns.size === 1) {
|
|
31753
|
+
return this.exports.get(Array.from(fqns)[0]);
|
|
31754
|
+
}
|
|
31755
|
+
return void 0;
|
|
31756
|
+
}
|
|
31757
|
+
/**
|
|
31758
|
+
* Resolve a type name to FQN, considering imports
|
|
31759
|
+
*/
|
|
31760
|
+
resolveTypeName(name2, fromFile) {
|
|
31761
|
+
const symbol = this.resolveSymbol(name2, fromFile);
|
|
31762
|
+
if (symbol && (symbol.kind === "class" || symbol.kind === "interface" || symbol.kind === "enum")) {
|
|
31763
|
+
return symbol.fqn;
|
|
31764
|
+
}
|
|
31765
|
+
return void 0;
|
|
31766
|
+
}
|
|
31767
|
+
/**
|
|
31768
|
+
* Get all methods of a type by FQN
|
|
31769
|
+
*/
|
|
31770
|
+
getMethodsOfType(typeFqn2) {
|
|
31771
|
+
const results = [];
|
|
31772
|
+
for (const symbol of this.exports.values()) {
|
|
31773
|
+
if (symbol.kind === "method" && symbol.parentType === typeFqn2) {
|
|
31774
|
+
results.push(symbol);
|
|
31775
|
+
}
|
|
31776
|
+
}
|
|
31777
|
+
return results;
|
|
31778
|
+
}
|
|
31779
|
+
/**
|
|
31780
|
+
* Find a method by name in a type
|
|
31781
|
+
*/
|
|
31782
|
+
findMethod(typeFqn2, methodName) {
|
|
31783
|
+
const methodFqn = `${typeFqn2}.${methodName}`;
|
|
31784
|
+
return this.exports.get(methodFqn);
|
|
31785
|
+
}
|
|
31786
|
+
/**
|
|
31787
|
+
* Get the file where a symbol is defined
|
|
31788
|
+
*/
|
|
31789
|
+
getFile(fqn) {
|
|
31790
|
+
return this.fqnToFile.get(fqn);
|
|
31791
|
+
}
|
|
31792
|
+
/**
|
|
31793
|
+
* Get all exported symbols from a file
|
|
31794
|
+
*/
|
|
31795
|
+
getFileExports(filePath) {
|
|
31796
|
+
const results = [];
|
|
31797
|
+
for (const symbol of this.exports.values()) {
|
|
31798
|
+
if (symbol.file === filePath) {
|
|
31799
|
+
results.push(symbol);
|
|
31800
|
+
}
|
|
31801
|
+
}
|
|
31802
|
+
return results;
|
|
31803
|
+
}
|
|
31804
|
+
/**
|
|
31805
|
+
* Get all types in a package
|
|
31806
|
+
*/
|
|
31807
|
+
getPackageTypes(packageName) {
|
|
31808
|
+
return Array.from(this.packageTypes.get(packageName) || []);
|
|
31809
|
+
}
|
|
31810
|
+
/**
|
|
31811
|
+
* Get all known packages
|
|
31812
|
+
*/
|
|
31813
|
+
getPackages() {
|
|
31814
|
+
return Array.from(this.packageTypes.keys());
|
|
31815
|
+
}
|
|
31816
|
+
/**
|
|
31817
|
+
* Check if a symbol exists
|
|
31818
|
+
*/
|
|
31819
|
+
hasSymbol(fqn) {
|
|
31820
|
+
return this.exports.has(fqn);
|
|
31821
|
+
}
|
|
31822
|
+
/**
|
|
31823
|
+
* Get symbol by FQN
|
|
31824
|
+
*/
|
|
31825
|
+
getSymbol(fqn) {
|
|
31826
|
+
return this.exports.get(fqn);
|
|
31827
|
+
}
|
|
31828
|
+
/**
|
|
31829
|
+
* Get all possible FQNs for a simple name
|
|
31830
|
+
*/
|
|
31831
|
+
getPossibleFqns(simpleName) {
|
|
31832
|
+
return Array.from(this.nameToFqns.get(simpleName) || []);
|
|
31833
|
+
}
|
|
31834
|
+
/**
|
|
31835
|
+
* Get imports for a file
|
|
31836
|
+
*/
|
|
31837
|
+
getFileImports(filePath) {
|
|
31838
|
+
return this.fileImports.get(filePath)?.imports || [];
|
|
31839
|
+
}
|
|
31840
|
+
/**
|
|
31841
|
+
* Get statistics
|
|
31842
|
+
*/
|
|
31843
|
+
getStats() {
|
|
31844
|
+
let types = 0, methods = 0, fields = 0;
|
|
31845
|
+
const files = /* @__PURE__ */ new Set();
|
|
31846
|
+
for (const symbol of this.exports.values()) {
|
|
31847
|
+
files.add(symbol.file);
|
|
31848
|
+
if (symbol.kind === "class" || symbol.kind === "interface" || symbol.kind === "enum") {
|
|
31849
|
+
types++;
|
|
31850
|
+
} else if (symbol.kind === "method") {
|
|
31851
|
+
methods++;
|
|
31852
|
+
} else if (symbol.kind === "field") {
|
|
31853
|
+
fields++;
|
|
31854
|
+
}
|
|
31855
|
+
}
|
|
31856
|
+
return {
|
|
31857
|
+
totalSymbols: this.exports.size,
|
|
31858
|
+
types,
|
|
31859
|
+
methods,
|
|
31860
|
+
fields,
|
|
31861
|
+
files: files.size,
|
|
31862
|
+
packages: this.packageTypes.size
|
|
31863
|
+
};
|
|
31864
|
+
}
|
|
31865
|
+
/**
|
|
31866
|
+
* Clear all data
|
|
31867
|
+
*/
|
|
31868
|
+
clear() {
|
|
31869
|
+
this.exports.clear();
|
|
31870
|
+
this.nameToFqns.clear();
|
|
31871
|
+
this.fileImports.clear();
|
|
31872
|
+
this.packageTypes.clear();
|
|
31873
|
+
this.fqnToFile.clear();
|
|
31874
|
+
}
|
|
31875
|
+
// --- Private helpers ---
|
|
31876
|
+
/**
|
|
31877
|
+
* Extract visibility from annotations (for types)
|
|
31878
|
+
*/
|
|
31879
|
+
getVisibility(_annotations) {
|
|
31880
|
+
return "public";
|
|
31881
|
+
}
|
|
31882
|
+
/**
|
|
31883
|
+
* Extract visibility from modifiers
|
|
31884
|
+
*/
|
|
31885
|
+
getVisibilityFromModifiers(modifiers) {
|
|
31886
|
+
if (modifiers.includes("public")) return "public";
|
|
31887
|
+
if (modifiers.includes("protected")) return "protected";
|
|
31888
|
+
if (modifiers.includes("private")) return "private";
|
|
31889
|
+
return "package";
|
|
31890
|
+
}
|
|
31891
|
+
};
|
|
31892
|
+
|
|
31893
|
+
// src/resolution/cross-file.ts
|
|
31894
|
+
function buildFileIndex(ir) {
|
|
31895
|
+
const callsByLine = /* @__PURE__ */ new Map();
|
|
31896
|
+
for (const c of ir.calls) {
|
|
31897
|
+
const ln = c.location.line;
|
|
31898
|
+
let arr = callsByLine.get(ln);
|
|
31899
|
+
if (!arr) {
|
|
31900
|
+
arr = [];
|
|
31901
|
+
callsByLine.set(ln, arr);
|
|
31902
|
+
}
|
|
31903
|
+
arr.push(c);
|
|
31904
|
+
}
|
|
31905
|
+
const defsByLine = /* @__PURE__ */ new Map();
|
|
31906
|
+
for (const d of ir.dfg.defs) {
|
|
31907
|
+
let arr = defsByLine.get(d.line);
|
|
31908
|
+
if (!arr) {
|
|
31909
|
+
arr = [];
|
|
31910
|
+
defsByLine.set(d.line, arr);
|
|
31911
|
+
}
|
|
31912
|
+
arr.push(d);
|
|
31913
|
+
}
|
|
31914
|
+
const usesByLine = /* @__PURE__ */ new Map();
|
|
31915
|
+
for (const u of ir.dfg.uses) {
|
|
31916
|
+
let arr = usesByLine.get(u.line);
|
|
31917
|
+
if (!arr) {
|
|
31918
|
+
arr = [];
|
|
31919
|
+
usesByLine.set(u.line, arr);
|
|
31920
|
+
}
|
|
31921
|
+
arr.push(u);
|
|
31922
|
+
}
|
|
31923
|
+
const callsSorted = [...ir.calls].sort((a, b) => a.location.line - b.location.line);
|
|
31924
|
+
const sinksSorted = [...ir.taint.sinks].sort((a, b) => a.line - b.line);
|
|
31925
|
+
const defsSorted = [...ir.dfg.defs].sort((a, b) => a.line - b.line);
|
|
31926
|
+
const callsByMethod = /* @__PURE__ */ new Map();
|
|
31927
|
+
const sinksByMethod = /* @__PURE__ */ new Map();
|
|
31928
|
+
const defsByMethod = /* @__PURE__ */ new Map();
|
|
31929
|
+
for (const type of ir.types) {
|
|
31930
|
+
for (const method of type.methods) {
|
|
31931
|
+
const start2 = method.start_line;
|
|
31932
|
+
const end = method.end_line;
|
|
31933
|
+
const inCalls = [];
|
|
31934
|
+
for (const c of callsSorted) {
|
|
31935
|
+
const ln = c.location.line;
|
|
31936
|
+
if (ln < start2) continue;
|
|
31937
|
+
if (ln > end) break;
|
|
31938
|
+
inCalls.push(c);
|
|
31939
|
+
}
|
|
31940
|
+
callsByMethod.set(method, inCalls);
|
|
31941
|
+
const inSinks = [];
|
|
31942
|
+
for (const s of sinksSorted) {
|
|
31943
|
+
if (s.line < start2) continue;
|
|
31944
|
+
if (s.line > end) break;
|
|
31945
|
+
inSinks.push(s);
|
|
31946
|
+
}
|
|
31947
|
+
sinksByMethod.set(method, inSinks);
|
|
31948
|
+
const inDefs = [];
|
|
31949
|
+
for (const d of defsSorted) {
|
|
31950
|
+
if (d.line < start2) continue;
|
|
31951
|
+
if (d.line > end) break;
|
|
31952
|
+
inDefs.push(d);
|
|
31953
|
+
}
|
|
31954
|
+
defsByMethod.set(method, inDefs);
|
|
31955
|
+
}
|
|
31956
|
+
}
|
|
31957
|
+
return { callsByLine, defsByLine, usesByLine, callsByMethod, sinksByMethod, defsByMethod };
|
|
31958
|
+
}
|
|
31959
|
+
function escapeRegExp(s) {
|
|
31960
|
+
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
31961
|
+
}
|
|
31962
|
+
var CrossFileResolver = class {
|
|
31963
|
+
// -- pre-3.89.0 pre-index cache (see FileIndex above) --
|
|
31964
|
+
fileIndexes = /* @__PURE__ */ new WeakMap();
|
|
31965
|
+
getFileIndex(ir) {
|
|
31966
|
+
let idx = this.fileIndexes.get(ir);
|
|
31967
|
+
if (idx) return idx;
|
|
31968
|
+
idx = buildFileIndex(ir);
|
|
31969
|
+
this.fileIndexes.set(ir, idx);
|
|
31970
|
+
return idx;
|
|
31971
|
+
}
|
|
31972
|
+
symbolTable;
|
|
31973
|
+
typeHierarchy;
|
|
31974
|
+
// Cache: file -> IR
|
|
31975
|
+
fileIRs = /* @__PURE__ */ new Map();
|
|
31976
|
+
sourceLines;
|
|
31977
|
+
// Cache: method FQN -> taint info
|
|
31978
|
+
methodTaintInfo = /* @__PURE__ */ new Map();
|
|
31979
|
+
// Cache: `${typeFqn}.${fieldName}` -> field taint info
|
|
31980
|
+
fieldTaintInfo = /* @__PURE__ */ new Map();
|
|
31981
|
+
/** cognium-dev#638 step 4 — `ClassName.staticField` written from a real source. */
|
|
31982
|
+
csharpStaticFieldWriters = /* @__PURE__ */ new Map();
|
|
31983
|
+
// Resolved calls cache
|
|
31984
|
+
resolvedCalls = /* @__PURE__ */ new Map();
|
|
31985
|
+
constructor(symbolTable, typeHierarchy) {
|
|
31986
|
+
this.symbolTable = symbolTable;
|
|
31987
|
+
this.typeHierarchy = typeHierarchy;
|
|
31988
|
+
}
|
|
31989
|
+
/**
|
|
31990
|
+
* Add a file's IR for analysis
|
|
31991
|
+
*/
|
|
31992
|
+
/**
|
|
31993
|
+
* Raw source lines per file. Optional: the JS/TS parameter-to-sink check reads a
|
|
31994
|
+
* def's right-hand side from them (the DFG carries none) to stop at literal-only
|
|
31995
|
+
* values; without them the check still runs, only less precisely.
|
|
31996
|
+
*/
|
|
31997
|
+
setSourceLines(lines) {
|
|
31998
|
+
this.sourceLines = lines;
|
|
31999
|
+
}
|
|
32000
|
+
addFile(filePath, ir) {
|
|
32001
|
+
this.fileIRs.set(filePath, ir);
|
|
32002
|
+
this.symbolTable.addFromIR(ir, filePath);
|
|
32003
|
+
this.typeHierarchy.addFromIR(ir, filePath);
|
|
32004
|
+
this.analyzeMethodTaint(ir, filePath);
|
|
32005
|
+
this.analyzeFieldTaint(ir, filePath);
|
|
32006
|
+
this.analyzeCSharpStaticFieldWriters(ir, filePath);
|
|
32007
|
+
}
|
|
32008
|
+
/**
|
|
32009
|
+
* Resolve a call to its target method(s)
|
|
32010
|
+
*/
|
|
32011
|
+
resolveCall(call, fromFile) {
|
|
32012
|
+
const cacheKey = `${fromFile}:${call.location.line}:${call.method_name}`;
|
|
32013
|
+
if (this.resolvedCalls.has(cacheKey)) {
|
|
32014
|
+
return this.resolvedCalls.get(cacheKey);
|
|
32015
|
+
}
|
|
32016
|
+
let resolved;
|
|
32017
|
+
if (call.receiver) {
|
|
32018
|
+
resolved = this.resolveWithReceiver(call, fromFile);
|
|
32019
|
+
} else {
|
|
32020
|
+
resolved = this.resolveStaticOrLocal(call, fromFile);
|
|
32021
|
+
}
|
|
32022
|
+
if (resolved) {
|
|
32023
|
+
this.resolvedCalls.set(cacheKey, resolved);
|
|
32024
|
+
}
|
|
32025
|
+
return resolved;
|
|
32026
|
+
}
|
|
32027
|
+
/**
|
|
32028
|
+
* Resolve call with a receiver (instance method call)
|
|
32029
|
+
*/
|
|
32030
|
+
resolveWithReceiver(call, fromFile) {
|
|
32031
|
+
const receiver = call.receiver;
|
|
32032
|
+
let receiverType = call.receiver_type_fqn ?? this.inferReceiverType(receiver, fromFile);
|
|
32033
|
+
if (!receiverType && call.receiver_type) {
|
|
32034
|
+
receiverType = this.symbolTable.resolveTypeName(call.receiver_type, fromFile);
|
|
32035
|
+
}
|
|
32036
|
+
if (receiverType) {
|
|
32037
|
+
const methodSymbol = this.symbolTable.findMethod(receiverType, call.method_name);
|
|
32038
|
+
if (methodSymbol) {
|
|
32039
|
+
const parent = methodSymbol.parentType ? this.symbolTable.getSymbol(methodSymbol.parentType) : void 0;
|
|
32040
|
+
if (parent && parent.kind === "interface") {
|
|
32041
|
+
const candidates2 = this.findPolymorphicCandidates(receiverType, call.method_name);
|
|
32042
|
+
if (candidates2.length > 0) {
|
|
32043
|
+
const primary = candidates2[0];
|
|
32044
|
+
return {
|
|
32045
|
+
call,
|
|
32046
|
+
sourceFile: fromFile,
|
|
32047
|
+
targetFile: primary.file,
|
|
32048
|
+
targetMethod: primary.fqn,
|
|
32049
|
+
targetClass: primary.parentType || receiverType,
|
|
32050
|
+
resolution: "polymorphic",
|
|
32051
|
+
candidates: candidates2.map((c) => c.fqn)
|
|
32052
|
+
};
|
|
32053
|
+
}
|
|
32054
|
+
}
|
|
32055
|
+
return {
|
|
32056
|
+
call,
|
|
32057
|
+
sourceFile: fromFile,
|
|
32058
|
+
targetFile: methodSymbol.file,
|
|
32059
|
+
targetMethod: methodSymbol.fqn,
|
|
32060
|
+
targetClass: methodSymbol.parentType || receiverType,
|
|
32061
|
+
resolution: "exact"
|
|
32062
|
+
};
|
|
32063
|
+
}
|
|
32064
|
+
const candidates = this.findPolymorphicCandidates(receiverType, call.method_name);
|
|
32065
|
+
if (candidates.length > 0) {
|
|
32066
|
+
const primary = candidates[0];
|
|
32067
|
+
return {
|
|
32068
|
+
call,
|
|
32069
|
+
sourceFile: fromFile,
|
|
32070
|
+
targetFile: primary.file,
|
|
32071
|
+
targetMethod: primary.fqn,
|
|
32072
|
+
targetClass: primary.parentType || receiverType,
|
|
32073
|
+
resolution: "polymorphic",
|
|
32074
|
+
candidates: candidates.map((c) => c.fqn)
|
|
32075
|
+
};
|
|
32076
|
+
}
|
|
32077
|
+
}
|
|
32078
|
+
const lang = this.fileIRs.get(fromFile)?.meta.language;
|
|
32079
|
+
if (receiverType ? isJdkType(receiverType, lang) : isJdkClassReceiver(receiver, lang)) return void 0;
|
|
32080
|
+
if (!receiverType && (lang === "javascript" || lang === "typescript")) {
|
|
32081
|
+
const byName = this.resolveByMethodName(call, fromFile);
|
|
32082
|
+
if (byName && byName.targetClass === "<module>" && !this.isImportBinding(fromFile, receiver)) return void 0;
|
|
32083
|
+
return byName;
|
|
32084
|
+
}
|
|
32085
|
+
return this.resolveByMethodName(call, fromFile);
|
|
32086
|
+
}
|
|
32087
|
+
/** Is `name` bound by an import in `file` (alias, default or namespace import)? */
|
|
32088
|
+
isImportBinding(file, name2) {
|
|
32089
|
+
const ir = this.fileIRs.get(file);
|
|
32090
|
+
return (ir?.imports ?? []).some((i2) => (i2.alias ?? i2.imported_name) === name2);
|
|
32091
|
+
}
|
|
32092
|
+
/**
|
|
32093
|
+
* Resolve static or local method call
|
|
32094
|
+
*/
|
|
32095
|
+
resolveStaticOrLocal(call, fromFile) {
|
|
32096
|
+
const ir = this.fileIRs.get(fromFile);
|
|
32097
|
+
if (ir) {
|
|
32098
|
+
for (const type of ir.types) {
|
|
32099
|
+
const pkg = type.package || ir.meta.package || "";
|
|
32100
|
+
const typeFqn2 = pkg ? `${pkg}.${type.name}` : type.name;
|
|
32101
|
+
for (const method of type.methods) {
|
|
32102
|
+
if (method.name === call.method_name) {
|
|
32103
|
+
return {
|
|
32104
|
+
call,
|
|
32105
|
+
sourceFile: fromFile,
|
|
32106
|
+
targetFile: fromFile,
|
|
32107
|
+
targetMethod: `${typeFqn2}.${method.name}`,
|
|
32108
|
+
targetClass: typeFqn2,
|
|
32109
|
+
resolution: "exact"
|
|
32110
|
+
};
|
|
32111
|
+
}
|
|
32112
|
+
}
|
|
32113
|
+
}
|
|
32114
|
+
}
|
|
32115
|
+
return this.resolveByMethodName(call, fromFile);
|
|
32116
|
+
}
|
|
32117
|
+
/**
|
|
32118
|
+
* Resolve by searching all known methods
|
|
32119
|
+
*/
|
|
32120
|
+
resolveByMethodName(call, fromFile) {
|
|
32121
|
+
const possibleFqns = this.symbolTable.getPossibleFqns(call.method_name);
|
|
32122
|
+
for (const fqn of possibleFqns) {
|
|
32123
|
+
const symbol = this.symbolTable.getSymbol(fqn);
|
|
32124
|
+
if (symbol && symbol.kind === "method") {
|
|
32125
|
+
return {
|
|
32126
|
+
call,
|
|
32127
|
+
sourceFile: fromFile,
|
|
32128
|
+
targetFile: symbol.file,
|
|
32129
|
+
targetMethod: symbol.fqn,
|
|
32130
|
+
targetClass: symbol.parentType || "",
|
|
32131
|
+
resolution: "inferred"
|
|
32132
|
+
};
|
|
32133
|
+
}
|
|
32134
|
+
}
|
|
32135
|
+
return void 0;
|
|
32136
|
+
}
|
|
32137
|
+
/**
|
|
32138
|
+
* Infer the type of a receiver variable
|
|
32139
|
+
*/
|
|
32140
|
+
inferReceiverType(receiver, fromFile) {
|
|
32141
|
+
const directType = this.symbolTable.resolveTypeName(receiver, fromFile);
|
|
32142
|
+
if (directType) return directType;
|
|
32143
|
+
const newExpr = /^new\s+([A-Za-z_][\w.$]*)\s*(?:<[^>]*>)?\s*\(/.exec(receiver.trim());
|
|
32144
|
+
if (newExpr) {
|
|
32145
|
+
return this.symbolTable.resolveTypeName(newExpr[1], fromFile);
|
|
32146
|
+
}
|
|
32147
|
+
const ir = this.fileIRs.get(fromFile);
|
|
32148
|
+
if (ir) {
|
|
32149
|
+
for (const def of ir.dfg.defs) {
|
|
32150
|
+
if (def.variable === receiver) {
|
|
32151
|
+
const callsAtLine = ir.calls.filter((c) => c.location.line === def.line);
|
|
32152
|
+
for (const call of callsAtLine) {
|
|
32153
|
+
if (call.method_name === receiver || call.method_name === "<init>") {
|
|
32154
|
+
return this.symbolTable.resolveTypeName(receiver, fromFile);
|
|
32155
|
+
}
|
|
32156
|
+
}
|
|
32157
|
+
}
|
|
32158
|
+
}
|
|
32159
|
+
}
|
|
32160
|
+
const commonTypes = {
|
|
32161
|
+
"stmt": "java.sql.Statement",
|
|
32162
|
+
"pstmt": "java.sql.PreparedStatement",
|
|
32163
|
+
"conn": "java.sql.Connection",
|
|
32164
|
+
"rs": "java.sql.ResultSet",
|
|
32165
|
+
"request": "javax.servlet.http.HttpServletRequest",
|
|
32166
|
+
"response": "javax.servlet.http.HttpServletResponse",
|
|
32167
|
+
"req": "javax.servlet.http.HttpServletRequest",
|
|
32168
|
+
"res": "javax.servlet.http.HttpServletResponse",
|
|
32169
|
+
"session": "javax.servlet.http.HttpSession",
|
|
32170
|
+
"runtime": "java.lang.Runtime",
|
|
32171
|
+
"out": "java.io.PrintWriter"
|
|
32172
|
+
};
|
|
32173
|
+
const lowerReceiver = receiver.toLowerCase();
|
|
32174
|
+
const commonEntries = Object.entries(commonTypes);
|
|
32175
|
+
for (const [abbrev, type] of commonEntries) {
|
|
32176
|
+
if (lowerReceiver.includes(abbrev)) {
|
|
32177
|
+
return type;
|
|
32178
|
+
}
|
|
32179
|
+
}
|
|
32180
|
+
return void 0;
|
|
32181
|
+
}
|
|
32182
|
+
/**
|
|
32183
|
+
* Find polymorphic candidates (implementations/subclasses)
|
|
32184
|
+
*/
|
|
32185
|
+
findPolymorphicCandidates(typeName, methodName) {
|
|
32186
|
+
const candidates = [];
|
|
32187
|
+
const implementations = this.typeHierarchy.getAllImplementations(typeName);
|
|
32188
|
+
for (const impl of implementations) {
|
|
32189
|
+
const method = this.symbolTable.findMethod(impl, methodName);
|
|
32190
|
+
if (method) {
|
|
32191
|
+
candidates.push(method);
|
|
32192
|
+
}
|
|
32193
|
+
}
|
|
32194
|
+
const subtypes = this.typeHierarchy.getAllSubtypes(typeName);
|
|
32195
|
+
for (const subtype of subtypes) {
|
|
32196
|
+
const method = this.symbolTable.findMethod(subtype, methodName);
|
|
32197
|
+
if (method) {
|
|
32198
|
+
candidates.push(method);
|
|
32199
|
+
}
|
|
32200
|
+
}
|
|
32201
|
+
return candidates;
|
|
32202
|
+
}
|
|
32203
|
+
/**
|
|
32204
|
+
* Analyze methods for taint propagation characteristics
|
|
32205
|
+
*/
|
|
32206
|
+
analyzeMethodTaint(ir, filePath) {
|
|
32207
|
+
const pkg = ir.meta.package || "";
|
|
32208
|
+
for (const type of ir.types) {
|
|
32209
|
+
const typeFqn2 = pkg ? `${pkg}.${type.name}` : type.name;
|
|
32210
|
+
for (const method of type.methods) {
|
|
32211
|
+
const methodFqn = `${typeFqn2}.${method.name}`;
|
|
32212
|
+
const isSource = this.isMethodTaintSource(method, ir.taint.sources);
|
|
32213
|
+
const taintedParams = this.findTaintedParams(method, ir);
|
|
32214
|
+
const sanitizes = method.annotations.includes("sanitizer") || this.isSanitizerMethod(method.name);
|
|
32215
|
+
const taintInfo = {
|
|
32216
|
+
methodFqn,
|
|
32217
|
+
file: filePath,
|
|
32218
|
+
taintedParams,
|
|
32219
|
+
returnsSource: isSource,
|
|
32220
|
+
sourceType: isSource ? this.getSourceType(method, ir.taint.sources) : void 0,
|
|
32221
|
+
sanitizes,
|
|
32222
|
+
sanitizedTypes: sanitizes ? this.getSanitizedTypes(method.name) : void 0
|
|
32223
|
+
};
|
|
32224
|
+
this.methodTaintInfo.set(methodFqn, taintInfo);
|
|
32225
|
+
}
|
|
32226
|
+
}
|
|
32227
|
+
}
|
|
32228
|
+
/**
|
|
32229
|
+
* Per-file analysis of cross-instance field bindings.
|
|
32230
|
+
*
|
|
32231
|
+
* Records `FieldTaintInfo` entries for fields written by:
|
|
32232
|
+
* 1. `@DataBoundConstructor`-style constructors — surfaced as
|
|
32233
|
+
* `constructor_field` sources by `LanguageSourcesPass`.
|
|
32234
|
+
* 2. Setter methods `set<Field>(<param>)` — assume the canonical
|
|
32235
|
+
* `this.<field> = <param>` body shape, so the setter PARAMETER acts
|
|
32236
|
+
* as the taint conduit at call sites.
|
|
32237
|
+
* 3. `@Autowired` field annotations — the field itself is a framework
|
|
32238
|
+
* injection point; the writer is synthetic (line = field decl).
|
|
32239
|
+
*
|
|
32240
|
+
* The entries are keyed `${typeFqn}.${fieldName}` and consumed by
|
|
32241
|
+
* `findFieldBindingTaintPaths()` to surface flows of the canonical Jenkins
|
|
32242
|
+
* shape: ctor writes field → another class reads instance.field → sink.
|
|
32243
|
+
*/
|
|
32244
|
+
analyzeFieldTaint(ir, filePath) {
|
|
32245
|
+
const pkg = ir.meta.package || "";
|
|
32246
|
+
const ctorFieldRe = /^(\w+)\.(\w+)\(\) returns tainted field '([^']+)' \(from constructor param '([^']+)'\)/;
|
|
32247
|
+
for (const src of ir.taint.sources) {
|
|
32248
|
+
if (src.type !== "constructor_field") continue;
|
|
32249
|
+
const m = ctorFieldRe.exec(src.location);
|
|
32250
|
+
if (!m) continue;
|
|
32251
|
+
const [, className, , fieldName, sourceParam] = m;
|
|
32252
|
+
const typeFqn2 = pkg ? `${pkg}.${className}` : className;
|
|
32253
|
+
const type = ir.types.find((t) => t.name === className);
|
|
32254
|
+
if (!type) continue;
|
|
32255
|
+
const writerMethod = type.methods.find(
|
|
32256
|
+
(mth) => mth.name === className && mth.parameters.some((p) => p.name === sourceParam)
|
|
32257
|
+
) ?? type.methods.find((mth) => mth.parameters.some((p) => p.name === sourceParam));
|
|
32258
|
+
if (!writerMethod) continue;
|
|
32259
|
+
const field = type.fields?.find((f) => f.name === fieldName);
|
|
32260
|
+
const key = `${typeFqn2}.${fieldName}`;
|
|
32261
|
+
const existing = this.fieldTaintInfo.get(key);
|
|
32262
|
+
const writer = {
|
|
32263
|
+
methodFqn: `${typeFqn2}.${writerMethod.name}`,
|
|
32264
|
+
methodName: writerMethod.name,
|
|
32265
|
+
writeLine: writerMethod.start_line,
|
|
32266
|
+
sourceType: "constructor_field",
|
|
32267
|
+
sourceLine: src.line
|
|
32268
|
+
};
|
|
32269
|
+
if (existing) {
|
|
32270
|
+
if (!existing.writers.some((w) => w.methodFqn === writer.methodFqn)) {
|
|
32271
|
+
existing.writers.push(writer);
|
|
32272
|
+
}
|
|
32273
|
+
} else {
|
|
32274
|
+
this.fieldTaintInfo.set(key, {
|
|
32275
|
+
typeFqn: typeFqn2,
|
|
32276
|
+
fieldName,
|
|
32277
|
+
fieldType: field?.type ?? null,
|
|
32278
|
+
file: filePath,
|
|
32279
|
+
writers: [writer]
|
|
32280
|
+
});
|
|
32281
|
+
}
|
|
32282
|
+
}
|
|
32283
|
+
for (const type of ir.types) {
|
|
32284
|
+
const typeFqn2 = pkg ? `${pkg}.${type.name}` : type.name;
|
|
32285
|
+
for (const method of type.methods) {
|
|
32286
|
+
if (!method.name.startsWith("set") || method.name.length <= 3) continue;
|
|
32287
|
+
if (method.parameters.length !== 1) continue;
|
|
32288
|
+
const fieldName = method.name.charAt(3).toLowerCase() + method.name.substring(4);
|
|
32289
|
+
const field = type.fields?.find((f) => f.name === fieldName);
|
|
32290
|
+
if (!field) continue;
|
|
32291
|
+
const key = `${typeFqn2}.${fieldName}`;
|
|
32292
|
+
const writer = {
|
|
32293
|
+
methodFqn: `${typeFqn2}.${method.name}`,
|
|
32294
|
+
methodName: method.name,
|
|
32295
|
+
writeLine: method.start_line,
|
|
32296
|
+
sourceType: "setter_param",
|
|
32297
|
+
sourceLine: method.start_line
|
|
32298
|
+
};
|
|
32299
|
+
const existing = this.fieldTaintInfo.get(key);
|
|
32300
|
+
if (existing) {
|
|
32301
|
+
if (!existing.writers.some((w) => w.methodFqn === writer.methodFqn)) {
|
|
32302
|
+
existing.writers.push(writer);
|
|
32303
|
+
}
|
|
32304
|
+
} else {
|
|
32305
|
+
this.fieldTaintInfo.set(key, {
|
|
32306
|
+
typeFqn: typeFqn2,
|
|
32307
|
+
fieldName,
|
|
32308
|
+
fieldType: field.type ?? null,
|
|
32309
|
+
file: filePath,
|
|
32310
|
+
writers: [writer]
|
|
32311
|
+
});
|
|
32312
|
+
}
|
|
32313
|
+
}
|
|
32314
|
+
}
|
|
32315
|
+
const injectAnnotations = /* @__PURE__ */ new Set(["Autowired", "Inject", "Resource"]);
|
|
32316
|
+
for (const type of ir.types) {
|
|
32317
|
+
const typeFqn2 = pkg ? `${pkg}.${type.name}` : type.name;
|
|
32318
|
+
for (const field of type.fields ?? []) {
|
|
32319
|
+
if (!field.annotations?.some((a) => injectAnnotations.has(a))) continue;
|
|
32320
|
+
const key = `${typeFqn2}.${field.name}`;
|
|
32321
|
+
const writer = {
|
|
32322
|
+
methodFqn: `${typeFqn2}.<injected>`,
|
|
32323
|
+
methodName: "<injected>",
|
|
32324
|
+
writeLine: type.start_line,
|
|
32325
|
+
sourceType: "autowired_field",
|
|
32326
|
+
sourceLine: type.start_line
|
|
32327
|
+
};
|
|
32328
|
+
const existing = this.fieldTaintInfo.get(key);
|
|
32329
|
+
if (existing) {
|
|
32330
|
+
if (!existing.writers.some((w) => w.methodFqn === writer.methodFqn)) {
|
|
32331
|
+
existing.writers.push(writer);
|
|
32332
|
+
}
|
|
32333
|
+
} else {
|
|
32334
|
+
this.fieldTaintInfo.set(key, {
|
|
32335
|
+
typeFqn: typeFqn2,
|
|
32336
|
+
fieldName: field.name,
|
|
32337
|
+
fieldType: field.type ?? null,
|
|
32338
|
+
file: filePath,
|
|
32339
|
+
writers: [writer]
|
|
32340
|
+
});
|
|
32341
|
+
}
|
|
32342
|
+
}
|
|
32343
|
+
}
|
|
32344
|
+
}
|
|
32345
|
+
/**
|
|
32346
|
+
* Check if method is a taint source.
|
|
32347
|
+
*
|
|
32348
|
+
* Excludes synthetic `interprocedural_param` sources — those are per-file
|
|
32349
|
+
* meta-analysis signals saying "this method's parameter MIGHT be tainted
|
|
32350
|
+
* when called with tainted data", not confirmed external inputs. Treating
|
|
32351
|
+
* them as sources for cross-file `returnsSource` would propagate ghost
|
|
32352
|
+
* taint into every callee with typed parameters.
|
|
32353
|
+
*/
|
|
32354
|
+
isMethodTaintSource(method, sources) {
|
|
32355
|
+
const sourceAnnotations = ["RequestParam", "RequestBody", "PathVariable", "QueryParam"];
|
|
32356
|
+
for (const param of method.parameters) {
|
|
32357
|
+
if (param.annotations.some((a) => sourceAnnotations.includes(a))) {
|
|
32358
|
+
return true;
|
|
32359
|
+
}
|
|
32360
|
+
}
|
|
32361
|
+
for (const source of sources) {
|
|
32362
|
+
if (source.type === "interprocedural_param") continue;
|
|
32363
|
+
if (source.line >= method.start_line && source.line <= method.end_line) {
|
|
32364
|
+
return true;
|
|
32365
|
+
}
|
|
32366
|
+
}
|
|
32367
|
+
return false;
|
|
32368
|
+
}
|
|
32369
|
+
/**
|
|
32370
|
+
* Get source type for a method (excluding synthetic interprocedural_param)
|
|
32371
|
+
*/
|
|
32372
|
+
getSourceType(method, sources) {
|
|
32373
|
+
for (const source of sources) {
|
|
32374
|
+
if (source.type === "interprocedural_param") continue;
|
|
32375
|
+
if (source.line >= method.start_line && source.line <= method.end_line) {
|
|
32376
|
+
return source.type;
|
|
32377
|
+
}
|
|
32378
|
+
}
|
|
32379
|
+
return void 0;
|
|
32380
|
+
}
|
|
32381
|
+
/**
|
|
32382
|
+
* Find which parameters propagate taint to a sink within this method.
|
|
32383
|
+
*
|
|
32384
|
+
* Two heuristics, combined:
|
|
32385
|
+
* 1. Annotation-based: params with @RequestParam/@RequestBody/@PathVariable.
|
|
32386
|
+
* 2. Sink-arg matching: if a known sink call in the method body references
|
|
32387
|
+
* a param by name in its arguments, that param propagates taint to a
|
|
32388
|
+
* sink — this is the summary that cross-file chaining needs to link
|
|
32389
|
+
* a caller's tainted argument to a downstream dangerous operation.
|
|
32390
|
+
*/
|
|
32391
|
+
findTaintedParams(method, ir) {
|
|
32392
|
+
const taintedParams = /* @__PURE__ */ new Set();
|
|
32393
|
+
const numParams = method.parameters.length;
|
|
32394
|
+
for (let i2 = 0; i2 < numParams; i2++) {
|
|
32395
|
+
const param = method.parameters[i2];
|
|
32396
|
+
if (param.annotations.some((a) => ["RequestParam", "RequestBody", "PathVariable"].includes(a))) {
|
|
32397
|
+
taintedParams.add(i2);
|
|
32398
|
+
}
|
|
32399
|
+
}
|
|
32400
|
+
const paramNameToIndex = /* @__PURE__ */ new Map();
|
|
32401
|
+
for (let i2 = 0; i2 < numParams; i2++) {
|
|
32402
|
+
const name2 = method.parameters[i2].name;
|
|
32403
|
+
if (name2) paramNameToIndex.set(name2, i2);
|
|
32404
|
+
}
|
|
32405
|
+
const isJs2 = ir.meta.language === "javascript" || ir.meta.language === "typescript";
|
|
32406
|
+
for (const sink of ir.taint.sinks) {
|
|
32407
|
+
if (sink.line < method.start_line || sink.line > method.end_line) continue;
|
|
32408
|
+
const callsAtSink = ir.calls.filter((c) => c.location.line === sink.line && (!isJs2 || !sink.method || this.callMatchesSink(sink, c)));
|
|
32409
|
+
for (const call of callsAtSink) {
|
|
32410
|
+
for (const arg of call.arguments) {
|
|
32411
|
+
if (isJs2 && sink.argPositions && sink.argPositions.length > 0 && !sink.argPositions.includes(arg.position)) continue;
|
|
32412
|
+
const candidates = [];
|
|
32413
|
+
if (arg.variable) candidates.push(arg.variable);
|
|
32414
|
+
if (arg.expression) {
|
|
32415
|
+
for (const [name2] of paramNameToIndex) {
|
|
32416
|
+
const re = new RegExp(`\\b${escapeRegExp(name2)}\\b`);
|
|
32417
|
+
if (re.test(arg.expression)) candidates.push(name2);
|
|
32418
|
+
}
|
|
32419
|
+
}
|
|
32420
|
+
for (const cand of candidates) {
|
|
32421
|
+
const idx = paramNameToIndex.get(cand);
|
|
32422
|
+
if (idx !== void 0) taintedParams.add(idx);
|
|
32423
|
+
}
|
|
32424
|
+
}
|
|
32425
|
+
}
|
|
32426
|
+
}
|
|
32427
|
+
return [...taintedParams].sort((a, b) => a - b);
|
|
32428
|
+
}
|
|
32429
|
+
/**
|
|
32430
|
+
* Check if method name suggests sanitization
|
|
32431
|
+
*/
|
|
32432
|
+
isSanitizerMethod(methodName) {
|
|
32433
|
+
const sanitizerPatterns = [
|
|
32434
|
+
"escape",
|
|
32435
|
+
"encode",
|
|
32436
|
+
"sanitize",
|
|
32437
|
+
"validate",
|
|
32438
|
+
"filter",
|
|
32439
|
+
"htmlEncode",
|
|
32440
|
+
"urlEncode",
|
|
32441
|
+
"prepareStatement"
|
|
32442
|
+
];
|
|
32443
|
+
const lowerName = methodName.toLowerCase();
|
|
32444
|
+
return sanitizerPatterns.some((p) => lowerName.includes(p.toLowerCase()));
|
|
32445
|
+
}
|
|
32446
|
+
/**
|
|
32447
|
+
* Get types sanitized by a method
|
|
32448
|
+
*/
|
|
32449
|
+
getSanitizedTypes(methodName) {
|
|
32450
|
+
const lowerName = methodName.toLowerCase();
|
|
32451
|
+
const types = [];
|
|
32452
|
+
if (lowerName.includes("html") || lowerName.includes("xss")) {
|
|
32453
|
+
types.push("xss");
|
|
32454
|
+
}
|
|
32455
|
+
if (lowerName.includes("sql") || lowerName.includes("prepare")) {
|
|
32456
|
+
types.push("sql_injection");
|
|
32457
|
+
}
|
|
32458
|
+
if (lowerName.includes("url")) {
|
|
32459
|
+
types.push("ssrf", "path_traversal");
|
|
32460
|
+
}
|
|
32461
|
+
if (lowerName.includes("command") || lowerName.includes("shell")) {
|
|
32462
|
+
types.push("command_injection");
|
|
32463
|
+
}
|
|
32464
|
+
return types.length > 0 ? types : ["unknown"];
|
|
32465
|
+
}
|
|
32466
|
+
/**
|
|
32467
|
+
* Find all callers of a method across the project
|
|
32468
|
+
*/
|
|
32469
|
+
findCallers(methodFqn) {
|
|
32470
|
+
const callers = [];
|
|
32471
|
+
for (const [filePath, ir] of this.fileIRs) {
|
|
32472
|
+
for (const call of ir.calls) {
|
|
32473
|
+
const resolved = this.resolveCall(call, filePath);
|
|
32474
|
+
if (resolved && resolved.targetMethod === methodFqn) {
|
|
32475
|
+
callers.push(resolved);
|
|
32476
|
+
}
|
|
32477
|
+
}
|
|
32478
|
+
}
|
|
32479
|
+
return callers;
|
|
32480
|
+
}
|
|
32481
|
+
/**
|
|
32482
|
+
* Find cross-file taint flows
|
|
32483
|
+
*/
|
|
32484
|
+
/**
|
|
32485
|
+
* Optional wall-clock deadline for the three project-wide walks
|
|
32486
|
+
* (cognium-dev#366). Returns true once the caller's budget is spent.
|
|
32487
|
+
*
|
|
32488
|
+
* `CrossFilePass` already had a budget, but it was only evaluated BETWEEN
|
|
32489
|
+
* phases, so a single phase ran unbounded and the documented "bounded"
|
|
32490
|
+
* contract did not hold — which is what makes a large multi-module repo look
|
|
32491
|
+
* like a sync hang to a consumer whose own `Promise.race` timeout cannot
|
|
32492
|
+
* interrupt synchronous work. These walks are the O(F·T·M) ones called out
|
|
32493
|
+
* at the top of this file, so the check goes in their OUTER per-file loops:
|
|
32494
|
+
* frequent enough to bound the work, cheap enough not to matter (one
|
|
32495
|
+
* `Date.now()` per file).
|
|
32496
|
+
*
|
|
32497
|
+
* When the deadline fires the walk returns what it has found so far, which
|
|
32498
|
+
* is the pre-existing `budgetExceeded` semantic — partial results, kept.
|
|
32499
|
+
*/
|
|
32500
|
+
findCrossFileTaintFlows(deadline) {
|
|
32501
|
+
const flows = [];
|
|
32502
|
+
const seen = /* @__PURE__ */ new Set();
|
|
32503
|
+
for (const [filePath, ir] of this.fileIRs) {
|
|
32504
|
+
if (deadline?.()) break;
|
|
32505
|
+
for (const source of ir.taint.sources) {
|
|
32506
|
+
if (source.type === "interprocedural_param") continue;
|
|
32507
|
+
const sourceVar = source.variable ?? this.getLocalDefVarAt(ir, source.line);
|
|
32508
|
+
const reachable = sourceVar ? this.collectTaintReachable(ir, sourceVar, source.line, filePath) : void 0;
|
|
32509
|
+
for (const call of ir.calls) {
|
|
32510
|
+
if (call.location.line < source.line) continue;
|
|
32511
|
+
if (!reachable && call.location.line !== source.line) continue;
|
|
32512
|
+
const resolved = this.resolveCall(call, filePath);
|
|
32513
|
+
if (!resolved || resolved.targetFile === filePath) continue;
|
|
32514
|
+
let carriedPositions;
|
|
32515
|
+
if (reachable) {
|
|
32516
|
+
let matchedName;
|
|
32517
|
+
for (const arg of call.arguments) {
|
|
32518
|
+
if (arg.variable && reachable.names.has(arg.variable)) {
|
|
32519
|
+
matchedName = arg.variable;
|
|
32520
|
+
break;
|
|
32521
|
+
}
|
|
32522
|
+
if (arg.expression) {
|
|
32523
|
+
for (const v of reachable.names) {
|
|
32524
|
+
if (new RegExp(`\\b${escapeRegExp(v)}\\b`).test(arg.expression)) {
|
|
32525
|
+
matchedName = v;
|
|
32526
|
+
break;
|
|
32527
|
+
}
|
|
32528
|
+
}
|
|
32529
|
+
if (matchedName) break;
|
|
32530
|
+
}
|
|
32531
|
+
}
|
|
32532
|
+
if (!matchedName) continue;
|
|
32533
|
+
const names = [...reachable.names];
|
|
32534
|
+
carriedPositions = call.arguments.flatMap((arg, i2) => arg.variable && reachable.names.has(arg.variable) || names.some((v) => arg.expression && new RegExp(`\\b${escapeRegExp(v)}\\b`).test(arg.expression)) ? [i2] : []);
|
|
32535
|
+
if (this.taintClobbered(ir, call.location.line, matchedName, reachable.defIds)) {
|
|
32536
|
+
continue;
|
|
32537
|
+
}
|
|
32538
|
+
}
|
|
32539
|
+
const startIR = this.fileIRs.get(resolved.targetFile);
|
|
32540
|
+
const terminals = startIR?.meta.language === "csharp" ? this.csharpChainTerminals(
|
|
32541
|
+
resolved.targetFile,
|
|
32542
|
+
resolved.targetMethod,
|
|
32543
|
+
carriedPositions ?? call.arguments.map((_, i2) => i2),
|
|
32544
|
+
0,
|
|
32545
|
+
/* @__PURE__ */ new Set()
|
|
32546
|
+
) : [{
|
|
32547
|
+
file: resolved.targetFile,
|
|
32548
|
+
method: resolved.targetMethod,
|
|
32549
|
+
positions: carriedPositions ?? call.arguments.map((_, i2) => i2)
|
|
32550
|
+
}];
|
|
32551
|
+
for (const term of terminals) {
|
|
32552
|
+
const targetIR = this.fileIRs.get(term.file);
|
|
32553
|
+
if (!targetIR || targetIR.taint.sinks.length === 0) continue;
|
|
32554
|
+
const shortName = term.method.split(".").pop() ?? term.method;
|
|
32555
|
+
let targetMethod;
|
|
32556
|
+
for (const type of targetIR.types) {
|
|
32557
|
+
const m = type.methods.find((m2) => m2.name === shortName);
|
|
32558
|
+
if (m) {
|
|
32559
|
+
targetMethod = m;
|
|
32560
|
+
break;
|
|
32561
|
+
}
|
|
32562
|
+
}
|
|
32563
|
+
if (!targetMethod) continue;
|
|
32564
|
+
const targetIdx = this.getFileIndex(targetIR);
|
|
32565
|
+
const sinksInMethod = targetIdx.sinksByMethod.get(targetMethod) ?? [];
|
|
32566
|
+
if (sinksInMethod.length === 0) continue;
|
|
32567
|
+
for (const sink of sinksInMethod) {
|
|
32568
|
+
if ((targetIR.meta.language === "javascript" || targetIR.meta.language === "typescript") && !this.jsParamReachesSinkArgs(targetIR, targetMethod, targetMethod.parameters.map((_, i2) => i2), sink, term.file)) continue;
|
|
32569
|
+
const key = `${filePath}:${source.line}\u2192${term.file}:${sink.line}`;
|
|
32570
|
+
if (seen.has(key)) continue;
|
|
32571
|
+
seen.add(key);
|
|
32572
|
+
flows.push({
|
|
32573
|
+
sourceFile: filePath,
|
|
32574
|
+
sourceLine: source.line,
|
|
32575
|
+
sourceType: source.type,
|
|
32576
|
+
targetFile: term.file,
|
|
32577
|
+
targetLine: sink.line,
|
|
32578
|
+
// actual sink line in target file
|
|
32579
|
+
targetMethod: term.method,
|
|
32580
|
+
flowType: "call_arg",
|
|
32581
|
+
taintedArgPositions: term.positions,
|
|
32582
|
+
callLine: call.location.line
|
|
32583
|
+
});
|
|
32584
|
+
}
|
|
32585
|
+
}
|
|
32586
|
+
}
|
|
32587
|
+
}
|
|
32588
|
+
}
|
|
32589
|
+
return flows;
|
|
32590
|
+
}
|
|
32591
|
+
/**
|
|
32592
|
+
* JS/TS: does a value in one of the parameters at `positions` of `method` reach the
|
|
32593
|
+
* arguments of `sink`? Names derived from those parameters by def-use chains are matched
|
|
32594
|
+
* against the sink call's dangerous arguments (`argPositions`, else all). Conservative:
|
|
32595
|
+
* true when the sink call or the parameter defs cannot be found, so it only drops a
|
|
32596
|
+
* flow whose sink call is present and mentions none of those names.
|
|
32597
|
+
*/
|
|
32598
|
+
jsParamReachesSinkArgs(ir, method, positions, sink, file) {
|
|
32599
|
+
const params = positions.map((i2) => method.parameters[i2]?.name).filter((n) => !!n);
|
|
32600
|
+
if (params.length === 0) return true;
|
|
32601
|
+
const calls = (this.getFileIndex(ir).callsByLine.get(sink.line) ?? []).filter((c) => c.method_name === sink.method && (sink.callColumn === void 0 || c.location.column === void 0 || c.location.column === sink.callColumn));
|
|
32602
|
+
if (calls.length === 0) return true;
|
|
32603
|
+
const seeds = ir.dfg.defs.filter((d) => params.includes(d.variable) && d.line >= method.start_line && d.line <= method.end_line).map((d) => d.id);
|
|
32604
|
+
const names = new Set(params);
|
|
32605
|
+
if (seeds.length > 0) {
|
|
32606
|
+
const lines = this.sourceLines?.get(file);
|
|
32607
|
+
const defById = new Map(ir.dfg.defs.map((d) => [d.id, d]));
|
|
32608
|
+
const visited = new Set(seeds);
|
|
32609
|
+
const frontier = [...seeds];
|
|
32610
|
+
while (frontier.length > 0) {
|
|
32611
|
+
const cur = frontier.shift();
|
|
32612
|
+
for (const ch of ir.dfg.chains ?? []) {
|
|
32613
|
+
if (ch.from_def !== cur || visited.has(ch.to_def)) continue;
|
|
32614
|
+
visited.add(ch.to_def);
|
|
32615
|
+
const d = defById.get(ch.to_def);
|
|
32616
|
+
if (!d || lines && literalOnlyAssignment(lines[d.line - 1] ?? "", d.variable)) continue;
|
|
32617
|
+
if (d.variable) names.add(d.variable);
|
|
32618
|
+
frontier.push(ch.to_def);
|
|
32619
|
+
}
|
|
32620
|
+
}
|
|
32621
|
+
}
|
|
32622
|
+
const res = [...names].map((n) => new RegExp(`(?<![\\w$.])${escapeRegExp(n)}(?![\\w$])`));
|
|
32623
|
+
return calls.some((c) => c.arguments.filter((a) => !sink.argPositions || sink.argPositions.length === 0 || sink.argPositions.includes(a.position)).some((a) => a.variable && names.has(a.variable) || res.some((re) => re.test(a.expression ?? ""))));
|
|
32624
|
+
}
|
|
32625
|
+
/** Sink call on this line (method + optional column), same filter as `jsParamReachesSinkArgs`. */
|
|
32626
|
+
callMatchesSink(sink, call) {
|
|
32627
|
+
return call.method_name === sink.method && (sink.callColumn === void 0 || call.location?.column === void 0 || call.location.column === sink.callColumn);
|
|
32628
|
+
}
|
|
32629
|
+
/** Arguments the sink marks dangerous (`argPositions`, else all). */
|
|
32630
|
+
dangerousSinkArguments(sink, call) {
|
|
32631
|
+
const args2 = call.arguments ?? [];
|
|
32632
|
+
if (!sink.argPositions || sink.argPositions.length === 0) return args2;
|
|
32633
|
+
return args2.filter((a) => sink.argPositions.includes(a.position));
|
|
32634
|
+
}
|
|
32635
|
+
/**
|
|
32636
|
+
* C# (cognium-dev#637): the methods a value ends in after a chain of pure
|
|
32637
|
+
* forwarders. A callee that holds a sink is its own terminal. One that holds no
|
|
32638
|
+
* sink only passes the tainted parameter, as a bare argument, to calls that each
|
|
32639
|
+
* resolve exactly to a method in another file; those are followed (depth <= 4,
|
|
32640
|
+
* a visited set stops loops). Anything else — a transformed argument, an
|
|
32641
|
+
* unresolved call, a forwarder with no onward call — contributes no terminal.
|
|
32642
|
+
*/
|
|
32643
|
+
csharpChainTerminals(file, methodFqn, positions, depth, visited) {
|
|
32644
|
+
const ir = this.fileIRs.get(file);
|
|
32645
|
+
if (!ir) return [];
|
|
32646
|
+
const shortName = methodFqn.split(".").pop() ?? methodFqn;
|
|
32647
|
+
const method = ir.types.flatMap((t) => t.methods).find((m) => m.name === shortName);
|
|
32648
|
+
if (!method) return [];
|
|
32649
|
+
const idx = this.getFileIndex(ir);
|
|
32650
|
+
const here = [{ file, method: methodFqn, positions }];
|
|
32651
|
+
if ((idx.sinksByMethod.get(method) ?? []).length > 0) return here;
|
|
32652
|
+
if (depth >= 4) return [];
|
|
32653
|
+
const key = `${file}#${methodFqn}`;
|
|
32654
|
+
if (visited.has(key)) return [];
|
|
32655
|
+
visited.add(key);
|
|
32656
|
+
const names = positions.map((i2) => method.parameters[i2]?.name).filter((n) => !!n);
|
|
32657
|
+
if (names.length === 0) return [];
|
|
32658
|
+
const out2 = [];
|
|
32659
|
+
for (const call of idx.callsByMethod.get(method) ?? []) {
|
|
32660
|
+
const carried = call.arguments.flatMap((a, i2) => names.some((n) => new RegExp(`(?<![\\w.])${escapeRegExp(n)}(?!\\w)`).test(a.expression ?? "")) ? [i2] : []);
|
|
32661
|
+
if (carried.length === 0) continue;
|
|
32662
|
+
if (!carried.every((i2) => names.includes((call.arguments[i2].expression ?? "").trim()))) continue;
|
|
32663
|
+
const r = this.resolveCall(call, file);
|
|
32664
|
+
if (!r || r.resolution !== "exact" || r.targetFile === file) continue;
|
|
32665
|
+
out2.push(...this.csharpChainTerminals(r.targetFile, r.targetMethod, carried, depth + 1, visited));
|
|
32666
|
+
}
|
|
32667
|
+
visited.delete(key);
|
|
32668
|
+
return out2;
|
|
32669
|
+
}
|
|
32670
|
+
/**
|
|
32671
|
+
* Find inter-procedural taint chains spanning multiple files / call sites.
|
|
32672
|
+
*
|
|
32673
|
+
* Bridges the gap that `findCrossFileTaintFlows()` cannot cover: a real
|
|
32674
|
+
* source lives in callee A, its return value bubbles up to caller C as a
|
|
32675
|
+
* tainted local, and C then passes that local to callee B which contains
|
|
32676
|
+
* the actual dangerous sink. Neither A nor C alone has a co-located
|
|
32677
|
+
* source-and-sink, but the chain A → C → B is a real vulnerability.
|
|
32678
|
+
*
|
|
32679
|
+
* Algorithm (per caller method M):
|
|
32680
|
+
* 1. Seed `tainted` with real (non-`interprocedural_param`) sources in M.
|
|
32681
|
+
* 2. Walk calls in M in line order:
|
|
32682
|
+
* a. If callee has `returnsSource = true` and is not a sanitizer,
|
|
32683
|
+
* mark every `local` DFG def at this line as tainted, anchored to
|
|
32684
|
+
* the callee's source.
|
|
32685
|
+
* b. For each tainted arg in this call, if the callee's
|
|
32686
|
+
* `taintedParams` covers that position, emit one
|
|
32687
|
+
* `InterproceduralTaintPath` per sink inside the callee body.
|
|
32688
|
+
*/
|
|
32689
|
+
findInterproceduralTaintPaths(deadline) {
|
|
32690
|
+
const paths = [];
|
|
32691
|
+
const seen = /* @__PURE__ */ new Set();
|
|
32692
|
+
const methodIndex = this.buildMethodIndex();
|
|
32693
|
+
for (const [callerFile, callerIR] of this.fileIRs) {
|
|
32694
|
+
if (deadline?.()) break;
|
|
32695
|
+
const callerIdx = this.getFileIndex(callerIR);
|
|
32696
|
+
for (const type of callerIR.types) {
|
|
32697
|
+
for (const method of type.methods) {
|
|
32698
|
+
const tainted = /* @__PURE__ */ new Map();
|
|
32699
|
+
for (const src of callerIR.taint.sources) {
|
|
32700
|
+
if (src.type === "interprocedural_param") continue;
|
|
32701
|
+
if (src.line < method.start_line || src.line > method.end_line) continue;
|
|
32702
|
+
if (!src.variable) continue;
|
|
32703
|
+
tainted.set(src.variable, {
|
|
32704
|
+
file: callerFile,
|
|
32705
|
+
line: src.line,
|
|
32706
|
+
type: src.type,
|
|
32707
|
+
hopChain: [{ file: callerFile, line: src.line, method: method.name, kind: "source" }],
|
|
32708
|
+
defIds: this.collectTaintReachable(callerIR, src.variable, src.line, callerFile).defIds
|
|
32709
|
+
});
|
|
32710
|
+
}
|
|
32711
|
+
const callsInMethod = callerIdx.callsByMethod.get(method) ?? [];
|
|
32712
|
+
for (const call of callsInMethod) {
|
|
32713
|
+
const resolved = this.resolveCall(call, callerFile);
|
|
32714
|
+
if (!resolved) continue;
|
|
32715
|
+
const callee = this.methodTaintInfo.get(resolved.targetMethod);
|
|
32716
|
+
if (!callee) continue;
|
|
32717
|
+
const calleeNode0 = methodIndex.get(resolved.targetMethod);
|
|
32718
|
+
if (callee.returnsSource && !callee.sanitizes && callee.sourceType && !(calleeNode0 && this.sourcesOnlySteerBranches(callee.file, calleeNode0.ir, calleeNode0.method))) {
|
|
32719
|
+
const calleeNode = calleeNode0;
|
|
32720
|
+
const calleeSourceLine = calleeNode ? this.findRealSourceLineInMethod(calleeNode.ir, calleeNode.method) : void 0;
|
|
32721
|
+
const sourceLine = calleeSourceLine ?? call.location.line;
|
|
32722
|
+
const sourceFile = callee.file;
|
|
32723
|
+
const sourceType = callee.sourceType;
|
|
32724
|
+
const defsAtLine = (callerIdx.defsByLine.get(call.location.line) ?? []).filter((d) => d.kind === "local");
|
|
32725
|
+
for (const def of defsAtLine) {
|
|
32726
|
+
if (!def.variable) continue;
|
|
32727
|
+
const baseChain = [
|
|
32728
|
+
{ file: sourceFile, line: sourceLine, method: resolved.targetMethod, kind: "source" },
|
|
32729
|
+
{ file: callerFile, line: call.location.line, method: method.name, kind: "wrapper_return" }
|
|
32730
|
+
];
|
|
32731
|
+
tainted.set(def.variable, {
|
|
32732
|
+
file: sourceFile,
|
|
32733
|
+
line: sourceLine,
|
|
32734
|
+
type: sourceType,
|
|
32735
|
+
hopChain: baseChain,
|
|
32736
|
+
defIds: this.forwardReachableDefs(callerIR, [def.id], callerFile)
|
|
32737
|
+
});
|
|
32738
|
+
}
|
|
32739
|
+
}
|
|
32740
|
+
if (callee.taintedParams.length === 0 || callee.sanitizes) continue;
|
|
32741
|
+
for (let argIdx = 0; argIdx < call.arguments.length; argIdx++) {
|
|
32742
|
+
if (!callee.taintedParams.includes(argIdx)) continue;
|
|
32743
|
+
const arg = call.arguments[argIdx];
|
|
32744
|
+
const matched = this.matchTaintedArg(
|
|
32745
|
+
arg,
|
|
32746
|
+
tainted,
|
|
32747
|
+
callerIR.meta.language === "javascript" || callerIR.meta.language === "typescript"
|
|
32748
|
+
);
|
|
32749
|
+
if (!matched) continue;
|
|
32750
|
+
if (this.taintClobbered(callerIR, call.location.line, matched.var, matched.origin.defIds)) {
|
|
32751
|
+
continue;
|
|
32752
|
+
}
|
|
32753
|
+
const calleeNode = methodIndex.get(resolved.targetMethod);
|
|
32754
|
+
if (!calleeNode) continue;
|
|
32755
|
+
const calleeIdx = this.getFileIndex(calleeNode.ir);
|
|
32756
|
+
const sinksInCallee = calleeIdx.sinksByMethod.get(calleeNode.method) ?? [];
|
|
32757
|
+
for (const sink of sinksInCallee) {
|
|
32758
|
+
const key = `${matched.origin.file}:${matched.origin.line}\u2192${callee.file}:${sink.line}`;
|
|
32759
|
+
if (seen.has(key)) continue;
|
|
32760
|
+
seen.add(key);
|
|
32761
|
+
const hops = [
|
|
32762
|
+
...matched.origin.hopChain,
|
|
32763
|
+
{ file: callerFile, line: call.location.line, method: method.name, kind: "sink_call" },
|
|
32764
|
+
{ file: callee.file, line: sink.line, method: resolved.targetMethod, kind: "sink" }
|
|
32765
|
+
];
|
|
32766
|
+
const decay = Math.max(0.3, Math.pow(0.85, Math.max(hops.length - 1, 0)));
|
|
32767
|
+
paths.push({
|
|
32768
|
+
source: {
|
|
32769
|
+
file: matched.origin.file,
|
|
32770
|
+
line: matched.origin.line,
|
|
32771
|
+
type: matched.origin.type
|
|
32772
|
+
},
|
|
32773
|
+
sink: {
|
|
32774
|
+
file: callee.file,
|
|
32775
|
+
line: sink.line,
|
|
32776
|
+
type: sink.type,
|
|
32777
|
+
cwe: sink.cwe
|
|
32778
|
+
},
|
|
32779
|
+
hops,
|
|
32780
|
+
confidence: decay,
|
|
32781
|
+
calleeArgPositions: [argIdx]
|
|
32782
|
+
});
|
|
32783
|
+
}
|
|
32784
|
+
}
|
|
32785
|
+
}
|
|
32786
|
+
if (tainted.size > 0) {
|
|
32787
|
+
this.extendInterproceduralTaintedVars(callerIR, callerFile, tainted);
|
|
32788
|
+
}
|
|
32789
|
+
if (tainted.size > 0) {
|
|
32790
|
+
const sinksInCaller = callerIdx.sinksByMethod.get(method) ?? [];
|
|
32791
|
+
const isJs2 = callerIR.meta.language === "javascript" || callerIR.meta.language === "typescript";
|
|
32792
|
+
for (const sink of sinksInCaller) {
|
|
32793
|
+
const callsAtSink = (callerIdx.callsByLine.get(sink.line) ?? []).filter((c) => this.callMatchesSink(sink, c));
|
|
32794
|
+
for (const sinkCall of callsAtSink) {
|
|
32795
|
+
for (const arg of this.dangerousSinkArguments(sink, sinkCall)) {
|
|
32796
|
+
const matched = this.matchTaintedArg(arg, tainted, isJs2);
|
|
32797
|
+
if (!matched) continue;
|
|
32798
|
+
const key = `${matched.origin.file}:${matched.origin.line}\u2192${callerFile}:${sink.line}`;
|
|
32799
|
+
if (seen.has(key)) continue;
|
|
32800
|
+
seen.add(key);
|
|
32801
|
+
const hops = [
|
|
32802
|
+
...matched.origin.hopChain,
|
|
32803
|
+
{ file: callerFile, line: sink.line, method: method.name, kind: "sink" }
|
|
32804
|
+
];
|
|
32805
|
+
const decay = Math.max(0.3, Math.pow(0.85, Math.max(hops.length - 1, 0)));
|
|
32806
|
+
paths.push({
|
|
32807
|
+
source: {
|
|
32808
|
+
file: matched.origin.file,
|
|
32809
|
+
line: matched.origin.line,
|
|
32810
|
+
type: matched.origin.type
|
|
32811
|
+
},
|
|
32812
|
+
sink: {
|
|
32813
|
+
file: callerFile,
|
|
32814
|
+
line: sink.line,
|
|
32815
|
+
type: sink.type,
|
|
32816
|
+
cwe: sink.cwe
|
|
32817
|
+
},
|
|
32818
|
+
hops,
|
|
32819
|
+
confidence: decay
|
|
32820
|
+
});
|
|
32821
|
+
}
|
|
32822
|
+
}
|
|
32823
|
+
}
|
|
32824
|
+
}
|
|
32825
|
+
}
|
|
32826
|
+
}
|
|
32827
|
+
}
|
|
32828
|
+
return paths;
|
|
32829
|
+
}
|
|
32830
|
+
/**
|
|
32831
|
+
* Find cross-instance field-binding taint paths.
|
|
32832
|
+
*
|
|
32833
|
+
* Closes the canonical Jenkins / framework-DI shape that
|
|
32834
|
+
* `findInterproceduralTaintPaths()` cannot cover because the "source" lives
|
|
32835
|
+
* on an aliased object's field, not in a callee return:
|
|
32836
|
+
*
|
|
32837
|
+
* File A: class C { @DataBoundConstructor C(p) { this.f = p; } }
|
|
32838
|
+
* File B: class E { final C step; E(C step){ this.step = step; }
|
|
32839
|
+
* m() { String x = step.f; sink(x); } }
|
|
32840
|
+
*
|
|
32841
|
+
* Algorithm (per caller method M in file B):
|
|
32842
|
+
* 1. Seed `tainted` with sources inside M (mirrors findInterproc step 1).
|
|
32843
|
+
* 2. Scan M's local-def DFG entries for expressions of shape
|
|
32844
|
+
* `<receiver>.<field>` where receiver's declared type owns `<field>`
|
|
32845
|
+
* in the FieldTaintInfo cache. Mark the LHS local as tainted, anchor
|
|
32846
|
+
* its origin to the field-binding writer (e.g. the ctor in file A).
|
|
32847
|
+
* 3. After seeding, walk caller-body sinks the same way
|
|
32848
|
+
* `findInterproceduralTaintPaths()` step 2c does, and also forward
|
|
32849
|
+
* tainted locals into cross-file callees whose `taintedParams` mark
|
|
32850
|
+
* the arg position as sink-propagating.
|
|
32851
|
+
*/
|
|
32852
|
+
findFieldBindingTaintPaths(deadline) {
|
|
32853
|
+
const paths = [];
|
|
32854
|
+
const seen = /* @__PURE__ */ new Set();
|
|
32855
|
+
if (this.fieldTaintInfo.size === 0) return paths;
|
|
32856
|
+
const fieldExprRe = /^(\w+)\.(\w+)$/;
|
|
32857
|
+
const methodIndex = this.buildMethodIndex();
|
|
32858
|
+
for (const [callerFile, callerIR] of this.fileIRs) {
|
|
32859
|
+
if (deadline?.()) break;
|
|
32860
|
+
const callerIdx = this.getFileIndex(callerIR);
|
|
32861
|
+
for (const type of callerIR.types) {
|
|
32862
|
+
const callerTypeFqn = callerIR.meta.package ? `${callerIR.meta.package}.${type.name}` : type.name;
|
|
32863
|
+
for (const method of type.methods) {
|
|
32864
|
+
const tainted = /* @__PURE__ */ new Map();
|
|
32865
|
+
for (const src of callerIR.taint.sources) {
|
|
32866
|
+
if (src.type === "interprocedural_param") continue;
|
|
32867
|
+
if (src.line < method.start_line || src.line > method.end_line) continue;
|
|
32868
|
+
if (!src.variable) continue;
|
|
32869
|
+
tainted.set(src.variable, {
|
|
32870
|
+
file: callerFile,
|
|
32871
|
+
line: src.line,
|
|
32872
|
+
type: src.type,
|
|
32873
|
+
hopChain: [{ file: callerFile, line: src.line, method: method.name, kind: "source" }]
|
|
32874
|
+
});
|
|
32875
|
+
}
|
|
32876
|
+
const defsInMethod = (callerIdx.defsByMethod.get(method) ?? []).filter(
|
|
32877
|
+
(d) => d.kind === "local" && !!d.variable
|
|
32878
|
+
);
|
|
32879
|
+
for (const def of defsInMethod) {
|
|
32880
|
+
const usesAtLine = callerIdx.usesByLine.get(def.line) ?? [];
|
|
32881
|
+
if (usesAtLine.length < 2) continue;
|
|
32882
|
+
let receiver = null;
|
|
32883
|
+
let fieldName = null;
|
|
32884
|
+
if (def.expression) {
|
|
32885
|
+
const exprMatch = fieldExprRe.exec(def.expression.trim());
|
|
32886
|
+
if (exprMatch) {
|
|
32887
|
+
receiver = exprMatch[1];
|
|
32888
|
+
fieldName = exprMatch[2];
|
|
32889
|
+
}
|
|
32890
|
+
}
|
|
32891
|
+
const resolveReceiverType2 = (rcv) => {
|
|
32892
|
+
const param = method.parameters.find((p) => p.name === rcv);
|
|
32893
|
+
if (param?.type) return param.type;
|
|
32894
|
+
const fieldOnSelf = type.fields?.find((f) => f.name === rcv);
|
|
32895
|
+
if (fieldOnSelf?.type) return fieldOnSelf.type;
|
|
32896
|
+
return null;
|
|
32897
|
+
};
|
|
32898
|
+
let receiverType = null;
|
|
32899
|
+
if (receiver && fieldName) {
|
|
32900
|
+
receiverType = resolveReceiverType2(receiver);
|
|
32901
|
+
}
|
|
32902
|
+
if (!receiverType) {
|
|
32903
|
+
for (const rcvUse of usesAtLine) {
|
|
32904
|
+
if (!rcvUse.variable || rcvUse.variable === def.variable) continue;
|
|
32905
|
+
const rt = resolveReceiverType2(rcvUse.variable);
|
|
32906
|
+
if (!rt) continue;
|
|
32907
|
+
const fieldUse = usesAtLine.find(
|
|
32908
|
+
(u) => u !== rcvUse && !!u.variable && u.variable !== def.variable && u.variable !== rcvUse.variable && this.typeHasField(rt, u.variable)
|
|
32909
|
+
);
|
|
32910
|
+
if (fieldUse) {
|
|
32911
|
+
receiver = rcvUse.variable;
|
|
32912
|
+
fieldName = fieldUse.variable;
|
|
32913
|
+
receiverType = rt;
|
|
32914
|
+
break;
|
|
32915
|
+
}
|
|
32916
|
+
}
|
|
32917
|
+
}
|
|
32918
|
+
if (!receiver || !fieldName || !receiverType) continue;
|
|
32919
|
+
const fieldKey = this.resolveFieldTaintKey(receiverType, fieldName, callerIR);
|
|
32920
|
+
if (!fieldKey) continue;
|
|
32921
|
+
const fieldInfo = this.fieldTaintInfo.get(fieldKey);
|
|
32922
|
+
if (!fieldInfo || fieldInfo.writers.length === 0) continue;
|
|
32923
|
+
const writer = fieldInfo.writers.find(
|
|
32924
|
+
(w) => w.sourceType === "constructor_field" || w.sourceType === "autowired_field"
|
|
32925
|
+
) ?? null;
|
|
32926
|
+
if (!writer) continue;
|
|
32927
|
+
const hopChain = [
|
|
32928
|
+
{
|
|
32929
|
+
file: fieldInfo.file,
|
|
32930
|
+
line: writer.sourceLine,
|
|
32931
|
+
method: writer.methodName,
|
|
32932
|
+
kind: "source"
|
|
32933
|
+
},
|
|
32934
|
+
{
|
|
32935
|
+
file: fieldInfo.file,
|
|
32936
|
+
line: writer.writeLine,
|
|
32937
|
+
method: writer.methodName,
|
|
32938
|
+
kind: "field_write"
|
|
32939
|
+
},
|
|
32940
|
+
{
|
|
32941
|
+
file: callerFile,
|
|
32942
|
+
line: def.line,
|
|
32943
|
+
method: method.name,
|
|
32944
|
+
kind: "field_read"
|
|
32945
|
+
}
|
|
32946
|
+
];
|
|
32947
|
+
tainted.set(def.variable, {
|
|
32948
|
+
file: fieldInfo.file,
|
|
32949
|
+
line: writer.sourceLine,
|
|
32950
|
+
type: writer.sourceType,
|
|
32951
|
+
hopChain
|
|
32952
|
+
});
|
|
32953
|
+
}
|
|
32954
|
+
if (tainted.size === 0) continue;
|
|
32955
|
+
const sinksInCaller = callerIdx.sinksByMethod.get(method) ?? [];
|
|
32956
|
+
for (const sink of sinksInCaller) {
|
|
32957
|
+
const callsAtSink = (callerIdx.callsByLine.get(sink.line) ?? []).filter((c) => this.callMatchesSink(sink, c));
|
|
32958
|
+
for (const sinkCall of callsAtSink) {
|
|
32959
|
+
for (const arg of this.dangerousSinkArguments(sink, sinkCall)) {
|
|
32960
|
+
const matched = this.matchTaintedArg(arg, tainted);
|
|
32961
|
+
if (!matched) continue;
|
|
32962
|
+
const key = `fb:${matched.origin.file}:${matched.origin.line}\u2192${callerFile}:${sink.line}`;
|
|
32963
|
+
if (seen.has(key)) continue;
|
|
32964
|
+
seen.add(key);
|
|
32965
|
+
const hops = [
|
|
32966
|
+
...matched.origin.hopChain,
|
|
32967
|
+
{ file: callerFile, line: sink.line, method: method.name, kind: "sink" }
|
|
32968
|
+
];
|
|
32969
|
+
const decay = Math.max(0.3, Math.pow(0.85, Math.max(hops.length - 1, 0)));
|
|
32970
|
+
paths.push({
|
|
32971
|
+
source: {
|
|
32972
|
+
file: matched.origin.file,
|
|
32973
|
+
line: matched.origin.line,
|
|
32974
|
+
type: matched.origin.type
|
|
32975
|
+
},
|
|
32976
|
+
sink: {
|
|
32977
|
+
file: callerFile,
|
|
32978
|
+
line: sink.line,
|
|
32979
|
+
type: sink.type,
|
|
32980
|
+
cwe: sink.cwe
|
|
32981
|
+
},
|
|
32982
|
+
hops,
|
|
32983
|
+
confidence: decay
|
|
32984
|
+
});
|
|
32985
|
+
}
|
|
32986
|
+
}
|
|
32987
|
+
}
|
|
32988
|
+
const callsInMethod = callerIdx.callsByMethod.get(method) ?? [];
|
|
32989
|
+
for (const call of callsInMethod) {
|
|
32990
|
+
const resolved = this.resolveCall(call, callerFile);
|
|
32991
|
+
if (!resolved) continue;
|
|
32992
|
+
const callee = this.methodTaintInfo.get(resolved.targetMethod);
|
|
32993
|
+
if (!callee || callee.sanitizes || callee.taintedParams.length === 0) continue;
|
|
32994
|
+
for (let argIdx = 0; argIdx < call.arguments.length; argIdx++) {
|
|
32995
|
+
if (!callee.taintedParams.includes(argIdx)) continue;
|
|
32996
|
+
const matched = this.matchTaintedArg(call.arguments[argIdx], tainted);
|
|
32997
|
+
if (!matched) continue;
|
|
32998
|
+
const calleeNode = methodIndex.get(resolved.targetMethod);
|
|
32999
|
+
if (!calleeNode) continue;
|
|
33000
|
+
const calleeIdx = this.getFileIndex(calleeNode.ir);
|
|
33001
|
+
const sinksInCallee = calleeIdx.sinksByMethod.get(calleeNode.method) ?? [];
|
|
33002
|
+
for (const sink of sinksInCallee) {
|
|
33003
|
+
const key = `fb:${matched.origin.file}:${matched.origin.line}\u2192${callee.file}:${sink.line}`;
|
|
33004
|
+
if (seen.has(key)) continue;
|
|
33005
|
+
seen.add(key);
|
|
33006
|
+
const hops = [
|
|
33007
|
+
...matched.origin.hopChain,
|
|
33008
|
+
{ file: callerFile, line: call.location.line, method: method.name, kind: "sink_call" },
|
|
33009
|
+
{ file: callee.file, line: sink.line, method: resolved.targetMethod, kind: "sink" }
|
|
33010
|
+
];
|
|
33011
|
+
const decay = Math.max(0.3, Math.pow(0.85, Math.max(hops.length - 1, 0)));
|
|
33012
|
+
paths.push({
|
|
33013
|
+
source: {
|
|
33014
|
+
file: matched.origin.file,
|
|
33015
|
+
line: matched.origin.line,
|
|
33016
|
+
type: matched.origin.type
|
|
33017
|
+
},
|
|
33018
|
+
sink: {
|
|
33019
|
+
file: callee.file,
|
|
33020
|
+
line: sink.line,
|
|
33021
|
+
type: sink.type,
|
|
33022
|
+
cwe: sink.cwe
|
|
33023
|
+
},
|
|
33024
|
+
hops,
|
|
33025
|
+
confidence: decay
|
|
33026
|
+
});
|
|
33027
|
+
}
|
|
33028
|
+
}
|
|
33029
|
+
}
|
|
33030
|
+
void callerTypeFqn;
|
|
33031
|
+
}
|
|
33032
|
+
}
|
|
33033
|
+
}
|
|
33034
|
+
return paths;
|
|
33035
|
+
}
|
|
33036
|
+
/**
|
|
33037
|
+
* Cross-file C# flows through a static field (`A.stored = req…` in file A,
|
|
33038
|
+
* `data = A.stored` → sink in file B). cognium-dev#638 `_68`.
|
|
33039
|
+
*/
|
|
33040
|
+
findCSharpStaticFieldTaintPaths(deadline) {
|
|
33041
|
+
const paths = [];
|
|
33042
|
+
const seen = /* @__PURE__ */ new Set();
|
|
33043
|
+
if (this.csharpStaticFieldWriters.size === 0) return paths;
|
|
33044
|
+
for (const [readerFile, callerIR] of this.fileIRs) {
|
|
33045
|
+
if (deadline?.()) break;
|
|
33046
|
+
if (callerIR.meta.language !== "csharp") continue;
|
|
33047
|
+
const callerIdx = this.getFileIndex(callerIR);
|
|
33048
|
+
for (const type of callerIR.types) {
|
|
33049
|
+
for (const method of type.methods) {
|
|
33050
|
+
const tainted = /* @__PURE__ */ new Map();
|
|
33051
|
+
const defsInMethod = (callerIdx.defsByMethod.get(method) ?? []).filter(
|
|
33052
|
+
(d) => d.kind === "local" && !!d.variable
|
|
33053
|
+
);
|
|
33054
|
+
for (const def of defsInMethod) {
|
|
33055
|
+
const usesAtLine = callerIdx.usesByLine.get(def.line) ?? [];
|
|
33056
|
+
const fieldKey = this.resolveCSharpStaticFieldReadKey(type, usesAtLine);
|
|
33057
|
+
if (!fieldKey) continue;
|
|
33058
|
+
const writer = this.csharpStaticFieldWriters.get(fieldKey);
|
|
33059
|
+
if (!writer) continue;
|
|
33060
|
+
const hopChain = [
|
|
33061
|
+
{ file: writer.file, line: writer.line, method: writer.methodName, kind: "source" },
|
|
33062
|
+
{ file: writer.file, line: writer.line, method: writer.methodName, kind: "field_write" },
|
|
33063
|
+
{ file: readerFile, line: def.line, method: method.name, kind: "field_read" }
|
|
33064
|
+
];
|
|
33065
|
+
tainted.set(def.variable, {
|
|
33066
|
+
file: writer.file,
|
|
33067
|
+
line: writer.line,
|
|
33068
|
+
type: writer.type,
|
|
33069
|
+
hopChain
|
|
33070
|
+
});
|
|
33071
|
+
}
|
|
33072
|
+
if (tainted.size === 0) continue;
|
|
33073
|
+
const sinksInCaller = callerIdx.sinksByMethod.get(method) ?? [];
|
|
33074
|
+
for (const sink of sinksInCaller) {
|
|
33075
|
+
const callsAtSink = callerIdx.callsByLine.get(sink.line) ?? [];
|
|
33076
|
+
for (const sinkCall of callsAtSink) {
|
|
33077
|
+
for (const arg of sinkCall.arguments ?? []) {
|
|
33078
|
+
const matched = this.matchTaintedArg(arg, tainted);
|
|
33079
|
+
if (!matched) continue;
|
|
33080
|
+
const key = `csf:${matched.origin.file}:${matched.origin.line}\u2192${readerFile}:${sink.line}`;
|
|
33081
|
+
if (seen.has(key)) continue;
|
|
33082
|
+
seen.add(key);
|
|
33083
|
+
const hops = [
|
|
33084
|
+
...matched.origin.hopChain,
|
|
33085
|
+
{ file: readerFile, line: sink.line, method: method.name, kind: "sink" }
|
|
33086
|
+
];
|
|
33087
|
+
const decay = Math.max(0.3, Math.pow(0.85, Math.max(hops.length - 1, 0)));
|
|
33088
|
+
paths.push({
|
|
33089
|
+
source: {
|
|
33090
|
+
file: matched.origin.file,
|
|
33091
|
+
line: matched.origin.line,
|
|
33092
|
+
type: matched.origin.type
|
|
33093
|
+
},
|
|
33094
|
+
sink: {
|
|
33095
|
+
file: readerFile,
|
|
33096
|
+
line: sink.line,
|
|
33097
|
+
type: sink.type,
|
|
33098
|
+
cwe: sink.cwe
|
|
33099
|
+
},
|
|
33100
|
+
hops,
|
|
33101
|
+
confidence: decay
|
|
33102
|
+
});
|
|
33103
|
+
}
|
|
33104
|
+
}
|
|
33105
|
+
}
|
|
33106
|
+
}
|
|
33107
|
+
}
|
|
33108
|
+
}
|
|
33109
|
+
return paths;
|
|
33110
|
+
}
|
|
33111
|
+
analyzeCSharpStaticFieldWriters(ir, filePath) {
|
|
33112
|
+
if (ir.meta.language !== "csharp") return;
|
|
33113
|
+
for (const type of ir.types) {
|
|
33114
|
+
const staticFields = new Set(
|
|
33115
|
+
(type.fields ?? []).filter((f) => f.modifiers?.includes("static")).map((f) => f.name)
|
|
33116
|
+
);
|
|
33117
|
+
if (staticFields.size === 0) continue;
|
|
33118
|
+
for (const src of ir.taint.sources ?? []) {
|
|
33119
|
+
if (src.type === "interprocedural_param") continue;
|
|
33120
|
+
if (!src.variable) continue;
|
|
33121
|
+
const fieldName = src.variable.replace(/^this\./, "");
|
|
33122
|
+
if (!staticFields.has(fieldName)) continue;
|
|
33123
|
+
const method = type.methods.find(
|
|
33124
|
+
(m) => src.line >= m.start_line && src.line <= m.end_line
|
|
33125
|
+
);
|
|
33126
|
+
const key = `${type.name}.${fieldName}`;
|
|
33127
|
+
this.csharpStaticFieldWriters.set(key, {
|
|
33128
|
+
file: filePath,
|
|
33129
|
+
line: src.line,
|
|
33130
|
+
type: src.type,
|
|
33131
|
+
methodName: method?.name ?? ""
|
|
33132
|
+
});
|
|
33133
|
+
}
|
|
33134
|
+
}
|
|
33135
|
+
}
|
|
33136
|
+
resolveCSharpStaticFieldReadKey(containingType, usesAtLine) {
|
|
33137
|
+
const extUses = usesAtLine.filter((u) => u.def_id === null && u.variable);
|
|
33138
|
+
const names = extUses.map((u) => u.variable);
|
|
33139
|
+
for (let i2 = 0; i2 < names.length; i2++) {
|
|
33140
|
+
for (let j = 0; j < names.length; j++) {
|
|
33141
|
+
if (i2 === j) continue;
|
|
33142
|
+
const key = `${names[i2]}.${names[j]}`;
|
|
33143
|
+
if (this.csharpStaticFieldWriters.has(key)) return key;
|
|
33144
|
+
}
|
|
33145
|
+
}
|
|
33146
|
+
for (const name2 of names) {
|
|
33147
|
+
const field = containingType.fields?.find((f) => f.name === name2);
|
|
33148
|
+
if (!field?.modifiers?.includes("static")) continue;
|
|
33149
|
+
const key = `${containingType.name}.${name2}`;
|
|
33150
|
+
if (this.csharpStaticFieldWriters.has(key)) return key;
|
|
33151
|
+
}
|
|
33152
|
+
return null;
|
|
33153
|
+
}
|
|
33154
|
+
/**
|
|
33155
|
+
* Check whether any loaded type with name `typeName` (simple or FQN suffix)
|
|
33156
|
+
* declares a field named `fieldName`.
|
|
33157
|
+
*/
|
|
33158
|
+
typeHasField(typeName, fieldName) {
|
|
33159
|
+
for (const [, ir] of this.fileIRs) {
|
|
33160
|
+
for (const t of ir.types) {
|
|
33161
|
+
if (t.name !== typeName) continue;
|
|
33162
|
+
if ((t.fields ?? []).some((f) => f.name === fieldName)) return true;
|
|
33163
|
+
}
|
|
33164
|
+
}
|
|
33165
|
+
return false;
|
|
33166
|
+
}
|
|
33167
|
+
/**
|
|
33168
|
+
* Resolve a receiver type-name + field-name to the cache key used by
|
|
33169
|
+
* `fieldTaintInfo`. Handles simple-name receivers (e.g. `ReadTrustedStep`)
|
|
33170
|
+
* by looking up matching FQN keys across loaded files.
|
|
33171
|
+
*/
|
|
33172
|
+
resolveFieldTaintKey(receiverType, fieldName, _callerIR) {
|
|
33173
|
+
const direct = `${receiverType}.${fieldName}`;
|
|
33174
|
+
if (this.fieldTaintInfo.has(direct)) return direct;
|
|
33175
|
+
const suffix = `.${receiverType}.${fieldName}`;
|
|
33176
|
+
for (const key of this.fieldTaintInfo.keys()) {
|
|
33177
|
+
if (key === direct) return key;
|
|
33178
|
+
if (key.endsWith(suffix)) return key;
|
|
33179
|
+
}
|
|
33180
|
+
return void 0;
|
|
33181
|
+
}
|
|
33182
|
+
/**
|
|
33183
|
+
* Find which method a tainted arg expression references.
|
|
33184
|
+
*/
|
|
33185
|
+
/**
|
|
33186
|
+
* After cross-file wrapper-return seeding (step 2a), add same-file locals
|
|
33187
|
+
* DFG-derived from that assignment so caller-body sinks see `sql` as well
|
|
33188
|
+
* as `invoice` (cognium-dev#590). In-method sources already reach derived
|
|
33189
|
+
* names via `findCrossFileTaintFlows` / `collectTaintReachable`; extending
|
|
33190
|
+
* those here duplicates paths and emits `external_taint_escape` on calls
|
|
33191
|
+
* that bypass pass-level suppressions (cognium-dev#412).
|
|
33192
|
+
*/
|
|
33193
|
+
extendInterproceduralTaintedVars(callerIR, callerFile, tainted) {
|
|
33194
|
+
for (const [varName, origin] of [...tainted.entries()]) {
|
|
33195
|
+
const wrapperHop = origin.hopChain.find(
|
|
33196
|
+
(h) => h.kind === "wrapper_return" && h.file === callerFile
|
|
33197
|
+
);
|
|
33198
|
+
if (!wrapperHop) continue;
|
|
33199
|
+
const anchorLine = wrapperHop.line;
|
|
33200
|
+
const reachable = this.collectTaintReachable(callerIR, varName, anchorLine, callerFile);
|
|
33201
|
+
for (const derived of reachable.names) {
|
|
33202
|
+
if (derived === varName || tainted.has(derived)) continue;
|
|
33203
|
+
tainted.set(derived, { ...origin, defIds: reachable.defIds });
|
|
33204
|
+
}
|
|
33205
|
+
}
|
|
33206
|
+
}
|
|
33207
|
+
matchTaintedArg(arg, tainted, jsMember = false) {
|
|
33208
|
+
if (tainted.size === 0) return null;
|
|
33209
|
+
const lengthOnly = (tv) => arg.expression?.replace(
|
|
33210
|
+
new RegExp(`(?<![\\w$.])${escapeRegExp(tv)}\\s*\\??\\.\\s*length(?![\\w$(\\[])`, "g"),
|
|
33211
|
+
"0"
|
|
33212
|
+
);
|
|
33213
|
+
if (arg.variable && tainted.has(arg.variable)) {
|
|
33214
|
+
const rest = jsMember ? lengthOnly(arg.variable) : void 0;
|
|
33215
|
+
if (rest === void 0 || rest === arg.expression || new RegExp(`(?<![\\w$])${escapeRegExp(arg.variable)}(?![\\w$])`).test(rest)) {
|
|
33216
|
+
return { var: arg.variable, origin: tainted.get(arg.variable) };
|
|
33217
|
+
}
|
|
33218
|
+
}
|
|
33219
|
+
if (arg.expression) {
|
|
33220
|
+
for (const [tv, origin] of tainted) {
|
|
33221
|
+
const re = jsMember ? new RegExp(`(?<![\\w$])(?<!(?:^|[^.])\\.)${escapeRegExp(tv)}(?![\\w$])`) : new RegExp(`\\b${escapeRegExp(tv)}\\b`);
|
|
33222
|
+
if (re.test(jsMember ? lengthOnly(tv) : arg.expression)) return { var: tv, origin };
|
|
33223
|
+
}
|
|
33224
|
+
}
|
|
33225
|
+
return null;
|
|
33226
|
+
}
|
|
33227
|
+
/**
|
|
33228
|
+
* Index methods by FQN for quick lookup during chain construction.
|
|
33229
|
+
*/
|
|
33230
|
+
buildMethodIndex() {
|
|
33231
|
+
const idx = /* @__PURE__ */ new Map();
|
|
33232
|
+
for (const [, ir] of this.fileIRs) {
|
|
33233
|
+
const pkg = ir.meta.package || "";
|
|
33234
|
+
for (const type of ir.types) {
|
|
33235
|
+
const typeFqn2 = pkg ? `${pkg}.${type.name}` : type.name;
|
|
33236
|
+
for (const method of type.methods) {
|
|
33237
|
+
idx.set(`${typeFqn2}.${method.name}`, { ir, method });
|
|
33238
|
+
}
|
|
33239
|
+
}
|
|
33240
|
+
}
|
|
33241
|
+
return idx;
|
|
33242
|
+
}
|
|
33243
|
+
/** Return the first local-def variable name at a given line, if any. */
|
|
33244
|
+
getLocalDefVarAt(ir, line) {
|
|
33245
|
+
for (const def of ir.dfg.defs) {
|
|
33246
|
+
if (def.line === line && def.kind === "local" && def.variable) return def.variable;
|
|
33247
|
+
}
|
|
33248
|
+
return void 0;
|
|
33249
|
+
}
|
|
33250
|
+
/**
|
|
33251
|
+
* Collect the set of variable names DFG-reachable from `sourceVar` within
|
|
33252
|
+
* a single file — the source variable itself plus every local whose
|
|
33253
|
+
* definition transitively consumes it via def-use chains (cognium-dev
|
|
33254
|
+
* #146). Bounded forward BFS over `dfg.chains`.
|
|
33255
|
+
*
|
|
33256
|
+
* Used by the cross-file variable-connectivity gate so a tainted value
|
|
33257
|
+
* that is rebound before the cross-file call still connects. Example
|
|
33258
|
+
* (Rust actix): the source variable is the extractor param `q`, but the
|
|
33259
|
+
* call passes `cmd` from `let cmd = q.get("cmd").unwrap()`; the chain
|
|
33260
|
+
* `q → cmd` makes `cmd` reachable.
|
|
33261
|
+
*
|
|
33262
|
+
* Soundness guard: the walk does NOT follow a derivation whose def is
|
|
33263
|
+
* produced on a line carrying a *cross-file-resolvable call*. Such a
|
|
33264
|
+
* value crossed a file boundary and may have been transformed or
|
|
33265
|
+
* sanitized (e.g. `String safe = sanitizer.sanitizeUrl(raw)` — the
|
|
33266
|
+
* wrapper-sanitizer negative control). Verifying whether that call
|
|
33267
|
+
* preserves taint is the job of `findInterproceduralTaintPaths`, which
|
|
33268
|
+
* is sanitizer-aware; this coarse pass must stay conservative and stop
|
|
33269
|
+
* at the boundary. Same-file / stdlib accessor calls (`q.get(...)`,
|
|
33270
|
+
* `.unwrap()`) do not resolve cross-file, so genuine taint derivatives
|
|
33271
|
+
* are still followed.
|
|
33272
|
+
*/
|
|
33273
|
+
collectTaintReachable(ir, sourceVar, sourceLine, filePath) {
|
|
33274
|
+
const defs = ir.dfg.defs;
|
|
33275
|
+
let seedDefs = defs.filter((d) => d.variable === sourceVar && d.line === sourceLine);
|
|
33276
|
+
if (seedDefs.length === 0) {
|
|
33277
|
+
const named2 = defs.filter((d) => d.variable === sourceVar).sort((a, b) => a.line - b.line);
|
|
33278
|
+
if (named2.length > 0) seedDefs = [named2[0]];
|
|
33279
|
+
}
|
|
33280
|
+
const defIds = this.forwardReachableDefs(ir, seedDefs.map((d) => d.id), filePath);
|
|
33281
|
+
const names = /* @__PURE__ */ new Set([sourceVar]);
|
|
33282
|
+
for (const d of defs) {
|
|
33283
|
+
if (d.variable && defIds.has(d.id)) names.add(d.variable);
|
|
33284
|
+
}
|
|
33285
|
+
return { names, defIds };
|
|
33286
|
+
}
|
|
33287
|
+
/**
|
|
33288
|
+
* Forward-reachable def set from a seed set of def ids, following
|
|
33289
|
+
* `dfg.chains` (cognium-dev #146/#266). Stops at any def produced on a
|
|
33290
|
+
* line carrying a cross-file-resolvable call (potential sanitizer
|
|
33291
|
+
* boundary — the #146 soundness guard). Returns the seed ∪ all
|
|
33292
|
+
* transitively derived def ids. Empty/absent DFG → just the seed.
|
|
33293
|
+
*/
|
|
33294
|
+
forwardReachableDefs(ir, seedDefIds, filePath) {
|
|
33295
|
+
const defIds = new Set(seedDefIds);
|
|
33296
|
+
const chains = ir.dfg.chains;
|
|
33297
|
+
if (!chains || chains.length === 0 || seedDefIds.length === 0) return defIds;
|
|
33298
|
+
const lineByDefId = /* @__PURE__ */ new Map();
|
|
33299
|
+
for (const d of ir.dfg.defs) lineByDefId.set(d.id, d.line);
|
|
33300
|
+
const crossFileCallLines = /* @__PURE__ */ new Set();
|
|
33301
|
+
for (const call of ir.calls) {
|
|
33302
|
+
const resolved = this.resolveCall(call, filePath);
|
|
33303
|
+
if (resolved && resolved.targetFile !== filePath) {
|
|
33304
|
+
crossFileCallLines.add(call.location.line);
|
|
33305
|
+
}
|
|
33306
|
+
}
|
|
33307
|
+
const frontier = [...seedDefIds];
|
|
33308
|
+
const visited = new Set(frontier);
|
|
33309
|
+
while (frontier.length > 0) {
|
|
33310
|
+
const cur = frontier.shift();
|
|
33311
|
+
for (const ch of chains) {
|
|
33312
|
+
if (ch.from_def !== cur || visited.has(ch.to_def)) continue;
|
|
33313
|
+
visited.add(ch.to_def);
|
|
33314
|
+
const toLine = lineByDefId.get(ch.to_def);
|
|
33315
|
+
if (toLine !== void 0 && crossFileCallLines.has(toLine)) continue;
|
|
33316
|
+
defIds.add(ch.to_def);
|
|
33317
|
+
frontier.push(ch.to_def);
|
|
33318
|
+
}
|
|
33319
|
+
}
|
|
33320
|
+
return defIds;
|
|
33321
|
+
}
|
|
33322
|
+
/**
|
|
33323
|
+
* Def-precise clobber check for the interprocedural walker (cognium-dev
|
|
33324
|
+
* #266). Given a bare-variable call arg matched to a tainted var whose
|
|
33325
|
+
* caller-side taint reaches `taintDefIds`, returns true when the DFG
|
|
33326
|
+
* proves the arg's reaching def at the call line is NOT one of those
|
|
33327
|
+
* defs — i.e. the variable was reassigned to a non-tainted value between
|
|
33328
|
+
* the taint point and the call (`a = source(); a = "safe"; run(a)`).
|
|
33329
|
+
*
|
|
33330
|
+
* Conservative: returns false whenever the proof is unavailable (no bare
|
|
33331
|
+
* variable, no precise reaching def, empty def set / DFG), so it only
|
|
33332
|
+
* removes flows the DFG positively disproves — recall risk stays minimal
|
|
33333
|
+
* for the shared interprocedural pass, and empty-DFG languages (Python)
|
|
33334
|
+
* are unaffected.
|
|
33335
|
+
*/
|
|
33336
|
+
/**
|
|
33337
|
+
* Def-precise clobber check for the cross-file gates (cognium-dev #266).
|
|
33338
|
+
* Given the matched taint variable `varName` carried by a call at
|
|
33339
|
+
* `callLine` and the source's reachable def set `taintDefIds`, returns
|
|
33340
|
+
* true when the DFG proves `varName`'s reaching def at the call is NOT
|
|
33341
|
+
* one of those defs — i.e. the variable was reassigned to a non-tainted
|
|
33342
|
+
* value between the taint point and the call
|
|
33343
|
+
* (`a = source(); a = "safe"; run(a)` / `run(&a)`). Keyed on the variable
|
|
33344
|
+
* name (not `arg.variable`) so it also covers expression args
|
|
33345
|
+
* (Rust `&a`, `"p" + a`, …).
|
|
33346
|
+
*
|
|
33347
|
+
* Conservative: returns false whenever the proof is unavailable (no
|
|
33348
|
+
* precise reaching def, empty def set / DFG), so it only removes flows
|
|
33349
|
+
* the DFG positively disproves — recall risk stays minimal for the
|
|
33350
|
+
* shared cross-file passes, and empty-DFG languages (Python) are
|
|
33351
|
+
* unaffected.
|
|
33352
|
+
*/
|
|
33353
|
+
taintClobbered(ir, callLine, varName, taintDefIds) {
|
|
33354
|
+
if (!taintDefIds || taintDefIds.size === 0) return false;
|
|
33355
|
+
const use = ir.dfg.uses.find(
|
|
33356
|
+
(u) => u.line === callLine && u.variable === varName && u.def_id !== null
|
|
33357
|
+
);
|
|
33358
|
+
if (!use || use.def_id === null) return false;
|
|
33359
|
+
return !taintDefIds.has(use.def_id);
|
|
33360
|
+
}
|
|
33361
|
+
/**
|
|
33362
|
+
* True when every real source inside `method` lands in a local that is only
|
|
33363
|
+
* ever read in a branch condition (`if (...)`, `while (...)`) after it is
|
|
33364
|
+
* assigned, so no source value can reach what the method returns (#914).
|
|
33365
|
+
*
|
|
33366
|
+
* OWASP `Utils.getOSCommandString(append)` reads
|
|
33367
|
+
* `String osName = System.getProperty("os.name");` only to choose between
|
|
33368
|
+
* `"cmd.exe /c " + append` and `append`. Without this, `returnsSource`
|
|
33369
|
+
* marks the method's return as `env_input` and every caller's
|
|
33370
|
+
* `exec(... getOSCommandString("ls ") ...)` became a command_injection path.
|
|
33371
|
+
*
|
|
33372
|
+
* Java / JS / TS when the source text is available; otherwise false
|
|
33373
|
+
* (the method keeps `returnsSource`).
|
|
33374
|
+
*/
|
|
33375
|
+
sourcesOnlySteerBranches(file, ir, method) {
|
|
33376
|
+
const lang = ir.meta.language;
|
|
33377
|
+
if (lang !== "java" && lang !== "javascript" && lang !== "typescript") return false;
|
|
33378
|
+
const lines = this.sourceLines?.get(file);
|
|
33379
|
+
if (!lines) return false;
|
|
33380
|
+
const real = ir.taint.sources.filter((s) => s.type !== "interprocedural_param" && s.line >= method.start_line && s.line <= method.end_line);
|
|
33381
|
+
if (real.length === 0) return false;
|
|
33382
|
+
for (const src of real) {
|
|
33383
|
+
if (lang === "java") {
|
|
33384
|
+
if (!this.javaSourceOnlySteersBranches(lines, method, src)) return false;
|
|
33385
|
+
} else if (!this.jsTsSourceOnlySteersBranches(lines, method, src)) {
|
|
33386
|
+
return false;
|
|
33387
|
+
}
|
|
33388
|
+
}
|
|
33389
|
+
return true;
|
|
33390
|
+
}
|
|
33391
|
+
/** #914 — local assigned from a source, then only read in branch conditions. */
|
|
33392
|
+
javaSourceOnlySteersBranches(lines, method, src) {
|
|
33393
|
+
const v = src.variable;
|
|
33394
|
+
if (!v || !/^[A-Za-z_$][\w$]*$/.test(v)) return false;
|
|
33395
|
+
const decl = new RegExp(`^\\s*(?:final\\s+)?[\\w<>\\[\\].]+\\s+${v}\\s*=[^;]*;\\s*$`);
|
|
33396
|
+
if (!decl.test(stripJavaLiterals(lines[src.line - 1] ?? ""))) return false;
|
|
33397
|
+
const mention = new RegExp(`(?<![\\w$.])${v.replace(/\$/g, "\\$")}(?![\\w$])`);
|
|
33398
|
+
for (let l = src.line + 1; l <= method.end_line; l++) {
|
|
33399
|
+
const text = withoutLeadingConditions(stripJavaLiterals(lines[l - 1] ?? ""));
|
|
33400
|
+
if (mention.test(text)) return false;
|
|
33401
|
+
}
|
|
33402
|
+
return true;
|
|
33403
|
+
}
|
|
33404
|
+
/**
|
|
33405
|
+
* #1136 — JS/TS counterpart of #914: a read used only to steer a branch
|
|
33406
|
+
* (including inline `if (guard(read(...))) push(path)`) does not taint the
|
|
33407
|
+
* helper's return for cross-file chaining.
|
|
33408
|
+
*/
|
|
33409
|
+
jsTsSourceOnlySteersBranches(lines, method, src) {
|
|
33410
|
+
const v = src.variable;
|
|
33411
|
+
if (v && /^[A-Za-z_$][\w$]*$/.test(v)) {
|
|
33412
|
+
const decl = new RegExp(`^\\s*(?:const|let|var)\\s+${v.replace(/\$/g, "\\$")}\\s*=`);
|
|
33413
|
+
if (decl.test(stripJavaLiterals(lines[src.line - 1] ?? ""))) {
|
|
33414
|
+
const mention = new RegExp(`(?<![\\w$.])${v.replace(/\$/g, "\\$")}(?![\\w$])`);
|
|
33415
|
+
for (let l = src.line + 1; l <= method.end_line; l++) {
|
|
33416
|
+
const text = withoutLeadingConditions(stripJavaLiterals(lines[l - 1] ?? ""));
|
|
33417
|
+
if (mention.test(text)) return false;
|
|
33418
|
+
}
|
|
33419
|
+
return true;
|
|
33420
|
+
}
|
|
33421
|
+
}
|
|
33422
|
+
const anchor = this.jsTsBranchOnlyAnchor(lines, src);
|
|
33423
|
+
if (!anchor) return false;
|
|
33424
|
+
for (let l = method.start_line; l <= method.end_line; l++) {
|
|
33425
|
+
const text = stripJavaLiterals(lines[l - 1] ?? "");
|
|
33426
|
+
if (!text.includes(anchor)) continue;
|
|
33427
|
+
const outsideCond = withoutLeadingConditions(text);
|
|
33428
|
+
if (outsideCond.includes(anchor)) return false;
|
|
33429
|
+
}
|
|
33430
|
+
return true;
|
|
33431
|
+
}
|
|
33432
|
+
/** Stable substring for an inline read (e.g. `readFileSync`) on the source line. */
|
|
33433
|
+
jsTsBranchOnlyAnchor(lines, src) {
|
|
33434
|
+
const line = stripJavaLiterals(lines[src.line - 1] ?? "");
|
|
33435
|
+
const readCall = line.match(/\b(readFileSync|readFile|readSync)\s*\(/);
|
|
33436
|
+
if (readCall) return readCall[1];
|
|
33437
|
+
if (src.location) {
|
|
33438
|
+
const m = src.location.match(/\b(readFileSync|readFile|readSync)\b/);
|
|
33439
|
+
if (m) return m[1];
|
|
33440
|
+
}
|
|
33441
|
+
return void 0;
|
|
33442
|
+
}
|
|
33443
|
+
findRealSourceLineInMethod(ir, method) {
|
|
33444
|
+
for (const src of ir.taint.sources) {
|
|
33445
|
+
if (src.type === "interprocedural_param") continue;
|
|
33446
|
+
if (src.line >= method.start_line && src.line <= method.end_line) {
|
|
33447
|
+
return src.line;
|
|
33448
|
+
}
|
|
33449
|
+
}
|
|
33450
|
+
return void 0;
|
|
33451
|
+
}
|
|
33452
|
+
/**
|
|
33453
|
+
* Get taint info for a method
|
|
33454
|
+
*/
|
|
33455
|
+
getMethodTaintInfo(methodFqn) {
|
|
33456
|
+
return this.methodTaintInfo.get(methodFqn);
|
|
33457
|
+
}
|
|
33458
|
+
/**
|
|
33459
|
+
* Get all resolved calls from a file
|
|
33460
|
+
*/
|
|
33461
|
+
getResolvedCallsFromFile(filePath) {
|
|
33462
|
+
const ir = this.fileIRs.get(filePath);
|
|
33463
|
+
if (!ir) return [];
|
|
33464
|
+
const resolved = [];
|
|
33465
|
+
for (const call of ir.calls) {
|
|
33466
|
+
const r = this.resolveCall(call, filePath);
|
|
33467
|
+
if (r) {
|
|
33468
|
+
resolved.push(r);
|
|
33469
|
+
}
|
|
33470
|
+
}
|
|
33471
|
+
return resolved;
|
|
33472
|
+
}
|
|
33473
|
+
/**
|
|
33474
|
+
* Get statistics
|
|
33475
|
+
*/
|
|
33476
|
+
getStats() {
|
|
33477
|
+
let totalCalls = 0;
|
|
33478
|
+
let crossFileCalls = 0;
|
|
33479
|
+
for (const [filePath, ir] of this.fileIRs) {
|
|
33480
|
+
totalCalls += ir.calls.length;
|
|
33481
|
+
for (const call of ir.calls) {
|
|
33482
|
+
const resolved = this.resolveCall(call, filePath);
|
|
33483
|
+
if (resolved && resolved.targetFile !== filePath) {
|
|
33484
|
+
crossFileCalls++;
|
|
33485
|
+
}
|
|
33486
|
+
}
|
|
33487
|
+
}
|
|
33488
|
+
return {
|
|
33489
|
+
totalFiles: this.fileIRs.size,
|
|
33490
|
+
totalCalls,
|
|
33491
|
+
resolvedCalls: this.resolvedCalls.size,
|
|
33492
|
+
crossFileCalls,
|
|
33493
|
+
methodsWithTaintInfo: this.methodTaintInfo.size
|
|
33494
|
+
};
|
|
33495
|
+
}
|
|
33496
|
+
/**
|
|
33497
|
+
* Clear all caches
|
|
33498
|
+
*/
|
|
33499
|
+
clear() {
|
|
33500
|
+
this.fileIRs.clear();
|
|
33501
|
+
this.methodTaintInfo.clear();
|
|
33502
|
+
this.fieldTaintInfo.clear();
|
|
33503
|
+
this.resolvedCalls.clear();
|
|
33504
|
+
}
|
|
33505
|
+
/** Expose field-taint summary (for tests + diagnostics). */
|
|
33506
|
+
getFieldTaintInfo(typeFqn2, fieldName) {
|
|
33507
|
+
return this.fieldTaintInfo.get(`${typeFqn2}.${fieldName}`);
|
|
33508
|
+
}
|
|
33509
|
+
};
|
|
33510
|
+
function stripJavaLiterals(text) {
|
|
33511
|
+
return text.replace(/"(?:[^"\\]|\\.)*"/g, '""').replace(/'(?:[^'\\]|\\.)'/g, "''").replace(/\/\/.*$/, "");
|
|
33512
|
+
}
|
|
33513
|
+
function withoutLeadingConditions(text) {
|
|
33514
|
+
let out2 = text;
|
|
33515
|
+
for (; ; ) {
|
|
33516
|
+
const m = /\b(?:if|while)\s*\(/.exec(out2);
|
|
33517
|
+
if (!m) return out2;
|
|
33518
|
+
const open = m.index + m[0].length - 1;
|
|
33519
|
+
let depth = 0;
|
|
33520
|
+
let close = -1;
|
|
33521
|
+
for (let i2 = open; i2 < out2.length; i2++) {
|
|
33522
|
+
if (out2[i2] === "(") depth++;
|
|
33523
|
+
else if (out2[i2] === ")" && --depth === 0) {
|
|
33524
|
+
close = i2;
|
|
33525
|
+
break;
|
|
33526
|
+
}
|
|
33527
|
+
}
|
|
33528
|
+
if (close < 0) return out2;
|
|
33529
|
+
out2 = out2.slice(0, m.index) + out2.slice(close + 1);
|
|
33530
|
+
}
|
|
33531
|
+
}
|
|
33532
|
+
var JAVA_LANG_CLASSES = /* @__PURE__ */ new Set([
|
|
33533
|
+
"System",
|
|
33534
|
+
"Math",
|
|
33535
|
+
"StrictMath",
|
|
33536
|
+
"Integer",
|
|
33537
|
+
"Long",
|
|
33538
|
+
"Short",
|
|
33539
|
+
"Byte",
|
|
33540
|
+
"Double",
|
|
33541
|
+
"Float",
|
|
33542
|
+
"Boolean",
|
|
33543
|
+
"Character",
|
|
33544
|
+
"String",
|
|
33545
|
+
"StringBuilder",
|
|
33546
|
+
"StringBuffer",
|
|
33547
|
+
"Objects",
|
|
33548
|
+
"Thread",
|
|
33549
|
+
"Runtime",
|
|
33550
|
+
"Class",
|
|
33551
|
+
"ClassLoader",
|
|
33552
|
+
"Enum",
|
|
33553
|
+
"Process",
|
|
33554
|
+
"ProcessBuilder",
|
|
33555
|
+
"Number"
|
|
33556
|
+
]);
|
|
33557
|
+
function isJdkType(fqn, language) {
|
|
33558
|
+
return (language === void 0 || language === "java") && /^javax?\.[a-z]/.test(fqn);
|
|
33559
|
+
}
|
|
33560
|
+
function isJdkClassReceiver(receiver, language) {
|
|
33561
|
+
if (language !== void 0 && language !== "java") return false;
|
|
33562
|
+
if (/^javax?\.[a-z]/.test(receiver)) return true;
|
|
33563
|
+
return JAVA_LANG_CLASSES.has(receiver);
|
|
33564
|
+
}
|
|
33565
|
+
var JS_LITERAL = "(?:'(?:[^'\\\\]|\\\\.)*'|\"(?:[^\"\\\\]|\\\\.)*\"|`[^`$\\\\]*`|-?\\d+(?:\\.\\d+)?|true|false|null|undefined)";
|
|
33566
|
+
var LITERAL_RHS = new RegExp(`^(?:${JS_LITERAL}|[^?;]+\\?\\s*${JS_LITERAL}\\s*:\\s*${JS_LITERAL})$`);
|
|
33567
|
+
function literalOnlyAssignment(line, variable) {
|
|
33568
|
+
const m = new RegExp(`(?:^|[^\\w$.])${escapeRegExp(variable)}\\s*(?::[^=]+)?=(?!=)\\s*(.+?);?\\s*$`).exec(line);
|
|
33569
|
+
return m !== null && LITERAL_RHS.test(m[1].trim());
|
|
33570
|
+
}
|
|
33571
|
+
|
|
33572
|
+
// src/graph/project-graph.ts
|
|
33573
|
+
var ProjectGraph = class {
|
|
33574
|
+
files = /* @__PURE__ */ new Map();
|
|
33575
|
+
// Lazy caches — nulled whenever a new file is added
|
|
33576
|
+
_symbolTable = null;
|
|
33577
|
+
_typeHierarchy = null;
|
|
33578
|
+
_resolver = null;
|
|
33579
|
+
/**
|
|
33580
|
+
* Register a file's CodeGraph. Invalidates all lazy caches.
|
|
33581
|
+
*/
|
|
33582
|
+
addFile(filePath, graph) {
|
|
33583
|
+
this.files.set(filePath, { graph, ir: graph.ir });
|
|
33584
|
+
this._symbolTable = null;
|
|
33585
|
+
this._typeHierarchy = null;
|
|
33586
|
+
this._resolver = null;
|
|
33587
|
+
}
|
|
33588
|
+
/** Registered file paths in insertion order. */
|
|
33589
|
+
get filePaths() {
|
|
33590
|
+
return [...this.files.keys()];
|
|
33591
|
+
}
|
|
33592
|
+
/** Total number of registered files. */
|
|
33593
|
+
get fileCount() {
|
|
33594
|
+
return this.files.size;
|
|
33595
|
+
}
|
|
33596
|
+
/** Retrieve a file's CodeGraph, or undefined if not registered. */
|
|
33597
|
+
getGraph(filePath) {
|
|
33598
|
+
return this.files.get(filePath)?.graph;
|
|
33599
|
+
}
|
|
33600
|
+
/** Retrieve a file's CircleIR, or undefined if not registered. */
|
|
33601
|
+
getIR(filePath) {
|
|
33602
|
+
return this.files.get(filePath)?.ir;
|
|
33603
|
+
}
|
|
33604
|
+
/** Lazily-built SymbolTable covering all registered files. */
|
|
33605
|
+
get symbolTable() {
|
|
33606
|
+
if (!this._symbolTable) {
|
|
33607
|
+
const st = new SymbolTable();
|
|
33608
|
+
for (const [path, { ir }] of this.files) st.addFromIR(ir, path);
|
|
33609
|
+
this._symbolTable = st;
|
|
33610
|
+
}
|
|
33611
|
+
return this._symbolTable;
|
|
33612
|
+
}
|
|
33613
|
+
/** Lazily-built TypeHierarchyResolver covering all registered files. */
|
|
33614
|
+
get typeHierarchy() {
|
|
33615
|
+
if (!this._typeHierarchy) {
|
|
33616
|
+
const th = new TypeHierarchyResolver();
|
|
33617
|
+
for (const [path, { ir }] of this.files) th.addFromIR(ir, path);
|
|
33618
|
+
this._typeHierarchy = th;
|
|
33619
|
+
}
|
|
33620
|
+
return this._typeHierarchy;
|
|
33621
|
+
}
|
|
33622
|
+
/**
|
|
33623
|
+
* Lazily-built CrossFileResolver.
|
|
33624
|
+
* Accesses `this.symbolTable` and `this.typeHierarchy` (also lazy) so all
|
|
33625
|
+
* three are computed together on the first call after any `addFile()`.
|
|
33626
|
+
*/
|
|
33627
|
+
get resolver() {
|
|
33628
|
+
if (!this._resolver) {
|
|
33629
|
+
const r = new CrossFileResolver(this.symbolTable, this.typeHierarchy);
|
|
33630
|
+
for (const [path, { ir }] of this.files) r.addFile(path, ir);
|
|
33631
|
+
this._resolver = r;
|
|
33632
|
+
}
|
|
33633
|
+
return this._resolver;
|
|
33634
|
+
}
|
|
33635
|
+
};
|
|
33636
|
+
|
|
31315
33637
|
// src/graph/dominator-graph.ts
|
|
31316
33638
|
function computeRPO(cfg, entryId) {
|
|
31317
33639
|
const outgoing = /* @__PURE__ */ new Map();
|
|
@@ -32497,13 +34819,13 @@ function isJavaStaticFormatterCall(call, declaredTypeNames, imports, calls) {
|
|
|
32497
34819
|
if (other === call || other.method_name === "format") continue;
|
|
32498
34820
|
if (other.arguments.some((a) => a.expression.includes(needle))) return false;
|
|
32499
34821
|
}
|
|
32500
|
-
return
|
|
34822
|
+
return isJdkClassReceiver2(call.receiver, JAVA_FORMATTER_CLASSES, declaredTypeNames, imports);
|
|
32501
34823
|
}
|
|
32502
34824
|
function isJavaObjectsNullCheckCall(call, declaredTypeNames, imports) {
|
|
32503
34825
|
if (!call.receiver || !JAVA_OBJECTS_NULL_CHECK_METHODS.has(call.method_name)) return false;
|
|
32504
|
-
return
|
|
34826
|
+
return isJdkClassReceiver2(call.receiver, JAVA_OBJECTS_CLASS, declaredTypeNames, imports);
|
|
32505
34827
|
}
|
|
32506
|
-
function
|
|
34828
|
+
function isJdkClassReceiver2(receiver, classes, declaredTypeNames, imports) {
|
|
32507
34829
|
const dot = receiver.lastIndexOf(".");
|
|
32508
34830
|
const simple = dot < 0 ? receiver : receiver.slice(dot + 1);
|
|
32509
34831
|
const pkg = classes.get(simple);
|
|
@@ -32551,7 +34873,7 @@ function isJavaCharacterPredicateCall(call, declaredTypeNames, imports) {
|
|
|
32551
34873
|
if (!JAVA_CHARACTER_PREDICATES.has(call.method_name) && !JAVA_CHARACTER_METADATA.has(call.method_name)) {
|
|
32552
34874
|
return false;
|
|
32553
34875
|
}
|
|
32554
|
-
return
|
|
34876
|
+
return isJdkClassReceiver2(call.receiver, JAVA_CHARACTER_CLASS, declaredTypeNames, imports);
|
|
32555
34877
|
}
|
|
32556
34878
|
function isJavaNonEscapeCall(call, declaredTypeNames, imports, calls) {
|
|
32557
34879
|
if (isJavaStaticFormatterCall(call, declaredTypeNames, imports, calls)) return true;
|
|
@@ -32624,7 +34946,9 @@ function analyzeInterprocedural(graphOrTypes, callsOrSources, dfgOrSinks, source
|
|
|
32624
34946
|
const calls = graph.ir.calls;
|
|
32625
34947
|
const declaredTypeNames = new Set(types.map((t) => t.name));
|
|
32626
34948
|
const methodNodes = buildMethodNodes(types);
|
|
32627
|
-
const
|
|
34949
|
+
const lang = graph.ir.meta.language;
|
|
34950
|
+
const collectionReceiver = (lang === "typescript" || lang === "javascript") && typeof options.sourceCode === "string" ? makeBuiltinCollectionReceiverTest(options.sourceCode) : null;
|
|
34951
|
+
const callEdges = buildCallEdges(calls, methodNodes, types, collectionReceiver);
|
|
32628
34952
|
const taintedMethods = /* @__PURE__ */ new Set();
|
|
32629
34953
|
const taintedReturns = /* @__PURE__ */ new Map();
|
|
32630
34954
|
for (const source of sources) {
|
|
@@ -32860,8 +35184,9 @@ function analyzeInterprocedural(graphOrTypes, callsOrSources, dfgOrSinks, source
|
|
|
32860
35184
|
}
|
|
32861
35185
|
}
|
|
32862
35186
|
}
|
|
32863
|
-
const
|
|
32864
|
-
const
|
|
35187
|
+
const builtinReceiver = collectionReceiver !== null && collectionReceiver(call.receiver);
|
|
35188
|
+
const resolvedCalleeFqn = builtinReceiver ? null : resolveMethodCall2(call, methodNodes, types);
|
|
35189
|
+
const targetMethod = builtinReceiver ? void 0 : resolvedCalleeFqn ? methodNodes.byFqn.get(resolvedCalleeFqn) : getMethodNode(methodNodes, call.method_name);
|
|
32865
35190
|
if (!targetMethod) {
|
|
32866
35191
|
if (taintedArgPositions.length > 0 && !collectionMethods.has(call.method_name) && !sanitizerMethods.has(call.method_name) && !safeUtilityMethods.has(call.method_name) && !ormQueryBuilderMethods.has(call.method_name)) {
|
|
32867
35192
|
const isBash = graph.ir.meta.language === "bash";
|
|
@@ -33070,9 +35395,29 @@ function resolveMethodCall2(call, methodNodes, types) {
|
|
|
33070
35395
|
}
|
|
33071
35396
|
return null;
|
|
33072
35397
|
}
|
|
33073
|
-
function
|
|
35398
|
+
function makeBuiltinCollectionReceiverTest(sourceCode) {
|
|
35399
|
+
const memo = /* @__PURE__ */ new Map();
|
|
35400
|
+
return (receiver) => {
|
|
35401
|
+
const raw = (receiver ?? "").trim();
|
|
35402
|
+
const m = /^(?:this\.)?([A-Za-z_$][\w$]*)$/.exec(raw);
|
|
35403
|
+
if (!m || raw === "this") return false;
|
|
35404
|
+
const name2 = m[1];
|
|
35405
|
+
const hit = memo.get(name2);
|
|
35406
|
+
if (hit !== void 0) return hit;
|
|
35407
|
+
const n = name2.replace(/[$]/g, "\\$&");
|
|
35408
|
+
const coll = "(?:Readonly)?(?:Weak)?(?:Map|Set)";
|
|
35409
|
+
const ctor = new RegExp(`(?<![\\w$.])${n}\\s*(?::[^=;]*)?=\\s*new\\s+(?:Weak)?(?:Map|Set)\\s*(?:<[^;]*>)?\\s*\\(`);
|
|
35410
|
+
const typed = new RegExp(`(?<![\\w$.])${n}\\s*[?!]?\\s*:\\s*${coll}\\s*<`);
|
|
35411
|
+
const thisCtor = new RegExp(`\\bthis\\.${n}\\s*=\\s*new\\s+(?:Weak)?(?:Map|Set)\\s*(?:<[^;]*>)?\\s*\\(`);
|
|
35412
|
+
const result = ctor.test(sourceCode) || typed.test(sourceCode) || thisCtor.test(sourceCode);
|
|
35413
|
+
memo.set(name2, result);
|
|
35414
|
+
return result;
|
|
35415
|
+
};
|
|
35416
|
+
}
|
|
35417
|
+
function buildCallEdges(calls, methodNodes, types, collectionReceiver = null) {
|
|
33074
35418
|
const edges = [];
|
|
33075
35419
|
for (const call of calls) {
|
|
35420
|
+
if (collectionReceiver !== null && collectionReceiver(call.receiver)) continue;
|
|
33076
35421
|
const resolvedFqn = resolveMethodCall2(call, methodNodes, types);
|
|
33077
35422
|
if (!resolvedFqn) continue;
|
|
33078
35423
|
const callerMethod = call.in_method;
|
|
@@ -33613,10 +35958,11 @@ var ConstantPropagator = class _ConstantPropagator {
|
|
|
33613
35958
|
/**
|
|
33614
35959
|
* Analyze source code and build constant propagation state.
|
|
33615
35960
|
*/
|
|
33616
|
-
analyze(tree, sourceCode, additionalTaintPatterns = [], sanitizerMethods = [], taintedParameters = []) {
|
|
35961
|
+
analyze(tree, sourceCode, additionalTaintPatterns = [], sanitizerMethods = [], taintedParameters = [], language) {
|
|
33617
35962
|
this.source = sourceCode;
|
|
33618
35963
|
this.additionalTaintPatterns = additionalTaintPatterns;
|
|
33619
35964
|
this.taintedParametersList = taintedParameters;
|
|
35965
|
+
const omitJavaUnscopedTaintAliases = language === "java";
|
|
33620
35966
|
this.symbols.clear();
|
|
33621
35967
|
this.tainted.clear();
|
|
33622
35968
|
this.unreachableLines.clear();
|
|
@@ -33675,10 +36021,22 @@ var ConstantPropagator = class _ConstantPropagator {
|
|
|
33675
36021
|
if (/^[^:]+:b\d+:/.test(name2)) {
|
|
33676
36022
|
continue;
|
|
33677
36023
|
}
|
|
36024
|
+
if (omitJavaUnscopedTaintAliases) {
|
|
36025
|
+
continue;
|
|
36026
|
+
}
|
|
33678
36027
|
const unscoped = name2.substring(name2.indexOf(":") + 1);
|
|
33679
36028
|
resultTainted.add(unscoped);
|
|
33680
36029
|
}
|
|
33681
36030
|
}
|
|
36031
|
+
if (omitJavaUnscopedTaintAliases) {
|
|
36032
|
+
for (const name2 of this.tainted) {
|
|
36033
|
+
if (!name2.includes(":") || /^[^:]+:b\d+:/.test(name2)) continue;
|
|
36034
|
+
const local = name2.substring(name2.indexOf(":") + 1);
|
|
36035
|
+
if (this.classFields.has(local)) {
|
|
36036
|
+
resultTainted.add(local);
|
|
36037
|
+
}
|
|
36038
|
+
}
|
|
36039
|
+
}
|
|
33682
36040
|
const resultScopes = new Map(this.sanitizedVarUncovered);
|
|
33683
36041
|
for (const name2 of this.sanitizedVars) {
|
|
33684
36042
|
if (name2.includes(":")) {
|
|
@@ -36130,7 +38488,8 @@ function analyzeConstantPropagation(tree, sourceCode, options = {}) {
|
|
|
36130
38488
|
sourceCode,
|
|
36131
38489
|
options.additionalTaintPatterns ?? [],
|
|
36132
38490
|
options.sanitizerMethods ?? [],
|
|
36133
|
-
options.taintedParameters ?? []
|
|
38491
|
+
options.taintedParameters ?? [],
|
|
38492
|
+
options.language
|
|
36134
38493
|
);
|
|
36135
38494
|
}
|
|
36136
38495
|
function constPropScopedVar(method, varName, line, result) {
|
|
@@ -36659,10 +39018,10 @@ function classifyJavaEntryPoint(method, enclosingType) {
|
|
|
36659
39018
|
}
|
|
36660
39019
|
return "TIER_3_LIBRARY_API";
|
|
36661
39020
|
}
|
|
36662
|
-
function shouldGateInterproceduralParam(sourceType,
|
|
39021
|
+
function shouldGateInterproceduralParam(sourceType, enclosingMethod3, enclosingType, ctx) {
|
|
36663
39022
|
if (sourceType !== "interprocedural_param") return false;
|
|
36664
|
-
if (!
|
|
36665
|
-
const tier = classifyEntryPointTier(
|
|
39023
|
+
if (!enclosingMethod3) return false;
|
|
39024
|
+
const tier = classifyEntryPointTier(enclosingMethod3, enclosingType, ctx);
|
|
36666
39025
|
return tier === "TIER_3_LIBRARY_API";
|
|
36667
39026
|
}
|
|
36668
39027
|
var POLYGLOT_LIBRARY_PATH_FRAGMENTS = [
|
|
@@ -37172,6 +39531,314 @@ function methodIsRuntimeRegistrationHandler(method, regs) {
|
|
|
37172
39531
|
return false;
|
|
37173
39532
|
}
|
|
37174
39533
|
|
|
39534
|
+
// src/analysis/constant-caller-gate.ts
|
|
39535
|
+
var STRING_LITERAL = /^@?"(?:[^"\\]|\\.)*"$/;
|
|
39536
|
+
function typeFqn(type, ir) {
|
|
39537
|
+
const pkg = type.package || ir.meta.package || "";
|
|
39538
|
+
return pkg ? `${pkg}.${type.name}` : type.name;
|
|
39539
|
+
}
|
|
39540
|
+
function enclosingMethod(ir, line) {
|
|
39541
|
+
let best;
|
|
39542
|
+
for (const type of ir.types) {
|
|
39543
|
+
for (const method of type.methods) {
|
|
39544
|
+
if (line < method.start_line || line > method.end_line) continue;
|
|
39545
|
+
if (!best || method.end_line - method.start_line < best.method.end_line - best.method.start_line) {
|
|
39546
|
+
best = { type, method };
|
|
39547
|
+
}
|
|
39548
|
+
}
|
|
39549
|
+
}
|
|
39550
|
+
return best;
|
|
39551
|
+
}
|
|
39552
|
+
function isLiteralLocal(ir, lines, call, name2) {
|
|
39553
|
+
if (!/^[A-Za-z_]\w*$/.test(name2)) return false;
|
|
39554
|
+
const encl = enclosingMethod(ir, call.location.line);
|
|
39555
|
+
if (!encl) return false;
|
|
39556
|
+
const { method } = encl;
|
|
39557
|
+
if (method.parameters.some((p) => p.name === name2)) return false;
|
|
39558
|
+
const assignOp = new RegExp(`(?<![\\w.])${name2}\\s*(?:[-+*/%&|^?]|<<|>>)?=(?!=)`, "g");
|
|
39559
|
+
const literal = '@?"(?:[^"\\\\]|\\\\.)*"';
|
|
39560
|
+
const lang = ir.meta.language;
|
|
39561
|
+
const typeDecl = lang === "java" ? `(?:final\\s+)?[\\w<>\\[\\],.?]+` : `(?:const\\s+)?[\\w<>\\[\\],.?]+`;
|
|
39562
|
+
const declLiteral = new RegExp(`^\\s*${typeDecl}\\s+${name2}\\s*=\\s*${literal}\\s*;\\s*(?://.*)?$`);
|
|
39563
|
+
const plainLiteral = new RegExp(`^\\s*${name2}\\s*=\\s*${literal}\\s*;\\s*(?://.*)?$`);
|
|
39564
|
+
const bareDecl = new RegExp(`^\\s*${typeDecl}\\s+${name2}\\s*;`);
|
|
39565
|
+
const mutate = new RegExp(`\\b(?:out|ref)\\s+${name2}\\b|(?:\\+\\+|--)\\s*${name2}\\b|\\b${name2}\\s*(?:\\+\\+|--)`);
|
|
39566
|
+
let assignments = 0;
|
|
39567
|
+
let assignLine = -1;
|
|
39568
|
+
let assignIsDecl = false;
|
|
39569
|
+
let declared = false;
|
|
39570
|
+
for (let l = method.start_line; l <= method.end_line; l++) {
|
|
39571
|
+
const text = lines[l - 1] ?? "";
|
|
39572
|
+
const n = text.match(assignOp)?.length ?? 0;
|
|
39573
|
+
assignments += n;
|
|
39574
|
+
if (n > 0) {
|
|
39575
|
+
assignLine = l;
|
|
39576
|
+
assignIsDecl = declLiteral.test(text);
|
|
39577
|
+
if (!assignIsDecl && !plainLiteral.test(text)) return false;
|
|
39578
|
+
}
|
|
39579
|
+
if (bareDecl.test(text)) declared = true;
|
|
39580
|
+
if (mutate.test(text)) return false;
|
|
39581
|
+
}
|
|
39582
|
+
return assignments === 1 && assignLine > 0 && assignLine < call.location.line && (assignIsDecl || declared);
|
|
39583
|
+
}
|
|
39584
|
+
var LITERAL_IN_BRACES = /^@?"(?:[^"\\]|\\.)*"(?:\s*,\s*@?"(?:[^"\\]|\\.)*")*\s*$/;
|
|
39585
|
+
function isLiteralArrayLocal(ir, lines, call, name2) {
|
|
39586
|
+
if (!/^[A-Za-z_]\w*$/.test(name2)) return false;
|
|
39587
|
+
const encl = enclosingMethod(ir, call.location.line);
|
|
39588
|
+
if (!encl) return false;
|
|
39589
|
+
const { method } = encl;
|
|
39590
|
+
if (method.parameters.some((p) => p.name === name2)) return false;
|
|
39591
|
+
const declNew = new RegExp(
|
|
39592
|
+
`^\\s*(?:var\\s+)?[\\w<>\\[\\],\\s]*\\b${name2}\\s*=\\s*new\\s+[\\w<>\\[\\],\\s]+\\[\\s*\\d+\\s*\\]\\s*;\\s*(?://.*)?$`
|
|
39593
|
+
);
|
|
39594
|
+
const declInit = new RegExp(
|
|
39595
|
+
`^\\s*(?:var\\s+)?[\\w<>\\[\\],\\s]*\\b${name2}\\s*=\\s*(?:new\\s+[\\w<>\\[\\],\\s]+\\[\\s*\\]\\s*)?\\{([^}]*)\\}\\s*;\\s*(?://.*)?$`
|
|
39596
|
+
);
|
|
39597
|
+
const plainReassign = new RegExp(`^\\s*${name2}\\s*(?![\\[])(?:[-+*/%&|^?]|<<|>>)?=(?!=)`);
|
|
39598
|
+
const elementWrite = new RegExp(`^\\s*${name2}\\s*\\[[^\\]]+\\]\\s*=\\s*(.+?)\\s*;\\s*(?://.*)?$`);
|
|
39599
|
+
const alias = new RegExp(`^\\s*\\w+\\s*=\\s*${name2}\\s*;`);
|
|
39600
|
+
const mutate = new RegExp(`\\b(?:out|ref)\\s+${name2}\\b|(?:\\+\\+|--)\\s*${name2}\\b|\\b${name2}\\s*(?:\\+\\+|--)`);
|
|
39601
|
+
const copyStyle = new RegExp(`\\b(?:Array\\.Copy|CopyTo|\\.Add)\\s*\\([^)]*\\b${name2}\\b`);
|
|
39602
|
+
let declared = false;
|
|
39603
|
+
let declLine = -1;
|
|
39604
|
+
for (let l = method.start_line; l <= method.end_line; l++) {
|
|
39605
|
+
const text = lines[l - 1] ?? "";
|
|
39606
|
+
if (mutate.test(text) || alias.test(text) || copyStyle.test(text)) return false;
|
|
39607
|
+
const initMatch = declInit.exec(text);
|
|
39608
|
+
if (initMatch) {
|
|
39609
|
+
declared = true;
|
|
39610
|
+
declLine = l;
|
|
39611
|
+
const inner = (initMatch[1] ?? "").trim();
|
|
39612
|
+
if (inner.length > 0 && !LITERAL_IN_BRACES.test(inner)) return false;
|
|
39613
|
+
continue;
|
|
39614
|
+
}
|
|
39615
|
+
if (declNew.test(text)) {
|
|
39616
|
+
declared = true;
|
|
39617
|
+
declLine = l;
|
|
39618
|
+
continue;
|
|
39619
|
+
}
|
|
39620
|
+
const ew = elementWrite.exec(text);
|
|
39621
|
+
if (ew) {
|
|
39622
|
+
const rhs = ew[1].trim();
|
|
39623
|
+
if (STRING_LITERAL.test(rhs)) continue;
|
|
39624
|
+
if (/^[A-Za-z_]\w*$/.test(rhs) && isLiteralLocal(ir, lines, call, rhs)) continue;
|
|
39625
|
+
return false;
|
|
39626
|
+
}
|
|
39627
|
+
if (l !== declLine && plainReassign.test(text)) return false;
|
|
39628
|
+
}
|
|
39629
|
+
if (!declared) return false;
|
|
39630
|
+
for (const c of ir.calls) {
|
|
39631
|
+
if (c.location.line < method.start_line || c.location.line > method.end_line) continue;
|
|
39632
|
+
if (c.location.line >= call.location.line) continue;
|
|
39633
|
+
if (c === call) continue;
|
|
39634
|
+
if (c.arguments.some((a) => (a.variable ?? a.expression?.trim()) === name2)) return false;
|
|
39635
|
+
}
|
|
39636
|
+
return true;
|
|
39637
|
+
}
|
|
39638
|
+
function isDirectConstantArg(ir, lines, call, position) {
|
|
39639
|
+
const arg = call.arguments.find((a) => a.position === position);
|
|
39640
|
+
if (!arg) return false;
|
|
39641
|
+
const expr = (arg.expression ?? "").trim();
|
|
39642
|
+
if (STRING_LITERAL.test(expr)) return true;
|
|
39643
|
+
if (arg.variable && expr === arg.variable && isLiteralLocal(ir, lines, call, arg.variable)) return true;
|
|
39644
|
+
return !!arg.variable && expr === arg.variable && isLiteralArrayLocal(ir, lines, call, arg.variable);
|
|
39645
|
+
}
|
|
39646
|
+
function hasEnumerableCallers(type, method, derivedFrom, language) {
|
|
39647
|
+
if (type.kind !== "class") return false;
|
|
39648
|
+
if (method.modifiers.some((m) => m === "abstract")) return false;
|
|
39649
|
+
if (language === "csharp" && method.modifiers.some((m) => m === "virtual" || m === "override")) return false;
|
|
39650
|
+
if (derivedFrom.has(type.name)) return false;
|
|
39651
|
+
return type.methods.filter((m) => m.name === method.name).length === 1;
|
|
39652
|
+
}
|
|
39653
|
+
var TRANSITIVE_MAX_DEPTH = 4;
|
|
39654
|
+
function isConstantArgRecursive(ctx, ir, lines, call, position, depth, visiting) {
|
|
39655
|
+
if (isDirectConstantArg(ir, lines, call, position)) return true;
|
|
39656
|
+
if (isConstantReturnLocal(ctx, ir, lines, call, position)) return true;
|
|
39657
|
+
if (depth >= TRANSITIVE_MAX_DEPTH) return false;
|
|
39658
|
+
const arg = call.arguments.find((a) => a.position === position);
|
|
39659
|
+
if (!arg?.variable || (arg.expression ?? "").trim() !== arg.variable) return false;
|
|
39660
|
+
const encl = enclosingMethod(ir, call.location.line);
|
|
39661
|
+
if (!encl) return false;
|
|
39662
|
+
if (!hasEnumerableCallers(encl.type, encl.method, ctx.derivedFrom, ir.meta.language)) return false;
|
|
39663
|
+
const paramIdx = encl.method.parameters.findIndex((p) => p.name === arg.variable);
|
|
39664
|
+
if (paramIdx < 0) return false;
|
|
39665
|
+
const fqn = `${typeFqn(encl.type, ir)}.${encl.method.name}`;
|
|
39666
|
+
const relayFile = ctx.fileAnalyses.find((f) => f.analysis === ir)?.file;
|
|
39667
|
+
const visitKey = `${fqn}:${paramIdx}`;
|
|
39668
|
+
if (visiting.has(visitKey)) return false;
|
|
39669
|
+
visiting.add(visitKey);
|
|
39670
|
+
let resolvedToMethod = 0;
|
|
39671
|
+
for (const site of ctx.callsByName.get(encl.method.name) ?? []) {
|
|
39672
|
+
if (relayFile !== void 0 && site.file !== relayFile && declaresType(ctx.fileAnalyses, site.file, encl.type.name)) continue;
|
|
39673
|
+
const r = ctx.resolver.resolveCall(site.call, site.file);
|
|
39674
|
+
if (resolvesElsewhere(r, fqn)) continue;
|
|
39675
|
+
if (!r || r.resolution !== "exact") {
|
|
39676
|
+
visiting.delete(visitKey);
|
|
39677
|
+
return false;
|
|
39678
|
+
}
|
|
39679
|
+
if (r.targetMethod !== fqn || relayFile !== void 0 && site.file !== relayFile && r.targetFile !== relayFile) continue;
|
|
39680
|
+
const callerIr = ctx.fileAnalyses.find((f) => f.file === site.file)?.analysis;
|
|
39681
|
+
const callerLines = ctx.sourceLinesByFile.get(site.file);
|
|
39682
|
+
if (!callerIr || !callerLines) {
|
|
39683
|
+
visiting.delete(visitKey);
|
|
39684
|
+
return false;
|
|
39685
|
+
}
|
|
39686
|
+
if (!isConstantArgRecursive(ctx, callerIr, callerLines, site.call, paramIdx, depth + 1, visiting)) {
|
|
39687
|
+
visiting.delete(visitKey);
|
|
39688
|
+
return false;
|
|
39689
|
+
}
|
|
39690
|
+
resolvedToMethod++;
|
|
39691
|
+
}
|
|
39692
|
+
visiting.delete(visitKey);
|
|
39693
|
+
return resolvedToMethod > 0;
|
|
39694
|
+
}
|
|
39695
|
+
function applySingleFileJavaMapConstantCallerGate(file, ir, lines) {
|
|
39696
|
+
if (ir.meta.language !== "java") return;
|
|
39697
|
+
const flows = ir.taint?.flows ?? [];
|
|
39698
|
+
if (!flows.some((f) => f.source_type === "plugin_param")) return;
|
|
39699
|
+
const fileAnalyses = [{ file, analysis: ir }];
|
|
39700
|
+
const projectGraph = new ProjectGraph();
|
|
39701
|
+
projectGraph.addFile(file, new CodeGraph(ir));
|
|
39702
|
+
const sourceLinesByFile = /* @__PURE__ */ new Map([[file, lines]]);
|
|
39703
|
+
const resolver = projectGraph.resolver;
|
|
39704
|
+
const callsByName = /* @__PURE__ */ new Map();
|
|
39705
|
+
const derivedFrom = /* @__PURE__ */ new Set();
|
|
39706
|
+
for (const call of ir.calls) {
|
|
39707
|
+
const arr = callsByName.get(call.method_name) ?? [];
|
|
39708
|
+
arr.push({ file, call });
|
|
39709
|
+
callsByName.set(call.method_name, arr);
|
|
39710
|
+
}
|
|
39711
|
+
for (const type of ir.types) {
|
|
39712
|
+
if (type.extends) derivedFrom.add(type.extends.split(".").pop() ?? type.extends);
|
|
39713
|
+
for (const i2 of type.implements) derivedFrom.add(i2.split(".").pop() ?? i2);
|
|
39714
|
+
}
|
|
39715
|
+
const gateCtx = {
|
|
39716
|
+
fileAnalyses,
|
|
39717
|
+
callsByName,
|
|
39718
|
+
resolver,
|
|
39719
|
+
sourceLinesByFile,
|
|
39720
|
+
derivedFrom
|
|
39721
|
+
};
|
|
39722
|
+
const callersConstant = (type, method, position) => {
|
|
39723
|
+
const fqn = `${typeFqn(type, ir)}.${method.name}`;
|
|
39724
|
+
let resolvedToMethod = 0;
|
|
39725
|
+
for (const site of callsByName.get(method.name) ?? []) {
|
|
39726
|
+
if (site.file !== file && declaresType(fileAnalyses, site.file, type.name)) continue;
|
|
39727
|
+
const r = resolver.resolveCall(site.call, site.file);
|
|
39728
|
+
if (resolvesElsewhere(r, fqn)) continue;
|
|
39729
|
+
if (!r || r.resolution !== "exact") return false;
|
|
39730
|
+
if (r.targetMethod !== fqn || site.file !== file && r.targetFile !== file) continue;
|
|
39731
|
+
const callerIr = fileAnalyses.find((f) => f.file === site.file)?.analysis;
|
|
39732
|
+
const callerLines = sourceLinesByFile.get(site.file);
|
|
39733
|
+
if (!callerIr || !callerLines || !isConstantArgRecursive(gateCtx, callerIr, callerLines, site.call, position, 0, /* @__PURE__ */ new Set())) {
|
|
39734
|
+
return false;
|
|
39735
|
+
}
|
|
39736
|
+
resolvedToMethod++;
|
|
39737
|
+
}
|
|
39738
|
+
return resolvedToMethod > 0;
|
|
39739
|
+
};
|
|
39740
|
+
const kept = flows.filter((flow) => {
|
|
39741
|
+
if (flow.source_type !== "plugin_param") return true;
|
|
39742
|
+
if (flow.sink_type !== "sql_injection") return true;
|
|
39743
|
+
if (flows.some((o) => o !== flow && o.sink_line === flow.sink_line && o.source_type !== "interprocedural_param" && o.source_type !== "plugin_param")) return true;
|
|
39744
|
+
const encl = enclosingMethod(ir, flow.source_line);
|
|
39745
|
+
if (!encl || !hasEnumerableCallers(encl.type, encl.method, derivedFrom, ir.meta.language)) return true;
|
|
39746
|
+
const positions = localMapParamPositions(lines, encl.method, flow.source_line);
|
|
39747
|
+
if (!positions) return true;
|
|
39748
|
+
return !positions.every((pos) => callersConstant(encl.type, encl.method, pos));
|
|
39749
|
+
});
|
|
39750
|
+
if (kept.length !== flows.length) ir.taint.flows = kept;
|
|
39751
|
+
}
|
|
39752
|
+
function resolvesElsewhere(r, fqn) {
|
|
39753
|
+
if (!r || r.resolution !== "polymorphic" || r.targetMethod === fqn) return false;
|
|
39754
|
+
return Array.isArray(r.candidates) && r.candidates.length > 0 && !r.candidates.includes(fqn);
|
|
39755
|
+
}
|
|
39756
|
+
function isConstantReturnLocal(ctx, ir, lines, call, position) {
|
|
39757
|
+
if (ir.meta.language !== "java") return false;
|
|
39758
|
+
const arg = call.arguments.find((a) => a.position === position);
|
|
39759
|
+
const name2 = arg?.variable;
|
|
39760
|
+
if (!name2 || (arg.expression ?? "").trim() !== name2 || !/^[A-Za-z_]\w*$/.test(name2)) return false;
|
|
39761
|
+
const encl = enclosingMethod(ir, call.location.line);
|
|
39762
|
+
if (!encl || encl.method.parameters.some((p) => p.name === name2)) return false;
|
|
39763
|
+
const file = ctx.fileAnalyses.find((f) => f.analysis === ir)?.file;
|
|
39764
|
+
if (!file) return false;
|
|
39765
|
+
const assign = new RegExp(`(?:^|[;{]|\\b(?:if|else)\\b[^;]*?)\\s*(?:[\\w<>\\[\\].]+\\s+)?${name2}\\s*=(?!=)\\s*(.+?);`);
|
|
39766
|
+
const literal = /^"(?:[^"\\]|\\.)*"$/;
|
|
39767
|
+
let viaCall = 0;
|
|
39768
|
+
for (let l = encl.method.start_line; l < call.location.line; l++) {
|
|
39769
|
+
const text = (lines[l - 1] ?? "").replace(/\/\/.*$/, "");
|
|
39770
|
+
if (new RegExp(`(?:\\+\\+|--)\\s*${name2}\\b|\\b${name2}\\s*(?:\\+\\+|--|[-+*/%&|^]=)`).test(text)) return false;
|
|
39771
|
+
const m = assign.exec(text);
|
|
39772
|
+
if (!m) continue;
|
|
39773
|
+
const rhs = m[1].trim();
|
|
39774
|
+
if (literal.test(rhs)) continue;
|
|
39775
|
+
if (/\.getTheValue\s*\(\s*"(?:[^"\\]|\\.)*"\s*\)/.test(rhs)) {
|
|
39776
|
+
viaCall++;
|
|
39777
|
+
continue;
|
|
39778
|
+
}
|
|
39779
|
+
const callee = ir.calls.find((c) => c.location.line === l && rhs.includes(`${c.method_name}(`));
|
|
39780
|
+
if (!callee) return false;
|
|
39781
|
+
const r = ctx.resolver.resolveCall(callee, file);
|
|
39782
|
+
if (!r || r.resolution !== "exact" || !methodReturnsOnlyLiterals(ctx, r.targetFile, r.targetMethod)) return false;
|
|
39783
|
+
viaCall++;
|
|
39784
|
+
}
|
|
39785
|
+
return viaCall > 0;
|
|
39786
|
+
}
|
|
39787
|
+
function methodReturnsOnlyLiterals(ctx, file, fqn) {
|
|
39788
|
+
const ir = ctx.fileAnalyses.find((f) => f.file === file)?.analysis;
|
|
39789
|
+
const lines = ctx.sourceLinesByFile.get(file);
|
|
39790
|
+
if (!ir || !lines) return false;
|
|
39791
|
+
const name2 = fqn.split(".").pop();
|
|
39792
|
+
for (const type of ir.types) {
|
|
39793
|
+
if (fqn !== `${typeFqn(type, ir)}.${name2}`) continue;
|
|
39794
|
+
const methods = type.methods.filter((m2) => m2.name === name2);
|
|
39795
|
+
if (methods.length !== 1) return false;
|
|
39796
|
+
const m = methods[0];
|
|
39797
|
+
let returns = 0;
|
|
39798
|
+
for (let l = m.start_line; l <= m.end_line; l++) {
|
|
39799
|
+
const text = (lines[l - 1] ?? "").replace(/\/\/.*$/, "");
|
|
39800
|
+
if (!/\breturn\b/.test(text)) continue;
|
|
39801
|
+
for (const m2 of text.matchAll(/\breturn\b([^;]*);?/g)) {
|
|
39802
|
+
if (!/^\s*"(?:[^"\\]|\\.)*"\s*$/.test(m2[1])) return false;
|
|
39803
|
+
returns++;
|
|
39804
|
+
}
|
|
39805
|
+
}
|
|
39806
|
+
return returns > 0;
|
|
39807
|
+
}
|
|
39808
|
+
return false;
|
|
39809
|
+
}
|
|
39810
|
+
function declaresType(fileAnalyses, file, name2) {
|
|
39811
|
+
const ir = fileAnalyses.find((f) => f.file === file)?.analysis;
|
|
39812
|
+
return !!ir && ir.meta.language === "java" && ir.types.some((t) => t.name === name2);
|
|
39813
|
+
}
|
|
39814
|
+
function localMapParamPositions(lines, method, sourceLine) {
|
|
39815
|
+
const read = /([A-Za-z_]\w*)\s*\.\s*get\s*\(/.exec(lines[sourceLine - 1] ?? "");
|
|
39816
|
+
if (!read) return null;
|
|
39817
|
+
const map = read[1];
|
|
39818
|
+
const body2 = [];
|
|
39819
|
+
for (let l = method.start_line; l <= method.end_line; l++) body2.push((lines[l - 1] ?? "").replace(/\/\/.*$/, ""));
|
|
39820
|
+
const text = body2.join("\n");
|
|
39821
|
+
const created = new RegExp(`\\b${map}\\s*=\\s*new\\s+[\\w.]*Map\\b`).test(text);
|
|
39822
|
+
const assigned = text.match(new RegExp(`(?<![\\w.])${map}\\s*=(?!=)`, "g"))?.length ?? 0;
|
|
39823
|
+
if (!created || assigned !== 1) return null;
|
|
39824
|
+
if (new RegExp(`[(,]\\s*${map}\\s*[,)]|\\breturn\\s+${map}\\b`).test(text)) return null;
|
|
39825
|
+
const params = method.parameters.map((p) => p.name);
|
|
39826
|
+
const positions = /* @__PURE__ */ new Set();
|
|
39827
|
+
let puts = 0;
|
|
39828
|
+
for (const m of text.matchAll(new RegExp(`\\b${map}\\s*\\.\\s*(put|putAll|putIfAbsent|compute\\w*|merge|replace\\w*)\\s*\\(([^;]*)\\)\\s*;`, "g"))) {
|
|
39829
|
+
if (m[1] !== "put") return null;
|
|
39830
|
+
const comma = m[2].indexOf(",");
|
|
39831
|
+
if (comma < 0) return null;
|
|
39832
|
+
const value = m[2].slice(comma + 1).trim();
|
|
39833
|
+
puts++;
|
|
39834
|
+
if (/^"(?:[^"\\]|\\.)*"$/.test(value)) continue;
|
|
39835
|
+
const idx = params.indexOf(value);
|
|
39836
|
+
if (idx < 0) return null;
|
|
39837
|
+
positions.add(idx);
|
|
39838
|
+
}
|
|
39839
|
+
return puts > 0 ? [...positions] : null;
|
|
39840
|
+
}
|
|
39841
|
+
|
|
37175
39842
|
// src/analysis/project-profile-transform.ts
|
|
37176
39843
|
var DOWNGRADE_ELIGIBLE_RULE_IDS = /* @__PURE__ */ new Set([
|
|
37177
39844
|
"code_injection",
|
|
@@ -40464,6 +43131,7 @@ var INERT_WHEN_ALPHANUMERIC = /* @__PURE__ */ new Set([
|
|
|
40464
43131
|
"code_injection"
|
|
40465
43132
|
]);
|
|
40466
43133
|
var IDENT = "[A-Za-z_]\\w*";
|
|
43134
|
+
var URI_KIND_ARG = String.raw`(?:,\s*(?:System\s*\.\s*)?UriKind\s*\.\s*\w+\s*)?`;
|
|
40467
43135
|
var ASSIGN_RE = new RegExp(`^\\s*(?:var\\s+|[A-Za-z_][\\w.<>\\[\\]?]*\\s+)?(${IDENT})\\s*=(?!=)\\s*(.+?);?\\s*$`);
|
|
40468
43136
|
var INNER_ASSIGN_RE = new RegExp(`\\b(${IDENT})\\s*=(?!=)\\s*([^;{}]+)`, "g");
|
|
40469
43137
|
var APPEND_RE = new RegExp(`^\\s*(${IDENT})\\s*\\+=\\s*(.+?);?\\s*$`);
|
|
@@ -40520,6 +43188,30 @@ function leadingIf(text) {
|
|
|
40520
43188
|
if (cond === null) return null;
|
|
40521
43189
|
return { cond: cond.trim(), rest: text.slice(open + cond.length + 2).trim() };
|
|
40522
43190
|
}
|
|
43191
|
+
function splitTernary(text) {
|
|
43192
|
+
const body2 = text.trim().replace(/;\s*(?:\/\/.*)?$/, "").replace(new RegExp(`^(?:return\\s+|(?:var\\s+|[A-Za-z_][\\w.<>\\[\\]?]*\\s+)?${IDENT}\\s*=(?!=)\\s*)`), "");
|
|
43193
|
+
let depth = 0;
|
|
43194
|
+
let q = -1;
|
|
43195
|
+
let c = -1;
|
|
43196
|
+
let inStr = false;
|
|
43197
|
+
for (let i2 = 0; i2 < body2.length; i2++) {
|
|
43198
|
+
const ch = body2[i2];
|
|
43199
|
+
if (inStr) {
|
|
43200
|
+
if (ch === "\\") i2++;
|
|
43201
|
+
else if (ch === '"') inStr = false;
|
|
43202
|
+
continue;
|
|
43203
|
+
}
|
|
43204
|
+
if (ch === '"') inStr = true;
|
|
43205
|
+
else if (ch === "(" || ch === "[" || ch === "{") depth++;
|
|
43206
|
+
else if (ch === ")" || ch === "]" || ch === "}") depth--;
|
|
43207
|
+
else if (depth === 0 && ch === "?" && body2[i2 + 1] !== "?" && body2[i2 + 1] !== "." && body2[i2 - 1] !== "?") {
|
|
43208
|
+
if (q !== -1) return null;
|
|
43209
|
+
q = i2;
|
|
43210
|
+
} else if (depth === 0 && ch === ":" && q !== -1 && c === -1) c = i2;
|
|
43211
|
+
}
|
|
43212
|
+
if (q === -1 || c === -1) return null;
|
|
43213
|
+
return { cond: body2.slice(0, q).trim(), whenTrue: body2.slice(q + 1, c).trim(), whenFalse: body2.slice(c + 1).trim() };
|
|
43214
|
+
}
|
|
40523
43215
|
var EXITS_RE = /^(?:\{\s*)?(?:return\b|throw\b|continue\b|break\b)/;
|
|
40524
43216
|
var CSharpCredit = class {
|
|
40525
43217
|
constructor(code, methods) {
|
|
@@ -40868,7 +43560,7 @@ var CSharpCredit = class {
|
|
|
40868
43560
|
const e = escapeRegex(expr).replace(/\\ /g, "\\s*");
|
|
40869
43561
|
return new RegExp(`${e}\\s*==\\s*@?"[^"]+"`).test(cond) || new RegExp(`@?"[^"]+"\\s*==\\s*${e}`).test(cond) || new RegExp(`${e}\\s*\\.\\s*Equals\\s*\\(`).test(cond) || new RegExp(`\\.\\s*Contains\\s*\\(\\s*${e}\\s*[),]`).test(cond) || new RegExp(`\\bIndexOf\\s*\\([^()]*,\\s*${e}\\s*\\)\\s*>=\\s*0`).test(cond);
|
|
40870
43562
|
};
|
|
40871
|
-
const direct = new RegExp(`new\\s+(?:System\\s*\\.\\s*)?Uri\\s*\\(\\s*(${IDENT})\\s
|
|
43563
|
+
const direct = new RegExp(`new\\s+(?:System\\s*\\.\\s*)?Uri\\s*\\(\\s*(${IDENT})\\s*${URI_KIND_ARG}\\)\\s*\\.\\s*Host\\b`, "g");
|
|
40872
43564
|
for (const m of cond.matchAll(direct)) {
|
|
40873
43565
|
if (compares(m[0])) out2.push(m[1]);
|
|
40874
43566
|
}
|
|
@@ -40932,7 +43624,7 @@ var CSharpCredit = class {
|
|
|
40932
43624
|
const kinds = [];
|
|
40933
43625
|
if (INERT_WHEN_ALPHANUMERIC.has(type)) kinds.push("allowlist", "numeric");
|
|
40934
43626
|
if (type === "ssrf") kinds.push("host");
|
|
40935
|
-
if (type === "open_redirect") kinds.push("localUrl");
|
|
43627
|
+
if (type === "open_redirect") kinds.push("localUrl", "host");
|
|
40936
43628
|
const proven = /* @__PURE__ */ new Set();
|
|
40937
43629
|
if (kinds.length === 0) return proven;
|
|
40938
43630
|
const scopeStart = this.methodAt(sinkLine)?.start_line ?? 1;
|
|
@@ -40951,7 +43643,7 @@ var CSharpCredit = class {
|
|
|
40951
43643
|
const [, lhs, rhs] = m;
|
|
40952
43644
|
const parse2 = new RegExp(`^(?:\\([^)]*\\)\\s*)?(?:int|long|short|byte|uint|ulong|decimal|double|float|Int32|Int64)\\s*\\.\\s*Parse\\s*\\(\\s*(${IDENT})\\s*[,)]`).exec(rhs);
|
|
40953
43645
|
if (parse2) parsedFrom.set(lhs, parse2[1]);
|
|
40954
|
-
const host = new RegExp(`^new\\s+(?:System\\s*\\.\\s*)?Uri\\s*\\(\\s*(${IDENT})\\s
|
|
43646
|
+
const host = new RegExp(`^new\\s+(?:System\\s*\\.\\s*)?Uri\\s*\\(\\s*(${IDENT})\\s*${URI_KIND_ARG}\\)\\s*\\.\\s*Host$`).exec(rhs.trim());
|
|
40955
43647
|
if (host) hostOf.set(lhs, host[1]);
|
|
40956
43648
|
boolOf.set(lhs, rhs);
|
|
40957
43649
|
}
|
|
@@ -40992,6 +43684,16 @@ var CSharpCredit = class {
|
|
|
40992
43684
|
credit(wrapped ? inner.slice(1, -1) : inner);
|
|
40993
43685
|
} else if (/!=/.test(guard.cond) && !/[|&]/.test(guard.cond)) credit(guard.cond.replace("!=", "=="));
|
|
40994
43686
|
}
|
|
43687
|
+
const ternary = splitTernary(this.sinkText(sinkLine));
|
|
43688
|
+
if (ternary && !ternary.cond.startsWith("!")) {
|
|
43689
|
+
const before2 = new Set(proven);
|
|
43690
|
+
proven.clear();
|
|
43691
|
+
credit(ternary.cond);
|
|
43692
|
+
const fromTernary = [...proven].filter((v) => !before2.has(v) && mentions(ternary.whenTrue, v) && !mentions(ternary.whenFalse, v));
|
|
43693
|
+
proven.clear();
|
|
43694
|
+
for (const v of before2) proven.add(v);
|
|
43695
|
+
for (const v of fromTernary) proven.add(v);
|
|
43696
|
+
}
|
|
40995
43697
|
return proven;
|
|
40996
43698
|
}
|
|
40997
43699
|
/**
|
|
@@ -41108,7 +43810,8 @@ var InterproceduralPass = class {
|
|
|
41108
43810
|
const csCredit = language === "csharp" && typeof ctx.code === "string" ? new CSharpCredit(ctx.code, graph.ir.types.flatMap((t) => t.methods)) : null;
|
|
41109
43811
|
if (sinks.length > 0) {
|
|
41110
43812
|
const interProc = analyzeInterprocedural(graph, sources, sinks, sanitizers, {
|
|
41111
|
-
taintedVariables: constProp.tainted
|
|
43813
|
+
taintedVariables: constProp.tainted,
|
|
43814
|
+
sourceCode: typeof ctx.code === "string" ? ctx.code : void 0
|
|
41112
43815
|
});
|
|
41113
43816
|
for (const sink of interProc.propagatedSinks) {
|
|
41114
43817
|
if (sink.type === "external_taint_escape") continue;
|
|
@@ -41135,6 +43838,9 @@ var InterproceduralPass = class {
|
|
|
41135
43838
|
if (language === "csharp" && typeof ctx.code === "string" && !csharpParamReachesSink(ctx.code, method, edge.taintedArgs, sink, csCredit)) {
|
|
41136
43839
|
continue;
|
|
41137
43840
|
}
|
|
43841
|
+
if ((language === "javascript" || language === "typescript") && jsSinkArgsAreConstant(graph.ir, method, sink)) {
|
|
43842
|
+
continue;
|
|
43843
|
+
}
|
|
41138
43844
|
for (const source of sources) {
|
|
41139
43845
|
if (source.line > edge.callLine) continue;
|
|
41140
43846
|
if (source.type === "interprocedural_param" && source.confidence < 0.6) continue;
|
|
@@ -41182,7 +43888,8 @@ var InterproceduralPass = class {
|
|
|
41182
43888
|
interProc,
|
|
41183
43889
|
additionalFlows,
|
|
41184
43890
|
language === "java" ? ctx.code : void 0,
|
|
41185
|
-
language === "java" ? constProp : void 0
|
|
43891
|
+
language === "java" ? constProp : void 0,
|
|
43892
|
+
language === "java" || language === "javascript" || language === "typescript" ? ctx.code : void 0
|
|
41186
43893
|
);
|
|
41187
43894
|
const taintBridges = findTaintBridges(interProc);
|
|
41188
43895
|
interprocedural = {
|
|
@@ -41205,7 +43912,8 @@ var InterproceduralPass = class {
|
|
|
41205
43912
|
return { additionalSinks, additionalFlows, interprocedural };
|
|
41206
43913
|
}
|
|
41207
43914
|
const interProc = analyzeInterprocedural(graph, fallbackSources, [], sanitizers, {
|
|
41208
|
-
taintedVariables: constProp.tainted
|
|
43915
|
+
taintedVariables: constProp.tainted,
|
|
43916
|
+
sourceCode: typeof ctx.code === "string" ? ctx.code : void 0
|
|
41209
43917
|
});
|
|
41210
43918
|
const cleared = ctx.hasResult("taint-matcher") ? ctx.getResult("taint-matcher").sinks.filter((s) => s.method && !sinks.some((k) => k.line === s.line && k.method === s.method)) : [];
|
|
41211
43919
|
const isClearedCall = (esc) => cleared.some((s) => s.line === esc.line && s.method === esc.method && (!s.argPositions?.length || !esc.argPositions?.length || esc.argPositions.every((p) => s.argPositions.includes(p))));
|
|
@@ -41405,13 +44113,13 @@ function storeBase(line) {
|
|
|
41405
44113
|
if (!m || m[1] === "this") return null;
|
|
41406
44114
|
return m[1];
|
|
41407
44115
|
}
|
|
41408
|
-
function appendCalleeSourceCallerSinkFlows(graph, sources, sinks, interProc, additionalFlows, fileCode, constProp) {
|
|
44116
|
+
function appendCalleeSourceCallerSinkFlows(graph, sources, sinks, interProc, additionalFlows, fileCode, constProp, returnReachCode) {
|
|
41409
44117
|
const types = graph.ir.types ?? [];
|
|
41410
44118
|
for (const edge of interProc.callEdges) {
|
|
41411
44119
|
const callee = interProc.methodNodes.get(edge.calleeMethod);
|
|
41412
44120
|
if (!callee) continue;
|
|
41413
44121
|
const calleeSources = sources.filter(
|
|
41414
|
-
(s) => s.line >= callee.startLine && s.line <= callee.endLine && (!
|
|
44122
|
+
(s) => s.line >= callee.startLine && s.line <= callee.endLine && (!returnReachCode || s.type === "interprocedural_param" || calleeSourceReachesReturn(graph, returnReachCode, callee.startLine, callee.endLine, s.line))
|
|
41415
44123
|
);
|
|
41416
44124
|
if (calleeSources.length === 0) continue;
|
|
41417
44125
|
const assignee = graph.ir.dfg.defs.find(
|
|
@@ -41455,6 +44163,19 @@ function appendCalleeSourceCallerSinkFlows(graph, sources, sinks, interProc, add
|
|
|
41455
44163
|
)) {
|
|
41456
44164
|
continue;
|
|
41457
44165
|
}
|
|
44166
|
+
if (fileCode && (sink.type === "trust_boundary" || (sink.type === "sql_injection" || sink.type === "command_injection" || sink.type === "path_traversal" || sink.type === "xss" || sink.type === "format_string") && javaHelperCallHasInstanceReceiver(graph, edge)) && calleeSources.every(
|
|
44167
|
+
(s) => (s.type === "interprocedural_param" || s.type === "plugin_param") && !!s.variable
|
|
44168
|
+
) && skipPassThroughTrustBoundaryWithoutHttpArg(
|
|
44169
|
+
graph,
|
|
44170
|
+
fileCode,
|
|
44171
|
+
edge,
|
|
44172
|
+
callee.startLine,
|
|
44173
|
+
callee.endLine,
|
|
44174
|
+
sources,
|
|
44175
|
+
calleeSources.map((s) => s.variable)
|
|
44176
|
+
)) {
|
|
44177
|
+
continue;
|
|
44178
|
+
}
|
|
41458
44179
|
additionalFlows.push({
|
|
41459
44180
|
source_line: source.line,
|
|
41460
44181
|
sink_line: sink.line,
|
|
@@ -41488,7 +44209,11 @@ var HELPER_RETURN_GATED_SINKS = /* @__PURE__ */ new Set([
|
|
|
41488
44209
|
"path_traversal",
|
|
41489
44210
|
// #976: the same helper shapes feed LDAP and XPath sinks (OWASP ldapi/xpathi).
|
|
41490
44211
|
"ldap_injection",
|
|
41491
|
-
"xpath_injection"
|
|
44212
|
+
"xpath_injection",
|
|
44213
|
+
// #915: the same helper shapes feed XSS sinks (OWASP xss inner-class `Test`), and a
|
|
44214
|
+
// `getWriter().format(locale, bar, …)` sink is both xss and format_string on one line.
|
|
44215
|
+
"xss",
|
|
44216
|
+
"format_string"
|
|
41492
44217
|
]);
|
|
41493
44218
|
function calleeReturnMayCarryParam(code, startLine, endLine, sourceVars) {
|
|
41494
44219
|
const raw = code.split("\n").slice(startLine - 1, endLine);
|
|
@@ -41704,6 +44429,77 @@ function enclosingMethodName(types, line) {
|
|
|
41704
44429
|
}
|
|
41705
44430
|
return null;
|
|
41706
44431
|
}
|
|
44432
|
+
function javaHelperCallHasInstanceReceiver(graph, edge) {
|
|
44433
|
+
const callSite = graph.ir.calls?.find(
|
|
44434
|
+
(c) => c.location.line === edge.callLine && (c.in_method ?? null) === edge.callerMethod
|
|
44435
|
+
);
|
|
44436
|
+
const recv = callSite?.receiver?.trim();
|
|
44437
|
+
return !!recv;
|
|
44438
|
+
}
|
|
44439
|
+
function skipPassThroughTrustBoundaryWithoutHttpArg(graph, fileCode, edge, calleeStart, calleeEnd, fileSources, paramVars) {
|
|
44440
|
+
const lines = fileCode.split("\n");
|
|
44441
|
+
const paramNames = javaMethodParamNames(lines.slice(calleeStart - 1, calleeEnd));
|
|
44442
|
+
const callSite = graph.ir.calls?.find(
|
|
44443
|
+
(c) => c.location.line === edge.callLine && (c.in_method ?? null) === edge.callerMethod
|
|
44444
|
+
);
|
|
44445
|
+
for (const paramVar of paramVars) {
|
|
44446
|
+
const idx = paramNames.indexOf(paramVar);
|
|
44447
|
+
if (idx < 0) continue;
|
|
44448
|
+
const fromCall = callSite?.arguments?.find((a) => a.position === idx);
|
|
44449
|
+
const argVar = fromCall?.variable ?? (fromCall?.expression && /^[A-Za-z_]\w*$/.test(fromCall.expression.trim()) ? fromCall.expression.trim() : void 0);
|
|
44450
|
+
if (!argVar) return false;
|
|
44451
|
+
const hasHttp = fileSources.some(
|
|
44452
|
+
(s) => s.variable === argVar && s.line <= edge.callLine && s.line < calleeStart && s.type.startsWith("http_") && (s.in_method ? s.in_method === edge.callerMethod : true)
|
|
44453
|
+
);
|
|
44454
|
+
if (hasHttp) return false;
|
|
44455
|
+
if (!callerArgFromSeparateClassGetTheValue(fileCode, edge.callLine, argVar)) {
|
|
44456
|
+
return false;
|
|
44457
|
+
}
|
|
44458
|
+
}
|
|
44459
|
+
return true;
|
|
44460
|
+
}
|
|
44461
|
+
function callerArgFromSeparateClassGetTheValue(fileCode, callLine, argVar) {
|
|
44462
|
+
const lines = fileCode.split("\n");
|
|
44463
|
+
const assignRe = new RegExp(`\\b${argVar}\\s*=`);
|
|
44464
|
+
for (let i2 = callLine - 2; i2 >= 0; i2--) {
|
|
44465
|
+
const line = lines[i2] ?? "";
|
|
44466
|
+
if (!assignRe.test(line)) continue;
|
|
44467
|
+
if (/\.getTheValue\s*\(/.test(line)) return true;
|
|
44468
|
+
if (/\.getTheParameter\s*\(/.test(line)) return false;
|
|
44469
|
+
return false;
|
|
44470
|
+
}
|
|
44471
|
+
return false;
|
|
44472
|
+
}
|
|
44473
|
+
function jsSinkArgsAreConstant(ir, method, sink) {
|
|
44474
|
+
const atLine = ir.calls.filter((c) => c.location.line === sink.line && (!sink.method || c.method_name === sink.method) && (sink.callColumn === void 0 || c.location.column === sink.callColumn));
|
|
44475
|
+
if (atLine.length !== 1) return false;
|
|
44476
|
+
const args2 = atLine[0].arguments;
|
|
44477
|
+
if (args2.length === 0) return false;
|
|
44478
|
+
const values = new Set(method.parameters.map((p) => p.name));
|
|
44479
|
+
for (const def of ir.dfg?.defs ?? []) {
|
|
44480
|
+
if (def.line >= method.startLine && def.line <= method.endLine) values.add(def.variable);
|
|
44481
|
+
}
|
|
44482
|
+
return args2.every((a) => jsExpressionIsConstant(a.expression ?? "", values));
|
|
44483
|
+
}
|
|
44484
|
+
var JS_KEYWORD_CONSTANTS = /* @__PURE__ */ new Set(["true", "false", "null", "undefined", "NaN", "Infinity"]);
|
|
44485
|
+
function jsExpressionIsConstant(expr, values) {
|
|
44486
|
+
if (expr.trim() === "") return false;
|
|
44487
|
+
if (/`(?:[^`\\]|\\.)*\$\{/.test(expr)) return false;
|
|
44488
|
+
const bare = expr.replace(/`(?:[^`\\]|\\.)*`/g, " 0 ").replace(/'(?:[^'\\\n]|\\.)*'/g, " 0 ").replace(/"(?:[^"\\\n]|\\.)*"/g, " 0 ");
|
|
44489
|
+
if (/[`'"]/.test(bare)) return false;
|
|
44490
|
+
if (!/\b0\b|\b\d/.test(bare)) return false;
|
|
44491
|
+
const callee = /(?<![\w$.])([A-Za-z_$][\w$]*)((?:\s*\.\s*[A-Za-z_$][\w$]*)*)\s*\(/g;
|
|
44492
|
+
let rest = bare;
|
|
44493
|
+
for (const m of bare.matchAll(callee)) {
|
|
44494
|
+
if (m[1] === "this" || values.has(m[1])) return false;
|
|
44495
|
+
}
|
|
44496
|
+
rest = rest.replace(callee, " (").replace(/\.\s*[A-Za-z_$][\w$]*\s*\(/g, " (");
|
|
44497
|
+
rest = rest.replace(/\b\d[\w.]*\b/g, " ");
|
|
44498
|
+
for (const id of rest.match(/[A-Za-z_$][\w$]*/g) ?? []) {
|
|
44499
|
+
if (!JS_KEYWORD_CONSTANTS.has(id)) return false;
|
|
44500
|
+
}
|
|
44501
|
+
return true;
|
|
44502
|
+
}
|
|
41707
44503
|
function csharpParamReachesSink(code, method, taintedArgs, sink, credit) {
|
|
41708
44504
|
const lines = code.split(/\r?\n/);
|
|
41709
44505
|
const params = taintedArgs.length > 0 ? method.parameters.filter((p) => taintedArgs.includes(p.position)) : method.parameters;
|
|
@@ -42446,7 +45242,8 @@ var ConstantPropagationPass = class {
|
|
|
42446
45242
|
}
|
|
42447
45243
|
const result = analyzeConstantPropagation(this.tree, code, {
|
|
42448
45244
|
sanitizerMethods: taintMatcher.sanitizerMethods,
|
|
42449
|
-
taintedParameters
|
|
45245
|
+
taintedParameters,
|
|
45246
|
+
language: ctx.language
|
|
42450
45247
|
});
|
|
42451
45248
|
if (ctx.language === "java") pruneDeadChains(ctx, result.unreachableLines);
|
|
42452
45249
|
return result;
|
|
@@ -43151,6 +45948,7 @@ var HTML_CONTENT_TYPE_RE = /text\/html|TEXT_HTML/;
|
|
|
43151
45948
|
var FETCH_GLOBAL_RECEIVER_RE = /(?:^|[^.\w])(?:window|globalThis|self|global)\s*\.\s*fetch\s*\(/;
|
|
43152
45949
|
var FETCH_MEMBER_RECEIVER_RE = /[\w$)\]]\s*\.\s*fetch\s*\(/;
|
|
43153
45950
|
var NOSQL_ARRAY_METHODS = /* @__PURE__ */ new Set(["find", "filter", "some", "every", "findIndex", "findLast"]);
|
|
45951
|
+
var SHELL_PROGRAM = /(?:^|[\\/])(?:sh|bash|zsh|dash|ksh|fish|cmd(?:\.exe)?|powershell(?:\.exe)?|pwsh|node|python3?|perl|ruby|php|osascript|env)$/i;
|
|
43154
45952
|
var FUNCTION_FIRST_ARG_RE = /\.\s*(?:find|filter|some|every|findIndex|findLast)\s*\(\s*(?:async\s+)?(?:function\b|(?:\([^()]*\)|[A-Za-z_$][\w$]*)\s*=>)/;
|
|
43155
45953
|
var NAMED_ARRAY_PREDICATE_RE = /([A-Za-z_$][\w$]*)\s*\.\s*(find|filter|some|every|findIndex|findLast)\s*\(\s*([A-Za-z_$][\w$]*)\s*\)/;
|
|
43156
45954
|
function isDeclaredFunctionName(name2, lines) {
|
|
@@ -43184,10 +45982,29 @@ function rustSsrfRequestUsesFixedHostFormat(code, sinkLine) {
|
|
|
43184
45982
|
const assignRe = new RegExp(`\\blet\\s+${escapeRegex2(varName)}\\s*=\\s*format!`);
|
|
43185
45983
|
for (let i2 = sinkLine - 2; i2 >= Math.max(0, sinkLine - 20); i2--) {
|
|
43186
45984
|
const line = lines[i2] ?? "";
|
|
43187
|
-
if (assignRe.test(line)
|
|
45985
|
+
if (!assignRe.test(line)) continue;
|
|
45986
|
+
if (RUST_FIXED_HOST_FORMAT_RE.test(line)) return true;
|
|
45987
|
+
if (rustFormatLeadsWithFixedHostConst(code, line)) return true;
|
|
43188
45988
|
}
|
|
43189
45989
|
return false;
|
|
43190
45990
|
}
|
|
45991
|
+
var RUST_FORMAT_CONST_LEAD_RE = /format!\(\s*"\{\}([^"]*)"\s*,\s*([A-Z_][A-Z0-9_]*)\s*[,)]/;
|
|
45992
|
+
var RUST_ORIGIN_RE = /^https?:\/\/[A-Za-z0-9.-]+(?::\d+)?(\/[^"]*)?$/;
|
|
45993
|
+
function rustFormatLeadsWithFixedHostConst(code, line) {
|
|
45994
|
+
const m = line.match(RUST_FORMAT_CONST_LEAD_RE);
|
|
45995
|
+
if (!m) return false;
|
|
45996
|
+
const rest = m[1] ?? "";
|
|
45997
|
+
const constName = m[2] ?? "";
|
|
45998
|
+
const declRe = new RegExp(
|
|
45999
|
+
`^\\s*(?:pub(?:\\([^)]*\\))?\\s+)?(?:const|static)\\s+${escapeRegex2(constName)}\\s*:\\s*&(?:'static\\s+)?str\\s*=\\s*"([^"\\\\]*)"\\s*;`,
|
|
46000
|
+
"m"
|
|
46001
|
+
);
|
|
46002
|
+
const decl = code.match(declRe);
|
|
46003
|
+
if (!decl) return false;
|
|
46004
|
+
const origin = RUST_ORIGIN_RE.exec(decl[1] ?? "");
|
|
46005
|
+
if (!origin) return false;
|
|
46006
|
+
return rest.startsWith("/") || origin[1] !== void 0;
|
|
46007
|
+
}
|
|
43191
46008
|
function literalEndsInitializer(code, end) {
|
|
43192
46009
|
let i2 = end;
|
|
43193
46010
|
let crossedNewline = false;
|
|
@@ -43247,6 +46064,52 @@ function regExpTemplateArgument(code, lines, line) {
|
|
|
43247
46064
|
return null;
|
|
43248
46065
|
}
|
|
43249
46066
|
var NESTED_QUANTIFIER_RE = /\([^()]*(?:[+*]|\{\d+,\d*\})[^()]*\)\s*[+*{]/;
|
|
46067
|
+
var JS_REGEXP_ESCAPE_CALL_RE = /^escape(?:RegExp|Re|Regex)\s*\(\s*[A-Za-z_$][\w$]*\s*\)$/;
|
|
46068
|
+
function jsRegexpFirstArgument(text) {
|
|
46069
|
+
const start2 = text.search(/new\s+RegExp\s*\(/);
|
|
46070
|
+
if (start2 < 0) return null;
|
|
46071
|
+
const open = text.indexOf("(", start2);
|
|
46072
|
+
if (open < 0) return null;
|
|
46073
|
+
let depth = 0;
|
|
46074
|
+
const argStart = open + 1;
|
|
46075
|
+
for (let i2 = open; i2 < text.length; i2++) {
|
|
46076
|
+
const c = text[i2];
|
|
46077
|
+
if (c === "(") depth++;
|
|
46078
|
+
else if (c === ")") {
|
|
46079
|
+
depth--;
|
|
46080
|
+
if (depth === 0) return text.slice(argStart, i2).trim();
|
|
46081
|
+
}
|
|
46082
|
+
}
|
|
46083
|
+
return null;
|
|
46084
|
+
}
|
|
46085
|
+
function jsRegexpPatternOnlyViaEscapeHelper(code, lines, sinkLine) {
|
|
46086
|
+
const text = lines[sinkLine - 1] ?? "";
|
|
46087
|
+
if (!/new\s+RegExp\s*\(/.test(text)) return false;
|
|
46088
|
+
const tpl = regExpTemplateArgument(code, lines, sinkLine);
|
|
46089
|
+
if (tpl !== null) {
|
|
46090
|
+
let sawInterpolation = false;
|
|
46091
|
+
for (const m of tpl.matchAll(/\$\{([^}]*)\}/g)) {
|
|
46092
|
+
sawInterpolation = true;
|
|
46093
|
+
if (!JS_REGEXP_ESCAPE_CALL_RE.test(m[1].trim())) return false;
|
|
46094
|
+
}
|
|
46095
|
+
return sawInterpolation;
|
|
46096
|
+
}
|
|
46097
|
+
const arg = jsRegexpFirstArgument(text);
|
|
46098
|
+
if (!arg) return false;
|
|
46099
|
+
if (!/escape(?:RegExp|Re|Regex)\s*\(/.test(arg)) return false;
|
|
46100
|
+
const segments = arg.split(/\s*\+\s*/);
|
|
46101
|
+
let sawEscape = false;
|
|
46102
|
+
for (const seg of segments) {
|
|
46103
|
+
const s = seg.trim();
|
|
46104
|
+
if (/^(['"`])(?:\\.|(?!\1)[^\\])*\1$/.test(s)) continue;
|
|
46105
|
+
if (JS_REGEXP_ESCAPE_CALL_RE.test(s)) {
|
|
46106
|
+
sawEscape = true;
|
|
46107
|
+
continue;
|
|
46108
|
+
}
|
|
46109
|
+
return false;
|
|
46110
|
+
}
|
|
46111
|
+
return sawEscape;
|
|
46112
|
+
}
|
|
43250
46113
|
var CONST_BASE_TEMPLATE_RE = /`\$\{\s*([A-Za-z_$][\w$]*)\s*\}\//g;
|
|
43251
46114
|
function isConstLiteralOrigin(code, name2) {
|
|
43252
46115
|
const esc = name2.replace(/\$/g, "\\$");
|
|
@@ -43355,6 +46218,9 @@ function isUnwrittenLocalMapKeyRead(code, source) {
|
|
|
43355
46218
|
if (source.type !== "plugin_param") return false;
|
|
43356
46219
|
const lines = code.split("\n");
|
|
43357
46220
|
const lineText = lines[source.line - 1] ?? "";
|
|
46221
|
+
return isUnwrittenLocalMapKeyReadJava(lines, lineText) || isUnwrittenLocalMapKeyReadJsMap(lines, lineText);
|
|
46222
|
+
}
|
|
46223
|
+
function isUnwrittenLocalMapKeyReadJava(lines, lineText) {
|
|
43358
46224
|
const read = /\b([A-Za-z_]\w*)\s*\.\s*get\s*\(\s*"([^"]*)"\s*\)/.exec(lineText);
|
|
43359
46225
|
if (!read) return false;
|
|
43360
46226
|
const [, recv, key] = read;
|
|
@@ -43364,14 +46230,38 @@ function isUnwrittenLocalMapKeyRead(code, source) {
|
|
|
43364
46230
|
`\\b${recv}\\s*=\\s*new\\s+(?:java\\.util\\.(?:concurrent\\.)?)?(?:Hash|Tree|LinkedHash|ConcurrentHash|Concurrent|Identity|Weak)?Map\\s*(?:<[^>]*>)?\\s*\\(`
|
|
43365
46231
|
);
|
|
43366
46232
|
if (!lines.some((l) => ctorRe.test(l))) return false;
|
|
46233
|
+
if (!localMapReceiverDoesNotEscape(lines, recv)) return false;
|
|
46234
|
+
const putRe = new RegExp(`\\b${recv}\\s*\\.\\s*put\\s*\\(\\s*"${key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}"`);
|
|
46235
|
+
if (lines.some((l) => putRe.test(l))) return isLiteralOnlyLocalMapKey(lines, recv, key);
|
|
46236
|
+
return true;
|
|
46237
|
+
}
|
|
46238
|
+
function isUnwrittenLocalMapKeyReadJsMap(lines, lineText) {
|
|
46239
|
+
const readLocal = /\b([A-Za-z_]\w*)\s*\.\s*get\s*\(\s*(['"])([^'"]*)\2\s*\)/.exec(lineText);
|
|
46240
|
+
const readThis = /\bthis\s*\.\s*([A-Za-z_]\w*)\s*\.\s*get\s*\(\s*(['"])([^'"]*)\2\s*\)/.exec(lineText);
|
|
46241
|
+
const read = readLocal ?? readThis;
|
|
46242
|
+
if (!read) return false;
|
|
46243
|
+
const recv = readLocal ? readLocal[1] : readThis[1];
|
|
46244
|
+
const quote = readLocal ? readLocal[2] : readThis[2];
|
|
46245
|
+
const key = readLocal ? readLocal[3] : readThis[3];
|
|
46246
|
+
const ctorRe = new RegExp(
|
|
46247
|
+
`(?:\\b${recv}\\s*=\\s*new\\s+Map\\s*(?:<[^>]*>)?\\s*\\(|\\bthis\\.${recv}\\s*=\\s*new\\s+Map\\s*(?:<[^>]*>)?\\s*\\(|\\b(?:private|readonly|public|protected)?\\s*\\w+\\s+${recv}\\s*(?:=|:)\\s*new\\s+Map\\s*(?:<[^>]*>)?\\s*\\()`
|
|
46248
|
+
);
|
|
46249
|
+
if (!lines.some((l) => ctorRe.test(l))) return false;
|
|
46250
|
+
if (!localMapReceiverDoesNotEscape(lines, recv)) return false;
|
|
46251
|
+
const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
46252
|
+
const setRe = new RegExp(
|
|
46253
|
+
`(?:\\b${recv}|\\bthis\\.${recv})\\s*\\.\\s*set\\s*\\(\\s*${quote}${escapedKey}${quote}`
|
|
46254
|
+
);
|
|
46255
|
+
if (lines.some((l) => setRe.test(l))) return isLiteralOnlyLocalMapKeyJs(lines, recv, key, quote);
|
|
46256
|
+
return true;
|
|
46257
|
+
}
|
|
46258
|
+
function localMapReceiverDoesNotEscape(lines, recv) {
|
|
43367
46259
|
const escapeRe2 = new RegExp(`\\w\\s*\\([^)]*(?<![\\w.])${recv}(?![\\w.])[^)]*\\)`);
|
|
43368
46260
|
for (const l of lines) {
|
|
43369
46261
|
if (!escapeRe2.test(l)) continue;
|
|
43370
|
-
const stripped = l.replace(new RegExp(`\\b
|
|
46262
|
+
const stripped = l.replace(new RegExp(`\\b(?:this\\.)?${recv}\\s*\\.\\s*\\w+\\s*\\(`, "g"), "X(");
|
|
43371
46263
|
if (escapeRe2.test(stripped)) return false;
|
|
43372
46264
|
}
|
|
43373
|
-
const putRe = new RegExp(`\\b${recv}\\s*\\.\\s*put\\s*\\(\\s*"${key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}"`);
|
|
43374
|
-
if (lines.some((l) => putRe.test(l))) return isLiteralOnlyLocalMapKey(lines, recv, key);
|
|
43375
46265
|
return true;
|
|
43376
46266
|
}
|
|
43377
46267
|
function isLiteralOnlyLocalMapKey(lines, recv, key) {
|
|
@@ -43392,6 +46282,22 @@ function isLiteralOnlyLocalMapKey(lines, recv, key) {
|
|
|
43392
46282
|
}
|
|
43393
46283
|
return putsForKey > 0 && putsForKey === literalPutsForKey;
|
|
43394
46284
|
}
|
|
46285
|
+
function isLiteralOnlyLocalMapKeyJs(lines, recv, key, quote) {
|
|
46286
|
+
const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
46287
|
+
const recvAlt = `(?:\\b${recv}|\\bthis\\.${recv})`;
|
|
46288
|
+
const anyKeySet = new RegExp(`${recvAlt}\\s*\\.\\s*set\\s*\\(\\s*${quote}${escapedKey}${quote}`);
|
|
46289
|
+
const qClass = quote === '"' ? '[^"\\\\]' : "[^'\\\\]";
|
|
46290
|
+
const literalSet = new RegExp(
|
|
46291
|
+
`${recvAlt}\\s*\\.\\s*set\\s*\\(\\s*${quote}${escapedKey}${quote}\\s*,\\s*${quote}(?:${qClass}|\\\\.)*${quote}\\s*\\)`
|
|
46292
|
+
);
|
|
46293
|
+
let setsForKey = 0;
|
|
46294
|
+
let literalSetsForKey = 0;
|
|
46295
|
+
for (const l of lines) {
|
|
46296
|
+
setsForKey += (l.match(anyKeySet) ?? []).length;
|
|
46297
|
+
literalSetsForKey += (l.match(literalSet) ?? []).length;
|
|
46298
|
+
}
|
|
46299
|
+
return setsForKey > 0 && setsForKey === literalSetsForKey;
|
|
46300
|
+
}
|
|
43395
46301
|
function isJsDisguisedCacheDbInputRead(code, source) {
|
|
43396
46302
|
if (source.type !== "db_input") return false;
|
|
43397
46303
|
const loc = source.location ?? "";
|
|
@@ -44289,12 +47195,58 @@ var SinkFilterPass = class {
|
|
|
44289
47195
|
return !FETCH_MEMBER_RECEIVER_RE.test(sinkLineText);
|
|
44290
47196
|
});
|
|
44291
47197
|
}
|
|
47198
|
+
if (["javascript", "typescript"].includes(language)) {
|
|
47199
|
+
const lines = ctx.code.split("\n");
|
|
47200
|
+
const STATEMENT_METHODS = /* @__PURE__ */ new Set(["get", "all", "run", "each", "iterate", "pluck"]);
|
|
47201
|
+
let statementVars = null;
|
|
47202
|
+
const isStatementVar = (name2) => {
|
|
47203
|
+
if (statementVars === null) {
|
|
47204
|
+
statementVars = /* @__PURE__ */ new Set();
|
|
47205
|
+
for (const m of ctx.code.matchAll(/(?:\b(?:const|let|var)\s+|\bthis\s*\.\s*|^\s*)([A-Za-z_$][\w$]*)\s*=\s*(?:await\s+)?[\w$.]*\.\s*prepare\s*\(/gm)) statementVars.add(m[1]);
|
|
47206
|
+
}
|
|
47207
|
+
return statementVars.has(name2);
|
|
47208
|
+
};
|
|
47209
|
+
filtered = filtered.filter((sink) => {
|
|
47210
|
+
if (sink.type !== "sql_injection" || !STATEMENT_METHODS.has(sink.method ?? "")) return true;
|
|
47211
|
+
const method = sink.method;
|
|
47212
|
+
const callRe = new RegExp(`\\.\\s*${method}\\s*\\(`);
|
|
47213
|
+
let stmt = lines[sink.line - 1] ?? "";
|
|
47214
|
+
for (let k = 0; k < 6 && !(callRe.test(stmt) && /[;)]\s*$/.test(stmt.replace(/\/\/.*$/, ""))); k++) stmt += " " + (lines[sink.line + k] ?? "").trim();
|
|
47215
|
+
if (new RegExp(`\\.\\s*prepare\\s*\\((?:[^()]|\\((?:[^()]|\\([^()]*\\))*\\))*\\)\\s*\\.\\s*${method}\\s*\\(`).test(stmt)) return false;
|
|
47216
|
+
const recv = new RegExp(`(?:\\bthis\\s*\\.\\s*)?([A-Za-z_$][\\w$]*)\\s*\\.\\s*${method}\\s*\\(`).exec(stmt);
|
|
47217
|
+
if (recv && isStatementVar(recv[1])) return false;
|
|
47218
|
+
return true;
|
|
47219
|
+
});
|
|
47220
|
+
}
|
|
47221
|
+
if (["javascript", "typescript"].includes(language)) {
|
|
47222
|
+
const lines = ctx.code.split("\n");
|
|
47223
|
+
const FIXED_PROGRAM_EXEC = /* @__PURE__ */ new Set(["spawn", "spawnSync", "execFile", "execFileSync"]);
|
|
47224
|
+
filtered = filtered.filter((sink) => {
|
|
47225
|
+
if (sink.type !== "command_injection" || !FIXED_PROGRAM_EXEC.has(sink.method ?? "")) return true;
|
|
47226
|
+
let stmt = lines[sink.line - 1] ?? "";
|
|
47227
|
+
for (let k = 0; k < 8 && !/\)\s*;?\s*$/.test(stmt.replace(/\/\/.*$/, "")); k++) {
|
|
47228
|
+
stmt += " " + (lines[sink.line + k] ?? "").trim();
|
|
47229
|
+
}
|
|
47230
|
+
const call = new RegExp(`\\b${sink.method}\\s*\\(\\s*([^,)]+)`).exec(stmt);
|
|
47231
|
+
if (!call) return true;
|
|
47232
|
+
const program = call[1].trim();
|
|
47233
|
+
const literal = /^(['"`])([^'"`$]*)\1$/.exec(program);
|
|
47234
|
+
const fixed = program === "process.execPath" || literal !== null && !SHELL_PROGRAM.test(literal[2]) && !runsArgvAsCommand(literal[2]);
|
|
47235
|
+
if (!fixed) return true;
|
|
47236
|
+
if (/\bshell\s*:\s*(?!false\b)/.test(stmt)) return true;
|
|
47237
|
+
if (/['"`]-(?:e|p|-eval|-print)['"`]/.test(stmt)) return true;
|
|
47238
|
+
return false;
|
|
47239
|
+
});
|
|
47240
|
+
}
|
|
44292
47241
|
if (["javascript", "typescript"].includes(language)) {
|
|
44293
47242
|
const sourceLines = ctx.code.split("\n");
|
|
44294
47243
|
filtered = filtered.filter((sink) => {
|
|
44295
47244
|
if (sink.type !== "nosql_injection") return true;
|
|
44296
47245
|
if (!NOSQL_ARRAY_METHODS.has(sink.method ?? "")) return true;
|
|
44297
|
-
|
|
47246
|
+
let sinkLineText = sourceLines[sink.line - 1] ?? "";
|
|
47247
|
+
for (let k = 0; k < 3 && /\(\s*$/.test(sinkLineText); k++) {
|
|
47248
|
+
sinkLineText += " " + (sourceLines[sink.line + k] ?? "").trim();
|
|
47249
|
+
}
|
|
44298
47250
|
if (FUNCTION_FIRST_ARG_RE.test(sinkLineText)) return false;
|
|
44299
47251
|
const named2 = NAMED_ARRAY_PREDICATE_RE.exec(sinkLineText);
|
|
44300
47252
|
if (named2) {
|
|
@@ -44358,6 +47310,10 @@ var SinkFilterPass = class {
|
|
|
44358
47310
|
if (interpolations === 0 || !allConst) return true;
|
|
44359
47311
|
return NESTED_QUANTIFIER_RE.test(pattern);
|
|
44360
47312
|
});
|
|
47313
|
+
filtered = filtered.filter((sink) => {
|
|
47314
|
+
if (sink.type !== "redos") return true;
|
|
47315
|
+
return !jsRegexpPatternOnlyViaEscapeHelper(ctx.code, sourceLines, sink.line);
|
|
47316
|
+
});
|
|
44361
47317
|
}
|
|
44362
47318
|
if (["javascript", "typescript"].includes(language)) {
|
|
44363
47319
|
const guardedLines = jsSsrfHostGuardedLines(ctx.code);
|
|
@@ -45057,9 +48013,9 @@ function filterSanitizedSinks(sinks, sanitizers, calls, sources) {
|
|
|
45057
48013
|
});
|
|
45058
48014
|
}
|
|
45059
48015
|
function isXPathQuoteEscapedOnLine(lineText, varName) {
|
|
45060
|
-
const
|
|
48016
|
+
const STRING_LITERAL2 = `'(?:[^'\\\\]|\\\\.)*'|"(?:[^"\\\\]|\\\\.)*"`;
|
|
45061
48017
|
const replaceCall = new RegExp(
|
|
45062
|
-
`^${varName}\\.replace\\s*\\(\\s*(${
|
|
48018
|
+
`^${varName}\\.replace\\s*\\(\\s*(${STRING_LITERAL2})\\s*,\\s*(${STRING_LITERAL2})\\s*\\)`
|
|
45063
48019
|
);
|
|
45064
48020
|
const decode = (literal) => literal.slice(1, -1).replace(/\\(.)/g, "$1");
|
|
45065
48021
|
const occurrence = new RegExp(`(?<![\\w.])${varName}\\b`, "g");
|
|
@@ -45275,6 +48231,36 @@ function fileHasUnsafePyYamlLoader(sourceLines, sinkLine) {
|
|
|
45275
48231
|
}
|
|
45276
48232
|
return false;
|
|
45277
48233
|
}
|
|
48234
|
+
function resolveDepFromPackageJson(packageJson, depName) {
|
|
48235
|
+
if (!packageJson || !depName) return null;
|
|
48236
|
+
let parsed;
|
|
48237
|
+
try {
|
|
48238
|
+
parsed = JSON.parse(packageJson);
|
|
48239
|
+
} catch {
|
|
48240
|
+
return null;
|
|
48241
|
+
}
|
|
48242
|
+
if (typeof parsed !== "object" || parsed === null) return null;
|
|
48243
|
+
const manifest = parsed;
|
|
48244
|
+
const sections = [
|
|
48245
|
+
"dependencies",
|
|
48246
|
+
"devDependencies",
|
|
48247
|
+
"peerDependencies",
|
|
48248
|
+
"optionalDependencies"
|
|
48249
|
+
];
|
|
48250
|
+
for (const section of sections) {
|
|
48251
|
+
const deps = manifest[section];
|
|
48252
|
+
if (typeof deps !== "object" || deps === null) continue;
|
|
48253
|
+
const depsRecord = deps;
|
|
48254
|
+
const raw = depsRecord[depName];
|
|
48255
|
+
if (typeof raw !== "string") continue;
|
|
48256
|
+
if (raw.startsWith("git+") || raw.startsWith("git://") || raw.startsWith("git@") || raw.startsWith("github:") || raw.startsWith("gitlab:") || raw.startsWith("bitbucket:") || raw.startsWith("file:") || raw.startsWith("link:") || raw.startsWith("workspace:") || raw.startsWith("http://") || raw.startsWith("https://")) {
|
|
48257
|
+
return null;
|
|
48258
|
+
}
|
|
48259
|
+
if (raw.startsWith("npm:") && !/@\d/.test(raw)) return null;
|
|
48260
|
+
return { version: raw, section };
|
|
48261
|
+
}
|
|
48262
|
+
return null;
|
|
48263
|
+
}
|
|
45278
48264
|
function fileReenablesFastjsonAutotype(source) {
|
|
45279
48265
|
if (!source) return false;
|
|
45280
48266
|
return /\bsetAutoTypeSupport\s*\(\s*true\b/.test(source);
|
|
@@ -45292,6 +48278,46 @@ function fileConfiguresSnakeYamlSafely(source) {
|
|
|
45292
48278
|
if (/\bSafeConstructor\s+\w+\s*=/.test(source)) return true;
|
|
45293
48279
|
return false;
|
|
45294
48280
|
}
|
|
48281
|
+
function resolveJsYamlMajor(js) {
|
|
48282
|
+
if (!js) return null;
|
|
48283
|
+
if (js.packageLock) {
|
|
48284
|
+
try {
|
|
48285
|
+
const lock = JSON.parse(js.packageLock);
|
|
48286
|
+
const v = lock.packages?.["node_modules/js-yaml"]?.version ?? lock.dependencies?.["js-yaml"]?.version;
|
|
48287
|
+
const m = v ? /^(\d+)\./.exec(v) : null;
|
|
48288
|
+
if (m) return { major: Number(m[1]), from: "lockfile" };
|
|
48289
|
+
} catch {
|
|
48290
|
+
}
|
|
48291
|
+
}
|
|
48292
|
+
if (js.packageJson) {
|
|
48293
|
+
const dep = resolveDepFromPackageJson(js.packageJson, "js-yaml");
|
|
48294
|
+
const m = dep ? /^\s*[\^~=v]?\s*(\d+)(?:\.(?:\d+|x|\*))*\s*$/i.exec(dep.version) : null;
|
|
48295
|
+
if (m) return { major: Number(m[1]), from: "package.json" };
|
|
48296
|
+
}
|
|
48297
|
+
return null;
|
|
48298
|
+
}
|
|
48299
|
+
function jsYamlBindings(source) {
|
|
48300
|
+
const namespaces = /* @__PURE__ */ new Set();
|
|
48301
|
+
const functions = /* @__PURE__ */ new Set();
|
|
48302
|
+
const from = String.raw`['"]js-yaml(?:/index(?:\.js)?)?['"]`;
|
|
48303
|
+
for (const m of source.matchAll(new RegExp(String.raw`import\s+(?:\*\s+as\s+)?([A-Za-z_$][\w$]*)\s*(?:,\s*\{[^}]*\}\s*)?from\s*` + from, "g"))) namespaces.add(m[1]);
|
|
48304
|
+
for (const m of source.matchAll(new RegExp(String.raw`(?:const|let|var)\s+([A-Za-z_$][\w$]*)\s*=\s*require\s*\(\s*` + from + String.raw`\s*\)`, "g"))) namespaces.add(m[1]);
|
|
48305
|
+
for (const m of source.matchAll(new RegExp(String.raw`import\s+(?:[A-Za-z_$][\w$]*\s*,\s*)?\{([^}]*)\}\s*from\s*` + from, "g"))) {
|
|
48306
|
+
for (const part of m[1].split(",")) {
|
|
48307
|
+
const [name2, alias] = part.trim().split(/\s+as\s+/);
|
|
48308
|
+
if (name2 === "load" || name2 === "loadAll") functions.add((alias ?? name2).trim());
|
|
48309
|
+
}
|
|
48310
|
+
}
|
|
48311
|
+
for (const m of source.matchAll(new RegExp(String.raw`(?:const|let|var)\s*\{([^}]*)\}\s*=\s*require\s*\(\s*` + from + String.raw`\s*\)`, "g"))) {
|
|
48312
|
+
for (const part of m[1].split(",")) {
|
|
48313
|
+
const [name2, alias] = part.trim().split(/\s*:\s*/);
|
|
48314
|
+
if (name2 === "load" || name2 === "loadAll") functions.add((alias ?? name2).trim());
|
|
48315
|
+
}
|
|
48316
|
+
}
|
|
48317
|
+
const full = /['"]js-yaml\/lib\/js-yaml(?:\.js)?['"]/.test(source) || /\bDEFAULT_FULL_SCHEMA\b/.test(source);
|
|
48318
|
+
return { namespaces, functions, full };
|
|
48319
|
+
}
|
|
48320
|
+
var JS_YAML_SAFE_SCHEMA_RE = /\bschema\s*:\s*(?:[A-Za-z_$][\w$]*\s*\.\s*)?(?:FAILSAFE_SCHEMA|JSON_SCHEMA|CORE_SCHEMA|DEFAULT_SCHEMA|DEFAULT_SAFE_SCHEMA)\b/;
|
|
45295
48321
|
|
|
45296
48322
|
// src/analysis/passes/deserialization-safety-gate-pass.ts
|
|
45297
48323
|
var FASTJSON_METHODS = /* @__PURE__ */ new Set(["parseObject", "parse"]);
|
|
@@ -45302,6 +48328,7 @@ var SNAKEYAML_METHODS = /* @__PURE__ */ new Set(["load", "loadAs", "loadAll"]);
|
|
|
45302
48328
|
var SNAKEYAML_CLASSES = /* @__PURE__ */ new Set(["Yaml"]);
|
|
45303
48329
|
var PYYAML_METHODS = /* @__PURE__ */ new Set(["load"]);
|
|
45304
48330
|
var PYYAML_CLASSES = /* @__PURE__ */ new Set(["yaml"]);
|
|
48331
|
+
var JSYAML_METHODS = /* @__PURE__ */ new Set(["load", "loadAll"]);
|
|
45305
48332
|
var DeserializationSafetyGatePass = class {
|
|
45306
48333
|
constructor(dependencyContext) {
|
|
45307
48334
|
this.dependencyContext = dependencyContext;
|
|
@@ -45311,6 +48338,7 @@ var DeserializationSafetyGatePass = class {
|
|
|
45311
48338
|
category = "security";
|
|
45312
48339
|
run(ctx) {
|
|
45313
48340
|
const { graph, language, code } = ctx;
|
|
48341
|
+
if (language === "javascript" || language === "typescript") return this.runJsYaml(ctx);
|
|
45314
48342
|
if (language !== "java" && language !== "python") {
|
|
45315
48343
|
return { droppedFastjson: 0, droppedJackson: 0, droppedSnakeYaml: 0, droppedPyYaml: 0 };
|
|
45316
48344
|
}
|
|
@@ -45363,6 +48391,40 @@ var DeserializationSafetyGatePass = class {
|
|
|
45363
48391
|
}
|
|
45364
48392
|
return { droppedFastjson, droppedJackson, droppedSnakeYaml, droppedPyYaml };
|
|
45365
48393
|
}
|
|
48394
|
+
/** Gate E — js-yaml (JS/TS). */
|
|
48395
|
+
runJsYaml(ctx) {
|
|
48396
|
+
const none = { droppedFastjson: 0, droppedJackson: 0, droppedSnakeYaml: 0, droppedPyYaml: 0, droppedJsYaml: 0 };
|
|
48397
|
+
const { graph, code } = ctx;
|
|
48398
|
+
const sinks = ctx.hasResult("sink-filter") ? ctx.getResult("sink-filter").sinks : graph.ir.taint.sinks;
|
|
48399
|
+
if (!sinks.some((s) => s.type === "deserialization" && s.method && JSYAML_METHODS.has(s.method))) return none;
|
|
48400
|
+
const { namespaces, functions, full } = jsYamlBindings(code);
|
|
48401
|
+
if (full || namespaces.size === 0 && functions.size === 0) return none;
|
|
48402
|
+
const major = resolveJsYamlMajor(this.dependencyContext?.js)?.major;
|
|
48403
|
+
const lines = code.split("\n");
|
|
48404
|
+
let droppedJsYaml = 0;
|
|
48405
|
+
const kept = sinks.filter((sink) => {
|
|
48406
|
+
if (sink.type !== "deserialization" || !sink.method || !JSYAML_METHODS.has(sink.method)) return true;
|
|
48407
|
+
let call = lines[sink.line - 1] ?? "";
|
|
48408
|
+
for (let k = 0; k < 8 && !/\)\s*[;,)]?\s*$/.test(call.replace(/\/\/.*$/, "")); k++) call += " " + (lines[sink.line + k] ?? "").trim();
|
|
48409
|
+
const m = new RegExp(`(?:([A-Za-z_$][\\w$]*)\\s*\\.\\s*)?\\b${sink.method}\\s*\\(`).exec(call);
|
|
48410
|
+
if (!m) return true;
|
|
48411
|
+
const onJsYaml = m[1] !== void 0 ? namespaces.has(m[1]) : functions.has(sink.method);
|
|
48412
|
+
if (!onJsYaml) return true;
|
|
48413
|
+
const after = call.slice(m.index);
|
|
48414
|
+
const safeSchema = JS_YAML_SAFE_SCHEMA_RE.test(after);
|
|
48415
|
+
if (!safeSchema && /\bschema\s*:/.test(after)) return true;
|
|
48416
|
+
if (safeSchema || major !== void 0 && major >= 4) {
|
|
48417
|
+
droppedJsYaml++;
|
|
48418
|
+
return false;
|
|
48419
|
+
}
|
|
48420
|
+
return true;
|
|
48421
|
+
});
|
|
48422
|
+
if (droppedJsYaml > 0) {
|
|
48423
|
+
sinks.length = 0;
|
|
48424
|
+
sinks.push(...kept);
|
|
48425
|
+
}
|
|
48426
|
+
return { ...none, droppedJsYaml };
|
|
48427
|
+
}
|
|
45366
48428
|
};
|
|
45367
48429
|
|
|
45368
48430
|
// src/analysis/passes/prompt-injection-safety-gate-pass.ts
|
|
@@ -45697,7 +48759,7 @@ var EXEMPT_LANGUAGES = /* @__PURE__ */ new Set(["java", "csharp"]);
|
|
|
45697
48759
|
var ROUTE_ANNOTATION = /(?:^|[.\s@])(?:route|api_route|get|post|put|patch|delete|head|options|websocket|api_view|view_config|RequestMapping|GetMapping|PostMapping|PutMapping|DeleteMapping|PatchMapping|All)\s*(?:\(|$)/i;
|
|
45698
48760
|
var RUST_ROUTE_ATTR = /^\s*#\[\s*(?:[A-Za-z_][\w]*::)*(?:get|post|put|patch|delete|head|options|route|handler)\s*[(\]]/;
|
|
45699
48761
|
var RUST_HANDLER_RETURN = /\b(?:HttpResponse|Responder|Reply|IntoResponse|Response(?:<[^>]*>)?)\b/;
|
|
45700
|
-
function
|
|
48762
|
+
function enclosingMethod2(methods, line) {
|
|
45701
48763
|
let best;
|
|
45702
48764
|
for (const m of methods) {
|
|
45703
48765
|
if (m.start_line <= line && line <= m.end_line) {
|
|
@@ -45838,7 +48900,7 @@ function realFedParams(ctx, sources) {
|
|
|
45838
48900
|
for (const d of graph.defsAtLine(s.line)) seeds.add(d.id);
|
|
45839
48901
|
if (s.variable) {
|
|
45840
48902
|
const where = boundVars.get(s.variable) ?? /* @__PURE__ */ new Set();
|
|
45841
|
-
where.add(
|
|
48903
|
+
where.add(enclosingMethod2(allMethods, s.line));
|
|
45842
48904
|
boundVars.set(s.variable, where);
|
|
45843
48905
|
}
|
|
45844
48906
|
const read = /^([\w$.]+?)(?:\(\))? in /.exec(s.location ?? "")?.[1];
|
|
@@ -45859,7 +48921,7 @@ function realFedParams(ctx, sources) {
|
|
|
45859
48921
|
const uses = graph.usesAtLine(line).filter((u) => u.def_id !== null && tainted.has(u.def_id));
|
|
45860
48922
|
const reads = inlineReads.get(line) ?? [];
|
|
45861
48923
|
const sanitizersHere = sanitizerNames.get(line) ?? [];
|
|
45862
|
-
const callMethod =
|
|
48924
|
+
const callMethod = enclosingMethod2(allMethods, line);
|
|
45863
48925
|
const isFed = (expr, variable) => (
|
|
45864
48926
|
// An argument passed through a sanitizer is not the raw request value.
|
|
45865
48927
|
!sanitizersHere.some((n) => expr.includes(`${n}(`)) && (!!variable && !!boundVars.get(variable)?.has(callMethod) || reads.some((r) => expr.includes(r)) || // The argument's own identifiers, not those of a sibling argument.
|
|
@@ -45945,7 +49007,7 @@ var ParamSourceFlowGatePass = class {
|
|
|
45945
49007
|
for (const f of flows) {
|
|
45946
49008
|
let keep = true;
|
|
45947
49009
|
if (f.source_type === "interprocedural_param" && !realSourceLines.has(f.source_line)) {
|
|
45948
|
-
const m =
|
|
49010
|
+
const m = enclosingMethod2(methods, f.source_line);
|
|
45949
49011
|
keep = m !== void 0 && (isHandler(m) || fedByRealSource(f, m) || isReactHtmlComponent(m, f, lines) || ctx.language === "python" && isPythonYamlLoadParamDeser(f, lines) || ctx.language === "rust" && isRustDieselSqlParamFlow(f, lines));
|
|
45950
49012
|
}
|
|
45951
49013
|
if (keep) flows[w++] = f;
|
|
@@ -47602,6 +50664,10 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
|
|
|
47602
50664
|
existing.push(call);
|
|
47603
50665
|
callsByLine.set(call.location.line, existing);
|
|
47604
50666
|
}
|
|
50667
|
+
const javaDerivedVars = typeof code === "string" ? buildJavaTaintedVars(
|
|
50668
|
+
code,
|
|
50669
|
+
new Set(sources.map((s) => s.variable).filter((v) => Boolean(v)))
|
|
50670
|
+
) : void 0;
|
|
47605
50671
|
for (const sink of sinks) {
|
|
47606
50672
|
if (unreachableLines.has(sink.line)) continue;
|
|
47607
50673
|
const callsAtSink = callsByLine.get(sink.line) ?? [];
|
|
@@ -47649,7 +50715,17 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
|
|
|
47649
50715
|
);
|
|
47650
50716
|
}
|
|
47651
50717
|
if (argTainted) {
|
|
47652
|
-
const source = pickScopedSource(
|
|
50718
|
+
const source = pickScopedSource(
|
|
50719
|
+
sources,
|
|
50720
|
+
sink.line,
|
|
50721
|
+
call.in_method ?? null,
|
|
50722
|
+
types,
|
|
50723
|
+
varName,
|
|
50724
|
+
code,
|
|
50725
|
+
"java",
|
|
50726
|
+
true,
|
|
50727
|
+
javaDerivedVars
|
|
50728
|
+
);
|
|
47653
50729
|
if (source) {
|
|
47654
50730
|
if (source.variable && source.variable !== varName && source.in_method && call.in_method && source.in_method !== call.in_method) {
|
|
47655
50731
|
continue;
|
|
@@ -47700,7 +50776,17 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
|
|
|
47700
50776
|
}
|
|
47701
50777
|
if (!collectionTainted) continue;
|
|
47702
50778
|
{
|
|
47703
|
-
const source = pickScopedSource(
|
|
50779
|
+
const source = pickScopedSource(
|
|
50780
|
+
sources,
|
|
50781
|
+
sink.line,
|
|
50782
|
+
call.in_method ?? null,
|
|
50783
|
+
types,
|
|
50784
|
+
collectionVar,
|
|
50785
|
+
code,
|
|
50786
|
+
"java",
|
|
50787
|
+
false,
|
|
50788
|
+
javaDerivedVars
|
|
50789
|
+
);
|
|
47704
50790
|
if (source) {
|
|
47705
50791
|
if (source.variable && source.variable !== collectionVar && source.in_method && call.in_method && source.in_method !== call.in_method) {
|
|
47706
50792
|
continue;
|
|
@@ -47753,7 +50839,13 @@ function detectArrayElementFlows(calls, sources, sinks, taintedArrayElements, un
|
|
|
47753
50839
|
if (taintedIndices) {
|
|
47754
50840
|
const isTainted = taintedIndices.has(indexKey) || taintedIndices.has("*");
|
|
47755
50841
|
if (isTainted) {
|
|
47756
|
-
const source = pickScopedSource(
|
|
50842
|
+
const source = pickScopedSource(
|
|
50843
|
+
sources,
|
|
50844
|
+
sink.line,
|
|
50845
|
+
call.in_method ?? null,
|
|
50846
|
+
types,
|
|
50847
|
+
base
|
|
50848
|
+
);
|
|
47757
50849
|
if (source) {
|
|
47758
50850
|
flows.push({
|
|
47759
50851
|
source_line: source.line,
|
|
@@ -47801,10 +50893,10 @@ function shouldGateCSharpPatPermsLibraryParamFlow(flow, sources, sinks, types, c
|
|
|
47801
50893
|
const methodName = src?.in_method;
|
|
47802
50894
|
if (!methodName) return false;
|
|
47803
50895
|
const enclosingType = types.find((t) => t.methods.some((m) => m.name === methodName));
|
|
47804
|
-
const
|
|
50896
|
+
const enclosingMethod3 = enclosingType?.methods.find((m) => m.name === methodName);
|
|
47805
50897
|
return shouldGateInterproceduralParam(
|
|
47806
50898
|
flow.source_type,
|
|
47807
|
-
|
|
50899
|
+
enclosingMethod3,
|
|
47808
50900
|
enclosingType,
|
|
47809
50901
|
ctx
|
|
47810
50902
|
);
|
|
@@ -47867,10 +50959,10 @@ function detectParameterSinkFlows(types, calls, sources, sinks, unreachableLines
|
|
|
47867
50959
|
const enclosingType = types.find(
|
|
47868
50960
|
(t) => t.methods.some((m) => m.name === methodName)
|
|
47869
50961
|
);
|
|
47870
|
-
const
|
|
50962
|
+
const enclosingMethod3 = enclosingType?.methods.find((m) => m.name === methodName);
|
|
47871
50963
|
if (shouldGateInterproceduralParam(
|
|
47872
50964
|
paramSource.type,
|
|
47873
|
-
|
|
50965
|
+
enclosingMethod3,
|
|
47874
50966
|
enclosingType,
|
|
47875
50967
|
{ language, types, filePath, calls }
|
|
47876
50968
|
)) {
|
|
@@ -48395,7 +51487,7 @@ function pythonSiblingBranchAssignsNonLiteral(lines, idx, variable, strLit, unre
|
|
|
48395
51487
|
}
|
|
48396
51488
|
return false;
|
|
48397
51489
|
}
|
|
48398
|
-
var MASKABLE_STRING_LANGUAGES = /* @__PURE__ */ new Set(["python", "javascript", "typescript"]);
|
|
51490
|
+
var MASKABLE_STRING_LANGUAGES = /* @__PURE__ */ new Set(["python", "javascript", "typescript", "java"]);
|
|
48399
51491
|
function maskStringLiteralsForTokenScan(expr) {
|
|
48400
51492
|
let out2 = "";
|
|
48401
51493
|
let i2 = 0;
|
|
@@ -48501,6 +51593,67 @@ function argsReferenceTaintedVar(expr, sources) {
|
|
|
48501
51593
|
).test(codePart)
|
|
48502
51594
|
);
|
|
48503
51595
|
}
|
|
51596
|
+
function matchingCloseParen(lineText, openParenIndex) {
|
|
51597
|
+
let depth = 0;
|
|
51598
|
+
let inStr = null;
|
|
51599
|
+
let esc = false;
|
|
51600
|
+
for (let i2 = openParenIndex; i2 < lineText.length; i2++) {
|
|
51601
|
+
const ch = lineText[i2];
|
|
51602
|
+
if (inStr) {
|
|
51603
|
+
if (esc) {
|
|
51604
|
+
esc = false;
|
|
51605
|
+
continue;
|
|
51606
|
+
}
|
|
51607
|
+
if (ch === "\\" && (inStr === '"' || inStr === "'")) {
|
|
51608
|
+
esc = true;
|
|
51609
|
+
continue;
|
|
51610
|
+
}
|
|
51611
|
+
if (ch === inStr) inStr = null;
|
|
51612
|
+
continue;
|
|
51613
|
+
}
|
|
51614
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
51615
|
+
inStr = ch;
|
|
51616
|
+
continue;
|
|
51617
|
+
}
|
|
51618
|
+
if (ch === "(") depth++;
|
|
51619
|
+
else if (ch === ")") {
|
|
51620
|
+
depth--;
|
|
51621
|
+
if (depth === 0) return i2;
|
|
51622
|
+
}
|
|
51623
|
+
}
|
|
51624
|
+
return -1;
|
|
51625
|
+
}
|
|
51626
|
+
function sinkNestedInJsTsParseArgs(lineText, sinkMethod) {
|
|
51627
|
+
if (!lineText || !sinkMethod?.length) return false;
|
|
51628
|
+
const needle = `${sinkMethod}(`;
|
|
51629
|
+
let i2 = 0;
|
|
51630
|
+
while (i2 < lineText.length) {
|
|
51631
|
+
const k = lineText.indexOf("parse", i2);
|
|
51632
|
+
if (k === -1) return false;
|
|
51633
|
+
if (k > 0 && /[\w$]/.test(lineText[k - 1])) {
|
|
51634
|
+
i2 = k + 5;
|
|
51635
|
+
continue;
|
|
51636
|
+
}
|
|
51637
|
+
if (lineText.slice(k, k + 5) !== "parse") {
|
|
51638
|
+
i2 = k + 1;
|
|
51639
|
+
continue;
|
|
51640
|
+
}
|
|
51641
|
+
const openParen = k + 5;
|
|
51642
|
+
if (lineText[openParen] !== "(") {
|
|
51643
|
+
i2 = k + 5;
|
|
51644
|
+
continue;
|
|
51645
|
+
}
|
|
51646
|
+
const closeIdx = matchingCloseParen(lineText, openParen);
|
|
51647
|
+
if (closeIdx === -1) {
|
|
51648
|
+
i2 = k + 5;
|
|
51649
|
+
continue;
|
|
51650
|
+
}
|
|
51651
|
+
const argSpan = lineText.slice(openParen + 1, closeIdx);
|
|
51652
|
+
if (argSpan.includes(needle)) return true;
|
|
51653
|
+
i2 = closeIdx + 1;
|
|
51654
|
+
}
|
|
51655
|
+
return false;
|
|
51656
|
+
}
|
|
48504
51657
|
function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachableLines, tainted, code, language, types) {
|
|
48505
51658
|
const flows = [];
|
|
48506
51659
|
const methodRanges = (langs) => language && langs.includes(language) && types ? types.flatMap((t) => t.methods.map((m) => [m.start_line, m.end_line])) : [];
|
|
@@ -48912,12 +52065,15 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
48912
52065
|
literal_kill_line: derivedLine
|
|
48913
52066
|
});
|
|
48914
52067
|
} else {
|
|
48915
|
-
|
|
48916
|
-
|
|
48917
|
-
|
|
48918
|
-
|
|
48919
|
-
|
|
48920
|
-
|
|
52068
|
+
const unrelatedEnvAnchor = scopedAnchor.type === "env_input" && scopedAnchor.variable !== varName && derivedLine < scopedAnchor.line;
|
|
52069
|
+
if (!unrelatedEnvAnchor) {
|
|
52070
|
+
sourcesWithVar.push({
|
|
52071
|
+
...scopedAnchor,
|
|
52072
|
+
variable: varName,
|
|
52073
|
+
literal_kill_line: derivedLine,
|
|
52074
|
+
...owner ? { in_method: owner } : {}
|
|
52075
|
+
});
|
|
52076
|
+
}
|
|
48921
52077
|
}
|
|
48922
52078
|
existingVars.add(varName);
|
|
48923
52079
|
}
|
|
@@ -49350,6 +52506,10 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
49350
52506
|
for (const source of colocSources) {
|
|
49351
52507
|
if (!canSourceReachSink(source.type, sink.type)) continue;
|
|
49352
52508
|
if (!sourceSemanticsAllowed(source, sink.type)) continue;
|
|
52509
|
+
const colocLineText = sink.code ?? "";
|
|
52510
|
+
if (colocLineText && (language === "javascript" || language === "typescript") && source.type === "io_input" && typeof source.location === "string" && source.location.includes(".parse()") && sinkNestedInJsTsParseArgs(colocLineText, sink.method)) {
|
|
52511
|
+
continue;
|
|
52512
|
+
}
|
|
49353
52513
|
const sourceVar = source.variable;
|
|
49354
52514
|
if (sourceVar && sourceVar.length > 0) {
|
|
49355
52515
|
const sinkCode = sink.code;
|
|
@@ -49368,6 +52528,12 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
49368
52528
|
if (source.type === "file_input" && sink.type === "path_traversal" && sink.method && source.location.includes(`${sink.method}(`)) {
|
|
49369
52529
|
continue;
|
|
49370
52530
|
}
|
|
52531
|
+
if (source.type === "env_input" && sink.type === "command_injection" && sink.method === "exec" && /System\s*\.\s*getProperty\s*\(/.test(source.location ?? "")) {
|
|
52532
|
+
const sinkCode = sink.code ?? "";
|
|
52533
|
+
if (/new\s+(?:java\.io\.)?File\s*\(\s*System\s*\.\s*getProperty\s*\(/.test(sinkCode)) {
|
|
52534
|
+
continue;
|
|
52535
|
+
}
|
|
52536
|
+
}
|
|
49371
52537
|
if (flows.some(
|
|
49372
52538
|
(f) => f.source_line === source.line && f.sink_line === sink.line && f.sink_type === sink.type
|
|
49373
52539
|
)) continue;
|
|
@@ -49387,7 +52553,7 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
49387
52553
|
}
|
|
49388
52554
|
return flows;
|
|
49389
52555
|
}
|
|
49390
|
-
function pickScopedSource(sources, sinkLine, methodName, types, taintedVar) {
|
|
52556
|
+
function pickScopedSource(sources, sinkLine, methodName, types, taintedVar, code, language, strictUnrelatedSourceGuard = false, javaDerivedVars) {
|
|
49391
52557
|
if (sources.length === 0) return void 0;
|
|
49392
52558
|
const closestPreceding = (cands) => {
|
|
49393
52559
|
let best;
|
|
@@ -49397,11 +52563,44 @@ function pickScopedSource(sources, sinkLine, methodName, types, taintedVar) {
|
|
|
49397
52563
|
}
|
|
49398
52564
|
return best;
|
|
49399
52565
|
};
|
|
52566
|
+
const methodAt = (line) => {
|
|
52567
|
+
if (!types) return null;
|
|
52568
|
+
for (const t of types) {
|
|
52569
|
+
for (const m of t.methods) {
|
|
52570
|
+
if (line >= m.start_line && line <= m.end_line) return m.name;
|
|
52571
|
+
}
|
|
52572
|
+
}
|
|
52573
|
+
return null;
|
|
52574
|
+
};
|
|
52575
|
+
if (taintedVar && strictUnrelatedSourceGuard && typeof code === "string" && (language === "java" || language === "csharp") && javaDerivedVars?.has(taintedVar)) {
|
|
52576
|
+
const owner = methodName ?? methodAt(sinkLine);
|
|
52577
|
+
const realSourceByVar = /* @__PURE__ */ new Map();
|
|
52578
|
+
for (const s of sources) {
|
|
52579
|
+
if (!s.variable) continue;
|
|
52580
|
+
const sOwner = s.in_method ?? methodAt(s.line);
|
|
52581
|
+
if (owner && sOwner !== owner) continue;
|
|
52582
|
+
const prev = realSourceByVar.get(s.variable);
|
|
52583
|
+
if (!prev || s.line < prev.line) realSourceByVar.set(s.variable, s);
|
|
52584
|
+
}
|
|
52585
|
+
const referenced = resolveJavaDerivedAnchor(
|
|
52586
|
+
taintedVar,
|
|
52587
|
+
javaDerivedVars,
|
|
52588
|
+
realSourceByVar,
|
|
52589
|
+
code.split("\n"),
|
|
52590
|
+
/* @__PURE__ */ new Set()
|
|
52591
|
+
);
|
|
52592
|
+
if (referenced && referenced.line < sinkLine) return referenced;
|
|
52593
|
+
}
|
|
49400
52594
|
if (taintedVar) {
|
|
49401
52595
|
const byVar = sources.filter((s) => s.variable === taintedVar);
|
|
49402
52596
|
const pick = closestPreceding(byVar);
|
|
49403
52597
|
if (pick) return pick;
|
|
49404
52598
|
}
|
|
52599
|
+
const hasPrecedingNamedSource = Boolean(
|
|
52600
|
+
taintedVar && sources.some((s) => s.variable === taintedVar && s.line < sinkLine)
|
|
52601
|
+
);
|
|
52602
|
+
const guardUnrelatedSources = strictUnrelatedSourceGuard && hasPrecedingNamedSource;
|
|
52603
|
+
const matchesTaintedVar = (s) => !guardUnrelatedSources || !taintedVar || s.variable === taintedVar;
|
|
49405
52604
|
if (methodName && types && types.length > 0) {
|
|
49406
52605
|
let methodStart = -1;
|
|
49407
52606
|
let methodEnd = -1;
|
|
@@ -49416,13 +52615,16 @@ function pickScopedSource(sources, sinkLine, methodName, types, taintedVar) {
|
|
|
49416
52615
|
if (methodStart > 0) break;
|
|
49417
52616
|
}
|
|
49418
52617
|
if (methodStart > 0 && methodEnd >= methodStart) {
|
|
49419
|
-
const inScope = sources.filter(
|
|
52618
|
+
const inScope = sources.filter(
|
|
52619
|
+
(s) => s.line >= methodStart && s.line <= methodEnd && matchesTaintedVar(s)
|
|
52620
|
+
);
|
|
49420
52621
|
const pick = closestPreceding(inScope);
|
|
49421
52622
|
if (pick) return pick;
|
|
49422
52623
|
}
|
|
49423
52624
|
}
|
|
49424
|
-
const globalPick = closestPreceding(sources);
|
|
52625
|
+
const globalPick = closestPreceding(sources.filter(matchesTaintedVar));
|
|
49425
52626
|
if (globalPick) return globalPick;
|
|
52627
|
+
if (guardUnrelatedSources && taintedVar) return void 0;
|
|
49426
52628
|
return sources[0];
|
|
49427
52629
|
}
|
|
49428
52630
|
|
|
@@ -50168,6 +53370,11 @@ var CLOSE_METHODS = /* @__PURE__ */ new Set([
|
|
|
50168
53370
|
"shutdownNow",
|
|
50169
53371
|
"terminate"
|
|
50170
53372
|
]);
|
|
53373
|
+
var JS_STREAM_CLOSE_METHODS = /* @__PURE__ */ new Set(["end"]);
|
|
53374
|
+
function jsBareReceiver(receiver) {
|
|
53375
|
+
if (!receiver) return null;
|
|
53376
|
+
return receiver.replace(/[!?]+$/, "");
|
|
53377
|
+
}
|
|
50171
53378
|
var WRAPPER_CTORS = /* @__PURE__ */ new Set([
|
|
50172
53379
|
// java.io wrappers
|
|
50173
53380
|
"BufferedInputStream",
|
|
@@ -50217,7 +53424,7 @@ var ResourceLeakPass = class {
|
|
|
50217
53424
|
for (const call of graph.ir.calls) {
|
|
50218
53425
|
const name2 = call.method_name;
|
|
50219
53426
|
const isConstructor = call.is_constructor === true && RESOURCE_CTORS.has(name2);
|
|
50220
|
-
const isFactory = !call.is_constructor && RESOURCE_FACTORY_METHODS.has(name2);
|
|
53427
|
+
const isFactory = !call.is_constructor && RESOURCE_FACTORY_METHODS.has(name2) && (name2 !== "open" || !!call.receiver || graph.ir.meta.language === "python");
|
|
50221
53428
|
if (!isConstructor && !isFactory) continue;
|
|
50222
53429
|
const openLine = call.location.line;
|
|
50223
53430
|
const defs = graph.defsAtLine(openLine);
|
|
@@ -50255,8 +53462,9 @@ var ResourceLeakPass = class {
|
|
|
50255
53462
|
)) {
|
|
50256
53463
|
continue;
|
|
50257
53464
|
}
|
|
53465
|
+
const isJs2 = graph.ir.meta.language === "javascript" || graph.ir.meta.language === "typescript";
|
|
50258
53466
|
const closeCall = graph.ir.calls.find(
|
|
50259
|
-
(c) => CLOSE_METHODS.has(c.method_name) && c.receiver === resourceVar && c.location.line > openLine && c.location.line <= methodEnd
|
|
53467
|
+
(c) => (CLOSE_METHODS.has(c.method_name) || isJs2 && JS_STREAM_CLOSE_METHODS.has(c.method_name)) && (c.receiver === resourceVar || isJs2 && jsBareReceiver(c.receiver) === resourceVar) && c.location.line > openLine && c.location.line <= methodEnd
|
|
50260
53468
|
);
|
|
50261
53469
|
const snippet = (codeLines[openLine - 1] ?? "").trim();
|
|
50262
53470
|
if (!closeCall) {
|
|
@@ -57794,7 +61002,46 @@ var JAVA_SAFE_EVIDENCE_RE = /(disallow-doctype-decl|external-general-entities|ex
|
|
|
57794
61002
|
var JAVA_XML_OUTPUT_ONLY_RE = /\bnew\s+(?:DOMSource|StreamResult)\s*\(/;
|
|
57795
61003
|
var JAVA_XML_PARSE_INPUT_RE = /\bnew\s+(?:StreamSource|SAXSource|InputSource)\s*\(/;
|
|
57796
61004
|
var JAVA_DOC_BUILDER_NEW_DOCUMENT_RE = /\.\s*newDocument\s*\(\s*\)/;
|
|
57797
|
-
var JAVA_DOC_BUILDER_PARSE_RE =
|
|
61005
|
+
var JAVA_DOC_BUILDER_PARSE_RE = /\.\s*parse\s*\(/;
|
|
61006
|
+
function stripJavaComments(source) {
|
|
61007
|
+
let out2 = "";
|
|
61008
|
+
let i2 = 0;
|
|
61009
|
+
while (i2 < source.length) {
|
|
61010
|
+
const ch = source[i2];
|
|
61011
|
+
if (ch === '"' || ch === "'") {
|
|
61012
|
+
const q = ch;
|
|
61013
|
+
out2 += ch;
|
|
61014
|
+
i2++;
|
|
61015
|
+
while (i2 < source.length) {
|
|
61016
|
+
if (source[i2] === "\\") {
|
|
61017
|
+
out2 += source[i2++];
|
|
61018
|
+
if (i2 < source.length) out2 += source[i2++];
|
|
61019
|
+
continue;
|
|
61020
|
+
}
|
|
61021
|
+
out2 += source[i2];
|
|
61022
|
+
if (source[i2] === q) {
|
|
61023
|
+
i2++;
|
|
61024
|
+
break;
|
|
61025
|
+
}
|
|
61026
|
+
i2++;
|
|
61027
|
+
}
|
|
61028
|
+
continue;
|
|
61029
|
+
}
|
|
61030
|
+
if (source.startsWith("//", i2)) {
|
|
61031
|
+
while (i2 < source.length && source[i2] !== "\n") i2++;
|
|
61032
|
+
continue;
|
|
61033
|
+
}
|
|
61034
|
+
if (source.startsWith("/*", i2)) {
|
|
61035
|
+
i2 += 2;
|
|
61036
|
+
while (i2 < source.length && !source.startsWith("*/", i2)) i2++;
|
|
61037
|
+
i2 += 2;
|
|
61038
|
+
continue;
|
|
61039
|
+
}
|
|
61040
|
+
out2 += ch;
|
|
61041
|
+
i2++;
|
|
61042
|
+
}
|
|
61043
|
+
return out2;
|
|
61044
|
+
}
|
|
57798
61045
|
var JAVA_HARDENING_SETTER_RE = /\.\s*(?:setFeature|setAttribute|setProperty|setXIncludeAware|setExpandEntityReferences)\s*\(/;
|
|
57799
61046
|
var JAVA_FACTORY_CHAINED_RE = /\bnewInstance\s*\([^()]*\)\s*\.\s*(?:newDocumentBuilder|newSAXParser|newTransformer|newTemplates|newSchema|createXMLStreamReader|createXMLEventReader)\s*\(/;
|
|
57800
61047
|
var PY_LXML_PARSER_INSECURE_DEFAULT_RE = /\bresolve_entities\s*=\s*False\b/;
|
|
@@ -57811,8 +61058,9 @@ var XmlEntityExpansionPass = class {
|
|
|
57811
61058
|
const processWide = safeInFile && /jdk\.xml\./.test(code);
|
|
57812
61059
|
const lines = safeInFile ? code.split("\n") : [];
|
|
57813
61060
|
const methodRanges = safeInFile ? this.methodRanges(graph.ir.types) : [];
|
|
57814
|
-
const
|
|
57815
|
-
const
|
|
61061
|
+
const codeFor173 = stripJavaComments(code);
|
|
61062
|
+
const isXmlOutputOnly = JAVA_XML_OUTPUT_ONLY_RE.test(codeFor173) && !JAVA_XML_PARSE_INPUT_RE.test(codeFor173);
|
|
61063
|
+
const isDocumentBuilderEmptyOnly = JAVA_DOC_BUILDER_NEW_DOCUMENT_RE.test(codeFor173) && !JAVA_DOC_BUILDER_PARSE_RE.test(codeFor173);
|
|
57816
61064
|
for (const call of graph.ir.calls) {
|
|
57817
61065
|
const det = this.detectJavaCall(call);
|
|
57818
61066
|
if (!det) continue;
|
|
@@ -59034,7 +62282,7 @@ async function initAnalyzer(options = {}) {
|
|
|
59034
62282
|
});
|
|
59035
62283
|
initialized = true;
|
|
59036
62284
|
}
|
|
59037
|
-
function
|
|
62285
|
+
function escapeRegExp2(s) {
|
|
59038
62286
|
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
59039
62287
|
}
|
|
59040
62288
|
function buildEnriched(types, _calls, sources, sinks) {
|
|
@@ -59292,6 +62540,11 @@ async function analyze(code, filePath, language, options = {}) {
|
|
|
59292
62540
|
if (!phaseTimingEnabled) return;
|
|
59293
62541
|
console.error(`[phase-timing] ${label} ${Date.now() - t0}ms file=${filePath}`);
|
|
59294
62542
|
};
|
|
62543
|
+
const checkDeadline = (phase) => {
|
|
62544
|
+
if (fileDeadline > 0 && Date.now() > fileDeadline) {
|
|
62545
|
+
throw new AnalysisTimeoutError(filePath, Date.now() - (fileDeadline - fileTimeoutMs), phase);
|
|
62546
|
+
}
|
|
62547
|
+
};
|
|
59295
62548
|
const tParse = phaseStart();
|
|
59296
62549
|
const tree = await parse(code, parseGrammar);
|
|
59297
62550
|
phaseEnd("parse", tParse);
|
|
@@ -59303,6 +62556,7 @@ async function analyze(code, filePath, language, options = {}) {
|
|
|
59303
62556
|
const tParseStatus = phaseStart();
|
|
59304
62557
|
const parseStatus = extractParseStatus(tree);
|
|
59305
62558
|
phaseEnd("extractParseStatus", tParseStatus);
|
|
62559
|
+
checkDeadline("extractParseStatus");
|
|
59306
62560
|
if (parseStatus.has_errors) {
|
|
59307
62561
|
logger.warn("Partial parse \u2014 IR may be incomplete", {
|
|
59308
62562
|
filePath,
|
|
@@ -59314,12 +62568,14 @@ async function analyze(code, filePath, language, options = {}) {
|
|
|
59314
62568
|
const tCollect = phaseStart();
|
|
59315
62569
|
const nodeCache = collectAllNodes(tree.rootNode, getNodeTypesForLanguage(language));
|
|
59316
62570
|
phaseEnd("collectAllNodes", tCollect);
|
|
62571
|
+
checkDeadline("collectAllNodes");
|
|
59317
62572
|
const tMeta = phaseStart();
|
|
59318
62573
|
const meta = extractMeta(code, tree, filePath, language);
|
|
59319
62574
|
if (options.projectProfile !== void 0) {
|
|
59320
62575
|
meta.projectProfile = makeProfileResolver(options.projectProfile)(filePath);
|
|
59321
62576
|
}
|
|
59322
62577
|
phaseEnd("extractMeta", tMeta);
|
|
62578
|
+
checkDeadline("extractMeta");
|
|
59323
62579
|
if (longestLineLength(code) > MAX_ANALYZABLE_LINE_LENGTH) {
|
|
59324
62580
|
logger.warn("Skipping analysis of a minified / single-line file", {
|
|
59325
62581
|
filePath,
|
|
@@ -59344,25 +62600,32 @@ async function analyze(code, filePath, language, options = {}) {
|
|
|
59344
62600
|
const tTypes = phaseStart();
|
|
59345
62601
|
const types = extractTypes(tree, nodeCache, language, { navigationTypes: options.navigationTypes });
|
|
59346
62602
|
phaseEnd("extractTypes", tTypes);
|
|
62603
|
+
checkDeadline("extractTypes");
|
|
59347
62604
|
const tCalls = phaseStart();
|
|
59348
62605
|
const calls = extractCalls(tree, nodeCache, language, { navigationTypes: options.navigationTypes });
|
|
59349
62606
|
phaseEnd("extractCalls", tCalls);
|
|
62607
|
+
checkDeadline("extractCalls");
|
|
59350
62608
|
const tImports = phaseStart();
|
|
59351
62609
|
const imports = extractImports(tree, language, nodeCache);
|
|
59352
62610
|
phaseEnd("extractImports", tImports);
|
|
62611
|
+
checkDeadline("extractImports");
|
|
59353
62612
|
const tExports = phaseStart();
|
|
59354
62613
|
if (options.declarationDetail && (language === "typescript" || language === "javascript")) enrichTsDeclarations(tree, types);
|
|
59355
62614
|
const exports = (options.declarationDetail && (language === "typescript" || language === "javascript") ? extractTsExports(types) : null) ?? extractExports(types);
|
|
59356
62615
|
phaseEnd("extractExports", tExports);
|
|
62616
|
+
checkDeadline("extractExports");
|
|
59357
62617
|
const tCFG = phaseStart();
|
|
59358
62618
|
const cfg = buildCFG(tree, language, nodeCache);
|
|
59359
62619
|
phaseEnd("buildCFG", tCFG);
|
|
62620
|
+
checkDeadline("buildCFG");
|
|
59360
62621
|
const tDFG = phaseStart();
|
|
59361
62622
|
const dfg = buildDFG(tree, nodeCache, language);
|
|
59362
62623
|
phaseEnd("buildDFG", tDFG);
|
|
62624
|
+
checkDeadline("buildDFG");
|
|
59363
62625
|
const tRuntime = phaseStart();
|
|
59364
62626
|
const runtimeRegistrations = extractRuntimeRegistrations(tree, nodeCache, language, imports);
|
|
59365
62627
|
phaseEnd("extractRuntimeRegistrations", tRuntime);
|
|
62628
|
+
checkDeadline("extractRuntimeRegistrations");
|
|
59366
62629
|
const tGraph = phaseStart();
|
|
59367
62630
|
const graph = new CodeGraph({
|
|
59368
62631
|
meta,
|
|
@@ -59382,6 +62645,7 @@ async function analyze(code, filePath, language, options = {}) {
|
|
|
59382
62645
|
...constTableLookupDefIds(dfg.defs, code, language)
|
|
59383
62646
|
]);
|
|
59384
62647
|
phaseEnd("buildCodeGraph", tGraph);
|
|
62648
|
+
checkDeadline("buildCodeGraph");
|
|
59385
62649
|
const config = options.taintConfig ?? getDefaultConfig();
|
|
59386
62650
|
const disabledPasses = new Set(options.disabledPasses ?? []);
|
|
59387
62651
|
const passOpts = options.passOptions ?? {};
|
|
@@ -59550,6 +62814,20 @@ async function analyze(code, filePath, language, options = {}) {
|
|
|
59550
62814
|
coalescedFindings,
|
|
59551
62815
|
options.perFileFindingCap ?? DEFAULT_PER_FILE_FINDING_CAP
|
|
59552
62816
|
);
|
|
62817
|
+
if (language === "java" && (taint.flows ?? []).some((f) => f.source_type === "plugin_param")) {
|
|
62818
|
+
applySingleFileJavaMapConstantCallerGate(filePath, {
|
|
62819
|
+
meta,
|
|
62820
|
+
types,
|
|
62821
|
+
calls,
|
|
62822
|
+
cfg,
|
|
62823
|
+
dfg,
|
|
62824
|
+
taint,
|
|
62825
|
+
imports,
|
|
62826
|
+
exports,
|
|
62827
|
+
unresolved,
|
|
62828
|
+
enriched
|
|
62829
|
+
}, code.split("\n"));
|
|
62830
|
+
}
|
|
59553
62831
|
return {
|
|
59554
62832
|
meta,
|
|
59555
62833
|
types,
|
|
@@ -59674,11 +62952,11 @@ async function analyzeForAPI(code, filePath, language, options = {}) {
|
|
|
59674
62952
|
if (sink.type !== "xpath_injection") return true;
|
|
59675
62953
|
const sinkLineText = sourceLines[sink.line - 1] ?? "";
|
|
59676
62954
|
const taintedVarOnLine = [...pythonTaintedVars.keys()].find(
|
|
59677
|
-
(v) => new RegExp(`\\b${
|
|
62955
|
+
(v) => new RegExp(`\\b${escapeRegExp2(v)}\\b`).test(sinkLineText)
|
|
59678
62956
|
);
|
|
59679
62957
|
if (!taintedVarOnLine) return false;
|
|
59680
62958
|
if (pythonSanitizedVars.has(taintedVarOnLine)) return false;
|
|
59681
|
-
const escVar =
|
|
62959
|
+
const escVar = escapeRegExp2(taintedVarOnLine);
|
|
59682
62960
|
if (new RegExp(`\\.xpath\\s*\\([^)]*\\b\\w+\\s*=\\s*\\b${escVar}\\b`).test(sinkLineText)) return false;
|
|
59683
62961
|
return true;
|
|
59684
62962
|
});
|