circle-ir 4.17.0 → 4.19.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 +186 -0
- package/dist/analysis/advisories.d.ts.map +1 -0
- package/dist/analysis/advisories.js +391 -0
- package/dist/analysis/advisories.js.map +1 -0
- package/dist/analysis/comment-lines.d.ts +14 -0
- package/dist/analysis/comment-lines.d.ts.map +1 -0
- package/dist/analysis/comment-lines.js +34 -0
- package/dist/analysis/comment-lines.js.map +1 -0
- package/dist/analysis/config-loader.d.ts.map +1 -1
- package/dist/analysis/config-loader.js +81 -27
- package/dist/analysis/config-loader.js.map +1 -1
- package/dist/analysis/constant-caller-gate.d.ts +2 -2
- package/dist/analysis/constant-caller-gate.d.ts.map +1 -1
- package/dist/analysis/constant-caller-gate.js +205 -29
- package/dist/analysis/constant-caller-gate.js.map +1 -1
- package/dist/analysis/constant-propagation/propagator.d.ts +4 -0
- package/dist/analysis/constant-propagation/propagator.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/propagator.js +99 -0
- package/dist/analysis/constant-propagation/propagator.js.map +1 -1
- package/dist/analysis/entry-point-detection.d.ts.map +1 -1
- package/dist/analysis/entry-point-detection.js +72 -0
- package/dist/analysis/entry-point-detection.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 +124 -10
- 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/maven-declared.d.ts +72 -0
- package/dist/analysis/maven-declared.d.ts.map +1 -0
- package/dist/analysis/maven-declared.js +216 -0
- package/dist/analysis/maven-declared.js.map +1 -0
- package/dist/analysis/maven-version.d.ts +28 -0
- package/dist/analysis/maven-version.d.ts.map +1 -0
- package/dist/analysis/maven-version.js +172 -0
- package/dist/analysis/maven-version.js.map +1 -0
- package/dist/analysis/passes/constant-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/constant-propagation-pass.js +29 -1
- 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 +81 -1
- package/dist/analysis/passes/cross-file-pass.js.map +1 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.d.ts +7 -0
- package/dist/analysis/passes/csharp-sanitizer-credit.d.ts.map +1 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.js +44 -1
- package/dist/analysis/passes/csharp-sanitizer-credit.js.map +1 -1
- package/dist/analysis/passes/insecure-cookie-pass.d.ts +2 -0
- package/dist/analysis/passes/insecure-cookie-pass.d.ts.map +1 -1
- package/dist/analysis/passes/insecure-cookie-pass.js +25 -3
- package/dist/analysis/passes/insecure-cookie-pass.js.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.d.ts +11 -14
- package/dist/analysis/passes/interprocedural-pass.d.ts.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.js +564 -0
- package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
- package/dist/analysis/passes/language-sources-pass.d.ts +18 -1
- package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
- package/dist/analysis/passes/language-sources-pass.js +1097 -15
- package/dist/analysis/passes/language-sources-pass.js.map +1 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.d.ts.map +1 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.js +66 -3
- package/dist/analysis/passes/param-source-flow-gate-pass.js.map +1 -1
- package/dist/analysis/passes/resource-leak-pass.d.ts.map +1 -1
- package/dist/analysis/passes/resource-leak-pass.js +5 -1
- package/dist/analysis/passes/resource-leak-pass.js.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.d.ts +44 -2
- package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.js +728 -13
- package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.js +133 -10
- package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
- package/dist/analysis/passes/tls-verify-disabled-pass.d.ts +18 -0
- package/dist/analysis/passes/tls-verify-disabled-pass.d.ts.map +1 -1
- package/dist/analysis/passes/tls-verify-disabled-pass.js +161 -0
- package/dist/analysis/passes/tls-verify-disabled-pass.js.map +1 -1
- package/dist/analysis/passes/weak-random-pass.d.ts +6 -0
- package/dist/analysis/passes/weak-random-pass.d.ts.map +1 -1
- package/dist/analysis/passes/weak-random-pass.js +29 -0
- package/dist/analysis/passes/weak-random-pass.js.map +1 -1
- package/dist/analysis/promote-cross-file-flows.d.ts +17 -0
- package/dist/analysis/promote-cross-file-flows.d.ts.map +1 -0
- package/dist/analysis/promote-cross-file-flows.js +32 -0
- package/dist/analysis/promote-cross-file-flows.js.map +1 -0
- package/dist/analysis/sbom.d.ts +100 -0
- package/dist/analysis/sbom.d.ts.map +1 -1
- package/dist/analysis/sbom.js +514 -3
- package/dist/analysis/sbom.js.map +1 -1
- package/dist/analysis/semver-version.d.ts +30 -0
- package/dist/analysis/semver-version.d.ts.map +1 -0
- package/dist/analysis/semver-version.js +76 -0
- package/dist/analysis/semver-version.js.map +1 -0
- package/dist/analysis/taint-matcher.d.ts +5 -0
- package/dist/analysis/taint-matcher.d.ts.map +1 -1
- package/dist/analysis/taint-matcher.js +293 -6
- package/dist/analysis/taint-matcher.js.map +1 -1
- package/dist/analyzer.d.ts +57 -0
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +69 -6
- package/dist/analyzer.js.map +1 -1
- package/dist/browser/circle-ir.js +3156 -323
- package/dist/core/circle-ir-core.cjs +951 -409
- package/dist/core/circle-ir-core.js +951 -409
- package/dist/core/extractors/dfg.js +244 -2
- package/dist/core/extractors/dfg.js.map +1 -1
- package/dist/core/extractors/ts-declaration-detail.d.ts +39 -0
- package/dist/core/extractors/ts-declaration-detail.d.ts.map +1 -0
- package/dist/core/extractors/ts-declaration-detail.js +266 -0
- package/dist/core/extractors/ts-declaration-detail.js.map +1 -0
- package/dist/graph/analysis-pass.d.ts +4 -1
- package/dist/graph/analysis-pass.d.ts.map +1 -1
- package/dist/graph/analysis-pass.js +4 -1
- package/dist/graph/analysis-pass.js.map +1 -1
- package/dist/graph-facts/dead-code.d.ts +62 -0
- package/dist/graph-facts/dead-code.d.ts.map +1 -0
- package/dist/graph-facts/dead-code.js +90 -0
- package/dist/graph-facts/dead-code.js.map +1 -0
- package/dist/graph-facts/dependency-calls.d.ts +86 -0
- package/dist/graph-facts/dependency-calls.d.ts.map +1 -0
- package/dist/graph-facts/dependency-calls.js +93 -0
- package/dist/graph-facts/dependency-calls.js.map +1 -0
- package/dist/graph-facts/index.d.ts +10 -0
- package/dist/graph-facts/index.d.ts.map +1 -0
- package/dist/graph-facts/index.js +10 -0
- package/dist/graph-facts/index.js.map +1 -0
- package/dist/graph-facts/maven-packages.d.ts +42 -0
- package/dist/graph-facts/maven-packages.d.ts.map +1 -0
- package/dist/graph-facts/maven-packages.js +133 -0
- package/dist/graph-facts/maven-packages.js.map +1 -0
- package/dist/graph-facts/reach.d.ts +203 -0
- package/dist/graph-facts/reach.d.ts.map +1 -0
- package/dist/graph-facts/reach.js +219 -0
- package/dist/graph-facts/reach.js.map +1 -0
- package/dist/graph-facts/removal-reach.d.ts +73 -0
- package/dist/graph-facts/removal-reach.d.ts.map +1 -0
- package/dist/graph-facts/removal-reach.js +64 -0
- package/dist/graph-facts/removal-reach.js.map +1 -0
- package/dist/index.d.ts +21 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20 -3
- package/dist/index.js.map +1 -1
- package/dist/navigation/go-graph.d.ts +68 -0
- package/dist/navigation/go-graph.d.ts.map +1 -0
- package/dist/navigation/go-graph.js +753 -0
- package/dist/navigation/go-graph.js.map +1 -0
- package/dist/navigation/index.d.ts +7 -1
- package/dist/navigation/index.d.ts.map +1 -1
- package/dist/navigation/index.js +6 -0
- package/dist/navigation/index.js.map +1 -1
- package/dist/navigation/java-entry-tables.d.ts +43 -0
- package/dist/navigation/java-entry-tables.d.ts.map +1 -0
- package/dist/navigation/java-entry-tables.js +56 -0
- package/dist/navigation/java-entry-tables.js.map +1 -0
- package/dist/navigation/java-graph.d.ts +64 -0
- package/dist/navigation/java-graph.d.ts.map +1 -0
- package/dist/navigation/java-graph.js +466 -0
- package/dist/navigation/java-graph.js.map +1 -0
- package/dist/navigation/navigation-index.d.ts +51 -1
- package/dist/navigation/navigation-index.d.ts.map +1 -1
- package/dist/navigation/navigation-index.js +72 -0
- package/dist/navigation/navigation-index.js.map +1 -1
- package/dist/navigation/python-graph.d.ts +73 -0
- package/dist/navigation/python-graph.d.ts.map +1 -0
- package/dist/navigation/python-graph.js +867 -0
- package/dist/navigation/python-graph.js.map +1 -0
- package/dist/navigation/ts-call-edges.d.ts +193 -0
- package/dist/navigation/ts-call-edges.d.ts.map +1 -0
- package/dist/navigation/ts-call-edges.js +2089 -0
- package/dist/navigation/ts-call-edges.js.map +1 -0
- package/dist/navigation/ts-entry-tables.d.ts +88 -0
- package/dist/navigation/ts-entry-tables.d.ts.map +1 -0
- package/dist/navigation/ts-entry-tables.js +50 -0
- package/dist/navigation/ts-entry-tables.js.map +1 -0
- package/dist/path-set/branches.d.ts +52 -0
- package/dist/path-set/branches.d.ts.map +1 -0
- package/dist/path-set/branches.js +124 -0
- package/dist/path-set/branches.js.map +1 -0
- package/dist/path-set/finding-diff.d.ts +63 -0
- package/dist/path-set/finding-diff.d.ts.map +1 -0
- package/dist/path-set/finding-diff.js +150 -0
- package/dist/path-set/finding-diff.js.map +1 -0
- package/dist/path-set/index.d.ts +18 -0
- package/dist/path-set/index.d.ts.map +1 -0
- package/dist/path-set/index.js +12 -0
- package/dist/path-set/index.js.map +1 -0
- package/dist/path-set/line-diff.d.ts +19 -0
- package/dist/path-set/line-diff.d.ts.map +1 -0
- package/dist/path-set/line-diff.js +98 -0
- package/dist/path-set/line-diff.js.map +1 -0
- package/dist/path-set/path-set.d.ts +88 -0
- package/dist/path-set/path-set.d.ts.map +1 -0
- package/dist/path-set/path-set.js +716 -0
- package/dist/path-set/path-set.js.map +1 -0
- package/dist/path-set/templates.d.ts +42 -0
- package/dist/path-set/templates.d.ts.map +1 -0
- package/dist/path-set/templates.js +119 -0
- package/dist/path-set/templates.js.map +1 -0
- package/dist/path-set/types.d.ts +195 -0
- package/dist/path-set/types.d.ts.map +1 -0
- package/dist/path-set/types.js +8 -0
- package/dist/path-set/types.js.map +1 -0
- package/dist/remedy-class/index.d.ts +12 -0
- package/dist/remedy-class/index.d.ts.map +1 -0
- package/dist/remedy-class/index.js +9 -0
- package/dist/remedy-class/index.js.map +1 -0
- package/dist/remedy-class/match.d.ts +165 -0
- package/dist/remedy-class/match.d.ts.map +1 -0
- package/dist/remedy-class/match.js +705 -0
- package/dist/remedy-class/match.js.map +1 -0
- package/dist/remedy-class/output-context.d.ts +25 -0
- package/dist/remedy-class/output-context.d.ts.map +1 -0
- package/dist/remedy-class/output-context.js +150 -0
- package/dist/remedy-class/output-context.js.map +1 -0
- package/dist/remedy-class/sha256.d.ts +18 -0
- package/dist/remedy-class/sha256.d.ts.map +1 -0
- package/dist/remedy-class/sha256.js +89 -0
- package/dist/remedy-class/sha256.js.map +1 -0
- package/dist/remedy-class/table.d.ts +130 -0
- package/dist/remedy-class/table.d.ts.map +1 -0
- package/dist/remedy-class/table.js +457 -0
- package/dist/remedy-class/table.js.map +1 -0
- package/dist/resolution/cross-file.d.ts +11 -0
- package/dist/resolution/cross-file.d.ts.map +1 -1
- package/dist/resolution/cross-file.js +82 -5
- package/dist/resolution/cross-file.js.map +1 -1
- package/dist/stable-ids/builder.d.ts +20 -0
- package/dist/stable-ids/builder.d.ts.map +1 -0
- package/dist/stable-ids/builder.js +65 -0
- package/dist/stable-ids/builder.js.map +1 -0
- package/dist/stable-ids/diff.d.ts +18 -0
- package/dist/stable-ids/diff.d.ts.map +1 -0
- package/dist/stable-ids/diff.js +37 -0
- package/dist/stable-ids/diff.js.map +1 -0
- package/dist/stable-ids/go.d.ts +28 -0
- package/dist/stable-ids/go.d.ts.map +1 -0
- package/dist/stable-ids/go.js +160 -0
- package/dist/stable-ids/go.js.map +1 -0
- package/dist/stable-ids/hash.d.ts +22 -0
- package/dist/stable-ids/hash.d.ts.map +1 -0
- package/dist/stable-ids/hash.js +167 -0
- package/dist/stable-ids/hash.js.map +1 -0
- package/dist/stable-ids/index.d.ts +30 -0
- package/dist/stable-ids/index.d.ts.map +1 -0
- package/dist/stable-ids/index.js +59 -0
- package/dist/stable-ids/index.js.map +1 -0
- package/dist/stable-ids/java.d.ts +28 -0
- package/dist/stable-ids/java.d.ts.map +1 -0
- package/dist/stable-ids/java.js +224 -0
- package/dist/stable-ids/java.js.map +1 -0
- package/dist/stable-ids/moves.d.ts +87 -0
- package/dist/stable-ids/moves.d.ts.map +1 -0
- package/dist/stable-ids/moves.js +222 -0
- package/dist/stable-ids/moves.js.map +1 -0
- package/dist/stable-ids/nodes.d.ts +32 -0
- package/dist/stable-ids/nodes.d.ts.map +1 -0
- package/dist/stable-ids/nodes.js +92 -0
- package/dist/stable-ids/nodes.js.map +1 -0
- package/dist/stable-ids/normalize.d.ts +35 -0
- package/dist/stable-ids/normalize.d.ts.map +1 -0
- package/dist/stable-ids/normalize.js +174 -0
- package/dist/stable-ids/normalize.js.map +1 -0
- package/dist/stable-ids/parse-errors.d.ts +24 -0
- package/dist/stable-ids/parse-errors.d.ts.map +1 -0
- package/dist/stable-ids/parse-errors.js +46 -0
- package/dist/stable-ids/parse-errors.js.map +1 -0
- package/dist/stable-ids/python.d.ts +27 -0
- package/dist/stable-ids/python.d.ts.map +1 -0
- package/dist/stable-ids/python.js +212 -0
- package/dist/stable-ids/python.js.map +1 -0
- package/dist/stable-ids/ts-parse-errors.d.ts +27 -0
- package/dist/stable-ids/ts-parse-errors.d.ts.map +1 -0
- package/dist/stable-ids/ts-parse-errors.js +75 -0
- package/dist/stable-ids/ts-parse-errors.js.map +1 -0
- package/dist/stable-ids/types.d.ts +106 -0
- package/dist/stable-ids/types.d.ts.map +1 -0
- package/dist/stable-ids/types.js +16 -0
- package/dist/stable-ids/types.js.map +1 -0
- package/dist/stable-ids/typescript.d.ts +30 -0
- package/dist/stable-ids/typescript.d.ts.map +1 -0
- package/dist/stable-ids/typescript.js +362 -0
- package/dist/stable-ids/typescript.js.map +1 -0
- package/dist/types/config.d.ts +9 -0
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/index.d.ts +35 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/package.json +3 -3
|
@@ -1405,11 +1405,11 @@ var Language = class _Language {
|
|
|
1405
1405
|
/**
|
|
1406
1406
|
* Get the node type id for a node type name.
|
|
1407
1407
|
*/
|
|
1408
|
-
idForNodeType(type,
|
|
1408
|
+
idForNodeType(type, named2) {
|
|
1409
1409
|
const typeLength = C.lengthBytesUTF8(type);
|
|
1410
1410
|
const typeAddress = C._malloc(typeLength + 1);
|
|
1411
1411
|
C.stringToUTF8(type, typeAddress, typeLength + 1);
|
|
1412
|
-
const result = C._ts_language_symbol_for_name(this[0], typeAddress, typeLength,
|
|
1412
|
+
const result = C._ts_language_symbol_for_name(this[0], typeAddress, typeLength, named2 ? 1 : 0);
|
|
1413
1413
|
C._free(typeAddress);
|
|
1414
1414
|
return result || null;
|
|
1415
1415
|
}
|
|
@@ -10410,6 +10410,116 @@ function processStatement2(stmt, startDefId, startUseId, scopeStack, isJavaScrip
|
|
|
10410
10410
|
carryBranchDefsOut(popped, scopeStack, alwaysRuns);
|
|
10411
10411
|
break;
|
|
10412
10412
|
}
|
|
10413
|
+
case "try_statement":
|
|
10414
|
+
case "try_with_resources_statement": {
|
|
10415
|
+
if (isJavaScript) {
|
|
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
|
+
}
|
|
10456
|
+
break;
|
|
10457
|
+
}
|
|
10458
|
+
scopeStack.push(/* @__PURE__ */ new Map());
|
|
10459
|
+
const resources = stmt.childForFieldName("resources");
|
|
10460
|
+
for (const res of resources?.namedChildren ?? []) {
|
|
10461
|
+
if (!res || res.type !== "resource") continue;
|
|
10462
|
+
const nameNode = res.childForFieldName("name");
|
|
10463
|
+
const value = res.childForFieldName("value");
|
|
10464
|
+
if (value) {
|
|
10465
|
+
const valueUses = extractUses(value, useId, scopeStack, isJavaScript);
|
|
10466
|
+
uses.push(...valueUses.uses);
|
|
10467
|
+
useId = valueUses.nextId;
|
|
10468
|
+
}
|
|
10469
|
+
if (nameNode && nameNode.type === "identifier") {
|
|
10470
|
+
const def = { id: defId++, variable: getNodeText(nameNode), line: nameNode.startPosition.row + 1, column: nameNode.startPosition.column, kind: "local" };
|
|
10471
|
+
defs.push(def);
|
|
10472
|
+
currentScope(scopeStack).set(def.variable, def.id);
|
|
10473
|
+
markDeclared(currentScope(scopeStack), def.variable);
|
|
10474
|
+
} else if (!value) {
|
|
10475
|
+
const resUses = extractUses(res, useId, scopeStack, isJavaScript);
|
|
10476
|
+
uses.push(...resUses.uses);
|
|
10477
|
+
useId = resUses.nextId;
|
|
10478
|
+
}
|
|
10479
|
+
}
|
|
10480
|
+
for (const part of stmt.namedChildren) {
|
|
10481
|
+
if (!part) continue;
|
|
10482
|
+
if (part.type === "block") {
|
|
10483
|
+
const r = processStatement2(part, defId, useId, scopeStack, isJavaScript);
|
|
10484
|
+
defs.push(...r.defs);
|
|
10485
|
+
uses.push(...r.uses);
|
|
10486
|
+
defId = r.nextDefId;
|
|
10487
|
+
useId = r.nextUseId;
|
|
10488
|
+
} else if (part.type === "catch_clause") {
|
|
10489
|
+
scopeStack.push(/* @__PURE__ */ new Map());
|
|
10490
|
+
for (const param of part.namedChildren) {
|
|
10491
|
+
if (!param || param.type !== "catch_formal_parameter") continue;
|
|
10492
|
+
const pname = param.childForFieldName("name");
|
|
10493
|
+
if (pname) {
|
|
10494
|
+
const def = { id: defId++, variable: getNodeText(pname), line: pname.startPosition.row + 1, column: pname.startPosition.column, kind: "local" };
|
|
10495
|
+
defs.push(def);
|
|
10496
|
+
currentScope(scopeStack).set(def.variable, def.id);
|
|
10497
|
+
markDeclared(currentScope(scopeStack), def.variable);
|
|
10498
|
+
}
|
|
10499
|
+
}
|
|
10500
|
+
const body2 = part.childForFieldName("body");
|
|
10501
|
+
if (body2) {
|
|
10502
|
+
const r = processStatement2(body2, defId, useId, scopeStack, isJavaScript);
|
|
10503
|
+
defs.push(...r.defs);
|
|
10504
|
+
uses.push(...r.uses);
|
|
10505
|
+
defId = r.nextDefId;
|
|
10506
|
+
useId = r.nextUseId;
|
|
10507
|
+
}
|
|
10508
|
+
carryBranchDefsOut(scopeStack.pop(), scopeStack, false);
|
|
10509
|
+
} else if (part.type === "finally_clause") {
|
|
10510
|
+
for (const b of part.namedChildren) {
|
|
10511
|
+
if (!b || b.type !== "block") continue;
|
|
10512
|
+
const r = processStatement2(b, defId, useId, scopeStack, isJavaScript);
|
|
10513
|
+
defs.push(...r.defs);
|
|
10514
|
+
uses.push(...r.uses);
|
|
10515
|
+
defId = r.nextDefId;
|
|
10516
|
+
useId = r.nextUseId;
|
|
10517
|
+
}
|
|
10518
|
+
}
|
|
10519
|
+
}
|
|
10520
|
+
carryBranchDefsOut(scopeStack.pop(), scopeStack, false);
|
|
10521
|
+
break;
|
|
10522
|
+
}
|
|
10413
10523
|
case "else_clause": {
|
|
10414
10524
|
for (let i2 = 0; i2 < stmt.childCount; i2++) {
|
|
10415
10525
|
const arm = stmt.child(i2);
|
|
@@ -11025,6 +11135,42 @@ function buildBashDFG(tree) {
|
|
|
11025
11135
|
defs.push(def);
|
|
11026
11136
|
currentScope(scopeStack).set(p, def.id);
|
|
11027
11137
|
}
|
|
11138
|
+
const bashFnDefs = /* @__PURE__ */ new Map();
|
|
11139
|
+
const bashFnByNodeId = /* @__PURE__ */ new Map();
|
|
11140
|
+
for (const fn of findNodes(tree.rootNode, "function_definition")) {
|
|
11141
|
+
const nameNode = fn.childForFieldName("name");
|
|
11142
|
+
if (!nameNode) continue;
|
|
11143
|
+
const fnName = getNodeText(nameNode);
|
|
11144
|
+
if (!fnName || bashFnDefs.has(fnName)) continue;
|
|
11145
|
+
const m = /* @__PURE__ */ new Map();
|
|
11146
|
+
for (const p of positionalParams) {
|
|
11147
|
+
const def = {
|
|
11148
|
+
id: defIdCounter++,
|
|
11149
|
+
variable: p,
|
|
11150
|
+
line: fn.startPosition.row + 1,
|
|
11151
|
+
kind: "param",
|
|
11152
|
+
expression: `bash-fn:${fnName}`
|
|
11153
|
+
};
|
|
11154
|
+
defs.push(def);
|
|
11155
|
+
m.set(p, def.id);
|
|
11156
|
+
}
|
|
11157
|
+
bashFnDefs.set(fnName, m);
|
|
11158
|
+
bashFnByNodeId.set(fn.id, fnName);
|
|
11159
|
+
}
|
|
11160
|
+
const enclosingBashFn = (node) => {
|
|
11161
|
+
let cur = node.parent;
|
|
11162
|
+
while (cur) {
|
|
11163
|
+
if (cur.type === "function_definition") return bashFnByNodeId.get(cur.id) ?? null;
|
|
11164
|
+
cur = cur.parent;
|
|
11165
|
+
}
|
|
11166
|
+
return null;
|
|
11167
|
+
};
|
|
11168
|
+
const positionalDef = (varName, node, fallback) => {
|
|
11169
|
+
if (!positionalParams.includes(varName)) return fallback;
|
|
11170
|
+
const fnName = enclosingBashFn(node);
|
|
11171
|
+
if (!fnName) return fallback;
|
|
11172
|
+
return bashFnDefs.get(fnName)?.get(varName) ?? fallback;
|
|
11173
|
+
};
|
|
11028
11174
|
walkTree(tree.rootNode, (node) => {
|
|
11029
11175
|
if (node.type === "variable_assignment") {
|
|
11030
11176
|
const nameNode = node.childForFieldName("name");
|
|
@@ -11077,7 +11223,7 @@ function buildBashDFG(tree) {
|
|
|
11077
11223
|
if (varNameNode) {
|
|
11078
11224
|
const varName = getNodeText(varNameNode);
|
|
11079
11225
|
if (varName && !varName.startsWith("?") && !varName.startsWith("#")) {
|
|
11080
|
-
let reachingDef = findReachingDef(varName, scopeStack);
|
|
11226
|
+
let reachingDef = positionalDef(varName, node, findReachingDef(varName, scopeStack));
|
|
11081
11227
|
if (reachingDef === null && !positionalParams.includes(varName)) {
|
|
11082
11228
|
const def = {
|
|
11083
11229
|
id: defIdCounter++,
|
|
@@ -11101,7 +11247,7 @@ function buildBashDFG(tree) {
|
|
|
11101
11247
|
const varNameNode = node.namedChildCount > 0 ? node.namedChild(0) : null;
|
|
11102
11248
|
if (varNameNode && varNameNode.type === "variable_name") {
|
|
11103
11249
|
const varName = getNodeText(varNameNode);
|
|
11104
|
-
let reachingDef = findReachingDef(varName, scopeStack);
|
|
11250
|
+
let reachingDef = positionalDef(varName, node, findReachingDef(varName, scopeStack));
|
|
11105
11251
|
if (reachingDef === null && !positionalParams.includes(varName)) {
|
|
11106
11252
|
const def = {
|
|
11107
11253
|
id: defIdCounter++,
|
|
@@ -11123,8 +11269,56 @@ function buildBashDFG(tree) {
|
|
|
11123
11269
|
}
|
|
11124
11270
|
});
|
|
11125
11271
|
const chains = computeChains(defs, uses);
|
|
11272
|
+
chains.push(...bashCallArgChains(tree, bashFnDefs, uses, positionalParams));
|
|
11126
11273
|
return { defs, uses, chains };
|
|
11127
11274
|
}
|
|
11275
|
+
function bashCallArgChains(tree, bashFnDefs, uses, positionalParams) {
|
|
11276
|
+
const chains = [];
|
|
11277
|
+
if (bashFnDefs.size === 0) return chains;
|
|
11278
|
+
const renumbers = /* @__PURE__ */ new Set();
|
|
11279
|
+
for (const fn of findNodes(tree.rootNode, "function_definition")) {
|
|
11280
|
+
const nameNode = fn.childForFieldName("name");
|
|
11281
|
+
if (!nameNode) continue;
|
|
11282
|
+
if (/\bshift\b|\bset\s+--/.test(getNodeText(fn))) renumbers.add(getNodeText(nameNode));
|
|
11283
|
+
}
|
|
11284
|
+
const usesByLine = /* @__PURE__ */ new Map();
|
|
11285
|
+
for (const u of uses) {
|
|
11286
|
+
const l = usesByLine.get(u.line) ?? [];
|
|
11287
|
+
l.push(u);
|
|
11288
|
+
usesByLine.set(u.line, l);
|
|
11289
|
+
}
|
|
11290
|
+
for (const cmd of findNodes(tree.rootNode, "command")) {
|
|
11291
|
+
const nameNode = cmd.childForFieldName("name");
|
|
11292
|
+
if (!nameNode) continue;
|
|
11293
|
+
const fnDefs = bashFnDefs.get(getNodeText(nameNode));
|
|
11294
|
+
if (!fnDefs) continue;
|
|
11295
|
+
const fnName = getNodeText(nameNode);
|
|
11296
|
+
let position = 0;
|
|
11297
|
+
for (let i2 = 0; i2 < cmd.childCount; i2++) {
|
|
11298
|
+
const arg = cmd.child(i2);
|
|
11299
|
+
if (!arg || arg.id === nameNode.id) continue;
|
|
11300
|
+
if (arg.type.includes("redirect") || arg.type === "heredoc_body" || arg.type === "file_descriptor") continue;
|
|
11301
|
+
const text = getNodeText(arg);
|
|
11302
|
+
if (!text.trim()) continue;
|
|
11303
|
+
position++;
|
|
11304
|
+
const names = /* @__PURE__ */ new Set();
|
|
11305
|
+
const re = /\$\{?([A-Za-z_][A-Za-z0-9_]*|[0-9@*])/g;
|
|
11306
|
+
let m;
|
|
11307
|
+
while ((m = re.exec(text)) !== null) names.add(m[1]);
|
|
11308
|
+
if (names.size === 0) continue;
|
|
11309
|
+
const spreads = /\$\{?[@*]/.test(text);
|
|
11310
|
+
const targets = spreads || renumbers.has(fnName) ? positionalParams.map((p) => fnDefs.get(p)).filter((d) => d !== void 0) : [fnDefs.get(String(position))].filter((d) => d !== void 0);
|
|
11311
|
+
const lineUses = usesByLine.get(arg.startPosition.row + 1) ?? [];
|
|
11312
|
+
for (const name2 of names) {
|
|
11313
|
+
for (const u of lineUses) {
|
|
11314
|
+
if (u.variable !== name2 || u.def_id === null) continue;
|
|
11315
|
+
for (const t of targets) chains.push({ from_def: u.def_id, to_def: t, via: name2 });
|
|
11316
|
+
}
|
|
11317
|
+
}
|
|
11318
|
+
}
|
|
11319
|
+
}
|
|
11320
|
+
return chains;
|
|
11321
|
+
}
|
|
11128
11322
|
function buildRustDFG(tree, cache) {
|
|
11129
11323
|
const defs = [];
|
|
11130
11324
|
const uses = [];
|
|
@@ -12360,6 +12554,195 @@ function parseDistributedSliceAttribute(attrItem) {
|
|
|
12360
12554
|
};
|
|
12361
12555
|
}
|
|
12362
12556
|
|
|
12557
|
+
// src/core/extractors/ts-declaration-detail.ts
|
|
12558
|
+
function named(node) {
|
|
12559
|
+
const out2 = [];
|
|
12560
|
+
for (let i2 = 0; i2 < node.namedChildCount; i2++) {
|
|
12561
|
+
const c = node.namedChild(i2);
|
|
12562
|
+
if (c && c.type !== "comment") out2.push(c);
|
|
12563
|
+
}
|
|
12564
|
+
return out2;
|
|
12565
|
+
}
|
|
12566
|
+
function tokens(node) {
|
|
12567
|
+
const out2 = [];
|
|
12568
|
+
for (let i2 = 0; i2 < node.childCount; i2++) {
|
|
12569
|
+
const c = node.child(i2);
|
|
12570
|
+
if (c && !c.isNamed) out2.push(c.text);
|
|
12571
|
+
}
|
|
12572
|
+
return out2;
|
|
12573
|
+
}
|
|
12574
|
+
function stringLiteral(node) {
|
|
12575
|
+
if (node.type !== "string") return void 0;
|
|
12576
|
+
return named(node).map((c) => c.text).join("");
|
|
12577
|
+
}
|
|
12578
|
+
function decoratorInfo(node) {
|
|
12579
|
+
const expr = named(node)[0];
|
|
12580
|
+
if (!expr) return null;
|
|
12581
|
+
let callee = expr;
|
|
12582
|
+
let args2 = [];
|
|
12583
|
+
if (expr.type === "call_expression") {
|
|
12584
|
+
callee = expr.childForFieldName("function");
|
|
12585
|
+
const a = expr.childForFieldName("arguments");
|
|
12586
|
+
args2 = a ? named(a) : [];
|
|
12587
|
+
}
|
|
12588
|
+
if (!callee) return null;
|
|
12589
|
+
const name2 = callee.type === "member_expression" ? callee.childForFieldName("property")?.text : callee.text;
|
|
12590
|
+
if (!name2) return null;
|
|
12591
|
+
return {
|
|
12592
|
+
name: name2,
|
|
12593
|
+
arguments: args2.map((a) => {
|
|
12594
|
+
const value = stringLiteral(a);
|
|
12595
|
+
return value === void 0 ? { text: a.text } : { text: a.text, value };
|
|
12596
|
+
})
|
|
12597
|
+
};
|
|
12598
|
+
}
|
|
12599
|
+
function decoratorsOf(nodes) {
|
|
12600
|
+
return nodes.filter((n) => n.type === "decorator").map(decoratorInfo).filter((d) => d !== null);
|
|
12601
|
+
}
|
|
12602
|
+
function exportModifiers(holder) {
|
|
12603
|
+
const stmt = holder.parent?.type === "export_statement" ? holder.parent : null;
|
|
12604
|
+
if (!stmt) return [];
|
|
12605
|
+
return tokens(stmt).includes("default") ? ["export", "default"] : ["export"];
|
|
12606
|
+
}
|
|
12607
|
+
var MEMBER_WORDS = ["readonly", "abstract", "override", "static", "declare"];
|
|
12608
|
+
function memberModifiers(member) {
|
|
12609
|
+
const out2 = [];
|
|
12610
|
+
for (let i2 = 0; i2 < member.childCount; i2++) {
|
|
12611
|
+
const c = member.child(i2);
|
|
12612
|
+
if (!c) continue;
|
|
12613
|
+
if (c.type === "accessibility_modifier") out2.push(c.text);
|
|
12614
|
+
else if (c.type === "override_modifier") out2.push("override");
|
|
12615
|
+
else if (!c.isNamed && MEMBER_WORDS.includes(c.text)) out2.push(c.text);
|
|
12616
|
+
}
|
|
12617
|
+
const name2 = member.childForFieldName("name") ?? member.childForFieldName("property");
|
|
12618
|
+
if (name2?.type === "private_property_identifier" && !out2.includes("private")) out2.push("private");
|
|
12619
|
+
return out2;
|
|
12620
|
+
}
|
|
12621
|
+
function annotationText(node) {
|
|
12622
|
+
return node ? node.text.replace(/^:\s*/, "") : null;
|
|
12623
|
+
}
|
|
12624
|
+
function addModifiers(target, extra) {
|
|
12625
|
+
for (const m of extra) if (!target.includes(m)) target.push(m);
|
|
12626
|
+
}
|
|
12627
|
+
function clauseExports(root) {
|
|
12628
|
+
const names = /* @__PURE__ */ new Set();
|
|
12629
|
+
let defaultName = null;
|
|
12630
|
+
for (const stmt of named(root)) {
|
|
12631
|
+
if (stmt.type !== "export_statement" || stmt.childForFieldName("source")) continue;
|
|
12632
|
+
const clause = named(stmt).find((c) => c.type === "export_clause");
|
|
12633
|
+
for (const s of clause ? named(clause) : []) {
|
|
12634
|
+
const name2 = s.childForFieldName("name")?.text;
|
|
12635
|
+
const alias = s.childForFieldName("alias")?.text;
|
|
12636
|
+
if (!name2) continue;
|
|
12637
|
+
if (alias === "default") defaultName = name2;
|
|
12638
|
+
else names.add(name2);
|
|
12639
|
+
}
|
|
12640
|
+
const value = stmt.childForFieldName("value");
|
|
12641
|
+
if (value?.type === "identifier") defaultName = value.text;
|
|
12642
|
+
}
|
|
12643
|
+
return { names, defaultName };
|
|
12644
|
+
}
|
|
12645
|
+
function enrichMethod(m, fn, decorators, extra) {
|
|
12646
|
+
addModifiers(m.modifiers, extra);
|
|
12647
|
+
const ret = fn.childForFieldName("return_type");
|
|
12648
|
+
if (ret && m.return_type === null) m.return_type = annotationText(ret);
|
|
12649
|
+
const decs = decoratorsOf(decorators);
|
|
12650
|
+
if (decs.length > 0) m.decorators = decs;
|
|
12651
|
+
const params = fn.childForFieldName("parameters");
|
|
12652
|
+
for (const p of params ? named(params) : []) {
|
|
12653
|
+
const pd = decoratorsOf(named(p));
|
|
12654
|
+
if (pd.length === 0) continue;
|
|
12655
|
+
const line = p.startPosition.row + 1;
|
|
12656
|
+
const info2 = m.parameters.find((x) => x.line === line && !x.decorators && p.text.includes(x.name.replace(/^\.\.\./, "")));
|
|
12657
|
+
if (info2) info2.decorators = pd;
|
|
12658
|
+
}
|
|
12659
|
+
}
|
|
12660
|
+
function enrichClassBody(type, body2) {
|
|
12661
|
+
let pending = [];
|
|
12662
|
+
for (const member of named(body2)) {
|
|
12663
|
+
if (member.type === "decorator") {
|
|
12664
|
+
pending.push(member);
|
|
12665
|
+
continue;
|
|
12666
|
+
}
|
|
12667
|
+
const line = member.startPosition.row + 1;
|
|
12668
|
+
const nameNode = member.childForFieldName("name") ?? member.childForFieldName("property");
|
|
12669
|
+
const name2 = nameNode?.text;
|
|
12670
|
+
if (member.type === "method_definition" && name2) {
|
|
12671
|
+
const m = type.methods.find((x) => x.name === name2 && x.start_line === line);
|
|
12672
|
+
if (m) enrichMethod(m, member, pending, memberModifiers(member));
|
|
12673
|
+
} else if ((member.type === "public_field_definition" || member.type === "field_definition") && name2) {
|
|
12674
|
+
const f = type.fields.find((x) => x.name === name2);
|
|
12675
|
+
if (f) {
|
|
12676
|
+
addModifiers(f.modifiers, memberModifiers(member));
|
|
12677
|
+
if (f.type === null) f.type = annotationText(member.childForFieldName("type"));
|
|
12678
|
+
const decs = decoratorsOf(pending);
|
|
12679
|
+
if (decs.length > 0) f.decorators = decs;
|
|
12680
|
+
}
|
|
12681
|
+
}
|
|
12682
|
+
pending = [];
|
|
12683
|
+
}
|
|
12684
|
+
}
|
|
12685
|
+
function enrichTsDeclarations(tree, types) {
|
|
12686
|
+
const root = tree.rootNode;
|
|
12687
|
+
const { names, defaultName } = clauseExports(root);
|
|
12688
|
+
const clauseMods = (name2) => name2 === defaultName ? ["export", "default"] : names.has(name2) ? ["export"] : [];
|
|
12689
|
+
const visit = (node) => {
|
|
12690
|
+
const t = node.type;
|
|
12691
|
+
if (t === "class_declaration" || t === "abstract_class_declaration" || t === "interface_declaration") {
|
|
12692
|
+
const line = node.startPosition.row + 1;
|
|
12693
|
+
const name2 = node.childForFieldName("name")?.text;
|
|
12694
|
+
const type = types.find((x) => x.name === name2 && x.start_line === line);
|
|
12695
|
+
if (type && name2) {
|
|
12696
|
+
const mods = [...exportModifiers(node), ...clauseMods(name2)];
|
|
12697
|
+
if (t === "abstract_class_declaration") mods.push("abstract");
|
|
12698
|
+
if (node.parent?.type === "ambient_declaration") mods.push("declare");
|
|
12699
|
+
type.modifiers = [...new Set(mods)];
|
|
12700
|
+
const decs = decoratorsOf([...node.parent?.type === "export_statement" ? named(node.parent) : [], ...named(node)]);
|
|
12701
|
+
if (decs.length > 0) type.decorators = decs;
|
|
12702
|
+
const body2 = node.childForFieldName("body");
|
|
12703
|
+
if (body2 && t !== "interface_declaration") enrichClassBody(type, body2);
|
|
12704
|
+
}
|
|
12705
|
+
} else if (t === "function_declaration" || t === "generator_function_declaration") {
|
|
12706
|
+
const module2 = types.find((x) => x.name === "<module>");
|
|
12707
|
+
const name2 = node.childForFieldName("name")?.text;
|
|
12708
|
+
const m = module2?.methods.find((x) => x.name === name2 && x.start_line === node.startPosition.row + 1);
|
|
12709
|
+
if (m && name2) enrichMethod(m, node, [], [...exportModifiers(node), ...clauseMods(name2)]);
|
|
12710
|
+
} else if (t === "variable_declarator") {
|
|
12711
|
+
const value = node.childForFieldName("value");
|
|
12712
|
+
const name2 = node.childForFieldName("name")?.text;
|
|
12713
|
+
const decl = node.parent;
|
|
12714
|
+
const module2 = types.find((x) => x.name === "<module>");
|
|
12715
|
+
const m = module2?.methods.find((x) => x.name === name2 && x.start_line === node.startPosition.row + 1);
|
|
12716
|
+
if (m && name2 && value?.type === "arrow_function" && decl) enrichMethod(m, value, [], [...exportModifiers(decl), ...clauseMods(name2)]);
|
|
12717
|
+
}
|
|
12718
|
+
for (const c of named(node)) visit(c);
|
|
12719
|
+
};
|
|
12720
|
+
visit(root);
|
|
12721
|
+
}
|
|
12722
|
+
function extractTsExports(types) {
|
|
12723
|
+
const esm = types.some((t) => t.modifiers?.includes("export") || t.methods.some((m) => m.modifiers.includes("export")));
|
|
12724
|
+
if (!esm) return null;
|
|
12725
|
+
const out2 = [];
|
|
12726
|
+
const visibility = (mods) => mods.includes("private") ? null : mods.includes("protected") ? "protected" : "public";
|
|
12727
|
+
for (const t of types) {
|
|
12728
|
+
if (t.name === "<module>") {
|
|
12729
|
+
for (const m of t.methods) if (m.modifiers.includes("export")) out2.push({ symbol: m.name, kind: "method", visibility: "public" });
|
|
12730
|
+
continue;
|
|
12731
|
+
}
|
|
12732
|
+
if (!t.modifiers?.includes("export")) continue;
|
|
12733
|
+
out2.push({ symbol: t.name, kind: t.kind === "enum" ? "class" : t.kind, visibility: "public" });
|
|
12734
|
+
for (const m of t.methods) {
|
|
12735
|
+
const v = visibility(m.modifiers);
|
|
12736
|
+
if (v) out2.push({ symbol: `${t.name}.${m.name}`, kind: "method", visibility: v });
|
|
12737
|
+
}
|
|
12738
|
+
for (const f of t.fields) {
|
|
12739
|
+
const v = visibility(f.modifiers);
|
|
12740
|
+
if (v) out2.push({ symbol: `${t.name}.${f.name}`, kind: "field", visibility: v });
|
|
12741
|
+
}
|
|
12742
|
+
}
|
|
12743
|
+
return out2;
|
|
12744
|
+
}
|
|
12745
|
+
|
|
12363
12746
|
// src/analysis/config-loader.ts
|
|
12364
12747
|
var DEFAULT_SOURCES = [
|
|
12365
12748
|
// HTTP Sources (Servlet API)
|
|
@@ -13061,6 +13444,10 @@ var DEFAULT_SOURCES = [
|
|
|
13061
13444
|
{ method: "get", class: "Redis", type: "db_input", severity: "medium", return_tainted: true, languages: ["javascript", "typescript"] },
|
|
13062
13445
|
{ method: "hget", class: "Redis", type: "db_input", severity: "medium", return_tainted: true, languages: ["javascript", "typescript"] },
|
|
13063
13446
|
{ method: "mget", class: "Redis", type: "db_input", severity: "medium", return_tainted: true, languages: ["javascript", "typescript"] },
|
|
13447
|
+
// Node redis clients are often bound to `cache` from `createClient()`; class
|
|
13448
|
+
// `cache` is scoped to JS/TS (Python Django cache above) and Map.get is
|
|
13449
|
+
// filtered in sink-filter-pass (#818 src14).
|
|
13450
|
+
{ method: "get", class: "cache", type: "db_input", severity: "medium", return_tainted: true, languages: ["javascript", "typescript"] },
|
|
13064
13451
|
{ method: "get", class: "Jedis", type: "db_input", severity: "medium", return_tainted: true, languages: ["java"] },
|
|
13065
13452
|
{ method: "hget", class: "Jedis", type: "db_input", severity: "medium", return_tainted: true, languages: ["java"] },
|
|
13066
13453
|
{ method: "mget", class: "Jedis", type: "db_input", severity: "medium", return_tainted: true, languages: ["java"] },
|
|
@@ -13240,7 +13627,9 @@ var TRUST_BOUNDARY_FRAMEWORK_SINKS = [
|
|
|
13240
13627
|
// on arg[1] (the *Cookie) catches struct-literal composite tainting.
|
|
13241
13628
|
{ method: "SetCookie", class: "http", type: "trust_boundary", cwe: "CWE-501", severity: "medium", arg_positions: [1], languages: ["go"] },
|
|
13242
13629
|
// gin: c.SetCookie(name, value, maxAge, path, domain, secure, httpOnly).
|
|
13243
|
-
{ method: "SetCookie", class: "Context", type: "trust_boundary", cwe: "CWE-501", severity: "medium", arg_positions: [1], languages: ["go"] }
|
|
13630
|
+
{ method: "SetCookie", class: "Context", type: "trust_boundary", cwe: "CWE-501", severity: "medium", arg_positions: [1], languages: ["go"] },
|
|
13631
|
+
// --- Rust: actix-session / tower-sessions write -------------------------
|
|
13632
|
+
{ method: "insert", class: "Session", type: "trust_boundary", cwe: "CWE-501", severity: "medium", arg_positions: [1], languages: ["rust"] }
|
|
13244
13633
|
];
|
|
13245
13634
|
var DEFAULT_SINKS = [
|
|
13246
13635
|
// SQL Injection (CWE-89)
|
|
@@ -13670,7 +14059,7 @@ var DEFAULT_SINKS = [
|
|
|
13670
14059
|
{ method: "renderHTML", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
13671
14060
|
{ method: "parseHTML", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
13672
14061
|
// HTML sanitizer/validator sinks (AntiSamy, OWASP HTML Sanitizer, etc.)
|
|
13673
|
-
{ method: "scan", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14062
|
+
{ method: "scan", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
|
|
13674
14063
|
{ method: "isValid", class: "SafeHtmlValidator", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
13675
14064
|
{ method: "sanitize", class: "PolicyFactory", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
13676
14065
|
{ method: "validate", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0] },
|
|
@@ -13686,8 +14075,8 @@ var DEFAULT_SINKS = [
|
|
|
13686
14075
|
{ method: "writeAttribute", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0, 1] },
|
|
13687
14076
|
// AntiSamy specific (SAX filters)
|
|
13688
14077
|
{ method: "startElement", class: "MagicSAXFilter", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0, 1, 2] },
|
|
13689
|
-
{ method: "scan", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
13690
|
-
{ method: "scan", class: "AntiSamySAXScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14078
|
+
{ method: "scan", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
|
|
14079
|
+
{ method: "scan", class: "AntiSamySAXScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
|
|
13691
14080
|
// Hibernate Validator
|
|
13692
14081
|
{ method: "getFragmentAsDocument", class: "SafeHtmlValidator", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
13693
14082
|
// JSPWiki specific
|
|
@@ -13737,15 +14126,15 @@ var DEFAULT_SINKS = [
|
|
|
13737
14126
|
{ method: "getValidListItem", class: "DefaultValidator", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0, 1] },
|
|
13738
14127
|
{ method: "isValidURI", class: "DefaultValidator", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0, 1] },
|
|
13739
14128
|
// AntiSamy test/processing methods
|
|
13740
|
-
{ method: "scriptAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
13741
|
-
{ method: "imgAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
13742
|
-
{ method: "hrefAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
13743
|
-
{ method: "cssAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
13744
|
-
{ method: "IllegalXML", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
13745
|
-
{ method: "testIssue2", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
13746
|
-
{ method: "issue41", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
13747
|
-
{ method: "testGithubIssue151", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
13748
|
-
{ method: "processStyleTag", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14129
|
+
{ method: "scriptAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14130
|
+
{ method: "imgAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14131
|
+
{ method: "hrefAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14132
|
+
{ method: "cssAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14133
|
+
{ method: "IllegalXML", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14134
|
+
{ method: "testIssue2", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14135
|
+
{ method: "issue41", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14136
|
+
{ method: "testGithubIssue151", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
|
|
14137
|
+
{ method: "processStyleTag", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
|
|
13749
14138
|
// JSON Sanitizer
|
|
13750
14139
|
{ method: "sanitizeString", class: "JsonSanitizer", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
13751
14140
|
{ method: "testIssue13", class: "JsonSanitizerTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
|
|
@@ -13901,7 +14290,9 @@ var DEFAULT_SINKS = [
|
|
|
13901
14290
|
{ method: "addParametersToContext", class: "StaticParametersInterceptor", type: "code_injection", cwe: "CWE-94", severity: "critical", arg_positions: [0] },
|
|
13902
14291
|
{ method: "build", class: "HttpParameters", type: "code_injection", cwe: "CWE-94", severity: "critical", arg_positions: [0] },
|
|
13903
14292
|
// Cron expression parsing (DoS/ReDoS)
|
|
13904
|
-
|
|
14293
|
+
// cognium-dev#998 — Java cron-utils `CronParser`; scoped to Java so a JS/TS
|
|
14294
|
+
// `parser.parse(...)` (tree-sitter, a lockfile parser) never matches it by name.
|
|
14295
|
+
{ method: "parse", class: "CronParser", type: "code_injection", cwe: "CWE-94", severity: "high", arg_positions: [0], languages: ["java"] },
|
|
13905
14296
|
{ method: "isValid", class: "CronValidator", type: "code_injection", cwe: "CWE-94", severity: "high", arg_positions: [0] },
|
|
13906
14297
|
// ff4j feature flags
|
|
13907
14298
|
{ method: "check", class: "FF4j", type: "code_injection", cwe: "CWE-94", severity: "high", arg_positions: [0] },
|
|
@@ -13998,9 +14389,13 @@ var DEFAULT_SINKS = [
|
|
|
13998
14389
|
{ method: "selectNodes", class: "Node", type: "xpath_injection", cwe: "CWE-643", severity: "high", arg_positions: [0] },
|
|
13999
14390
|
{ method: "selectSingleNode", class: "Node", type: "xpath_injection", cwe: "CWE-643", severity: "high", arg_positions: [0] },
|
|
14000
14391
|
// XXE - XML External Entity (CWE-611)
|
|
14001
|
-
|
|
14002
|
-
|
|
14003
|
-
|
|
14392
|
+
// cognium-dev#998 — JAXP parsers are JVM classes. Scoped to Java so the
|
|
14393
|
+
// receiver-name heuristic (`parser` → SAXParser) cannot turn a JS/TS
|
|
14394
|
+
// `parser.parse(text)` into an XXE sink. JS/TS XML parsers (sax, xml2js,
|
|
14395
|
+
// libxmljs, DOMParser) have their own entries.
|
|
14396
|
+
{ method: "parse", class: "DocumentBuilder", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0], languages: ["java"] },
|
|
14397
|
+
{ method: "parse", class: "SAXParser", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0], languages: ["java"] },
|
|
14398
|
+
{ method: "parse", class: "XMLReader", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0], languages: ["java"] },
|
|
14004
14399
|
{ method: "unmarshal", class: "Unmarshaller", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0] },
|
|
14005
14400
|
{ method: "newTransformer", class: "TransformerFactory", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0] },
|
|
14006
14401
|
{ method: "transform", class: "Transformer", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0] },
|
|
@@ -14255,6 +14650,46 @@ var DEFAULT_SINKS = [
|
|
|
14255
14650
|
{ method: "each", class: "Connection", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], allow_unresolved_receiver: true },
|
|
14256
14651
|
{ method: "get", class: "Connection", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], allow_unresolved_receiver: true },
|
|
14257
14652
|
{ method: "exec", class: "Connection", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], allow_unresolved_receiver: true },
|
|
14653
|
+
// DuckDB from JS/TS: `@duckdb/node-api` (DuckDBConnection), the classic
|
|
14654
|
+
// `duckdb` / `duckdb-async` bindings (Database / Connection) and
|
|
14655
|
+
// `react-native-duckdb` (Database / Transaction). The method names are
|
|
14656
|
+
// generic and the receivers come from factories (`await instance.connect()`,
|
|
14657
|
+
// `open({...})`), so the receiver cannot be typed: the import is the gate
|
|
14658
|
+
// (`requires_import`). Only the SQL text (arg 0) is a sink — values passed
|
|
14659
|
+
// as bound parameters (`run(sql, [v])`, `execute(sql, params)`,
|
|
14660
|
+
// `executeNamed(sql, {k: v})`, `stmt.bind(...)`) are parameterised and do
|
|
14661
|
+
// not reach it.
|
|
14662
|
+
{ method: "run", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["@duckdb/node-api", "duckdb", "duckdb-async"] },
|
|
14663
|
+
{ 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"] },
|
|
14664
|
+
{ 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"] },
|
|
14665
|
+
{ method: "runAndRead", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["@duckdb/node-api"] },
|
|
14666
|
+
{ method: "runAndReadAll", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["@duckdb/node-api"] },
|
|
14667
|
+
{ method: "runAndReadUntil", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["@duckdb/node-api"] },
|
|
14668
|
+
{ method: "streamAndRead", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["@duckdb/node-api"] },
|
|
14669
|
+
{ method: "streamAndReadAll", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["@duckdb/node-api"] },
|
|
14670
|
+
{ method: "streamAndReadUntil", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["@duckdb/node-api"] },
|
|
14671
|
+
{ method: "start", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["@duckdb/node-api"] },
|
|
14672
|
+
{ method: "startStream", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["@duckdb/node-api"] },
|
|
14673
|
+
{ method: "extractStatements", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["@duckdb/node-api"] },
|
|
14674
|
+
{ method: "all", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["duckdb", "duckdb-async"] },
|
|
14675
|
+
{ method: "each", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["duckdb", "duckdb-async"] },
|
|
14676
|
+
{ method: "exec", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["duckdb", "duckdb-async"] },
|
|
14677
|
+
{ method: "arrowIPCAll", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["duckdb", "duckdb-async"] },
|
|
14678
|
+
{ method: "arrowIPCStream", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["duckdb", "duckdb-async"] },
|
|
14679
|
+
{ method: "execute", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["react-native-duckdb"] },
|
|
14680
|
+
{ method: "executeSync", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["react-native-duckdb"] },
|
|
14681
|
+
{ method: "executeNamed", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["react-native-duckdb"] },
|
|
14682
|
+
{ method: "executeSyncNamed", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["react-native-duckdb"] },
|
|
14683
|
+
{ method: "streamNamed", type: "sql_injection", cwe: "CWE-89", severity: "critical", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["react-native-duckdb"] },
|
|
14684
|
+
// RxDB (Mango queries, any storage incl. SQLite): a selector or query
|
|
14685
|
+
// object, a field name passed to the query builder, or a `$regex` pattern
|
|
14686
|
+
// under caller control is NoSQL operator injection (CWE-943). Gated on the
|
|
14687
|
+
// `rxdb` import for the same reason as DuckDB above. `find` is already a
|
|
14688
|
+
// classless JS NoSQL sink in the JavaScript plugin.
|
|
14689
|
+
{ method: "findOne", type: "nosql_injection", cwe: "CWE-943", severity: "high", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["rxdb"] },
|
|
14690
|
+
{ method: "count", type: "nosql_injection", cwe: "CWE-943", severity: "high", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["rxdb"] },
|
|
14691
|
+
{ method: "where", type: "nosql_injection", cwe: "CWE-943", severity: "high", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["rxdb"] },
|
|
14692
|
+
{ method: "regex", type: "nosql_injection", cwe: "CWE-943", severity: "high", arg_positions: [0], languages: ["javascript", "typescript"], requires_import: ["rxdb"] },
|
|
14258
14693
|
// TypeORM QueryBuilder raw fragments (CWE-89). TypeORM's raw `.query(sql)`
|
|
14259
14694
|
// escape hatch is already covered by the classless `query` sink in the JS
|
|
14260
14695
|
// plugin (getBuiltinSinks), so it is NOT re-registered here — the dedup
|
|
@@ -14365,6 +14800,8 @@ var DEFAULT_SINKS = [
|
|
|
14365
14800
|
{ method: "get", class: "http", type: "ssrf", cwe: "CWE-918", severity: "high", arg_positions: [0] },
|
|
14366
14801
|
{ method: "request", class: "https", type: "ssrf", cwe: "CWE-918", severity: "high", arg_positions: [0] },
|
|
14367
14802
|
{ method: "get", class: "https", type: "ssrf", cwe: "CWE-918", severity: "high", arg_positions: [0] },
|
|
14803
|
+
// Node.js dns.promises (CWE-918 / NUL-in-name SSRF class — #895)
|
|
14804
|
+
{ method: "resolve", class: "dns.promises", type: "ssrf", cwe: "CWE-918", severity: "high", arg_positions: [0], languages: ["javascript", "typescript"] },
|
|
14368
14805
|
// needle library (used in NodeGoat)
|
|
14369
14806
|
{ method: "get", class: "needle", type: "ssrf", cwe: "CWE-918", severity: "high", arg_positions: [0] },
|
|
14370
14807
|
{ method: "post", class: "needle", type: "ssrf", cwe: "CWE-918", severity: "high", arg_positions: [0] },
|
|
@@ -14523,16 +14960,16 @@ var DEFAULT_SINKS = [
|
|
|
14523
14960
|
{ method: "parse", class: "sax", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0] },
|
|
14524
14961
|
{ method: "XMLParser", class: "lxml", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0] },
|
|
14525
14962
|
// Python LDAP Injection
|
|
14526
|
-
{ method: "search", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
|
|
14527
|
-
{ method: "search_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
|
|
14528
|
-
{ method: "search_ext", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
|
|
14529
|
-
{ method: "search_ext_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
|
|
14963
|
+
{ method: "search", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
|
|
14964
|
+
{ method: "search_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
|
|
14965
|
+
{ method: "search_ext", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
|
|
14966
|
+
{ method: "search_ext_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
|
|
14530
14967
|
// ldap3 library (different API from python-ldap)
|
|
14531
|
-
{ method: "search", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 1] },
|
|
14532
|
-
{ method: "extend", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
|
|
14533
|
-
{ method: "modify", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
|
|
14534
|
-
{ method: "add", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
|
|
14535
|
-
{ method: "delete", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
|
|
14968
|
+
{ method: "search", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 1], languages: ["python"] },
|
|
14969
|
+
{ method: "extend", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
|
|
14970
|
+
{ method: "modify", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
|
|
14971
|
+
{ method: "add", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
|
|
14972
|
+
{ method: "delete", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
|
|
14536
14973
|
// Python Trust Boundary (CWE-501)
|
|
14537
14974
|
// The vulnerability is storing untrusted data in session that gets trusted later
|
|
14538
14975
|
{ method: "__setitem__", class: "session", type: "trust_boundary", cwe: "CWE-501", severity: "medium", arg_positions: [1] },
|
|
@@ -14623,7 +15060,7 @@ var DEFAULT_SINKS = [
|
|
|
14623
15060
|
{ method: "put", class: "VelocityContext", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [1] },
|
|
14624
15061
|
{ method: "setVariable", class: "Context", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [1] },
|
|
14625
15062
|
// HTML sanitizer bypass markers (known CVE patterns)
|
|
14626
|
-
{ method: "clean", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0] },
|
|
15063
|
+
{ method: "clean", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0], languages: ["java"] },
|
|
14627
15064
|
{ method: "getValidSafeHTML", class: "ESAPI", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0] },
|
|
14628
15065
|
// NOTE (cognium-dev#270): `HttpServletRequest`/`HttpSession.getAttribute()`
|
|
14629
15066
|
// were registered here as xss sinks to model "attribute reflection XSS", but
|
|
@@ -14859,7 +15296,7 @@ var DEFAULT_SINKS = [
|
|
|
14859
15296
|
// receiver-taint or operator-LHS-taint tracking — the format string is the
|
|
14860
15297
|
// receiver, not an argument. Deferred to Sprint 6 (#86 follow-up).
|
|
14861
15298
|
// C-style: printf / fprintf / sprintf / snprintf via ctypes/cffi.
|
|
14862
|
-
{ method: "printf", type: "format_string", cwe: "CWE-134", severity: "high", arg_positions: [0], languages: ["python"] },
|
|
15299
|
+
{ method: "printf", type: "format_string", cwe: "CWE-134", severity: "high", arg_positions: [0], languages: ["python", "rust"] },
|
|
14863
15300
|
{ method: "fprintf", type: "format_string", cwe: "CWE-134", severity: "high", arg_positions: [1], languages: ["python"] },
|
|
14864
15301
|
// Go: fmt.Sprintf/Printf/Fprintf/Errorf — format string is first/second arg
|
|
14865
15302
|
{ method: "Sprintf", class: "fmt", type: "format_string", cwe: "CWE-134", severity: "medium", arg_positions: [0], languages: ["go"] },
|
|
@@ -16015,6 +16452,46 @@ var DEFAULT_HEADER_RULES = [
|
|
|
16015
16452
|
}
|
|
16016
16453
|
];
|
|
16017
16454
|
|
|
16455
|
+
// src/analysis/js-helper-return.ts
|
|
16456
|
+
function jsHelperReturnsNoParam(sourceCode, rawName) {
|
|
16457
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(rawName)) return false;
|
|
16458
|
+
const name2 = rawName.replace(/\$/g, "\\$");
|
|
16459
|
+
const decls = [...sourceCode.matchAll(new RegExp(`\\bfunction\\s+${name2}\\s*\\(([^)]*)\\)\\s*\\{`, "g"))];
|
|
16460
|
+
if (decls.length !== 1) return false;
|
|
16461
|
+
if (new RegExp(`(?:const|let|var)\\s+${name2}\\s*=`).test(sourceCode)) return false;
|
|
16462
|
+
const open = (decls[0].index ?? 0) + decls[0][0].length - 1;
|
|
16463
|
+
let depth = 0;
|
|
16464
|
+
let close = -1;
|
|
16465
|
+
for (let i2 = open; i2 < sourceCode.length; i2++) {
|
|
16466
|
+
const ch = sourceCode[i2];
|
|
16467
|
+
if (ch === "{") depth++;
|
|
16468
|
+
else if (ch === "}" && --depth === 0) {
|
|
16469
|
+
close = i2;
|
|
16470
|
+
break;
|
|
16471
|
+
}
|
|
16472
|
+
}
|
|
16473
|
+
if (close < 0) return false;
|
|
16474
|
+
const body2 = sourceCode.slice(open + 1, close).replace(/\/\/.*$/gm, "");
|
|
16475
|
+
if (/\bfunction\b|=>/.test(body2)) return false;
|
|
16476
|
+
const literal = /^(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`[^`$]*`|-?\d+(?:\.\d+)?|true|false|null)$/;
|
|
16477
|
+
const returns = [...body2.matchAll(/\breturn\b\s*([^;]*);?/g)].map((m) => m[1].trim());
|
|
16478
|
+
if (returns.length === 0) return false;
|
|
16479
|
+
for (const expr of returns) {
|
|
16480
|
+
if (literal.test(expr)) continue;
|
|
16481
|
+
const slot = /^([A-Za-z_$][\w$]*)\s*\[\s*(\d+)\s*\]$/.exec(expr);
|
|
16482
|
+
if (!slot) return false;
|
|
16483
|
+
const arr = slot[1].replace(/\$/g, "\\$");
|
|
16484
|
+
const declRe = new RegExp(`(?:const|let|var)\\s+${arr}\\s*=\\s*\\[([^\\]]*)\\]\\s*;?`);
|
|
16485
|
+
const d = declRe.exec(body2);
|
|
16486
|
+
if (!d) return false;
|
|
16487
|
+
if (new RegExp(`\\b${arr}\\s*(?:\\[[^\\]]*\\]\\s*=(?!=)|\\.\\s*(?:push|unshift|splice|shift|pop|reverse|sort|fill|copyWithin)\\s*\\()`).test(body2)) return false;
|
|
16488
|
+
const elems = d[1].split(",").map((e) => e.trim());
|
|
16489
|
+
const el = elems[Number(slot[2])];
|
|
16490
|
+
if (el === void 0 || !literal.test(el)) return false;
|
|
16491
|
+
}
|
|
16492
|
+
return true;
|
|
16493
|
+
}
|
|
16494
|
+
|
|
16018
16495
|
// src/analysis/literal-expression.ts
|
|
16019
16496
|
function isProvablyLiteralExpression(expr) {
|
|
16020
16497
|
let e = (expr ?? "").trim();
|
|
@@ -17117,6 +17594,198 @@ function constTableLookupDefIds(defs, code, language) {
|
|
|
17117
17594
|
return out2;
|
|
17118
17595
|
}
|
|
17119
17596
|
|
|
17597
|
+
// src/analysis/js-crlf-strip.ts
|
|
17598
|
+
var MAX_PATTERN_LENGTH = 200;
|
|
17599
|
+
var NEUTRAL_AFTER_REPLACE = /* @__PURE__ */ new Set([
|
|
17600
|
+
"replace",
|
|
17601
|
+
"replaceAll",
|
|
17602
|
+
"trim",
|
|
17603
|
+
"trimStart",
|
|
17604
|
+
"trimEnd",
|
|
17605
|
+
"toString",
|
|
17606
|
+
"toLowerCase",
|
|
17607
|
+
"toUpperCase",
|
|
17608
|
+
"slice",
|
|
17609
|
+
"substring"
|
|
17610
|
+
]);
|
|
17611
|
+
var PROBE = "a\r\rb\n\nc\r\nd\n\re x ";
|
|
17612
|
+
function readQuoted(s, i2) {
|
|
17613
|
+
const q = s[i2];
|
|
17614
|
+
if (q !== '"' && q !== "'" && q !== "`") return null;
|
|
17615
|
+
let out2 = "";
|
|
17616
|
+
for (let j = i2 + 1; j < s.length; j++) {
|
|
17617
|
+
const c = s[j];
|
|
17618
|
+
if (c === q) return { value: out2, end: j + 1 };
|
|
17619
|
+
if (q === "`" && c === "$" && s[j + 1] === "{") return null;
|
|
17620
|
+
if (c === "\\") {
|
|
17621
|
+
const n = s[j + 1];
|
|
17622
|
+
if (n === void 0) return null;
|
|
17623
|
+
switch (n) {
|
|
17624
|
+
case "n":
|
|
17625
|
+
out2 += "\n";
|
|
17626
|
+
j++;
|
|
17627
|
+
continue;
|
|
17628
|
+
case "r":
|
|
17629
|
+
out2 += "\r";
|
|
17630
|
+
j++;
|
|
17631
|
+
continue;
|
|
17632
|
+
case "t":
|
|
17633
|
+
out2 += " ";
|
|
17634
|
+
j++;
|
|
17635
|
+
continue;
|
|
17636
|
+
case "0":
|
|
17637
|
+
out2 += "\0";
|
|
17638
|
+
j++;
|
|
17639
|
+
continue;
|
|
17640
|
+
case "x": {
|
|
17641
|
+
const h = /^[0-9a-fA-F]{2}/.exec(s.slice(j + 2, j + 4));
|
|
17642
|
+
if (!h) return null;
|
|
17643
|
+
out2 += String.fromCharCode(parseInt(h[0], 16));
|
|
17644
|
+
j += 3;
|
|
17645
|
+
continue;
|
|
17646
|
+
}
|
|
17647
|
+
case "u": {
|
|
17648
|
+
const h = /^[0-9a-fA-F]{4}/.exec(s.slice(j + 2, j + 6));
|
|
17649
|
+
if (!h) return null;
|
|
17650
|
+
out2 += String.fromCharCode(parseInt(h[0], 16));
|
|
17651
|
+
j += 5;
|
|
17652
|
+
continue;
|
|
17653
|
+
}
|
|
17654
|
+
default:
|
|
17655
|
+
out2 += n;
|
|
17656
|
+
j++;
|
|
17657
|
+
continue;
|
|
17658
|
+
}
|
|
17659
|
+
}
|
|
17660
|
+
if (c === "\n" && q !== "`") return null;
|
|
17661
|
+
out2 += c;
|
|
17662
|
+
}
|
|
17663
|
+
return null;
|
|
17664
|
+
}
|
|
17665
|
+
function readRegexLiteral(s, i2) {
|
|
17666
|
+
if (s[i2] !== "/") return null;
|
|
17667
|
+
let inClass = false;
|
|
17668
|
+
for (let j = i2 + 1; j < s.length; j++) {
|
|
17669
|
+
const c = s[j];
|
|
17670
|
+
if (c === "\n") return null;
|
|
17671
|
+
if (c === "\\") {
|
|
17672
|
+
j++;
|
|
17673
|
+
continue;
|
|
17674
|
+
}
|
|
17675
|
+
if (inClass) {
|
|
17676
|
+
if (c === "]") inClass = false;
|
|
17677
|
+
continue;
|
|
17678
|
+
}
|
|
17679
|
+
if (c === "[") {
|
|
17680
|
+
inClass = true;
|
|
17681
|
+
continue;
|
|
17682
|
+
}
|
|
17683
|
+
if (c === "/") {
|
|
17684
|
+
const flags2 = /^[dgimsuvy]*/.exec(s.slice(j + 1))[0];
|
|
17685
|
+
return { source: s.slice(i2 + 1, j), flags: flags2, end: j + 1 + flags2.length };
|
|
17686
|
+
}
|
|
17687
|
+
}
|
|
17688
|
+
return null;
|
|
17689
|
+
}
|
|
17690
|
+
var skipWs = (s, i2) => {
|
|
17691
|
+
while (i2 < s.length && /\s/.test(s[i2])) i2++;
|
|
17692
|
+
return i2;
|
|
17693
|
+
};
|
|
17694
|
+
function parseSteps(chainText) {
|
|
17695
|
+
const steps = [];
|
|
17696
|
+
const callRe = /\.\s*(replaceAll|replace)\s*\(/g;
|
|
17697
|
+
let m;
|
|
17698
|
+
while ((m = callRe.exec(chainText)) !== null) {
|
|
17699
|
+
const kind = m[1];
|
|
17700
|
+
let i2 = skipWs(chainText, m.index + m[0].length);
|
|
17701
|
+
let pattern;
|
|
17702
|
+
const rx = readRegexLiteral(chainText, i2);
|
|
17703
|
+
if (rx) {
|
|
17704
|
+
if (rx.source.length > MAX_PATTERN_LENGTH) return null;
|
|
17705
|
+
try {
|
|
17706
|
+
pattern = new RegExp(rx.source, rx.flags);
|
|
17707
|
+
} catch {
|
|
17708
|
+
return null;
|
|
17709
|
+
}
|
|
17710
|
+
i2 = rx.end;
|
|
17711
|
+
} else {
|
|
17712
|
+
const str = readQuoted(chainText, i2);
|
|
17713
|
+
if (!str) return null;
|
|
17714
|
+
pattern = str.value;
|
|
17715
|
+
i2 = str.end;
|
|
17716
|
+
}
|
|
17717
|
+
i2 = skipWs(chainText, i2);
|
|
17718
|
+
if (chainText[i2] !== ",") return null;
|
|
17719
|
+
i2 = skipWs(chainText, i2 + 1);
|
|
17720
|
+
const rep = readQuoted(chainText, i2);
|
|
17721
|
+
if (!rep) return null;
|
|
17722
|
+
i2 = skipWs(chainText, rep.end);
|
|
17723
|
+
if (chainText[i2] !== ")") return null;
|
|
17724
|
+
steps.push({ kind, pattern, replacement: rep.value });
|
|
17725
|
+
callRe.lastIndex = i2 + 1;
|
|
17726
|
+
}
|
|
17727
|
+
return steps;
|
|
17728
|
+
}
|
|
17729
|
+
function run2(steps, input) {
|
|
17730
|
+
let s = input;
|
|
17731
|
+
try {
|
|
17732
|
+
for (const st of steps) {
|
|
17733
|
+
if (st.kind === "replaceAll" && st.pattern instanceof RegExp && !st.pattern.global) return null;
|
|
17734
|
+
s = st.kind === "replaceAll" ? s.replaceAll(st.pattern, st.replacement) : s.replace(st.pattern, st.replacement);
|
|
17735
|
+
}
|
|
17736
|
+
} catch {
|
|
17737
|
+
return null;
|
|
17738
|
+
}
|
|
17739
|
+
return s;
|
|
17740
|
+
}
|
|
17741
|
+
function jsReplaceChainVerdict(chainText) {
|
|
17742
|
+
const steps = parseSteps(chainText);
|
|
17743
|
+
if (!steps || steps.length === 0) return "undecided";
|
|
17744
|
+
const first = chainText.search(/\.\s*(?:replaceAll|replace)\s*\(/);
|
|
17745
|
+
for (const seg of chainText.slice(first + 1).matchAll(/\.\s*([A-Za-z_$][\w$]*)\s*\(/g)) {
|
|
17746
|
+
if (!NEUTRAL_AFTER_REPLACE.has(seg[1])) return "undecided";
|
|
17747
|
+
}
|
|
17748
|
+
const out2 = run2(steps, PROBE);
|
|
17749
|
+
if (out2 === null) return "undecided";
|
|
17750
|
+
return out2.includes("\r") || out2.includes("\n") ? "leaves-crlf" : "strips-crlf";
|
|
17751
|
+
}
|
|
17752
|
+
function jsChainTextAt(sourceLines, line, column) {
|
|
17753
|
+
const text = [(sourceLines[line - 1] ?? "").slice(column), ...sourceLines.slice(line, line + 7)].join("\n");
|
|
17754
|
+
let depth = 0;
|
|
17755
|
+
let prevSig = "";
|
|
17756
|
+
let i2 = 0;
|
|
17757
|
+
for (; i2 < text.length; i2++) {
|
|
17758
|
+
const c = text[i2];
|
|
17759
|
+
if (c === '"' || c === "'" || c === "`") {
|
|
17760
|
+
for (i2++; i2 < text.length && text[i2] !== c; i2++) if (text[i2] === "\\") i2++;
|
|
17761
|
+
prevSig = c;
|
|
17762
|
+
continue;
|
|
17763
|
+
}
|
|
17764
|
+
if (c === "/" && depth > 0 && (prevSig === "(" || prevSig === ",")) {
|
|
17765
|
+
const rx = readRegexLiteral(text, i2);
|
|
17766
|
+
if (rx) {
|
|
17767
|
+
i2 = rx.end - 1;
|
|
17768
|
+
prevSig = "/";
|
|
17769
|
+
continue;
|
|
17770
|
+
}
|
|
17771
|
+
}
|
|
17772
|
+
if (c === "(" || c === "[" || c === "{") {
|
|
17773
|
+
depth++;
|
|
17774
|
+
prevSig = c;
|
|
17775
|
+
continue;
|
|
17776
|
+
}
|
|
17777
|
+
if (c === ")" || c === "]" || c === "}") {
|
|
17778
|
+
if (depth === 0) break;
|
|
17779
|
+
depth--;
|
|
17780
|
+
prevSig = c;
|
|
17781
|
+
continue;
|
|
17782
|
+
}
|
|
17783
|
+
if (depth === 0 && !/[\w$.\s]/.test(c)) break;
|
|
17784
|
+
if (!/\s/.test(c)) prevSig = c;
|
|
17785
|
+
}
|
|
17786
|
+
return text.slice(0, i2);
|
|
17787
|
+
}
|
|
17788
|
+
|
|
17120
17789
|
// src/analysis/passes/language-sources-pass.ts
|
|
17121
17790
|
var JS_DOM_XSS_SINKS = [
|
|
17122
17791
|
{ pattern: /\.innerHTML\s*=/, type: "xss", cwe: "CWE-79", severity: "critical" },
|
|
@@ -17368,6 +18037,7 @@ var LanguageSourcesPass = class {
|
|
|
17368
18037
|
}
|
|
17369
18038
|
additionalSanitizers.push(...findBashRegexAllowlistSanitizers(code));
|
|
17370
18039
|
additionalSanitizers.push(...findBashRealpathPrefixGuardSanitizers(code));
|
|
18040
|
+
additionalSanitizers.push(...findBashVerifiedPackageDownloadSanitizers(code));
|
|
17371
18041
|
additionalSanitizers.push(...findBashShellQuoteSanitizers(code));
|
|
17372
18042
|
}
|
|
17373
18043
|
if (language === "go") {
|
|
@@ -17483,8 +18153,13 @@ var LanguageSourcesPass = class {
|
|
|
17483
18153
|
}
|
|
17484
18154
|
}
|
|
17485
18155
|
if (language === "rust") {
|
|
18156
|
+
additionalSanitizers.push(...findRustConstSliceMembershipGuardSanitizers(code));
|
|
17486
18157
|
additionalSanitizers.push(...findRustSetAllowlistGuardSanitizers(code));
|
|
17487
18158
|
additionalSanitizers.push(...findRustCanonicalizeGuardSanitizers(code));
|
|
18159
|
+
additionalSanitizers.push(
|
|
18160
|
+
...findRustNumericRangeCheckGuardSanitizers(code)
|
|
18161
|
+
);
|
|
18162
|
+
additionalSanitizers.push(...findRustPatInfoHttpOnlyResponseSanitizers(code));
|
|
17488
18163
|
additionalSanitizers.push(...findRustLiteralEqualityGuardSanitizers(code));
|
|
17489
18164
|
additionalSanitizers.push(...findRustArgvCommandSanitizers(code));
|
|
17490
18165
|
const rustMisconfigFindings = findRustPatternFindings(code, graph.ir.meta.file);
|
|
@@ -17542,6 +18217,9 @@ var LanguageSourcesPass = class {
|
|
|
17542
18217
|
additionalSanitizers.push(
|
|
17543
18218
|
...findJsCommandAllowlistGuardSanitizers(code)
|
|
17544
18219
|
);
|
|
18220
|
+
additionalSanitizers.push(
|
|
18221
|
+
...findJsNumericRangeCheckGuardSanitizers(code)
|
|
18222
|
+
);
|
|
17545
18223
|
for (const finding of findJsPatternFindings(code, graph.ir.meta.file)) {
|
|
17546
18224
|
ctx.addFinding(finding);
|
|
17547
18225
|
}
|
|
@@ -17575,6 +18253,12 @@ var LanguageSourcesPass = class {
|
|
|
17575
18253
|
)) {
|
|
17576
18254
|
ctx.addFinding(finding);
|
|
17577
18255
|
}
|
|
18256
|
+
for (const finding of findJsZipHeaderFailopenFindings(
|
|
18257
|
+
code,
|
|
18258
|
+
graph.ir.meta.file
|
|
18259
|
+
)) {
|
|
18260
|
+
ctx.addFinding(finding);
|
|
18261
|
+
}
|
|
17578
18262
|
for (const finding of findJsJsonParseBodyFindings(
|
|
17579
18263
|
code,
|
|
17580
18264
|
graph.ir.meta.file
|
|
@@ -17624,6 +18308,7 @@ var LanguageSourcesPass = class {
|
|
|
17624
18308
|
}
|
|
17625
18309
|
additionalSanitizers.push(...findJavaInlineCrlfStripLogSanitizers(code));
|
|
17626
18310
|
additionalSanitizers.push(...findCrlfWrapperFunctionSanitizers(code, "java"));
|
|
18311
|
+
additionalSanitizers.push(...findJavaTemplateDelimiterWrapperSanitizers(code));
|
|
17627
18312
|
additionalSanitizers.push(...findJavaArgvFormExecSanitizers(code));
|
|
17628
18313
|
for (const finding of findJavaPatternFindings(code, graph.ir.meta.file)) {
|
|
17629
18314
|
ctx.addFinding(finding);
|
|
@@ -18600,12 +19285,37 @@ function classifyCSharpLambdaParam(raw) {
|
|
|
18600
19285
|
if (baseType === "string") return { type: "http_param", name: name2, via: "string param" };
|
|
18601
19286
|
return null;
|
|
18602
19287
|
}
|
|
19288
|
+
var REQUEST_FIELD_TYPES = {
|
|
19289
|
+
query: "http_param",
|
|
19290
|
+
params: "http_param",
|
|
19291
|
+
body: "http_body",
|
|
19292
|
+
headers: "http_header",
|
|
19293
|
+
cookies: "http_cookie"
|
|
19294
|
+
};
|
|
19295
|
+
function destructuredRequestPatterns(sourceCode) {
|
|
19296
|
+
const out2 = [];
|
|
19297
|
+
const seen = /* @__PURE__ */ new Set();
|
|
19298
|
+
for (const m of sourceCode.matchAll(/[(,]\s*\{([^{}]*)\}\s*:\s*(?:express\.)?Request\b/g)) {
|
|
19299
|
+
for (const part of m[1].split(",")) {
|
|
19300
|
+
const bind = /^\s*(\w+)\s*(?::\s*(\w+))?\s*(?:=[^,]*)?$/.exec(part);
|
|
19301
|
+
if (!bind) continue;
|
|
19302
|
+
const field = bind[1];
|
|
19303
|
+
const local = bind[2] ?? bind[1];
|
|
19304
|
+
const type = REQUEST_FIELD_TYPES[field];
|
|
19305
|
+
if (!type || seen.has(local)) continue;
|
|
19306
|
+
seen.add(local);
|
|
19307
|
+
out2.push({ pattern: new RegExp(`(?<![\\w.])${local}\\s*[.[]`), type });
|
|
19308
|
+
}
|
|
19309
|
+
}
|
|
19310
|
+
return out2;
|
|
19311
|
+
}
|
|
18603
19312
|
function findJavaScriptAssignmentSources(sourceCode, language) {
|
|
18604
19313
|
if (!["javascript", "typescript"].includes(language)) return [];
|
|
18605
19314
|
const sources = [];
|
|
18606
19315
|
const lines = sourceCode.split("\n");
|
|
18607
19316
|
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);
|
|
18608
|
-
const patterns = isRouteHandler2 ? [...JS_TAINTED_PATTERNS, { pattern: /\bparams\s*[.[]/, type: "http_path" }] : JS_TAINTED_PATTERNS;
|
|
19317
|
+
const patterns = isRouteHandler2 ? [...JS_TAINTED_PATTERNS, { pattern: /\bparams\s*[.[]/, type: "http_path" }] : [...JS_TAINTED_PATTERNS];
|
|
19318
|
+
patterns.push(...destructuredRequestPatterns(sourceCode));
|
|
18609
19319
|
const lookupTables = constLookupTables(sourceCode, language);
|
|
18610
19320
|
const assignmentRe2 = /(?:(?:var|let|const)\s+(\w+)\s*:\s*[^=;]+?\s*=(?![>=])|(?:(?:var|let|const)\s+)?(\w+)\s*=)\s*/g;
|
|
18611
19321
|
const rhsOwnStmt = /^(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`|[^;}"'`])*/;
|
|
@@ -18623,6 +19333,8 @@ function findJavaScriptAssignmentSources(sourceCode, language) {
|
|
|
18623
19333
|
rhs = rhsOwnStmt.exec(rhs)?.[0] ?? rhs;
|
|
18624
19334
|
}
|
|
18625
19335
|
if (isConstTableLookup(rhs, lookupTables)) continue;
|
|
19336
|
+
const wholeCall = /^\s*([A-Za-z_$][\w$]*)\s*\(.*\)\s*;?\s*$/.exec(rhs);
|
|
19337
|
+
if (wholeCall && jsHelperReturnsNoParam(sourceCode, wholeCall[1])) continue;
|
|
18626
19338
|
for (const { pattern, type } of patterns) {
|
|
18627
19339
|
if (pattern.test(rhs)) {
|
|
18628
19340
|
const alreadyExists = sources.some((s) => s.line === lineNumber && s.type === type && s.variable === varName);
|
|
@@ -18833,9 +19545,9 @@ function findGraphqlResolverArgSources(sourceCode) {
|
|
|
18833
19545
|
maps.push(open + inline.index + inline[0].length - 1);
|
|
18834
19546
|
continue;
|
|
18835
19547
|
}
|
|
18836
|
-
const
|
|
18837
|
-
if (!
|
|
18838
|
-
const ident =
|
|
19548
|
+
const named2 = opts.match(/\bresolvers\s*(?::\s*(\w+))?\s*[,}]/);
|
|
19549
|
+
if (!named2) continue;
|
|
19550
|
+
const ident = named2[1] ?? "resolvers";
|
|
18839
19551
|
const decl = new RegExp(
|
|
18840
19552
|
`\\b(?:const|let|var)\\s+${ident}\\s*(?::\\s*[A-Za-z_$][\\w$]*(?:\\s*\\.\\s*[A-Za-z_$][\\w$]*)*(?:\\s*<[^<>=]*(?:<[^<>=]*>[^<>=]*)*>)?\\s*)?=\\s*\\{`
|
|
18841
19553
|
).exec(sourceCode);
|
|
@@ -18998,15 +19710,15 @@ function evaluatePythonConstExpression(expr, consts) {
|
|
|
18998
19710
|
if (parts2.length !== 1) return void 0;
|
|
18999
19711
|
const matched = expr.match(/\d+|[A-Za-z_][A-Za-z0-9_]*|\/\/|[-+*/%()]|\S/g);
|
|
19000
19712
|
if (!matched) return void 0;
|
|
19001
|
-
const
|
|
19713
|
+
const tokens2 = matched;
|
|
19002
19714
|
let pos = 0;
|
|
19003
|
-
const peek = () =>
|
|
19715
|
+
const peek = () => tokens2[pos];
|
|
19004
19716
|
const parseFactor = () => {
|
|
19005
|
-
const tok =
|
|
19717
|
+
const tok = tokens2[pos++];
|
|
19006
19718
|
if (tok === void 0) return void 0;
|
|
19007
19719
|
if (tok === "(") {
|
|
19008
19720
|
const inner = parseSum();
|
|
19009
|
-
if (
|
|
19721
|
+
if (tokens2[pos++] !== ")") return void 0;
|
|
19010
19722
|
return inner;
|
|
19011
19723
|
}
|
|
19012
19724
|
if (tok === "-") {
|
|
@@ -19021,7 +19733,7 @@ function evaluatePythonConstExpression(expr, consts) {
|
|
|
19021
19733
|
let value = parseFactor();
|
|
19022
19734
|
if (value === void 0) return void 0;
|
|
19023
19735
|
while (peek() === "*" || peek() === "/" || peek() === "//" || peek() === "%") {
|
|
19024
|
-
const op =
|
|
19736
|
+
const op = tokens2[pos++];
|
|
19025
19737
|
const rhs = parseFactor();
|
|
19026
19738
|
if (rhs === void 0) return void 0;
|
|
19027
19739
|
if ((op === "/" || op === "//" || op === "%") && rhs === 0) return void 0;
|
|
@@ -19036,7 +19748,7 @@ function evaluatePythonConstExpression(expr, consts) {
|
|
|
19036
19748
|
let value = parseTerm();
|
|
19037
19749
|
if (value === void 0) return void 0;
|
|
19038
19750
|
while (peek() === "+" || peek() === "-") {
|
|
19039
|
-
const op =
|
|
19751
|
+
const op = tokens2[pos++];
|
|
19040
19752
|
const rhs = parseTerm();
|
|
19041
19753
|
if (rhs === void 0) return void 0;
|
|
19042
19754
|
value = op === "+" ? value + rhs : value - rhs;
|
|
@@ -19044,7 +19756,7 @@ function evaluatePythonConstExpression(expr, consts) {
|
|
|
19044
19756
|
return value;
|
|
19045
19757
|
}
|
|
19046
19758
|
const result = parseSum();
|
|
19047
|
-
return pos ===
|
|
19759
|
+
return pos === tokens2.length ? result : void 0;
|
|
19048
19760
|
}
|
|
19049
19761
|
function normalizeListIndex(index, length) {
|
|
19050
19762
|
const resolved = index < 0 ? length + index : index;
|
|
@@ -19092,6 +19804,140 @@ function computeDeadPythonBranchLines(lines) {
|
|
|
19092
19804
|
}
|
|
19093
19805
|
return dead;
|
|
19094
19806
|
}
|
|
19807
|
+
function parseJavaSwitchCaseLabel(label) {
|
|
19808
|
+
const t = label.trim();
|
|
19809
|
+
if (t === "default") return "default";
|
|
19810
|
+
const ch = t.match(/^'(\\.|[^'])'\s*$/);
|
|
19811
|
+
if (ch) {
|
|
19812
|
+
const inner = ch[1];
|
|
19813
|
+
if (inner.startsWith("\\")) {
|
|
19814
|
+
if (inner === "\\'") return 39;
|
|
19815
|
+
if (inner === "\\\\") return 92;
|
|
19816
|
+
if (inner === "\\n") return 10;
|
|
19817
|
+
return void 0;
|
|
19818
|
+
}
|
|
19819
|
+
return inner.charCodeAt(0);
|
|
19820
|
+
}
|
|
19821
|
+
const num = t.match(/^(-?\d+)\s*$/);
|
|
19822
|
+
if (num) return Number(num[1]);
|
|
19823
|
+
return void 0;
|
|
19824
|
+
}
|
|
19825
|
+
function parseJavaSwitchLabelLine(line) {
|
|
19826
|
+
const caseLine = line.match(/^\s*case\s+(.+?)\s*:\s*$/);
|
|
19827
|
+
if (caseLine) return parseJavaSwitchCaseLabel(caseLine[1]);
|
|
19828
|
+
if (/^\s*default\s*:\s*$/.test(line)) return "default";
|
|
19829
|
+
return void 0;
|
|
19830
|
+
}
|
|
19831
|
+
function markDeadJavaSwitchBodies(lines, switchLineIdx, switchValue, dead) {
|
|
19832
|
+
let depth = 0;
|
|
19833
|
+
let started = false;
|
|
19834
|
+
let groupLabels = [];
|
|
19835
|
+
let bodyStart = -1;
|
|
19836
|
+
let explicitCaseMatched = false;
|
|
19837
|
+
const groupIsTaken = () => {
|
|
19838
|
+
if (groupLabels.length === 0) return false;
|
|
19839
|
+
const explicit = groupLabels.some((v) => v !== "default" && v === switchValue);
|
|
19840
|
+
if (explicit) return true;
|
|
19841
|
+
return groupLabels.includes("default") && !explicitCaseMatched;
|
|
19842
|
+
};
|
|
19843
|
+
const flushGroup = (bodyEnd) => {
|
|
19844
|
+
if (bodyStart < 0 || groupLabels.length === 0) return;
|
|
19845
|
+
const taken = groupIsTaken();
|
|
19846
|
+
if (groupLabels.some((v) => v !== "default" && v === switchValue)) {
|
|
19847
|
+
explicitCaseMatched = true;
|
|
19848
|
+
}
|
|
19849
|
+
if (!taken) {
|
|
19850
|
+
for (let k = bodyStart; k < bodyEnd; k++) dead.add(k);
|
|
19851
|
+
}
|
|
19852
|
+
groupLabels = [];
|
|
19853
|
+
bodyStart = -1;
|
|
19854
|
+
};
|
|
19855
|
+
for (let j = switchLineIdx; j < lines.length; j++) {
|
|
19856
|
+
const line = lines[j];
|
|
19857
|
+
for (const ch of line) {
|
|
19858
|
+
if (ch === "{") {
|
|
19859
|
+
depth++;
|
|
19860
|
+
started = true;
|
|
19861
|
+
} else if (ch === "}") depth--;
|
|
19862
|
+
}
|
|
19863
|
+
if (!started) continue;
|
|
19864
|
+
const label = parseJavaSwitchLabelLine(line);
|
|
19865
|
+
if (label !== void 0) {
|
|
19866
|
+
if (bodyStart >= 0 && j === bodyStart) {
|
|
19867
|
+
groupLabels.push(label);
|
|
19868
|
+
bodyStart = j + 1;
|
|
19869
|
+
} else {
|
|
19870
|
+
flushGroup(j);
|
|
19871
|
+
groupLabels = [label];
|
|
19872
|
+
bodyStart = j + 1;
|
|
19873
|
+
}
|
|
19874
|
+
}
|
|
19875
|
+
if (started && depth === 0) {
|
|
19876
|
+
flushGroup(j);
|
|
19877
|
+
break;
|
|
19878
|
+
}
|
|
19879
|
+
}
|
|
19880
|
+
}
|
|
19881
|
+
function computeDeadJavaBranchLines(lines) {
|
|
19882
|
+
const dead = /* @__PURE__ */ new Set();
|
|
19883
|
+
const consts = /* @__PURE__ */ new Map();
|
|
19884
|
+
const stringConsts = /* @__PURE__ */ new Map();
|
|
19885
|
+
const charConsts = /* @__PURE__ */ new Map();
|
|
19886
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
19887
|
+
const line = lines[i2];
|
|
19888
|
+
const stringAssign = line.match(/^\s*String\s+([A-Za-z_]\w*)\s*=\s*"([^"]*)"\s*;\s*$/);
|
|
19889
|
+
if (stringAssign) {
|
|
19890
|
+
stringConsts.set(stringAssign[1], stringAssign[2]);
|
|
19891
|
+
continue;
|
|
19892
|
+
}
|
|
19893
|
+
const charAtAssign = line.match(
|
|
19894
|
+
/^\s*char\s+([A-Za-z_]\w*)\s*=\s*([A-Za-z_]\w*)\.charAt\s*\(\s*(\d+)\s*\)\s*;\s*(?:\/\/.*)?$/
|
|
19895
|
+
);
|
|
19896
|
+
if (charAtAssign) {
|
|
19897
|
+
const str = stringConsts.get(charAtAssign[2]);
|
|
19898
|
+
const idx = Number(charAtAssign[3]);
|
|
19899
|
+
if (str !== void 0 && idx >= 0 && idx < str.length) {
|
|
19900
|
+
charConsts.set(charAtAssign[1], str.charCodeAt(idx));
|
|
19901
|
+
} else {
|
|
19902
|
+
charConsts.delete(charAtAssign[1]);
|
|
19903
|
+
}
|
|
19904
|
+
continue;
|
|
19905
|
+
}
|
|
19906
|
+
const intAssign = line.match(/^\s*(?:int|long|short|byte)\s+([A-Za-z_]\w*)\s*=\s*(.+?);\s*$/);
|
|
19907
|
+
if (intAssign) {
|
|
19908
|
+
const v = evaluatePythonConstExpression(intAssign[2].trim(), consts);
|
|
19909
|
+
if (typeof v === "number") consts.set(intAssign[1], v);
|
|
19910
|
+
else consts.delete(intAssign[1]);
|
|
19911
|
+
continue;
|
|
19912
|
+
}
|
|
19913
|
+
const switchMatch = line.match(/^\s*switch\s*\(([^)]+)\)\s*\{?\s*$/);
|
|
19914
|
+
if (switchMatch) {
|
|
19915
|
+
const sel = switchMatch[1].trim();
|
|
19916
|
+
let switchVal = charConsts.get(sel);
|
|
19917
|
+
if (switchVal === void 0) {
|
|
19918
|
+
const n = evaluatePythonConstExpression(sel, consts);
|
|
19919
|
+
if (typeof n === "number") switchVal = n;
|
|
19920
|
+
}
|
|
19921
|
+
if (switchVal !== void 0) {
|
|
19922
|
+
markDeadJavaSwitchBodies(lines, i2, switchVal, dead);
|
|
19923
|
+
}
|
|
19924
|
+
continue;
|
|
19925
|
+
}
|
|
19926
|
+
const ifMatch = line.match(/^(\s*)if\s*\((.+)\)\s+(.+)$/);
|
|
19927
|
+
if (!ifMatch) continue;
|
|
19928
|
+
const decided = evaluatePythonConstExpression(ifMatch[2].trim(), consts);
|
|
19929
|
+
if (decided !== true && decided !== false) continue;
|
|
19930
|
+
const rest = ifMatch[3].trim();
|
|
19931
|
+
if (/\belse\b/.test(rest)) continue;
|
|
19932
|
+
if (i2 + 1 < lines.length && /^\s*else\b/.test(lines[i2 + 1])) {
|
|
19933
|
+
if (decided === true) dead.add(i2 + 1);
|
|
19934
|
+
else dead.add(i2);
|
|
19935
|
+
} else if (decided === false) {
|
|
19936
|
+
dead.add(i2);
|
|
19937
|
+
}
|
|
19938
|
+
}
|
|
19939
|
+
return dead;
|
|
19940
|
+
}
|
|
19095
19941
|
function buildPythonTaintedVars(sourceCode) {
|
|
19096
19942
|
const tainted = /* @__PURE__ */ new Map();
|
|
19097
19943
|
const containerTainted = /* @__PURE__ */ new Map();
|
|
@@ -19811,6 +20657,82 @@ function buildRustTaintedVars(sourceCode, seedVars) {
|
|
|
19811
20657
|
}
|
|
19812
20658
|
return derived;
|
|
19813
20659
|
}
|
|
20660
|
+
function stripJavaTrailingLineComment(line) {
|
|
20661
|
+
let quote = null;
|
|
20662
|
+
for (let i2 = 0; i2 < line.length; i2++) {
|
|
20663
|
+
const c = line[i2];
|
|
20664
|
+
if (quote) {
|
|
20665
|
+
if (c === "\\") i2++;
|
|
20666
|
+
else if (c === quote) quote = null;
|
|
20667
|
+
} else if (c === '"' || c === "'") {
|
|
20668
|
+
quote = c;
|
|
20669
|
+
} else if (c === "/" && line[i2 + 1] === "/") {
|
|
20670
|
+
return line.slice(0, i2).trimEnd();
|
|
20671
|
+
}
|
|
20672
|
+
}
|
|
20673
|
+
return line;
|
|
20674
|
+
}
|
|
20675
|
+
function javaExpressionIdents(expr) {
|
|
20676
|
+
const code = expr.replace(/"(?:[^"\\]|\\.)*"/g, " ").replace(/'(?:[^'\\]|\\.)'/g, " ");
|
|
20677
|
+
return code.match(/[\p{L}\p{N}_]+/gu) ?? [];
|
|
20678
|
+
}
|
|
20679
|
+
function recordJavaSlotStatement(line, listElems, mapSlots, intConsts) {
|
|
20680
|
+
const t = line.trimEnd().replace(/;\s*\/\/[^"]*$/, ";");
|
|
20681
|
+
const intDecl = /^\s*(?:final\s+)?(?:int|long|short|byte)\s+([A-Za-z_]\w*)\s*=\s*([^;]+);\s*$/.exec(t);
|
|
20682
|
+
if (intDecl) {
|
|
20683
|
+
const v = evaluatePythonConstExpression(intDecl[2].trim(), intConsts);
|
|
20684
|
+
if (typeof v === "number") intConsts.set(intDecl[1], v);
|
|
20685
|
+
else intConsts.delete(intDecl[1]);
|
|
20686
|
+
return false;
|
|
20687
|
+
}
|
|
20688
|
+
const add = /^\s*([A-Za-z_]\w*)\.add\s*\(\s*([A-Za-z_]\w*|"(?:[^"\\]|\\.)*")\s*\)\s*;\s*$/.exec(t);
|
|
20689
|
+
if (add) {
|
|
20690
|
+
const elems = listElems.get(add[1]) ?? [];
|
|
20691
|
+
elems.push(add[2].startsWith('"') ? null : add[2]);
|
|
20692
|
+
listElems.set(add[1], elems);
|
|
20693
|
+
return true;
|
|
20694
|
+
}
|
|
20695
|
+
const remove = /^\s*([A-Za-z_]\w*)\.remove\s*\(\s*(\d+)\s*\)\s*;\s*$/.exec(t);
|
|
20696
|
+
if (remove && listElems.has(remove[1])) {
|
|
20697
|
+
const elems = listElems.get(remove[1]);
|
|
20698
|
+
const idx = Number(remove[2]);
|
|
20699
|
+
if (idx < elems.length) elems.splice(idx, 1);
|
|
20700
|
+
else listElems.delete(remove[1]);
|
|
20701
|
+
return true;
|
|
20702
|
+
}
|
|
20703
|
+
const put = /^\s*([A-Za-z_]\w*)\.put\s*\(\s*"((?:[^"\\]|\\.)*)"\s*,\s*(.+?)\s*\)\s*;\s*$/.exec(t);
|
|
20704
|
+
if (put) {
|
|
20705
|
+
const keys = mapSlots.get(put[1]) ?? /* @__PURE__ */ new Map();
|
|
20706
|
+
keys.set(put[2], javaExpressionIdents(put[3]));
|
|
20707
|
+
mapSlots.set(put[1], keys);
|
|
20708
|
+
return true;
|
|
20709
|
+
}
|
|
20710
|
+
for (const table of [listElems, mapSlots]) {
|
|
20711
|
+
for (const name2 of [...table.keys()]) {
|
|
20712
|
+
const mention = new RegExp(`(?<![\\w.])${name2}(?!\\w)`);
|
|
20713
|
+
if (!mention.test(t)) continue;
|
|
20714
|
+
const reads = new RegExp(`(?<![\\w.])${name2}\\.(?:get|size|isEmpty|contains\\w*)\\s*\\(`, "g");
|
|
20715
|
+
if (mention.test(t.replace(reads, " "))) table.delete(name2);
|
|
20716
|
+
}
|
|
20717
|
+
}
|
|
20718
|
+
return false;
|
|
20719
|
+
}
|
|
20720
|
+
function javaSlotRead(rhs, listElems, mapSlots) {
|
|
20721
|
+
const m = /^(?:\(\s*[A-Za-z_][\w.<>]*\s*\)\s*)?([A-Za-z_]\w*)\.get\s*\(\s*(\d+|"(?:[^"\\]|\\.)*")\s*\)$/.exec(rhs.trim());
|
|
20722
|
+
if (!m) return void 0;
|
|
20723
|
+
const [, recv, arg] = m;
|
|
20724
|
+
if (arg.startsWith('"')) {
|
|
20725
|
+
const keys = mapSlots.get(recv);
|
|
20726
|
+
if (!keys) return void 0;
|
|
20727
|
+
return keys.get(arg.slice(1, -1)) ?? [];
|
|
20728
|
+
}
|
|
20729
|
+
const elems = listElems.get(recv);
|
|
20730
|
+
if (!elems) return void 0;
|
|
20731
|
+
const idx = Number(arg);
|
|
20732
|
+
if (idx >= elems.length) return void 0;
|
|
20733
|
+
const slot = elems[idx];
|
|
20734
|
+
return slot === null ? [] : [slot];
|
|
20735
|
+
}
|
|
19814
20736
|
function joinWrappedJavaStatement(lines, i2) {
|
|
19815
20737
|
const strip = (l) => l.replace(/"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)'/g, '""').replace(/\/\/.*$/, "");
|
|
19816
20738
|
const first = strip(lines[i2]);
|
|
@@ -19832,12 +20754,19 @@ function joinWrappedJavaStatement(lines, i2) {
|
|
|
19832
20754
|
}
|
|
19833
20755
|
return null;
|
|
19834
20756
|
}
|
|
19835
|
-
function buildJavaTaintedVars(sourceCode, seedVars) {
|
|
20757
|
+
function buildJavaTaintedVars(sourceCode, seedVars, deadBranchLines, options) {
|
|
19836
20758
|
const derived = /* @__PURE__ */ new Map();
|
|
19837
20759
|
const knownTainted = new Set(seedVars);
|
|
19838
|
-
const
|
|
20760
|
+
const trackSlots = options?.trackSlots === true;
|
|
20761
|
+
const lines = trackSlots ? sourceCode.split("\n").map(stripJavaTrailingLineComment) : sourceCode.split("\n");
|
|
20762
|
+
const dead = deadBranchLines ?? /* @__PURE__ */ new Set();
|
|
20763
|
+
const listElems = /* @__PURE__ */ new Map();
|
|
20764
|
+
const mapSlots = /* @__PURE__ */ new Map();
|
|
20765
|
+
const intConsts = /* @__PURE__ */ new Map();
|
|
19839
20766
|
const declRe = /^\s*(?:public|private|protected|static|final|volatile|transient|\s)*\s*(?:[A-Za-z_][\w.]*(?:\s*<[^>]*>)?(?:\s*\[\s*\])*)\s+([A-Za-z_]\w*)\s*=\s*(.+?);\s*$/;
|
|
19840
20767
|
const assignRe = /^\s*([A-Za-z_]\w*)\s*=\s*(.+?);\s*$/;
|
|
20768
|
+
const thisFieldAssignRe = /^\s*this\.([A-Za-z_]\w*)\s*=\s*(.+?);\s*$/;
|
|
20769
|
+
const beanSetterCallRe = /\bset([A-Z]\w*)\s*\((.*)\)\s*;?\s*$/;
|
|
19841
20770
|
const JAVA_KEYWORDS = /* @__PURE__ */ new Set([
|
|
19842
20771
|
"if",
|
|
19843
20772
|
"else",
|
|
@@ -19873,10 +20802,23 @@ function buildJavaTaintedVars(sourceCode, seedVars) {
|
|
|
19873
20802
|
while (changed && guard < lines.length + 2) {
|
|
19874
20803
|
changed = false;
|
|
19875
20804
|
guard++;
|
|
20805
|
+
listElems.clear();
|
|
20806
|
+
mapSlots.clear();
|
|
20807
|
+
intConsts.clear();
|
|
19876
20808
|
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
20809
|
+
if (deadBranchLines !== void 0 && dead.has(i2)) continue;
|
|
19877
20810
|
const line = lines[i2];
|
|
19878
20811
|
const trimmed = line.trimStart();
|
|
19879
20812
|
if (trimmed.startsWith("//") || trimmed.startsWith("*")) continue;
|
|
20813
|
+
if (trackSlots && recordJavaSlotStatement(line, listElems, mapSlots, intConsts)) {
|
|
20814
|
+
const add = /^\s*([A-Za-z_]\w*)\.add\s*\(\s*([A-Za-z_]\w*)\s*\)\s*;/.exec(line);
|
|
20815
|
+
if (add && knownTainted.has(add[2]) && !knownTainted.has(add[1])) {
|
|
20816
|
+
derived.set(add[1], i2 + 1);
|
|
20817
|
+
knownTainted.add(add[1]);
|
|
20818
|
+
changed = true;
|
|
20819
|
+
}
|
|
20820
|
+
continue;
|
|
20821
|
+
}
|
|
19880
20822
|
const arrayCopyRe = /\bSystem\.arraycopy\s*\(\s*([A-Za-z_]\w*)\s*,\s*[^,]+\s*,\s*([A-Za-z_]\w*)\s*,/;
|
|
19881
20823
|
const acMatch = arrayCopyRe.exec(line);
|
|
19882
20824
|
if (acMatch) {
|
|
@@ -19906,17 +20848,79 @@ function buildJavaTaintedVars(sourceCode, seedVars) {
|
|
|
19906
20848
|
let assignMatch = !declMatch ? assignRe.exec(statement) : null;
|
|
19907
20849
|
if (!declMatch && !assignMatch) {
|
|
19908
20850
|
const joined = joinWrappedJavaStatement(lines, i2);
|
|
19909
|
-
if (joined
|
|
19910
|
-
|
|
19911
|
-
|
|
19912
|
-
|
|
20851
|
+
if (joined !== null) {
|
|
20852
|
+
statement = joined;
|
|
20853
|
+
declMatch = declRe.exec(statement);
|
|
20854
|
+
assignMatch = !declMatch ? assignRe.exec(statement) : null;
|
|
20855
|
+
}
|
|
20856
|
+
}
|
|
20857
|
+
const thisFieldMatch = thisFieldAssignRe.exec(statement.trim());
|
|
20858
|
+
if (thisFieldMatch) {
|
|
20859
|
+
const fieldName = thisFieldMatch[1];
|
|
20860
|
+
const rhs2 = thisFieldMatch[2];
|
|
20861
|
+
const rhsCode2 = rhs2.replace(/\$@?"(?:[^"\\]|\\.)*"/g, (lit) => " " + [...lit.matchAll(/\{([^}]*)\}/g)].map((x) => x[1]).join(" ") + " ").replace(/@?"(?:[^"\\]|\\.)*"/g, " ").replace(/'(?:[^'\\]|\\.)'/g, " ");
|
|
20862
|
+
const rhsIdents2 = rhsCode2.match(/[\p{L}\p{N}_]+/gu);
|
|
20863
|
+
const ref2 = rhsIdents2 !== null && rhsIdents2.some((t) => knownTainted.has(t)) || complexTaintedRes.length > 0 && complexTaintedRes.some((re) => re.test(rhsCode2));
|
|
20864
|
+
if (ref2) {
|
|
20865
|
+
const thisField = `this.${fieldName}`;
|
|
20866
|
+
if (!knownTainted.has(thisField)) {
|
|
20867
|
+
derived.set(thisField, i2 + 1);
|
|
20868
|
+
knownTainted.add(thisField);
|
|
20869
|
+
changed = true;
|
|
20870
|
+
}
|
|
20871
|
+
if (!knownTainted.has(fieldName)) {
|
|
20872
|
+
derived.set(fieldName, i2 + 1);
|
|
20873
|
+
knownTainted.add(fieldName);
|
|
20874
|
+
changed = true;
|
|
20875
|
+
}
|
|
20876
|
+
}
|
|
20877
|
+
continue;
|
|
20878
|
+
}
|
|
20879
|
+
const setterCall = beanSetterCallRe.exec(statement);
|
|
20880
|
+
if (setterCall) {
|
|
20881
|
+
const fieldName = setterCall[1].charAt(0).toLowerCase() + setterCall[1].slice(1);
|
|
20882
|
+
const arg = setterCall[2];
|
|
20883
|
+
const rhsCode2 = arg.replace(/\$@?"(?:[^"\\]|\\.)*"/g, (lit) => " " + [...lit.matchAll(/\{([^}]*)\}/g)].map((x) => x[1]).join(" ") + " ").replace(/@?"(?:[^"\\]|\\.)*"/g, " ").replace(/'(?:[^'\\]|\\.)'/g, " ");
|
|
20884
|
+
const rhsIdents2 = rhsCode2.match(/[\p{L}\p{N}_]+/gu);
|
|
20885
|
+
const ref2 = rhsIdents2 !== null && rhsIdents2.some((t) => knownTainted.has(t)) || complexTaintedRes.length > 0 && complexTaintedRes.some((re) => re.test(rhsCode2));
|
|
20886
|
+
if (ref2) {
|
|
20887
|
+
const thisField = `this.${fieldName}`;
|
|
20888
|
+
if (!knownTainted.has(thisField)) {
|
|
20889
|
+
derived.set(thisField, i2 + 1);
|
|
20890
|
+
knownTainted.add(thisField);
|
|
20891
|
+
changed = true;
|
|
20892
|
+
}
|
|
20893
|
+
if (!knownTainted.has(fieldName)) {
|
|
20894
|
+
derived.set(fieldName, i2 + 1);
|
|
20895
|
+
knownTainted.add(fieldName);
|
|
20896
|
+
changed = true;
|
|
20897
|
+
}
|
|
20898
|
+
}
|
|
20899
|
+
continue;
|
|
19913
20900
|
}
|
|
19914
20901
|
const m = declMatch ?? assignMatch;
|
|
19915
20902
|
if (!m) continue;
|
|
19916
20903
|
const lhs = m[1];
|
|
19917
|
-
|
|
20904
|
+
let rhs = m[2];
|
|
19918
20905
|
if (JAVA_KEYWORDS.has(lhs)) continue;
|
|
19919
20906
|
if (knownTainted.has(lhs)) continue;
|
|
20907
|
+
if (trackSlots) {
|
|
20908
|
+
const slot = javaSlotRead(rhs, listElems, mapSlots);
|
|
20909
|
+
if (slot !== void 0) {
|
|
20910
|
+
if (slot.some((t) => knownTainted.has(t))) {
|
|
20911
|
+
derived.set(lhs, i2 + 1);
|
|
20912
|
+
knownTainted.add(lhs);
|
|
20913
|
+
changed = true;
|
|
20914
|
+
}
|
|
20915
|
+
continue;
|
|
20916
|
+
}
|
|
20917
|
+
const tern = /^([^?]+?)\s*\?\s*([^:]+?)\s*:\s*(.+)$/.exec(rhs.trim());
|
|
20918
|
+
if (tern) {
|
|
20919
|
+
const decided = evaluatePythonConstExpression(tern[1].trim().replace(/^\((.*)\)$/, "$1"), intConsts);
|
|
20920
|
+
if (decided === true) rhs = tern[2];
|
|
20921
|
+
else if (decided === false) rhs = tern[3];
|
|
20922
|
+
}
|
|
20923
|
+
}
|
|
19920
20924
|
const rhsCode = rhs.replace(/\$@?"(?:[^"\\]|\\.)*"/g, (lit) => " " + [...lit.matchAll(/\{([^}]*)\}/g)].map((x) => x[1]).join(" ") + " ").replace(/@?"(?:[^"\\]|\\.)*"/g, " ").replace(/'(?:[^'\\]|\\.)'/g, " ");
|
|
19921
20925
|
const rhsIdents = rhsCode.match(/[\p{L}\p{N}_]+/gu);
|
|
19922
20926
|
const ref = rhsIdents !== null && rhsIdents.some((t) => knownTainted.has(t)) || complexTaintedRes.length > 0 && complexTaintedRes.some((re) => re.test(rhsCode));
|
|
@@ -19968,8 +20972,11 @@ function findBashTaintSources(sourceCode, dfg) {
|
|
|
19968
20972
|
const insideFunction = braceDepth > 0;
|
|
19969
20973
|
if (!insideFunction) {
|
|
19970
20974
|
const positionalRe = /\$([1-9@*])|\$\{([1-9@*])\}/g;
|
|
20975
|
+
const header = /^\s*(?:function\s+)?[A-Za-z_][\w-]*\s*(?:\(\s*\))?\s*\{/.exec(line);
|
|
20976
|
+
const isFnHeader = header !== null && (/\(\s*\)/.test(header[0]) || /^\s*function\s/.test(header[0]));
|
|
20977
|
+
const topLevelText = (isFnHeader ? line.slice(0, header[0].length) : line).replace(/'[^']*'/g, "''");
|
|
19971
20978
|
let m;
|
|
19972
|
-
while ((m = positionalRe.exec(
|
|
20979
|
+
while ((m = positionalRe.exec(topLevelText)) !== null) {
|
|
19973
20980
|
const param = m[1] ?? m[2];
|
|
19974
20981
|
const alreadyExists = sources.some((s) => s.line === lineNumber && s.variable === param);
|
|
19975
20982
|
if (!alreadyExists) {
|
|
@@ -20025,10 +21032,10 @@ function findBashTaintSources(sourceCode, dfg) {
|
|
|
20025
21032
|
if (readMatch) {
|
|
20026
21033
|
const argStr = readMatch[1].trim();
|
|
20027
21034
|
const noRedirect = argStr.replace(/\s*<[^<].*$/, "").trim();
|
|
20028
|
-
const
|
|
21035
|
+
const tokens2 = noRedirect.split(/\s+/);
|
|
20029
21036
|
const varNames = [];
|
|
20030
|
-
for (let ti = 0; ti <
|
|
20031
|
-
const tok =
|
|
21037
|
+
for (let ti = 0; ti < tokens2.length; ti++) {
|
|
21038
|
+
const tok = tokens2[ti];
|
|
20032
21039
|
if (!tok) continue;
|
|
20033
21040
|
if (tok.startsWith("-")) {
|
|
20034
21041
|
if (/^-[antpidu]$|^-N$/.test(tok)) ti++;
|
|
@@ -20053,10 +21060,10 @@ function findBashTaintSources(sourceCode, dfg) {
|
|
|
20053
21060
|
const mapfileMatch = /^(?:mapfile|readarray)\s*\(/.test(trimmed) ? null : trimmed.match(/^(?:mapfile|readarray)\b([^#(]*)$/);
|
|
20054
21061
|
if (mapfileMatch) {
|
|
20055
21062
|
const argStr = mapfileMatch[1].trim();
|
|
20056
|
-
const
|
|
21063
|
+
const tokens2 = argStr.split(/\s+/);
|
|
20057
21064
|
const varNames = [];
|
|
20058
|
-
for (let ti = 0; ti <
|
|
20059
|
-
const tok =
|
|
21065
|
+
for (let ti = 0; ti < tokens2.length; ti++) {
|
|
21066
|
+
const tok = tokens2[ti];
|
|
20060
21067
|
if (!tok) continue;
|
|
20061
21068
|
if (tok.startsWith("-")) {
|
|
20062
21069
|
if (/^-[cCnOsud]$/.test(tok)) ti++;
|
|
@@ -20441,6 +21448,30 @@ function findBashRealpathPrefixGuardSanitizers(code) {
|
|
|
20441
21448
|
}
|
|
20442
21449
|
return sanitizers;
|
|
20443
21450
|
}
|
|
21451
|
+
function findBashVerifiedPackageDownloadSanitizers(code) {
|
|
21452
|
+
const lines = code.split("\n");
|
|
21453
|
+
if (!hasIntegrityVerifierAnywhere(lines)) {
|
|
21454
|
+
return [];
|
|
21455
|
+
}
|
|
21456
|
+
const hasDownload = lines.some((l) => /\b(curl|wget)\b/.test(l));
|
|
21457
|
+
const hasInstall = lines.some((l) => matchUnverifiedPackageInstall(l.trim()) !== null);
|
|
21458
|
+
if (!hasDownload || !hasInstall) {
|
|
21459
|
+
return [];
|
|
21460
|
+
}
|
|
21461
|
+
const sanitizers = [];
|
|
21462
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
21463
|
+
const line = lines[i2];
|
|
21464
|
+
if (line.trimStart().startsWith("#")) continue;
|
|
21465
|
+
if (!/\b(curl|wget)\b/.test(line)) continue;
|
|
21466
|
+
sanitizers.push({
|
|
21467
|
+
type: "verified_package_download",
|
|
21468
|
+
method: "curl",
|
|
21469
|
+
line: i2 + 1,
|
|
21470
|
+
sanitizes: ["ssrf"]
|
|
21471
|
+
});
|
|
21472
|
+
}
|
|
21473
|
+
return sanitizers;
|
|
21474
|
+
}
|
|
20444
21475
|
function findGoMapAllowlistGuardSanitizers(code) {
|
|
20445
21476
|
const sanitizers = [];
|
|
20446
21477
|
const lines = code.split("\n");
|
|
@@ -20596,6 +21627,160 @@ function findPythonNetlocAllowlistGuardSanitizers(code) {
|
|
|
20596
21627
|
}
|
|
20597
21628
|
return sanitizers;
|
|
20598
21629
|
}
|
|
21630
|
+
function findJsNumericRangeCheckGuardSanitizers(code) {
|
|
21631
|
+
const sanitizers = [];
|
|
21632
|
+
const lines = code.split("\n");
|
|
21633
|
+
const coerceDecl = /^\s*(?:const|let|var)\s+([A-Za-z_]\w*)\s*=\s*(?:Number|parseInt)\s*\(/;
|
|
21634
|
+
const lowerGuard = /\bif\s*\(\s*!(?:Number\.)?isFinite\s*\(\s*([A-Za-z_]\w*)\s*\)|\bif\s*\([^)]*\b([A-Za-z_]\w*)\s*<=\s*0/;
|
|
21635
|
+
const upperGuard = /\bif\s*\(\s*([A-Za-z_]\w*)\s*>\s*(?:\d+|[A-Z][A-Z0-9_]+)\s*\)/;
|
|
21636
|
+
const terminator = /\b(?:return|throw|res\s*\.\s*status\s*\([^)]*\)\s*\.\s*(?:send|end|json))/;
|
|
21637
|
+
const coerced = /* @__PURE__ */ new Map();
|
|
21638
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
21639
|
+
const m = coerceDecl.exec(lines[i2]);
|
|
21640
|
+
if (m) coerced.set(m[1], i2);
|
|
21641
|
+
}
|
|
21642
|
+
if (coerced.size === 0) return sanitizers;
|
|
21643
|
+
const state = /* @__PURE__ */ new Map();
|
|
21644
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
21645
|
+
const line = lines[i2];
|
|
21646
|
+
let varName = null;
|
|
21647
|
+
let kind = null;
|
|
21648
|
+
const low = lowerGuard.exec(line);
|
|
21649
|
+
if (low) {
|
|
21650
|
+
varName = low[1] ?? low[2];
|
|
21651
|
+
kind = "lower";
|
|
21652
|
+
} else {
|
|
21653
|
+
const up = upperGuard.exec(line);
|
|
21654
|
+
if (up) {
|
|
21655
|
+
varName = up[1];
|
|
21656
|
+
kind = "upper";
|
|
21657
|
+
}
|
|
21658
|
+
}
|
|
21659
|
+
if (!varName || !kind || !coerced.has(varName)) continue;
|
|
21660
|
+
if (!terminator.test(line)) {
|
|
21661
|
+
let bodyHasTerminator = false;
|
|
21662
|
+
let blockEnd = i2;
|
|
21663
|
+
let braceDepth = 0;
|
|
21664
|
+
let started = false;
|
|
21665
|
+
const maxScan = Math.min(lines.length, i2 + 26);
|
|
21666
|
+
for (let j = i2; j < maxScan; j++) {
|
|
21667
|
+
const ln = lines[j];
|
|
21668
|
+
for (const ch of ln) {
|
|
21669
|
+
if (ch === "{") {
|
|
21670
|
+
braceDepth++;
|
|
21671
|
+
started = true;
|
|
21672
|
+
} else if (ch === "}") {
|
|
21673
|
+
braceDepth--;
|
|
21674
|
+
if (started && braceDepth === 0) {
|
|
21675
|
+
blockEnd = j;
|
|
21676
|
+
break;
|
|
21677
|
+
}
|
|
21678
|
+
}
|
|
21679
|
+
}
|
|
21680
|
+
if (j > i2 && terminator.test(ln)) bodyHasTerminator = true;
|
|
21681
|
+
if (started && braceDepth === 0 && blockEnd !== i2) break;
|
|
21682
|
+
}
|
|
21683
|
+
if (!bodyHasTerminator && !started) continue;
|
|
21684
|
+
if (!bodyHasTerminator) continue;
|
|
21685
|
+
}
|
|
21686
|
+
const st = state.get(varName) ?? { lower: false, upper: false, lastGuardEnd: i2 };
|
|
21687
|
+
if (kind === "lower") st.lower = true;
|
|
21688
|
+
else st.upper = true;
|
|
21689
|
+
st.lastGuardEnd = i2;
|
|
21690
|
+
state.set(varName, st);
|
|
21691
|
+
}
|
|
21692
|
+
for (const [varName, st] of state) {
|
|
21693
|
+
if (!st.lower || !st.upper) continue;
|
|
21694
|
+
const varRefRe = new RegExp(`\\b${varName}\\b`);
|
|
21695
|
+
for (let l = st.lastGuardEnd + 1; l < lines.length; l++) {
|
|
21696
|
+
if (!varRefRe.test(lines[l])) continue;
|
|
21697
|
+
sanitizers.push({
|
|
21698
|
+
type: "js_numeric_range_check_guard",
|
|
21699
|
+
method: "if",
|
|
21700
|
+
line: l + 1,
|
|
21701
|
+
sanitizes: ["xss", "external_taint_escape"]
|
|
21702
|
+
});
|
|
21703
|
+
}
|
|
21704
|
+
}
|
|
21705
|
+
return sanitizers;
|
|
21706
|
+
}
|
|
21707
|
+
function findRustNumericRangeCheckGuardSanitizers(code) {
|
|
21708
|
+
const sanitizers = [];
|
|
21709
|
+
const lines = code.split("\n");
|
|
21710
|
+
const coerceDecl = /^\s*let\s+([A-Za-z_]\w*)\s*(?::\s*(?:i\d+|u\d+|isize|usize))?\s*=\s*[^;]*\.parse\s*(?:\(\s*\)|::<)/;
|
|
21711
|
+
const lowerGuard = /\bif\s+([A-Za-z_]\w*)\s*<=\s*0\b/;
|
|
21712
|
+
const upperGuard = /\bif\s+([A-Za-z_]\w*)\s*>\s*(?:\d+|[A-Z][A-Z0-9_]+)\b/;
|
|
21713
|
+
const terminator = /\b(?:return\s+HttpResponse::|return\s+StatusCode::|return\s+Err\s*\(|panic!\s*\()/;
|
|
21714
|
+
const coerced = /* @__PURE__ */ new Map();
|
|
21715
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
21716
|
+
const m = coerceDecl.exec(lines[i2]);
|
|
21717
|
+
if (m) coerced.set(m[1], i2);
|
|
21718
|
+
}
|
|
21719
|
+
if (coerced.size === 0) return sanitizers;
|
|
21720
|
+
const state = /* @__PURE__ */ new Map();
|
|
21721
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
21722
|
+
const line = lines[i2];
|
|
21723
|
+
let varName = null;
|
|
21724
|
+
let kind = null;
|
|
21725
|
+
const low = lowerGuard.exec(line);
|
|
21726
|
+
if (low) {
|
|
21727
|
+
varName = low[1];
|
|
21728
|
+
kind = "lower";
|
|
21729
|
+
} else {
|
|
21730
|
+
const up = upperGuard.exec(line);
|
|
21731
|
+
if (up) {
|
|
21732
|
+
varName = up[1];
|
|
21733
|
+
kind = "upper";
|
|
21734
|
+
}
|
|
21735
|
+
}
|
|
21736
|
+
if (!varName || !kind || !coerced.has(varName)) continue;
|
|
21737
|
+
if (!terminator.test(line)) {
|
|
21738
|
+
let bodyHasTerminator = false;
|
|
21739
|
+
let blockEnd = i2;
|
|
21740
|
+
let braceDepth = 0;
|
|
21741
|
+
let started = false;
|
|
21742
|
+
const maxScan = Math.min(lines.length, i2 + 26);
|
|
21743
|
+
for (let j = i2; j < maxScan; j++) {
|
|
21744
|
+
const ln = lines[j];
|
|
21745
|
+
for (const ch of ln) {
|
|
21746
|
+
if (ch === "{") {
|
|
21747
|
+
braceDepth++;
|
|
21748
|
+
started = true;
|
|
21749
|
+
} else if (ch === "}") {
|
|
21750
|
+
braceDepth--;
|
|
21751
|
+
if (started && braceDepth === 0) {
|
|
21752
|
+
blockEnd = j;
|
|
21753
|
+
break;
|
|
21754
|
+
}
|
|
21755
|
+
}
|
|
21756
|
+
}
|
|
21757
|
+
if (j > i2 && terminator.test(ln)) bodyHasTerminator = true;
|
|
21758
|
+
if (started && braceDepth === 0 && blockEnd !== i2) break;
|
|
21759
|
+
}
|
|
21760
|
+
if (!bodyHasTerminator && !started) continue;
|
|
21761
|
+
if (!bodyHasTerminator) continue;
|
|
21762
|
+
}
|
|
21763
|
+
const st = state.get(varName) ?? { lower: false, upper: false, lastGuardEnd: i2 };
|
|
21764
|
+
if (kind === "lower") st.lower = true;
|
|
21765
|
+
else st.upper = true;
|
|
21766
|
+
st.lastGuardEnd = i2;
|
|
21767
|
+
state.set(varName, st);
|
|
21768
|
+
}
|
|
21769
|
+
for (const [varName, st] of state) {
|
|
21770
|
+
if (!st.lower || !st.upper) continue;
|
|
21771
|
+
const varRefRe = new RegExp(`\\b${varName}\\b`);
|
|
21772
|
+
for (let l = st.lastGuardEnd + 1; l < lines.length; l++) {
|
|
21773
|
+
if (!varRefRe.test(lines[l])) continue;
|
|
21774
|
+
sanitizers.push({
|
|
21775
|
+
type: "rust_numeric_range_check_guard",
|
|
21776
|
+
method: "if",
|
|
21777
|
+
line: l + 1,
|
|
21778
|
+
sanitizes: ["xss", "external_taint_escape"]
|
|
21779
|
+
});
|
|
21780
|
+
}
|
|
21781
|
+
}
|
|
21782
|
+
return sanitizers;
|
|
21783
|
+
}
|
|
20599
21784
|
function findPythonRangeCheckGuardSanitizers(code) {
|
|
20600
21785
|
const sanitizers = [];
|
|
20601
21786
|
const lines = code.split("\n");
|
|
@@ -21182,6 +22367,127 @@ function findPythonDefusedXmlSanitizers(code) {
|
|
|
21182
22367
|
}
|
|
21183
22368
|
return sanitizers;
|
|
21184
22369
|
}
|
|
22370
|
+
function findRustPatInfoHttpOnlyResponseSanitizers(code) {
|
|
22371
|
+
const sanitizers = [];
|
|
22372
|
+
const lines = code.split("\n");
|
|
22373
|
+
const bodyFormatRe = /HttpResponse::\w+\(\)\s*\.\s*body\s*\(\s*format!\s*\(/;
|
|
22374
|
+
const envBindRe = /(?:^|[^:])env::var\s*\(|std::env::/;
|
|
22375
|
+
const httpGetRe = /\.get\s*\(\s*"[^"]+"\s*\)/;
|
|
22376
|
+
const letVarRe = (v) => new RegExp(String.raw`^\s*let\s+(?:mut\s+)?${v}\s*=`);
|
|
22377
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
22378
|
+
const sinkLine = lines[i2];
|
|
22379
|
+
if (!bodyFormatRe.test(sinkLine)) continue;
|
|
22380
|
+
if (envBindRe.test(sinkLine)) continue;
|
|
22381
|
+
const varRefs = [
|
|
22382
|
+
...sinkLine.matchAll(/\{([A-Za-z_][A-Za-z0-9_]*)\}/g)
|
|
22383
|
+
].map((m) => m[1]);
|
|
22384
|
+
if (varRefs.length === 0) continue;
|
|
22385
|
+
let allHttpOnly = true;
|
|
22386
|
+
for (const v of varRefs) {
|
|
22387
|
+
let sawBinding = false;
|
|
22388
|
+
let boundEnv = false;
|
|
22389
|
+
let boundHttp = false;
|
|
22390
|
+
for (let j = i2 - 1; j >= Math.max(0, i2 - 24); j--) {
|
|
22391
|
+
const line = lines[j];
|
|
22392
|
+
if (!letVarRe(v).test(line)) continue;
|
|
22393
|
+
sawBinding = true;
|
|
22394
|
+
if (envBindRe.test(line)) boundEnv = true;
|
|
22395
|
+
if (httpGetRe.test(line)) boundHttp = true;
|
|
22396
|
+
break;
|
|
22397
|
+
}
|
|
22398
|
+
if (!sawBinding || boundEnv || !boundHttp) {
|
|
22399
|
+
allHttpOnly = false;
|
|
22400
|
+
break;
|
|
22401
|
+
}
|
|
22402
|
+
}
|
|
22403
|
+
if (!allHttpOnly) continue;
|
|
22404
|
+
sanitizers.push({
|
|
22405
|
+
type: "rust_pat_info_http_only_body",
|
|
22406
|
+
method: "format",
|
|
22407
|
+
line: i2 + 1,
|
|
22408
|
+
sanitizes: [
|
|
22409
|
+
"xss",
|
|
22410
|
+
"external_taint_escape",
|
|
22411
|
+
"open_redirect",
|
|
22412
|
+
"log_injection"
|
|
22413
|
+
]
|
|
22414
|
+
});
|
|
22415
|
+
}
|
|
22416
|
+
return sanitizers;
|
|
22417
|
+
}
|
|
22418
|
+
function collectRustConstStrSliceNames(code) {
|
|
22419
|
+
const names = /* @__PURE__ */ new Set();
|
|
22420
|
+
const re = /^\s*const\s+([A-Z][A-Z0-9_]*)\s*:\s*&\s*\[\s*&\s*str\s*\]\s*=\s*&\s*\[([^\]]*)\]\s*;/;
|
|
22421
|
+
for (const line of code.split("\n")) {
|
|
22422
|
+
const m = re.exec(line);
|
|
22423
|
+
if (!m) continue;
|
|
22424
|
+
const inner = m[2].trim();
|
|
22425
|
+
if (!inner) {
|
|
22426
|
+
names.add(m[1]);
|
|
22427
|
+
continue;
|
|
22428
|
+
}
|
|
22429
|
+
const elems = inner.split(",").map((s) => s.trim()).filter(Boolean);
|
|
22430
|
+
if (elems.every((e) => /^"(?:[^"\\]|\\.)*"$/.test(e))) names.add(m[1]);
|
|
22431
|
+
}
|
|
22432
|
+
return names;
|
|
22433
|
+
}
|
|
22434
|
+
function findRustConstSliceMembershipGuardSanitizers(code) {
|
|
22435
|
+
const sanitizers = [];
|
|
22436
|
+
const slices = collectRustConstStrSliceNames(code);
|
|
22437
|
+
if (slices.size === 0) return sanitizers;
|
|
22438
|
+
const lines = code.split("\n");
|
|
22439
|
+
const guardOpen = /^\s*if\s+!\s*([A-Z][A-Z0-9_]*)\s*\.\s*contains\s*\(\s*&\s*([A-Za-z_]\w*)(?:\s*\.\s*as_str\s*\(\s*\))?\s*\)\s*\{?\s*$/;
|
|
22440
|
+
const terminator = /\b(?:return\s+HttpResponse::|return\s+StatusCode::|return\s+Err\s*\(|panic!\s*\()/;
|
|
22441
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
22442
|
+
const m = guardOpen.exec(lines[i2]);
|
|
22443
|
+
if (!m) continue;
|
|
22444
|
+
const sliceName = m[1];
|
|
22445
|
+
const guardedVar = m[2];
|
|
22446
|
+
if (!slices.has(sliceName)) continue;
|
|
22447
|
+
let depth = 0;
|
|
22448
|
+
for (const ch of lines[i2]) {
|
|
22449
|
+
if (ch === "{") depth++;
|
|
22450
|
+
else if (ch === "}") depth--;
|
|
22451
|
+
}
|
|
22452
|
+
let closeLine = i2;
|
|
22453
|
+
let bodyHasTerminator = terminator.test(lines[i2]);
|
|
22454
|
+
if (depth > 0) {
|
|
22455
|
+
for (let j = i2 + 1; j < Math.min(lines.length, i2 + 26); j++) {
|
|
22456
|
+
if (terminator.test(lines[j])) bodyHasTerminator = true;
|
|
22457
|
+
for (const ch of lines[j]) {
|
|
22458
|
+
if (ch === "{") depth++;
|
|
22459
|
+
else if (ch === "}") depth--;
|
|
22460
|
+
}
|
|
22461
|
+
if (depth === 0) {
|
|
22462
|
+
closeLine = j;
|
|
22463
|
+
break;
|
|
22464
|
+
}
|
|
22465
|
+
}
|
|
22466
|
+
}
|
|
22467
|
+
if (!bodyHasTerminator) continue;
|
|
22468
|
+
const varRe = new RegExp(String.raw`\b${guardedVar}\b`);
|
|
22469
|
+
const reassign = new RegExp(String.raw`^\s*(?:let\s+)?(?:mut\s+)?${guardedVar}\s*=(?!=)`);
|
|
22470
|
+
for (let l = closeLine + 2; l <= lines.length; l++) {
|
|
22471
|
+
const lineText = lines[l - 1];
|
|
22472
|
+
if (!lineText || !varRe.test(lineText)) continue;
|
|
22473
|
+
if (reassign.test(lineText)) break;
|
|
22474
|
+
sanitizers.push({
|
|
22475
|
+
type: "rust_const_slice_membership_guard",
|
|
22476
|
+
method: "if",
|
|
22477
|
+
line: l,
|
|
22478
|
+
sanitizes: [
|
|
22479
|
+
"trust_boundary",
|
|
22480
|
+
"external_taint_escape",
|
|
22481
|
+
"xss",
|
|
22482
|
+
"open_redirect",
|
|
22483
|
+
"ssrf",
|
|
22484
|
+
"command_injection"
|
|
22485
|
+
]
|
|
22486
|
+
});
|
|
22487
|
+
}
|
|
22488
|
+
}
|
|
22489
|
+
return sanitizers;
|
|
22490
|
+
}
|
|
21185
22491
|
function findRustSetAllowlistGuardSanitizers(code) {
|
|
21186
22492
|
const sanitizers = [];
|
|
21187
22493
|
const lines = code.split("\n");
|
|
@@ -21338,6 +22644,13 @@ function findJsCsvFormulaPrefixSanitizers(code) {
|
|
|
21338
22644
|
}
|
|
21339
22645
|
return sanitizers;
|
|
21340
22646
|
}
|
|
22647
|
+
function jsWrapperBodyReplaceChainText(body2) {
|
|
22648
|
+
const returnM = /\breturn\s+([^;}\n]+)/.exec(body2);
|
|
22649
|
+
if (returnM) return returnM[1].trim();
|
|
22650
|
+
const arrowM = /=>\s*([^;}\n]+)/.exec(body2);
|
|
22651
|
+
if (arrowM) return arrowM[1].trim();
|
|
22652
|
+
return null;
|
|
22653
|
+
}
|
|
21341
22654
|
function findJsWrapperFunctionSanitizers(code) {
|
|
21342
22655
|
const sanitizers = [];
|
|
21343
22656
|
const lines = code.split("\n");
|
|
@@ -21357,8 +22670,12 @@ function findJsWrapperFunctionSanitizers(code) {
|
|
|
21357
22670
|
kinds.add("external_taint_escape");
|
|
21358
22671
|
}
|
|
21359
22672
|
if (crlfCharClass.test(body2)) {
|
|
21360
|
-
|
|
21361
|
-
|
|
22673
|
+
const chainText = jsWrapperBodyReplaceChainText(body2);
|
|
22674
|
+
const verdict = chainText ? jsReplaceChainVerdict(chainText) : "undecided";
|
|
22675
|
+
if (verdict !== "leaves-crlf") {
|
|
22676
|
+
kinds.add("log_injection");
|
|
22677
|
+
kinds.add("external_taint_escape");
|
|
22678
|
+
}
|
|
21362
22679
|
}
|
|
21363
22680
|
if (kinds.size > 0) wrappers.set(name2, kinds);
|
|
21364
22681
|
}
|
|
@@ -22160,6 +23477,74 @@ function javaBodyStripsCrAndLf(body2) {
|
|
|
22160
23477
|
}
|
|
22161
23478
|
return cr && lf;
|
|
22162
23479
|
}
|
|
23480
|
+
function javaBodyStripsTemplateDelimiters(body2) {
|
|
23481
|
+
let open = false;
|
|
23482
|
+
let close = false;
|
|
23483
|
+
for (const m of body2.matchAll(/\.\s*(replace|replaceAll)\s*\(\s*(?:"((?:\\.|[^"\\])*)"|'(\\.|[^'\\])')/g)) {
|
|
23484
|
+
const lit = m[2] ?? m[3] ?? "";
|
|
23485
|
+
if (lit === "{") open = true;
|
|
23486
|
+
if (lit === "}") close = true;
|
|
23487
|
+
}
|
|
23488
|
+
return open && close;
|
|
23489
|
+
}
|
|
23490
|
+
function findJavaTemplateDelimiterWrapperSanitizers(code) {
|
|
23491
|
+
const sanitizers = [];
|
|
23492
|
+
const lines = code.split("\n");
|
|
23493
|
+
const declRe = /^\s*(?:public|private|protected)?\s*(?:static\s+)?(?:final\s+)?(?:String|CharSequence)\s+([A-Za-z_]\w*)\s*\(/;
|
|
23494
|
+
const bodyWindow = 10;
|
|
23495
|
+
const wrappers = /* @__PURE__ */ new Set();
|
|
23496
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
23497
|
+
const m = declRe.exec(lines[i2]);
|
|
23498
|
+
if (!m) continue;
|
|
23499
|
+
let end = Math.min(lines.length, i2 + bodyWindow);
|
|
23500
|
+
for (let j = i2 + 1; j < end; j++) {
|
|
23501
|
+
if (declRe.test(lines[j])) {
|
|
23502
|
+
end = j;
|
|
23503
|
+
break;
|
|
23504
|
+
}
|
|
23505
|
+
}
|
|
23506
|
+
const body2 = lines.slice(i2, end).join("\n");
|
|
23507
|
+
if (javaBodyStripsTemplateDelimiters(body2)) wrappers.add(m[1]);
|
|
23508
|
+
}
|
|
23509
|
+
if (wrappers.size === 0) return sanitizers;
|
|
23510
|
+
const kinds = ["code_injection", "external_taint_escape"];
|
|
23511
|
+
for (const name2 of wrappers) {
|
|
23512
|
+
const assignedCallRe = new RegExp(
|
|
23513
|
+
`\\b([A-Za-z_][A-Za-z0-9_]*)\\s*=\\s*${name2}\\s*\\(`
|
|
23514
|
+
);
|
|
23515
|
+
const bareCallRe = new RegExp(`\\b${name2}\\s*\\(`);
|
|
23516
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
23517
|
+
if (!bareCallRe.test(lines[i2])) continue;
|
|
23518
|
+
if (declRe.test(lines[i2]) && bareCallRe.test(lines[i2])) continue;
|
|
23519
|
+
sanitizers.push({
|
|
23520
|
+
type: "java_wrapper_template_delim_strip",
|
|
23521
|
+
method: name2,
|
|
23522
|
+
line: i2 + 1,
|
|
23523
|
+
sanitizes: [...kinds]
|
|
23524
|
+
});
|
|
23525
|
+
const am = assignedCallRe.exec(lines[i2]);
|
|
23526
|
+
if (!am) continue;
|
|
23527
|
+
const callIndent = lines[i2].length - lines[i2].trimStart().length;
|
|
23528
|
+
const validated = am[1];
|
|
23529
|
+
const validatedRe = new RegExp(`\\b${validated}\\b`);
|
|
23530
|
+
for (let j = i2 + 1; j < lines.length; j++) {
|
|
23531
|
+
const jline = lines[j];
|
|
23532
|
+
if (jline.trim() === "") continue;
|
|
23533
|
+
const jindent = jline.length - jline.trimStart().length;
|
|
23534
|
+
if (jindent < callIndent) break;
|
|
23535
|
+
if (validatedRe.test(jline)) {
|
|
23536
|
+
sanitizers.push({
|
|
23537
|
+
type: "java_wrapper_template_delim_strip",
|
|
23538
|
+
method: name2,
|
|
23539
|
+
line: j + 1,
|
|
23540
|
+
sanitizes: [...kinds]
|
|
23541
|
+
});
|
|
23542
|
+
}
|
|
23543
|
+
}
|
|
23544
|
+
}
|
|
23545
|
+
}
|
|
23546
|
+
return sanitizers;
|
|
23547
|
+
}
|
|
22163
23548
|
function findCrlfWrapperFunctionSanitizers(code, language) {
|
|
22164
23549
|
const sanitizers = [];
|
|
22165
23550
|
const lines = code.split("\n");
|
|
@@ -24575,6 +25960,79 @@ function findJsLdapInjectionFindings(code, file) {
|
|
|
24575
25960
|
snippet: line.trim()
|
|
24576
25961
|
});
|
|
24577
25962
|
}
|
|
25963
|
+
const positionalSearchRe = /\.\s*search\s*\(\s*(?:'[^']*'|"[^"]*")\s*,\s*([^,{]+)/;
|
|
25964
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
25965
|
+
const line = lines[i2];
|
|
25966
|
+
const pm = line.match(positionalSearchRe);
|
|
25967
|
+
if (!pm) continue;
|
|
25968
|
+
const expr = pm[1].trim();
|
|
25969
|
+
if (expr.startsWith("{")) continue;
|
|
25970
|
+
let tainted = false;
|
|
25971
|
+
for (const v of taintedVars) {
|
|
25972
|
+
if (new RegExp(`\\b${v}\\b`).test(expr)) {
|
|
25973
|
+
tainted = true;
|
|
25974
|
+
break;
|
|
25975
|
+
}
|
|
25976
|
+
}
|
|
25977
|
+
if (!tainted) continue;
|
|
25978
|
+
const lineNo = i2 + 1;
|
|
25979
|
+
if (seen.has(lineNo)) continue;
|
|
25980
|
+
seen.add(lineNo);
|
|
25981
|
+
findings.push({
|
|
25982
|
+
id: `ldap_injection-${file}-${lineNo}-js-ldap-positional-filter`,
|
|
25983
|
+
pass: "language-sources",
|
|
25984
|
+
category: "security",
|
|
25985
|
+
rule_id: "ldap_injection",
|
|
25986
|
+
cwe: "CWE-90",
|
|
25987
|
+
severity: "critical",
|
|
25988
|
+
level: "error",
|
|
25989
|
+
message: "LDAP injection: ldapjs/ldapts `client.search(base, <tainted-filter>, ...)` lets the attacker break out of the filter expression. Escape user input or use a structured filter builder.",
|
|
25990
|
+
file,
|
|
25991
|
+
line: lineNo,
|
|
25992
|
+
snippet: line.trim()
|
|
25993
|
+
});
|
|
25994
|
+
}
|
|
25995
|
+
return findings;
|
|
25996
|
+
}
|
|
25997
|
+
function findJsZipHeaderFailopenFindings(code, file) {
|
|
25998
|
+
const findings = [];
|
|
25999
|
+
if (typeof code !== "string" || code.length === 0) return findings;
|
|
26000
|
+
const lines = code.split("\n");
|
|
26001
|
+
const hasPkLocalSig = lines.some((l) => {
|
|
26002
|
+
const t = l.trim();
|
|
26003
|
+
if (t.startsWith("//")) return false;
|
|
26004
|
+
return /0x50/.test(t) && /0x4[bB]/.test(t) && /0x03/.test(t) && /0x04/.test(t);
|
|
26005
|
+
});
|
|
26006
|
+
if (!hasPkLocalSig) return findings;
|
|
26007
|
+
const seen = /* @__PURE__ */ new Set();
|
|
26008
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
26009
|
+
const trimmed = lines[i2].trim();
|
|
26010
|
+
if (trimmed.startsWith("//")) continue;
|
|
26011
|
+
const failBranch = trimmed.match(/^if\s*\(\s*!(\w+)\s*\)\s*(.+)$/);
|
|
26012
|
+
if (!failBranch) continue;
|
|
26013
|
+
const tail = failBranch[2];
|
|
26014
|
+
if (/\bthrow\b/.test(tail)) continue;
|
|
26015
|
+
if (!/\breturn\b/.test(tail)) continue;
|
|
26016
|
+
if (!/\.(subarray|slice)\s*\(/.test(tail) && !/Buffer\.from\s*\(/.test(tail)) {
|
|
26017
|
+
continue;
|
|
26018
|
+
}
|
|
26019
|
+
const lineNo = i2 + 1;
|
|
26020
|
+
if (seen.has(lineNo)) continue;
|
|
26021
|
+
seen.add(lineNo);
|
|
26022
|
+
findings.push({
|
|
26023
|
+
id: `input_validation-${file}-${lineNo}-js-zip-header-failopen`,
|
|
26024
|
+
pass: "language-sources",
|
|
26025
|
+
category: "security",
|
|
26026
|
+
rule_id: "input_validation",
|
|
26027
|
+
cwe: "CWE-20",
|
|
26028
|
+
severity: "high",
|
|
26029
|
+
level: "error",
|
|
26030
|
+
message: "Input validation fail-open: an invalid ZIP local header check still returns a slice of the caller-controlled buffer. On parse failure, throw or return empty \u2014 do not pass through untrusted bytes.",
|
|
26031
|
+
file,
|
|
26032
|
+
line: lineNo,
|
|
26033
|
+
snippet: trimmed.substring(0, 120)
|
|
26034
|
+
});
|
|
26035
|
+
}
|
|
24578
26036
|
return findings;
|
|
24579
26037
|
}
|
|
24580
26038
|
function findGoLdapInjectionFindings(code, file) {
|
|
@@ -25077,6 +26535,40 @@ function findGoGobDeserializationFindings(code, file) {
|
|
|
25077
26535
|
}
|
|
25078
26536
|
return findings;
|
|
25079
26537
|
}
|
|
26538
|
+
function maskJsLiteralsAndComments(code) {
|
|
26539
|
+
const out2 = code.split("");
|
|
26540
|
+
let i2 = 0;
|
|
26541
|
+
const blank = (from, to) => {
|
|
26542
|
+
for (let k = from; k < to; k++) if (out2[k] !== "\n") out2[k] = " ";
|
|
26543
|
+
};
|
|
26544
|
+
while (i2 < code.length) {
|
|
26545
|
+
const c = code[i2];
|
|
26546
|
+
const n = code[i2 + 1];
|
|
26547
|
+
if (c === "/" && n === "/") {
|
|
26548
|
+
let j = i2;
|
|
26549
|
+
while (j < code.length && code[j] !== "\n") j++;
|
|
26550
|
+
blank(i2, j);
|
|
26551
|
+
i2 = j;
|
|
26552
|
+
} else if (c === "/" && n === "*") {
|
|
26553
|
+
const end = code.indexOf("*/", i2 + 2);
|
|
26554
|
+
const j = end < 0 ? code.length : end + 2;
|
|
26555
|
+
blank(i2, j);
|
|
26556
|
+
i2 = j;
|
|
26557
|
+
} else if (c === '"' || c === "'" || c === "`") {
|
|
26558
|
+
let j = i2 + 1;
|
|
26559
|
+
while (j < code.length && code[j] !== c) {
|
|
26560
|
+
if (code[j] === "\\") j++;
|
|
26561
|
+
else if (c !== "`" && code[j] === "\n") break;
|
|
26562
|
+
j++;
|
|
26563
|
+
}
|
|
26564
|
+
blank(i2 + 1, Math.min(j, code.length));
|
|
26565
|
+
i2 = j + 1;
|
|
26566
|
+
} else {
|
|
26567
|
+
i2++;
|
|
26568
|
+
}
|
|
26569
|
+
}
|
|
26570
|
+
return out2.join("");
|
|
26571
|
+
}
|
|
25080
26572
|
function findJsJsonParseBodyFindings(code, file) {
|
|
25081
26573
|
const findings = [];
|
|
25082
26574
|
if (typeof code !== "string" || code.length === 0) return findings;
|
|
@@ -25110,12 +26602,13 @@ function findJsJsonParseBodyFindings(code, file) {
|
|
|
25110
26602
|
}
|
|
25111
26603
|
const callRe = /\bJSON\s*\.\s*parse\s*\(\s*([^)]+?)\s*\)/g;
|
|
25112
26604
|
const seen = /* @__PURE__ */ new Set();
|
|
26605
|
+
const codeLines = maskJsLiteralsAndComments(code).split("\n");
|
|
25113
26606
|
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
25114
26607
|
const line = lines[i2];
|
|
25115
|
-
|
|
26608
|
+
const codeLine = codeLines[i2] ?? "";
|
|
25116
26609
|
callRe.lastIndex = 0;
|
|
25117
26610
|
let m;
|
|
25118
|
-
while ((m = callRe.exec(
|
|
26611
|
+
while ((m = callRe.exec(codeLine)) !== null) {
|
|
25119
26612
|
const arg = m[1];
|
|
25120
26613
|
let tainted = reqBodyRe.test(arg);
|
|
25121
26614
|
if (!tainted) {
|
|
@@ -25535,198 +27028,6 @@ function findJavaSpringReturnXSSSinks(code, types, sources, xssSanitizerLines) {
|
|
|
25535
27028
|
return out2;
|
|
25536
27029
|
}
|
|
25537
27030
|
|
|
25538
|
-
// src/analysis/js-crlf-strip.ts
|
|
25539
|
-
var MAX_PATTERN_LENGTH = 200;
|
|
25540
|
-
var NEUTRAL_AFTER_REPLACE = /* @__PURE__ */ new Set([
|
|
25541
|
-
"replace",
|
|
25542
|
-
"replaceAll",
|
|
25543
|
-
"trim",
|
|
25544
|
-
"trimStart",
|
|
25545
|
-
"trimEnd",
|
|
25546
|
-
"toString",
|
|
25547
|
-
"toLowerCase",
|
|
25548
|
-
"toUpperCase",
|
|
25549
|
-
"slice",
|
|
25550
|
-
"substring"
|
|
25551
|
-
]);
|
|
25552
|
-
var PROBE = "a\r\rb\n\nc\r\nd\n\re x ";
|
|
25553
|
-
function readQuoted(s, i2) {
|
|
25554
|
-
const q = s[i2];
|
|
25555
|
-
if (q !== '"' && q !== "'" && q !== "`") return null;
|
|
25556
|
-
let out2 = "";
|
|
25557
|
-
for (let j = i2 + 1; j < s.length; j++) {
|
|
25558
|
-
const c = s[j];
|
|
25559
|
-
if (c === q) return { value: out2, end: j + 1 };
|
|
25560
|
-
if (q === "`" && c === "$" && s[j + 1] === "{") return null;
|
|
25561
|
-
if (c === "\\") {
|
|
25562
|
-
const n = s[j + 1];
|
|
25563
|
-
if (n === void 0) return null;
|
|
25564
|
-
switch (n) {
|
|
25565
|
-
case "n":
|
|
25566
|
-
out2 += "\n";
|
|
25567
|
-
j++;
|
|
25568
|
-
continue;
|
|
25569
|
-
case "r":
|
|
25570
|
-
out2 += "\r";
|
|
25571
|
-
j++;
|
|
25572
|
-
continue;
|
|
25573
|
-
case "t":
|
|
25574
|
-
out2 += " ";
|
|
25575
|
-
j++;
|
|
25576
|
-
continue;
|
|
25577
|
-
case "0":
|
|
25578
|
-
out2 += "\0";
|
|
25579
|
-
j++;
|
|
25580
|
-
continue;
|
|
25581
|
-
case "x": {
|
|
25582
|
-
const h = /^[0-9a-fA-F]{2}/.exec(s.slice(j + 2, j + 4));
|
|
25583
|
-
if (!h) return null;
|
|
25584
|
-
out2 += String.fromCharCode(parseInt(h[0], 16));
|
|
25585
|
-
j += 3;
|
|
25586
|
-
continue;
|
|
25587
|
-
}
|
|
25588
|
-
case "u": {
|
|
25589
|
-
const h = /^[0-9a-fA-F]{4}/.exec(s.slice(j + 2, j + 6));
|
|
25590
|
-
if (!h) return null;
|
|
25591
|
-
out2 += String.fromCharCode(parseInt(h[0], 16));
|
|
25592
|
-
j += 5;
|
|
25593
|
-
continue;
|
|
25594
|
-
}
|
|
25595
|
-
default:
|
|
25596
|
-
out2 += n;
|
|
25597
|
-
j++;
|
|
25598
|
-
continue;
|
|
25599
|
-
}
|
|
25600
|
-
}
|
|
25601
|
-
if (c === "\n" && q !== "`") return null;
|
|
25602
|
-
out2 += c;
|
|
25603
|
-
}
|
|
25604
|
-
return null;
|
|
25605
|
-
}
|
|
25606
|
-
function readRegexLiteral(s, i2) {
|
|
25607
|
-
if (s[i2] !== "/") return null;
|
|
25608
|
-
let inClass = false;
|
|
25609
|
-
for (let j = i2 + 1; j < s.length; j++) {
|
|
25610
|
-
const c = s[j];
|
|
25611
|
-
if (c === "\n") return null;
|
|
25612
|
-
if (c === "\\") {
|
|
25613
|
-
j++;
|
|
25614
|
-
continue;
|
|
25615
|
-
}
|
|
25616
|
-
if (inClass) {
|
|
25617
|
-
if (c === "]") inClass = false;
|
|
25618
|
-
continue;
|
|
25619
|
-
}
|
|
25620
|
-
if (c === "[") {
|
|
25621
|
-
inClass = true;
|
|
25622
|
-
continue;
|
|
25623
|
-
}
|
|
25624
|
-
if (c === "/") {
|
|
25625
|
-
const flags2 = /^[dgimsuvy]*/.exec(s.slice(j + 1))[0];
|
|
25626
|
-
return { source: s.slice(i2 + 1, j), flags: flags2, end: j + 1 + flags2.length };
|
|
25627
|
-
}
|
|
25628
|
-
}
|
|
25629
|
-
return null;
|
|
25630
|
-
}
|
|
25631
|
-
var skipWs = (s, i2) => {
|
|
25632
|
-
while (i2 < s.length && /\s/.test(s[i2])) i2++;
|
|
25633
|
-
return i2;
|
|
25634
|
-
};
|
|
25635
|
-
function parseSteps(chainText) {
|
|
25636
|
-
const steps = [];
|
|
25637
|
-
const callRe = /\.\s*(replaceAll|replace)\s*\(/g;
|
|
25638
|
-
let m;
|
|
25639
|
-
while ((m = callRe.exec(chainText)) !== null) {
|
|
25640
|
-
const kind = m[1];
|
|
25641
|
-
let i2 = skipWs(chainText, m.index + m[0].length);
|
|
25642
|
-
let pattern;
|
|
25643
|
-
const rx = readRegexLiteral(chainText, i2);
|
|
25644
|
-
if (rx) {
|
|
25645
|
-
if (rx.source.length > MAX_PATTERN_LENGTH) return null;
|
|
25646
|
-
try {
|
|
25647
|
-
pattern = new RegExp(rx.source, rx.flags);
|
|
25648
|
-
} catch {
|
|
25649
|
-
return null;
|
|
25650
|
-
}
|
|
25651
|
-
i2 = rx.end;
|
|
25652
|
-
} else {
|
|
25653
|
-
const str = readQuoted(chainText, i2);
|
|
25654
|
-
if (!str) return null;
|
|
25655
|
-
pattern = str.value;
|
|
25656
|
-
i2 = str.end;
|
|
25657
|
-
}
|
|
25658
|
-
i2 = skipWs(chainText, i2);
|
|
25659
|
-
if (chainText[i2] !== ",") return null;
|
|
25660
|
-
i2 = skipWs(chainText, i2 + 1);
|
|
25661
|
-
const rep = readQuoted(chainText, i2);
|
|
25662
|
-
if (!rep) return null;
|
|
25663
|
-
i2 = skipWs(chainText, rep.end);
|
|
25664
|
-
if (chainText[i2] !== ")") return null;
|
|
25665
|
-
steps.push({ kind, pattern, replacement: rep.value });
|
|
25666
|
-
callRe.lastIndex = i2 + 1;
|
|
25667
|
-
}
|
|
25668
|
-
return steps;
|
|
25669
|
-
}
|
|
25670
|
-
function run2(steps, input) {
|
|
25671
|
-
let s = input;
|
|
25672
|
-
try {
|
|
25673
|
-
for (const st of steps) {
|
|
25674
|
-
if (st.kind === "replaceAll" && st.pattern instanceof RegExp && !st.pattern.global) return null;
|
|
25675
|
-
s = st.kind === "replaceAll" ? s.replaceAll(st.pattern, st.replacement) : s.replace(st.pattern, st.replacement);
|
|
25676
|
-
}
|
|
25677
|
-
} catch {
|
|
25678
|
-
return null;
|
|
25679
|
-
}
|
|
25680
|
-
return s;
|
|
25681
|
-
}
|
|
25682
|
-
function jsReplaceChainVerdict(chainText) {
|
|
25683
|
-
const steps = parseSteps(chainText);
|
|
25684
|
-
if (!steps || steps.length === 0) return "undecided";
|
|
25685
|
-
const first = chainText.search(/\.\s*(?:replaceAll|replace)\s*\(/);
|
|
25686
|
-
for (const seg of chainText.slice(first + 1).matchAll(/\.\s*([A-Za-z_$][\w$]*)\s*\(/g)) {
|
|
25687
|
-
if (!NEUTRAL_AFTER_REPLACE.has(seg[1])) return "undecided";
|
|
25688
|
-
}
|
|
25689
|
-
const out2 = run2(steps, PROBE);
|
|
25690
|
-
if (out2 === null) return "undecided";
|
|
25691
|
-
return out2.includes("\r") || out2.includes("\n") ? "leaves-crlf" : "strips-crlf";
|
|
25692
|
-
}
|
|
25693
|
-
function jsChainTextAt(sourceLines, line, column) {
|
|
25694
|
-
const text = [(sourceLines[line - 1] ?? "").slice(column), ...sourceLines.slice(line, line + 7)].join("\n");
|
|
25695
|
-
let depth = 0;
|
|
25696
|
-
let prevSig = "";
|
|
25697
|
-
let i2 = 0;
|
|
25698
|
-
for (; i2 < text.length; i2++) {
|
|
25699
|
-
const c = text[i2];
|
|
25700
|
-
if (c === '"' || c === "'" || c === "`") {
|
|
25701
|
-
for (i2++; i2 < text.length && text[i2] !== c; i2++) if (text[i2] === "\\") i2++;
|
|
25702
|
-
prevSig = c;
|
|
25703
|
-
continue;
|
|
25704
|
-
}
|
|
25705
|
-
if (c === "/" && depth > 0 && (prevSig === "(" || prevSig === ",")) {
|
|
25706
|
-
const rx = readRegexLiteral(text, i2);
|
|
25707
|
-
if (rx) {
|
|
25708
|
-
i2 = rx.end - 1;
|
|
25709
|
-
prevSig = "/";
|
|
25710
|
-
continue;
|
|
25711
|
-
}
|
|
25712
|
-
}
|
|
25713
|
-
if (c === "(" || c === "[" || c === "{") {
|
|
25714
|
-
depth++;
|
|
25715
|
-
prevSig = c;
|
|
25716
|
-
continue;
|
|
25717
|
-
}
|
|
25718
|
-
if (c === ")" || c === "]" || c === "}") {
|
|
25719
|
-
if (depth === 0) break;
|
|
25720
|
-
depth--;
|
|
25721
|
-
prevSig = c;
|
|
25722
|
-
continue;
|
|
25723
|
-
}
|
|
25724
|
-
if (depth === 0 && !/[\w$.\s]/.test(c)) break;
|
|
25725
|
-
if (!/\s/.test(c)) prevSig = c;
|
|
25726
|
-
}
|
|
25727
|
-
return text.slice(0, i2);
|
|
25728
|
-
}
|
|
25729
|
-
|
|
25730
27031
|
// src/analysis/constant-propagation/patterns.ts
|
|
25731
27032
|
var TAINT_PATTERNS = [
|
|
25732
27033
|
// HTTP Sources (Servlet API)
|
|
@@ -26124,13 +27425,35 @@ function dropCSharpObjectCarriedWaypoints(sinks, calls) {
|
|
|
26124
27425
|
function analyzeTaint(calls, types, config = getDefaultConfig(), typeHierarchy, language, code, imports) {
|
|
26125
27426
|
const sourceLines = code !== void 0 ? code.split("\n") : void 0;
|
|
26126
27427
|
const sources = findSources(calls, types, config.sources, sourceLines, language, imports);
|
|
26127
|
-
let sinkPatterns =
|
|
27428
|
+
let sinkPatterns = config.sinks.filter((p) => sinkPatternImportApplies(p, imports));
|
|
27429
|
+
sinkPatterns = expandPromisifyAliases(sinkPatterns, sourceLines, language);
|
|
26128
27430
|
sinkPatterns = expandIndirectEvalAliases(sinkPatterns, sourceLines, language);
|
|
26129
27431
|
const sinks = findSinks(calls, sinkPatterns, typeHierarchy, language, sourceLines, types);
|
|
26130
27432
|
const gatedSinks = language === "csharp" ? dropCSharpObjectCarriedWaypoints(sinks, calls) : sinks;
|
|
26131
27433
|
const sanitizers = findSanitizers(calls, types, config.sanitizers, sourceLines, language);
|
|
26132
27434
|
return { sources, sinks: gatedSinks, sanitizers };
|
|
26133
27435
|
}
|
|
27436
|
+
function isBoundParameterCall(call, pattern, sourceLines) {
|
|
27437
|
+
if (!pattern.requires_import || pattern.type !== "sql_injection") return false;
|
|
27438
|
+
const first = call.arguments[0]?.expression?.trim() ?? "";
|
|
27439
|
+
if (first.startsWith("[") || first.startsWith("{")) return true;
|
|
27440
|
+
const receiver = call.receiver;
|
|
27441
|
+
if (!receiver || !sourceLines || !/^[A-Za-z_$][\w$]*$/.test(receiver)) return false;
|
|
27442
|
+
const assignedFromPrepare = new RegExp(
|
|
27443
|
+
`\\b${receiver.replace(/\$/g, "\\$")}\\s*(?::[^=]+)?=\\s*(?:await\\s+)?[\\w$.]+\\.prepare\\s*\\(`
|
|
27444
|
+
);
|
|
27445
|
+
return sourceLines.some((line) => assignedFromPrepare.test(line));
|
|
27446
|
+
}
|
|
27447
|
+
function sinkPatternImportApplies(pattern, imports) {
|
|
27448
|
+
const required = pattern.requires_import;
|
|
27449
|
+
if (!required || required.length === 0) return true;
|
|
27450
|
+
if (!imports || imports.length === 0) return false;
|
|
27451
|
+
return imports.some((imp) => {
|
|
27452
|
+
const from = imp.from_package;
|
|
27453
|
+
if (!from) return false;
|
|
27454
|
+
return required.some((m) => from === m || from.startsWith(m + "/"));
|
|
27455
|
+
});
|
|
27456
|
+
}
|
|
26134
27457
|
function sinkPatternAppliesTo(pattern, language) {
|
|
26135
27458
|
if (language === void 0) return true;
|
|
26136
27459
|
if (pattern.languages && pattern.languages.length > 0 && !pattern.languages.includes(language)) {
|
|
@@ -26356,7 +27679,14 @@ function findSources(calls, types, patterns, sourceLines, language, imports) {
|
|
|
26356
27679
|
}
|
|
26357
27680
|
const propertyPatterns = patterns.filter((p) => p.property && p.object && p.property_tainted);
|
|
26358
27681
|
const hasPropertyPatterns = propertyPatterns.length > 0;
|
|
27682
|
+
const jsCode = (language === "javascript" || language === "typescript") && sourceLines ? sourceLines.join("\n") : void 0;
|
|
27683
|
+
const noParamHelper = /* @__PURE__ */ new Map();
|
|
26359
27684
|
for (const call of calls) {
|
|
27685
|
+
if (jsCode !== void 0 && !call.receiver) {
|
|
27686
|
+
let drop = noParamHelper.get(call.method_name);
|
|
27687
|
+
if (drop === void 0) noParamHelper.set(call.method_name, drop = jsHelperReturnsNoParam(jsCode, call.method_name));
|
|
27688
|
+
if (drop) continue;
|
|
27689
|
+
}
|
|
26360
27690
|
for (const arg of call.arguments) {
|
|
26361
27691
|
if (arg.expression) {
|
|
26362
27692
|
const taintCheck = isJavaScriptTaintedArgument(arg.expression, hasPropertyPatterns ? patterns : void 0);
|
|
@@ -26548,6 +27878,46 @@ function isInterproceduralTaintableType(typeName, language) {
|
|
|
26548
27878
|
const leaf = baseType.split(".").pop() ?? baseType;
|
|
26549
27879
|
if (csharpTaintable.includes(baseType) || csharpTaintable.includes(leaf)) return true;
|
|
26550
27880
|
}
|
|
27881
|
+
if (language === "rust") {
|
|
27882
|
+
const trimmed = typeName.trim();
|
|
27883
|
+
const unref = trimmed.replace(/^&mut\s+/, "").replace(/^&\s*/, "");
|
|
27884
|
+
const rustBase = unref.split("<")[0].trim();
|
|
27885
|
+
const rustScalars = [
|
|
27886
|
+
"String",
|
|
27887
|
+
"str",
|
|
27888
|
+
"bool",
|
|
27889
|
+
"char",
|
|
27890
|
+
"i8",
|
|
27891
|
+
"i16",
|
|
27892
|
+
"i32",
|
|
27893
|
+
"i64",
|
|
27894
|
+
"i128",
|
|
27895
|
+
"isize",
|
|
27896
|
+
"u8",
|
|
27897
|
+
"u16",
|
|
27898
|
+
"u32",
|
|
27899
|
+
"u64",
|
|
27900
|
+
"u128",
|
|
27901
|
+
"usize",
|
|
27902
|
+
"f32",
|
|
27903
|
+
"f64"
|
|
27904
|
+
];
|
|
27905
|
+
if (rustScalars.includes(rustBase)) return true;
|
|
27906
|
+
if (rustBase === "()" || rustBase === "!") return false;
|
|
27907
|
+
if (unref.startsWith("Vec<") || unref.startsWith("Option<") || unref.startsWith("Result<")) {
|
|
27908
|
+
return true;
|
|
27909
|
+
}
|
|
27910
|
+
if (/^[A-Z][A-Za-z0-9_]*$/.test(rustBase)) return true;
|
|
27911
|
+
}
|
|
27912
|
+
if (language === "javascript" || language === "typescript") {
|
|
27913
|
+
const trimmed = typeName.trim();
|
|
27914
|
+
const jsScalars = ["string", "number", "boolean", "bigint", "any", "unknown", "object"];
|
|
27915
|
+
if (jsScalars.includes(baseType)) return true;
|
|
27916
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[") || trimmed.startsWith("(")) return true;
|
|
27917
|
+
if (/\bRecord\s*</.test(trimmed)) return true;
|
|
27918
|
+
if (["void", "undefined", "null", "never"].includes(baseType)) return false;
|
|
27919
|
+
if (/^[A-Za-z_][\w.$]*$/.test(baseType)) return true;
|
|
27920
|
+
}
|
|
26551
27921
|
if (typeName.endsWith("[]")) {
|
|
26552
27922
|
const elementType = typeName.slice(0, -2);
|
|
26553
27923
|
if (elementType === "String" || elementType === "Object" || elementType === "byte") {
|
|
@@ -26662,6 +28032,31 @@ function isSafeGoExecCommandCall(call, pattern, language) {
|
|
|
26662
28032
|
return false;
|
|
26663
28033
|
}
|
|
26664
28034
|
}
|
|
28035
|
+
if (program === "git") {
|
|
28036
|
+
const subcommandArgPos = pattern.method === "CommandContext" ? 2 : 1;
|
|
28037
|
+
const subcommandArg = call.arguments.find((a) => a.position === subcommandArgPos);
|
|
28038
|
+
let subcommand;
|
|
28039
|
+
if (subcommandArg?.literal !== null && subcommandArg?.literal !== void 0) {
|
|
28040
|
+
subcommand = String(subcommandArg.literal);
|
|
28041
|
+
} else {
|
|
28042
|
+
const expr = (subcommandArg?.expression ?? "").trim();
|
|
28043
|
+
if (expr.startsWith('"') || expr.startsWith("`") || expr.startsWith("'")) {
|
|
28044
|
+
subcommand = expr.slice(1, -1);
|
|
28045
|
+
}
|
|
28046
|
+
}
|
|
28047
|
+
if (subcommand === "ls-remote") {
|
|
28048
|
+
const hasEndOfOptions = call.arguments.some((a) => {
|
|
28049
|
+
if (a.literal !== null && a.literal !== void 0) {
|
|
28050
|
+
return String(a.literal) === "--";
|
|
28051
|
+
}
|
|
28052
|
+
const expr = (a.expression ?? "").trim();
|
|
28053
|
+
return expr === '"--"' || expr === "'--'" || expr === "`--`";
|
|
28054
|
+
});
|
|
28055
|
+
if (!hasEndOfOptions) {
|
|
28056
|
+
return false;
|
|
28057
|
+
}
|
|
28058
|
+
}
|
|
28059
|
+
}
|
|
26665
28060
|
return true;
|
|
26666
28061
|
}
|
|
26667
28062
|
function isSafeJSChildProcessCall(call, pattern, language) {
|
|
@@ -27062,8 +28457,52 @@ function isRegexReceiver(receiver, sourceLines) {
|
|
|
27062
28457
|
if (r.startsWith("/") && /\/[a-z]*$/.test(r)) return true;
|
|
27063
28458
|
if (/^(?:new\s+)?RegExp\s*\(/.test(r)) return true;
|
|
27064
28459
|
if (!/^[A-Za-z_$][\w$]*$/.test(r) || !sourceLines) return false;
|
|
27065
|
-
const
|
|
27066
|
-
|
|
28460
|
+
const n = escapeRe(r);
|
|
28461
|
+
const decl = new RegExp(`(?:const|let|var)\\s+${n}\\s*(?::\\s*RegExp\\s*)?=\\s*(?:/|(?:new\\s+)?RegExp\\s*\\()`);
|
|
28462
|
+
if (sourceLines.some((l) => decl.test(l))) return true;
|
|
28463
|
+
const wrapped = new RegExp(`(?:const|let|var)\\s+${n}\\s*(?::\\s*RegExp\\s*)?=\\s*$`);
|
|
28464
|
+
const typed = new RegExp(`\\b${n}\\s*[?!]?\\s*:\\s*RegExp\\b`);
|
|
28465
|
+
return sourceLines.some((l, i2) => typed.test(l) || wrapped.test(l) && /^\s*(?:\/|(?:new\s+)?RegExp\s*\()/.test(sourceLines[i2 + 1] ?? ""));
|
|
28466
|
+
}
|
|
28467
|
+
var DB_TYPE_NAME = /(?:connection|database|\bdb\b|db$|^db|pool|client|knex|sql|statement|prisma|sequelize|repository|transaction|query|store)/i;
|
|
28468
|
+
function isTypedNonDbReceiver(receiver, sourceLines) {
|
|
28469
|
+
const raw = (receiver ?? "").trim();
|
|
28470
|
+
if (!raw || !sourceLines) return false;
|
|
28471
|
+
const lastDot = raw.lastIndexOf(".");
|
|
28472
|
+
const name2 = (lastDot >= 0 ? raw.slice(lastDot + 1) : raw).trim();
|
|
28473
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(name2) || DB_TYPE_NAME.test(name2)) return false;
|
|
28474
|
+
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*[;,)=]`);
|
|
28475
|
+
let typed;
|
|
28476
|
+
for (const l of sourceLines) {
|
|
28477
|
+
const m = decl.exec(l);
|
|
28478
|
+
if (!m) continue;
|
|
28479
|
+
if (typed !== void 0 && typed !== m[1]) return false;
|
|
28480
|
+
typed = m[1];
|
|
28481
|
+
}
|
|
28482
|
+
return typed !== void 0 && !DB_TYPE_NAME.test(typed) && !/^(?:any|unknown|object)$/.test(typed);
|
|
28483
|
+
}
|
|
28484
|
+
function isNavigationReceiverName(receiver) {
|
|
28485
|
+
const r = (receiver ?? "").trim();
|
|
28486
|
+
if (!r) return false;
|
|
28487
|
+
const last = r.slice(r.lastIndexOf(".") + 1).replace(/\(\)$/, "");
|
|
28488
|
+
return /router|history|navigat|^nav$/i.test(last);
|
|
28489
|
+
}
|
|
28490
|
+
function isInMemoryMapGetReceiver(receiver, sourceLines) {
|
|
28491
|
+
const raw = (receiver ?? "").trim();
|
|
28492
|
+
if (!raw || !sourceLines) return false;
|
|
28493
|
+
if (/\.properties$/i.test(raw)) return true;
|
|
28494
|
+
const lastDot = raw.lastIndexOf(".");
|
|
28495
|
+
const r = (lastDot >= 0 ? raw.slice(lastDot + 1) : raw).trim();
|
|
28496
|
+
if (/^(properties|memoryCache)$/i.test(r)) return true;
|
|
28497
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(r)) return false;
|
|
28498
|
+
const n = escapeRe(r);
|
|
28499
|
+
const mapCtor = new RegExp(
|
|
28500
|
+
`\\b${n}\\s*(?::[^=;]*)?=\\s*new\\s+(?:Weak)?Map\\s*(?:<.*>)?\\s*\\(`
|
|
28501
|
+
);
|
|
28502
|
+
const mapType = new RegExp(
|
|
28503
|
+
`\\b${n}\\s*\\??\\s*:\\s*(?:Readonly)?(?:Weak)?Map\\s*<`
|
|
28504
|
+
);
|
|
28505
|
+
return sourceLines.some((l) => mapCtor.test(l) || mapType.test(l));
|
|
27067
28506
|
}
|
|
27068
28507
|
function isDeclaredFunctionReference(arg, sourceLines) {
|
|
27069
28508
|
if (arg.literal !== null && arg.literal !== void 0) return false;
|
|
@@ -27077,7 +28516,10 @@ function isDeclaredFunctionReference(arg, sourceLines) {
|
|
|
27077
28516
|
// const connect = () => / function / async () =>
|
|
27078
28517
|
new RegExp(
|
|
27079
28518
|
`\\b(?:const|let|var)\\s+${n}\\s*=\\s*(?:async\\s+)?(?:function\\b|\\(|[A-Za-z_$][\\w$]*\\s*=>)`
|
|
27080
|
-
)
|
|
28519
|
+
),
|
|
28520
|
+
// A Promise executor's resolve / reject: `new Promise((r) => setTimeout(r, ms))`,
|
|
28521
|
+
// the sleep idiom (dogfood 2026-10-31, controldeck harness).
|
|
28522
|
+
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*[,)])`)
|
|
27081
28523
|
];
|
|
27082
28524
|
return sourceLines.some((l) => decls.some((re) => re.test(l)));
|
|
27083
28525
|
}
|
|
@@ -27269,6 +28711,12 @@ function findSinks(calls, patterns, typeHierarchy, language, sourceLines, types)
|
|
|
27269
28711
|
if (isParameterizedQueryCall(call, pattern)) {
|
|
27270
28712
|
continue;
|
|
27271
28713
|
}
|
|
28714
|
+
if ((language === "javascript" || language === "typescript") && (pattern.type === "sql_injection" || pattern.type === "nosql_injection") && call.arguments.length === 0 && pattern.arg_positions.every((p) => p >= 0)) {
|
|
28715
|
+
continue;
|
|
28716
|
+
}
|
|
28717
|
+
if (isBoundParameterCall(call, pattern, sourceLines)) {
|
|
28718
|
+
continue;
|
|
28719
|
+
}
|
|
27272
28720
|
if (isSafePythonSubprocessCall(call, pattern, language)) {
|
|
27273
28721
|
continue;
|
|
27274
28722
|
}
|
|
@@ -27326,9 +28774,18 @@ function findSinks(calls, patterns, typeHierarchy, language, sourceLines, types)
|
|
|
27326
28774
|
if (isArgumentlessJsResponseWriter(call, pattern, language)) {
|
|
27327
28775
|
continue;
|
|
27328
28776
|
}
|
|
28777
|
+
if (pattern.type === "open_redirect" && (language === "javascript" || language === "typescript") && (call.method_name === "push" || call.method_name === "replace") && (pattern.class ?? "").toLowerCase() === "router" && !call.receiver_type && !call.receiver_type_fqn && !isNavigationReceiverName(call.receiver)) {
|
|
28778
|
+
continue;
|
|
28779
|
+
}
|
|
27329
28780
|
if ((pattern.type === "command_injection" || pattern.type === "sql_injection") && call.method_name === "exec" && (language === "javascript" || language === "typescript") && isRegexReceiver(call.receiver, sourceLines)) {
|
|
27330
28781
|
continue;
|
|
27331
28782
|
}
|
|
28783
|
+
if (pattern.type === "sql_injection" && call.method_name === "get" && pattern.class === "Connection" && (language === "javascript" || language === "typescript") && (isInMemoryMapGetReceiver(call.receiver, sourceLines) || isTypedNonDbReceiver(call.receiver, sourceLines))) {
|
|
28784
|
+
continue;
|
|
28785
|
+
}
|
|
28786
|
+
if (call.method_name === "get" && (language === "javascript" || language === "typescript") && isInMemoryMapGetReceiver(call.receiver, sourceLines)) {
|
|
28787
|
+
continue;
|
|
28788
|
+
}
|
|
27332
28789
|
if (pattern.type === "code_injection" && language === "python" && call.method_name === "compile" && call.receiver && call.receiver !== "builtins") {
|
|
27333
28790
|
continue;
|
|
27334
28791
|
}
|
|
@@ -27345,7 +28802,7 @@ function findSinks(calls, patterns, typeHierarchy, language, sourceLines, types)
|
|
|
27345
28802
|
continue;
|
|
27346
28803
|
}
|
|
27347
28804
|
const location = formatCallLocation(call);
|
|
27348
|
-
const key = `${location}:${call.location.line}:${pattern.cwe}`;
|
|
28805
|
+
const key = `${location}:${call.location.line}:${call.location.column}:${pattern.cwe}`;
|
|
27349
28806
|
const confidence = calculateSinkConfidence(call, pattern);
|
|
27350
28807
|
const existing = sinkMap.get(key);
|
|
27351
28808
|
if (!existing || confidence > existing.confidence) {
|
|
@@ -27356,6 +28813,7 @@ function findSinks(calls, patterns, typeHierarchy, language, sourceLines, types)
|
|
|
27356
28813
|
cwe: pattern.cwe,
|
|
27357
28814
|
location,
|
|
27358
28815
|
line: call.location.line,
|
|
28816
|
+
callColumn: call.location.column,
|
|
27359
28817
|
confidence,
|
|
27360
28818
|
method: call.method_name,
|
|
27361
28819
|
argPositions: pattern.arg_positions,
|
|
@@ -27393,6 +28851,15 @@ function matchesSourcePattern(call, pattern, language, types, imports) {
|
|
|
27393
28851
|
return false;
|
|
27394
28852
|
}
|
|
27395
28853
|
}
|
|
28854
|
+
if (!pattern.class && pattern.return_tainted && pattern.method && (language === "javascript" || language === "typescript")) {
|
|
28855
|
+
const expressRequestAccessors = /* @__PURE__ */ new Set(["query", "body", "params", "headers", "cookies"]);
|
|
28856
|
+
if (expressRequestAccessors.has(pattern.method)) {
|
|
28857
|
+
const recv = call.receiver?.toLowerCase() ?? "";
|
|
28858
|
+
if (recv !== "req" && recv !== "request" && recv !== "ctx") {
|
|
28859
|
+
return false;
|
|
28860
|
+
}
|
|
28861
|
+
}
|
|
28862
|
+
}
|
|
27396
28863
|
return pattern.return_tainted === true;
|
|
27397
28864
|
}
|
|
27398
28865
|
return false;
|
|
@@ -27486,6 +28953,7 @@ var SAFE_RECEIVERS_BY_METHOD = {
|
|
|
27486
28953
|
"database",
|
|
27487
28954
|
"sqlite",
|
|
27488
28955
|
"conn",
|
|
28956
|
+
"con",
|
|
27489
28957
|
"connection",
|
|
27490
28958
|
"client",
|
|
27491
28959
|
"pool",
|
|
@@ -27762,7 +29230,7 @@ function matchesSinkPattern(call, pattern, typeHierarchy, language) {
|
|
|
27762
29230
|
}
|
|
27763
29231
|
}
|
|
27764
29232
|
}
|
|
27765
|
-
if (!pattern.class && call.receiver) {
|
|
29233
|
+
if (!pattern.class && call.receiver && !pattern.requires_import) {
|
|
27766
29234
|
if (isKnownSafeReceiverForMethod(call.receiver, call.method_name, pattern.type)) {
|
|
27767
29235
|
return false;
|
|
27768
29236
|
}
|
|
@@ -28495,6 +29963,8 @@ function javaReplaceChainCredit(chainText) {
|
|
|
28495
29963
|
let lf = false;
|
|
28496
29964
|
let lt = false;
|
|
28497
29965
|
let gt = false;
|
|
29966
|
+
let openBrace = false;
|
|
29967
|
+
let closeBrace = false;
|
|
28498
29968
|
for (const m of chainText.matchAll(JAVA_REPLACE_ARGS_RE)) {
|
|
28499
29969
|
const kind = m[1];
|
|
28500
29970
|
const rawFrom = m[2] ?? m[3] ?? "";
|
|
@@ -28505,10 +29975,13 @@ function javaReplaceChainCredit(chainText) {
|
|
|
28505
29975
|
if (cov.lf) lf = true;
|
|
28506
29976
|
if (from === "<" && to.startsWith("&")) lt = true;
|
|
28507
29977
|
if (from === ">" && to.startsWith("&")) gt = true;
|
|
29978
|
+
if (from === "{") openBrace = true;
|
|
29979
|
+
if (from === "}") closeBrace = true;
|
|
28508
29980
|
}
|
|
28509
29981
|
const out2 = [];
|
|
28510
29982
|
if (cr && lf) out2.push("log_injection");
|
|
28511
29983
|
if (lt && gt) out2.push("xss");
|
|
29984
|
+
if (openBrace && closeBrace) out2.push("code_injection");
|
|
28512
29985
|
return out2;
|
|
28513
29986
|
}
|
|
28514
29987
|
function matchesSanitizerPattern(call, pattern) {
|
|
@@ -30220,7 +31693,7 @@ var AnalysisPipeline = class {
|
|
|
30220
31693
|
this.passes.push(pass);
|
|
30221
31694
|
return this;
|
|
30222
31695
|
}
|
|
30223
|
-
run(graph, code, language, config, resources) {
|
|
31696
|
+
run(graph, code, language, config, resources, limit) {
|
|
30224
31697
|
const results = /* @__PURE__ */ new Map();
|
|
30225
31698
|
const findings = [];
|
|
30226
31699
|
const context = {
|
|
@@ -30249,6 +31722,7 @@ var AnalysisPipeline = class {
|
|
|
30249
31722
|
};
|
|
30250
31723
|
const timingEnabled = globalThis.__circleIrPassTiming === true;
|
|
30251
31724
|
for (const pass of this.passes) {
|
|
31725
|
+
if (limit && Date.now() > limit.deadline) throw limit.onExpired(pass.name);
|
|
30252
31726
|
if (timingEnabled) {
|
|
30253
31727
|
console.error(`[pass-start] ${pass.name} file=${graph.ir.meta.file}`);
|
|
30254
31728
|
}
|
|
@@ -31111,10 +32585,49 @@ var JAVA_LANG_EXCEPTION_TYPES = /* @__PURE__ */ new Set([
|
|
|
31111
32585
|
"Error",
|
|
31112
32586
|
"AssertionError"
|
|
31113
32587
|
]);
|
|
32588
|
+
var JAVA_LANG_STRING_ACCUMULATOR_TYPES = /* @__PURE__ */ new Set(["StringBuilder", "StringBuffer"]);
|
|
31114
32589
|
var JAVA_FORMATTER_CLASSES = /* @__PURE__ */ new Map([
|
|
31115
32590
|
["String", "java.lang"],
|
|
31116
32591
|
["MessageFormat", "java.text"]
|
|
31117
32592
|
]);
|
|
32593
|
+
var JAVA_LOGGER_METHODS = /* @__PURE__ */ new Set([
|
|
32594
|
+
"severe",
|
|
32595
|
+
"warning",
|
|
32596
|
+
"config",
|
|
32597
|
+
"fine",
|
|
32598
|
+
"finer",
|
|
32599
|
+
"finest",
|
|
32600
|
+
"logp",
|
|
32601
|
+
"logrb",
|
|
32602
|
+
"log",
|
|
32603
|
+
"trace",
|
|
32604
|
+
"debug",
|
|
32605
|
+
"info",
|
|
32606
|
+
"warn",
|
|
32607
|
+
"error",
|
|
32608
|
+
"fatal",
|
|
32609
|
+
"Log",
|
|
32610
|
+
"LogInformation",
|
|
32611
|
+
"LogWarning",
|
|
32612
|
+
"LogError",
|
|
32613
|
+
"LogDebug",
|
|
32614
|
+
"LogTrace",
|
|
32615
|
+
"LogCritical",
|
|
32616
|
+
"Information",
|
|
32617
|
+
"Warning",
|
|
32618
|
+
"Verbose",
|
|
32619
|
+
"Fatal",
|
|
32620
|
+
"BeginScope"
|
|
32621
|
+
]);
|
|
32622
|
+
function isJavaLoggerCall(call) {
|
|
32623
|
+
return JAVA_LOGGER_METHODS.has(call.method_name);
|
|
32624
|
+
}
|
|
32625
|
+
var JAVA_OBJECTS_CLASS = /* @__PURE__ */ new Map([["Objects", "java.util"]]);
|
|
32626
|
+
var JAVA_OBJECTS_NULL_CHECK_METHODS = /* @__PURE__ */ new Set([
|
|
32627
|
+
"requireNonNull",
|
|
32628
|
+
"requireNonNullElse",
|
|
32629
|
+
"requireNonNullElseGet"
|
|
32630
|
+
]);
|
|
31118
32631
|
function isJavaStaticFormatterCall(call, declaredTypeNames, imports, calls) {
|
|
31119
32632
|
if (call.method_name !== "format" || !call.receiver) return false;
|
|
31120
32633
|
const needle = `${call.receiver}.format(`;
|
|
@@ -31124,6 +32637,10 @@ function isJavaStaticFormatterCall(call, declaredTypeNames, imports, calls) {
|
|
|
31124
32637
|
}
|
|
31125
32638
|
return isJdkClassReceiver(call.receiver, JAVA_FORMATTER_CLASSES, declaredTypeNames, imports);
|
|
31126
32639
|
}
|
|
32640
|
+
function isJavaObjectsNullCheckCall(call, declaredTypeNames, imports) {
|
|
32641
|
+
if (!call.receiver || !JAVA_OBJECTS_NULL_CHECK_METHODS.has(call.method_name)) return false;
|
|
32642
|
+
return isJdkClassReceiver(call.receiver, JAVA_OBJECTS_CLASS, declaredTypeNames, imports);
|
|
32643
|
+
}
|
|
31127
32644
|
function isJdkClassReceiver(receiver, classes, declaredTypeNames, imports) {
|
|
31128
32645
|
const dot = receiver.lastIndexOf(".");
|
|
31129
32646
|
const simple = dot < 0 ? receiver : receiver.slice(dot + 1);
|
|
@@ -31166,12 +32683,18 @@ var JAVA_CHARACTER_PREDICATES = /* @__PURE__ */ new Set([
|
|
|
31166
32683
|
"isBmpCodePoint",
|
|
31167
32684
|
"isSupplementaryCodePoint"
|
|
31168
32685
|
]);
|
|
32686
|
+
var JAVA_CHARACTER_METADATA = /* @__PURE__ */ new Set(["getName", "getType", "getNumericValue"]);
|
|
31169
32687
|
function isJavaCharacterPredicateCall(call, declaredTypeNames, imports) {
|
|
31170
|
-
if (!call.receiver
|
|
32688
|
+
if (!call.receiver) return false;
|
|
32689
|
+
if (!JAVA_CHARACTER_PREDICATES.has(call.method_name) && !JAVA_CHARACTER_METADATA.has(call.method_name)) {
|
|
32690
|
+
return false;
|
|
32691
|
+
}
|
|
31171
32692
|
return isJdkClassReceiver(call.receiver, JAVA_CHARACTER_CLASS, declaredTypeNames, imports);
|
|
31172
32693
|
}
|
|
31173
32694
|
function isJavaNonEscapeCall(call, declaredTypeNames, imports, calls) {
|
|
31174
32695
|
if (isJavaStaticFormatterCall(call, declaredTypeNames, imports, calls)) return true;
|
|
32696
|
+
if (isJavaObjectsNullCheckCall(call, declaredTypeNames, imports)) return true;
|
|
32697
|
+
if (isJavaLoggerCall(call)) return true;
|
|
31175
32698
|
if (isJavaCharacterPredicateCall(call, declaredTypeNames, imports)) return true;
|
|
31176
32699
|
if (call.receiver) return false;
|
|
31177
32700
|
const isCtor = call.is_constructor === true || (call.resolution?.target ?? "").endsWith(".<init>");
|
|
@@ -31179,11 +32702,11 @@ function isJavaNonEscapeCall(call, declaredTypeNames, imports, calls) {
|
|
|
31179
32702
|
const written = call.method_name;
|
|
31180
32703
|
const simple = written.split(".").pop() ?? written;
|
|
31181
32704
|
if (written.includes(".")) {
|
|
31182
|
-
return written.startsWith("java.lang.") && (JAVA_LANG_EXCEPTION_TYPES.has(simple) || /(Exception|Error)$/.test(simple));
|
|
32705
|
+
return written.startsWith("java.lang.") && (JAVA_LANG_EXCEPTION_TYPES.has(simple) || JAVA_LANG_STRING_ACCUMULATOR_TYPES.has(simple) || /(Exception|Error)$/.test(simple));
|
|
31183
32706
|
}
|
|
31184
32707
|
if (call.receiver_type_fqn && !call.receiver_type_fqn.startsWith("java.lang.")) return false;
|
|
31185
32708
|
if (declaredTypeNames.has(simple)) return false;
|
|
31186
|
-
return JAVA_LANG_EXCEPTION_TYPES.has(simple);
|
|
32709
|
+
return JAVA_LANG_EXCEPTION_TYPES.has(simple) || JAVA_LANG_STRING_ACCUMULATOR_TYPES.has(simple);
|
|
31187
32710
|
}
|
|
31188
32711
|
function isGoConstRegexMatchCall(call, graph, calls) {
|
|
31189
32712
|
if (call.method_name !== "MatchString" || call.arguments.length !== 1) return false;
|
|
@@ -31239,7 +32762,9 @@ function analyzeInterprocedural(graphOrTypes, callsOrSources, dfgOrSinks, source
|
|
|
31239
32762
|
const calls = graph.ir.calls;
|
|
31240
32763
|
const declaredTypeNames = new Set(types.map((t) => t.name));
|
|
31241
32764
|
const methodNodes = buildMethodNodes(types);
|
|
31242
|
-
const
|
|
32765
|
+
const lang = graph.ir.meta.language;
|
|
32766
|
+
const collectionReceiver = (lang === "typescript" || lang === "javascript") && typeof options.sourceCode === "string" ? makeBuiltinCollectionReceiverTest(options.sourceCode) : null;
|
|
32767
|
+
const callEdges = buildCallEdges(calls, methodNodes, types, collectionReceiver);
|
|
31243
32768
|
const taintedMethods = /* @__PURE__ */ new Set();
|
|
31244
32769
|
const taintedReturns = /* @__PURE__ */ new Map();
|
|
31245
32770
|
for (const source of sources) {
|
|
@@ -31444,6 +32969,14 @@ function analyzeInterprocedural(graphOrTypes, callsOrSources, dfgOrSinks, source
|
|
|
31444
32969
|
sanitizerMethods.add(match[1]);
|
|
31445
32970
|
}
|
|
31446
32971
|
}
|
|
32972
|
+
const bashScriptFunctions = /* @__PURE__ */ new Set();
|
|
32973
|
+
if (graph.ir.meta.language === "bash") {
|
|
32974
|
+
for (const d of graph.ir.dfg.defs) {
|
|
32975
|
+
if (d.kind === "param" && d.expression?.startsWith("bash-fn:")) {
|
|
32976
|
+
bashScriptFunctions.add(d.expression.slice("bash-fn:".length));
|
|
32977
|
+
}
|
|
32978
|
+
}
|
|
32979
|
+
}
|
|
31447
32980
|
for (const call of calls) {
|
|
31448
32981
|
const taintedArgPositions = [];
|
|
31449
32982
|
const taintedArgVars = [];
|
|
@@ -31467,7 +33000,9 @@ function analyzeInterprocedural(graphOrTypes, callsOrSources, dfgOrSinks, source
|
|
|
31467
33000
|
}
|
|
31468
33001
|
}
|
|
31469
33002
|
}
|
|
31470
|
-
const
|
|
33003
|
+
const builtinReceiver = collectionReceiver !== null && collectionReceiver(call.receiver);
|
|
33004
|
+
const resolvedCalleeFqn = builtinReceiver ? null : resolveMethodCall2(call, methodNodes, types);
|
|
33005
|
+
const targetMethod = builtinReceiver ? void 0 : resolvedCalleeFqn ? methodNodes.byFqn.get(resolvedCalleeFqn) : getMethodNode(methodNodes, call.method_name);
|
|
31471
33006
|
if (!targetMethod) {
|
|
31472
33007
|
if (taintedArgPositions.length > 0 && !collectionMethods.has(call.method_name) && !sanitizerMethods.has(call.method_name) && !safeUtilityMethods.has(call.method_name) && !ormQueryBuilderMethods.has(call.method_name)) {
|
|
31473
33008
|
const isBash = graph.ir.meta.language === "bash";
|
|
@@ -31501,6 +33036,9 @@ function analyzeInterprocedural(graphOrTypes, callsOrSources, dfgOrSinks, source
|
|
|
31501
33036
|
if (isBash && bashSafeBuiltins.has(call.method_name)) {
|
|
31502
33037
|
continue;
|
|
31503
33038
|
}
|
|
33039
|
+
if (isBash && bashScriptFunctions.has(call.method_name)) {
|
|
33040
|
+
continue;
|
|
33041
|
+
}
|
|
31504
33042
|
if (isBash && taintedArgPositions.length > 0) {
|
|
31505
33043
|
const terminatorPos = call.arguments.filter((a) => a.expression === "--").map((a) => a.position).reduce((min, p) => min === null || p < min ? p : min, null);
|
|
31506
33044
|
const earliestTainted = Math.min(...taintedArgPositions);
|
|
@@ -31558,6 +33096,12 @@ function analyzeInterprocedural(graphOrTypes, callsOrSources, dfgOrSinks, source
|
|
|
31558
33096
|
if (pos < targetMethod.parameters.length) {
|
|
31559
33097
|
targetMethod.parameters[pos].isTainted = true;
|
|
31560
33098
|
targetMethod.parameters[pos].sourceLine = call.location.line;
|
|
33099
|
+
const paramName = targetMethod.parameters[pos].name;
|
|
33100
|
+
for (const def of graph.ir.dfg.defs) {
|
|
33101
|
+
if (def.kind === "param" && def.variable === paramName && def.line >= targetMethod.startLine && def.line <= targetMethod.endLine) {
|
|
33102
|
+
taintedDefIds.add(def.id);
|
|
33103
|
+
}
|
|
33104
|
+
}
|
|
31561
33105
|
}
|
|
31562
33106
|
}
|
|
31563
33107
|
taintedMethods.add(targetMethod.fqn);
|
|
@@ -31667,9 +33211,29 @@ function resolveMethodCall2(call, methodNodes, types) {
|
|
|
31667
33211
|
}
|
|
31668
33212
|
return null;
|
|
31669
33213
|
}
|
|
31670
|
-
function
|
|
33214
|
+
function makeBuiltinCollectionReceiverTest(sourceCode) {
|
|
33215
|
+
const memo = /* @__PURE__ */ new Map();
|
|
33216
|
+
return (receiver) => {
|
|
33217
|
+
const raw = (receiver ?? "").trim();
|
|
33218
|
+
const m = /^(?:this\.)?([A-Za-z_$][\w$]*)$/.exec(raw);
|
|
33219
|
+
if (!m || raw === "this") return false;
|
|
33220
|
+
const name2 = m[1];
|
|
33221
|
+
const hit = memo.get(name2);
|
|
33222
|
+
if (hit !== void 0) return hit;
|
|
33223
|
+
const n = name2.replace(/[$]/g, "\\$&");
|
|
33224
|
+
const coll = "(?:Readonly)?(?:Weak)?(?:Map|Set)";
|
|
33225
|
+
const ctor = new RegExp(`(?<![\\w$.])${n}\\s*(?::[^=;]*)?=\\s*new\\s+(?:Weak)?(?:Map|Set)\\s*(?:<[^;]*>)?\\s*\\(`);
|
|
33226
|
+
const typed = new RegExp(`(?<![\\w$.])${n}\\s*[?!]?\\s*:\\s*${coll}\\s*<`);
|
|
33227
|
+
const thisCtor = new RegExp(`\\bthis\\.${n}\\s*=\\s*new\\s+(?:Weak)?(?:Map|Set)\\s*(?:<[^;]*>)?\\s*\\(`);
|
|
33228
|
+
const result = ctor.test(sourceCode) || typed.test(sourceCode) || thisCtor.test(sourceCode);
|
|
33229
|
+
memo.set(name2, result);
|
|
33230
|
+
return result;
|
|
33231
|
+
};
|
|
33232
|
+
}
|
|
33233
|
+
function buildCallEdges(calls, methodNodes, types, collectionReceiver = null) {
|
|
31671
33234
|
const edges = [];
|
|
31672
33235
|
for (const call of calls) {
|
|
33236
|
+
if (collectionReceiver !== null && collectionReceiver(call.receiver)) continue;
|
|
31673
33237
|
const resolvedFqn = resolveMethodCall2(call, methodNodes, types);
|
|
31674
33238
|
if (!resolvedFqn) continue;
|
|
31675
33239
|
const callerMethod = call.in_method;
|
|
@@ -32942,6 +34506,9 @@ var ConstantPropagator = class _ConstantPropagator {
|
|
|
32942
34506
|
case "assignment_statement":
|
|
32943
34507
|
this.handleGoAssignment(node);
|
|
32944
34508
|
return false;
|
|
34509
|
+
case "var_declaration":
|
|
34510
|
+
this.handleGoVarDeclaration(node);
|
|
34511
|
+
return false;
|
|
32945
34512
|
case "update_expression":
|
|
32946
34513
|
this.handleUpdateExpression(node);
|
|
32947
34514
|
return false;
|
|
@@ -33349,6 +34916,64 @@ var ConstantPropagator = class _ConstantPropagator {
|
|
|
33349
34916
|
* helper that always returns a constant — clears the variable. Anything else stops being tracked here, which is what Go
|
|
33350
34917
|
* assignments got before this handler existed: the DFG decides.
|
|
33351
34918
|
*/
|
|
34919
|
+
/** `var x = expr` / `var x T = expr` — same clean/taint rules as `:=` (#783). */
|
|
34920
|
+
handleGoVarDeclaration(node) {
|
|
34921
|
+
for (let i2 = 0; i2 < node.childCount; i2++) {
|
|
34922
|
+
const spec = node.child(i2);
|
|
34923
|
+
if (!spec || spec.type !== "var_spec") continue;
|
|
34924
|
+
const nameNode = spec.childForFieldName("name");
|
|
34925
|
+
let valueNode = spec.childForFieldName("value");
|
|
34926
|
+
if (!nameNode || !valueNode) continue;
|
|
34927
|
+
const names = [];
|
|
34928
|
+
if (nameNode.type === "identifier") {
|
|
34929
|
+
names.push(getNodeText2(nameNode, this.source));
|
|
34930
|
+
} else if (nameNode.type === "identifier_list") {
|
|
34931
|
+
for (const c of nameNode.children) {
|
|
34932
|
+
if (c.type === "identifier") names.push(getNodeText2(c, this.source));
|
|
34933
|
+
}
|
|
34934
|
+
}
|
|
34935
|
+
if (valueNode.type === "expression_list") {
|
|
34936
|
+
valueNode = valueNode.children.find((c) => c.type !== "," && c.type !== "comment") ?? valueNode;
|
|
34937
|
+
}
|
|
34938
|
+
if (names.length === 0) continue;
|
|
34939
|
+
const line = getNodeLine(node);
|
|
34940
|
+
for (const varName of names) {
|
|
34941
|
+
if (varName === "_") continue;
|
|
34942
|
+
const scopedName = this.getScopedName(varName);
|
|
34943
|
+
this.goScopedNames.add(scopedName);
|
|
34944
|
+
if (this.isTaintedExpression(valueNode)) {
|
|
34945
|
+
this.goUnknownVars.add(scopedName);
|
|
34946
|
+
this.tainted.add(scopedName);
|
|
34947
|
+
this.sanitizedVars.delete(scopedName);
|
|
34948
|
+
this.sanitizedVarUncovered.delete(scopedName);
|
|
34949
|
+
this.definitionNodes.set(scopedName, valueNode);
|
|
34950
|
+
this.symbols.set(scopedName, createUnknown(line));
|
|
34951
|
+
continue;
|
|
34952
|
+
}
|
|
34953
|
+
if (!this.isGoKnownCleanRhs(valueNode) || this.goUnknownVars.has(scopedName)) {
|
|
34954
|
+
this.goUnknownVars.add(scopedName);
|
|
34955
|
+
this.symbols.delete(scopedName);
|
|
34956
|
+
this.sanitizedVars.delete(scopedName);
|
|
34957
|
+
this.sanitizedVarUncovered.delete(scopedName);
|
|
34958
|
+
if (!this.inConditionalBranch) {
|
|
34959
|
+
this.tainted.delete(scopedName);
|
|
34960
|
+
this.definitionNodes.delete(scopedName);
|
|
34961
|
+
}
|
|
34962
|
+
continue;
|
|
34963
|
+
}
|
|
34964
|
+
if (this.inConditionalBranch) {
|
|
34965
|
+
this.goUnknownVars.add(scopedName);
|
|
34966
|
+
this.symbols.delete(scopedName);
|
|
34967
|
+
continue;
|
|
34968
|
+
}
|
|
34969
|
+
this.tainted.delete(scopedName);
|
|
34970
|
+
this.definitionNodes.delete(scopedName);
|
|
34971
|
+
this.symbols.set(scopedName, this.evaluateExpression(valueNode));
|
|
34972
|
+
this.sanitizedVars.delete(scopedName);
|
|
34973
|
+
this.sanitizedVarUncovered.delete(scopedName);
|
|
34974
|
+
}
|
|
34975
|
+
}
|
|
34976
|
+
}
|
|
33352
34977
|
handleGoAssignment(node) {
|
|
33353
34978
|
const left = node.childForFieldName("left");
|
|
33354
34979
|
const right = node.childForFieldName("right");
|
|
@@ -34165,6 +35790,24 @@ var ConstantPropagator = class _ConstantPropagator {
|
|
|
34165
35790
|
cache.set(rootId, false);
|
|
34166
35791
|
return false;
|
|
34167
35792
|
}
|
|
35793
|
+
/** Is an argument of `call` an inline sanitizer call over tainted input (itself possibly nested)? */
|
|
35794
|
+
argIsSanitizedTaint(call) {
|
|
35795
|
+
const argsNode = call.childForFieldName("arguments");
|
|
35796
|
+
if (!argsNode) return false;
|
|
35797
|
+
for (const arg of argsNode.children) {
|
|
35798
|
+
if (arg.type !== "method_invocation") continue;
|
|
35799
|
+
const name2 = arg.childForFieldName("name");
|
|
35800
|
+
if (!name2 || !SANITIZER_METHODS.has(getNodeText2(name2, this.source))) continue;
|
|
35801
|
+
const inner = arg.childForFieldName("arguments");
|
|
35802
|
+
if (!inner) continue;
|
|
35803
|
+
for (const a of inner.children) {
|
|
35804
|
+
if (a.type === "(" || a.type === ")" || a.type === ",") continue;
|
|
35805
|
+
if (this.isTaintedExpression(a)) return true;
|
|
35806
|
+
}
|
|
35807
|
+
if (this.argIsSanitizedTaint(arg)) return true;
|
|
35808
|
+
}
|
|
35809
|
+
return false;
|
|
35810
|
+
}
|
|
34168
35811
|
isTaintedExpressionStep(node) {
|
|
34169
35812
|
const text = getNodeText2(node, this.source);
|
|
34170
35813
|
if (node.type === "method_invocation") {
|
|
@@ -34172,6 +35815,9 @@ var ConstantPropagator = class _ConstantPropagator {
|
|
|
34172
35815
|
const objectNode = node.childForFieldName("object");
|
|
34173
35816
|
if (nameNode) {
|
|
34174
35817
|
const methodName = getNodeText2(nameNode, this.source);
|
|
35818
|
+
if (ANTI_SANITIZER_METHODS.has(methodName) && this.argIsSanitizedTaint(node)) {
|
|
35819
|
+
return true;
|
|
35820
|
+
}
|
|
34175
35821
|
if (SANITIZER_METHODS.has(methodName) && !this.localNonSanitizing.has(methodName)) {
|
|
34176
35822
|
return false;
|
|
34177
35823
|
}
|
|
@@ -35147,6 +36793,8 @@ function classifyEntryPointTier(method, enclosingType, ctx) {
|
|
|
35147
36793
|
return classifyJsTsEntryPoint(method, enclosingType, ctx);
|
|
35148
36794
|
case "go":
|
|
35149
36795
|
return classifyGoEntryPoint(method, enclosingType, ctx);
|
|
36796
|
+
case "csharp":
|
|
36797
|
+
return classifyCSharpEntryPoint(method, enclosingType, ctx);
|
|
35150
36798
|
case "bash":
|
|
35151
36799
|
case "shell":
|
|
35152
36800
|
return classifyBashEntryPoint(method, enclosingType, ctx);
|
|
@@ -35399,6 +37047,84 @@ function fileHasJsTsFrameworkRegistration(regs) {
|
|
|
35399
37047
|
}
|
|
35400
37048
|
return false;
|
|
35401
37049
|
}
|
|
37050
|
+
var CSHARP_TIER_1_METHOD_ANNOTATIONS = /* @__PURE__ */ new Set([
|
|
37051
|
+
"HttpGet",
|
|
37052
|
+
"HttpPost",
|
|
37053
|
+
"HttpPut",
|
|
37054
|
+
"HttpDelete",
|
|
37055
|
+
"HttpPatch",
|
|
37056
|
+
"HttpHead",
|
|
37057
|
+
"HttpOptions",
|
|
37058
|
+
"Route",
|
|
37059
|
+
"AcceptVerbs",
|
|
37060
|
+
"MapGet",
|
|
37061
|
+
"MapPost",
|
|
37062
|
+
"MapPut",
|
|
37063
|
+
"MapDelete",
|
|
37064
|
+
"MapPatch"
|
|
37065
|
+
]);
|
|
37066
|
+
var CSHARP_TIER_1_PARAM_ANNOTATIONS = /* @__PURE__ */ new Set([
|
|
37067
|
+
"FromQuery",
|
|
37068
|
+
"FromBody",
|
|
37069
|
+
"FromRoute",
|
|
37070
|
+
"FromHeader",
|
|
37071
|
+
"FromForm",
|
|
37072
|
+
"FromServices"
|
|
37073
|
+
]);
|
|
37074
|
+
var CSHARP_TIER_1_CLASS_ANNOTATIONS = /* @__PURE__ */ new Set([
|
|
37075
|
+
"ApiController",
|
|
37076
|
+
"Controller",
|
|
37077
|
+
"Route"
|
|
37078
|
+
]);
|
|
37079
|
+
var CSHARP_MVC_BASE_SIMPLE_NAMES = /* @__PURE__ */ new Set([
|
|
37080
|
+
"Controller",
|
|
37081
|
+
"ControllerBase",
|
|
37082
|
+
"PageModel"
|
|
37083
|
+
]);
|
|
37084
|
+
function csharpBaseTypeLooksLikeMvc(base) {
|
|
37085
|
+
const simple = (base.split(".").pop() ?? base).trim();
|
|
37086
|
+
if (CSHARP_MVC_BASE_SIMPLE_NAMES.has(simple)) return true;
|
|
37087
|
+
return simple.endsWith("Controller") && simple !== "Controller";
|
|
37088
|
+
}
|
|
37089
|
+
function csharpTypeLooksLikeController(enclosingType) {
|
|
37090
|
+
if (!enclosingType) return false;
|
|
37091
|
+
if (annotationsInclude(enclosingType.annotations, CSHARP_TIER_1_CLASS_ANNOTATIONS)) return true;
|
|
37092
|
+
if (enclosingType.extends && csharpBaseTypeLooksLikeMvc(enclosingType.extends)) return true;
|
|
37093
|
+
const name2 = enclosingType.name ?? "";
|
|
37094
|
+
if (csharpBaseTypeLooksLikeMvc(name2)) return true;
|
|
37095
|
+
return name2.endsWith("Controller") && name2 !== "Controller";
|
|
37096
|
+
}
|
|
37097
|
+
function csharpMethodHasMvcBindingParams(method) {
|
|
37098
|
+
for (const p of method.parameters ?? []) {
|
|
37099
|
+
if (annotationsInclude(p.annotations, CSHARP_TIER_1_PARAM_ANNOTATIONS)) return true;
|
|
37100
|
+
}
|
|
37101
|
+
return false;
|
|
37102
|
+
}
|
|
37103
|
+
function looksLikeCSharpMain(method) {
|
|
37104
|
+
const mods = method.modifiers ?? [];
|
|
37105
|
+
if (!mods.includes("static")) return false;
|
|
37106
|
+
if (method.name !== "Main") return false;
|
|
37107
|
+
const params = method.parameters ?? [];
|
|
37108
|
+
return params.length === 0 || params.length === 1 && /\bstring\s*\[\s*\]/.test(params[0]?.type ?? "");
|
|
37109
|
+
}
|
|
37110
|
+
function classifyCSharpEntryPoint(method, enclosingType, ctx) {
|
|
37111
|
+
if (pathLooksLikeLibraryOrTest(ctx.filePath)) {
|
|
37112
|
+
return "TIER_3_LIBRARY_API";
|
|
37113
|
+
}
|
|
37114
|
+
if (annotationsInclude(method.annotations, CSHARP_TIER_1_METHOD_ANNOTATIONS)) {
|
|
37115
|
+
return "TIER_1_ENTRY_POINT";
|
|
37116
|
+
}
|
|
37117
|
+
if (csharpMethodHasMvcBindingParams(method)) {
|
|
37118
|
+
return "TIER_1_ENTRY_POINT";
|
|
37119
|
+
}
|
|
37120
|
+
if (csharpTypeLooksLikeController(enclosingType)) {
|
|
37121
|
+
return "TIER_1_ENTRY_POINT";
|
|
37122
|
+
}
|
|
37123
|
+
if (looksLikeCSharpMain(method)) {
|
|
37124
|
+
return "TIER_1_ENTRY_POINT";
|
|
37125
|
+
}
|
|
37126
|
+
return "TIER_3_LIBRARY_API";
|
|
37127
|
+
}
|
|
35402
37128
|
var GO_HTTP_REGISTRAR_METHODS = /* @__PURE__ */ new Set([
|
|
35403
37129
|
// net/http
|
|
35404
37130
|
"HandleFunc",
|
|
@@ -39007,6 +40733,10 @@ var CSharpCredit = class {
|
|
|
39007
40733
|
if (type === "path_traversal") {
|
|
39008
40734
|
if (/\b([A-Za-z_]\w*)\s*\.\s*StartsWith\s*\([^)]*\)\s*\?\s*\1\s*:\s*null\b/.test(text)) return true;
|
|
39009
40735
|
}
|
|
40736
|
+
if (type === "open_redirect") {
|
|
40737
|
+
if (/\b(?:Url\s*\.\s*)?IsLocalUrl\s*\(/.test(text)) return true;
|
|
40738
|
+
if (/\bLocalRedirect\s*\(/.test(text)) return true;
|
|
40739
|
+
}
|
|
39010
40740
|
return false;
|
|
39011
40741
|
}
|
|
39012
40742
|
/**
|
|
@@ -39020,6 +40750,10 @@ var CSharpCredit = class {
|
|
|
39020
40750
|
const set = /* @__PURE__ */ new Set();
|
|
39021
40751
|
this.helperCache.set(type, set);
|
|
39022
40752
|
for (const m of this.methods) {
|
|
40753
|
+
if (type === "open_redirect" && this.openRedirectHelperMethod(m)) {
|
|
40754
|
+
set.add(m.name);
|
|
40755
|
+
continue;
|
|
40756
|
+
}
|
|
39023
40757
|
const returns = this.returnExprs(m);
|
|
39024
40758
|
if (returns.length === 0) continue;
|
|
39025
40759
|
const ok = returns.every((r) => {
|
|
@@ -39031,6 +40765,23 @@ var CSharpCredit = class {
|
|
|
39031
40765
|
}
|
|
39032
40766
|
return set;
|
|
39033
40767
|
}
|
|
40768
|
+
/**
|
|
40769
|
+
* Same-file helper whose returns are safe for open_redirect: literal fallbacks
|
|
40770
|
+
* and parameters returned only under `Url.IsLocalUrl` (cognium-dev#946).
|
|
40771
|
+
*/
|
|
40772
|
+
openRedirectHelperMethod(m) {
|
|
40773
|
+
const returns = this.returnExprs(m);
|
|
40774
|
+
if (returns.length === 0) return false;
|
|
40775
|
+
for (const r of returns) {
|
|
40776
|
+
const e = r.expr.trim();
|
|
40777
|
+
if (/^"[^"]*"$/.test(e) || /^'[^']*'$/.test(e)) continue;
|
|
40778
|
+
if (this.builtinSanitizes("open_redirect", e)) continue;
|
|
40779
|
+
const id = /^([A-Za-z_]\w*)$/.exec(e);
|
|
40780
|
+
if (!id) return false;
|
|
40781
|
+
if (!this.guardedVarsAt("open_redirect", r.line).has(id[1])) return false;
|
|
40782
|
+
}
|
|
40783
|
+
return true;
|
|
40784
|
+
}
|
|
39034
40785
|
/** Every returned expression of a method: `return e;` and expression bodies. */
|
|
39035
40786
|
returnExprs(m) {
|
|
39036
40787
|
const out2 = [];
|
|
@@ -39263,6 +41014,14 @@ var CSharpCredit = class {
|
|
|
39263
41014
|
}
|
|
39264
41015
|
return out2;
|
|
39265
41016
|
}
|
|
41017
|
+
/** Variables proven local by `Url.IsLocalUrl(x)` (cognium-dev#275/#946). */
|
|
41018
|
+
localUrlVars(cond) {
|
|
41019
|
+
const out2 = [];
|
|
41020
|
+
for (const m of cond.matchAll(/\b(?:Url\s*\.\s*)?IsLocalUrl\s*\(\s*([A-Za-z_]\w*)\s*\)/g)) {
|
|
41021
|
+
out2.push(m[1]);
|
|
41022
|
+
}
|
|
41023
|
+
return out2;
|
|
41024
|
+
}
|
|
39266
41025
|
/** Variables whose host a condition compares against a constant or an allowlist. */
|
|
39267
41026
|
hostVars(cond, hostOf) {
|
|
39268
41027
|
const out2 = [];
|
|
@@ -39304,7 +41063,7 @@ var CSharpCredit = class {
|
|
|
39304
41063
|
return map;
|
|
39305
41064
|
}
|
|
39306
41065
|
provenBy(kind, cond, parsedFrom, hostOf, withHelpers) {
|
|
39307
|
-
const out2 = kind === "allowlist" ? this.allowlistVars(cond) : kind === "numeric" ? this.numericVars(cond, parsedFrom) : this.hostVars(cond, hostOf);
|
|
41066
|
+
const out2 = kind === "allowlist" ? this.allowlistVars(cond) : kind === "numeric" ? this.numericVars(cond, parsedFrom) : kind === "localUrl" ? this.localUrlVars(cond) : this.hostVars(cond, hostOf);
|
|
39308
41067
|
if (withHelpers) {
|
|
39309
41068
|
for (const [name2, pos] of this.guardHelpers(kind)) {
|
|
39310
41069
|
for (const call of cond.matchAll(new RegExp(`(?<![\\w.])${escapeRegex(name2)}\\s*\\(`, "g"))) {
|
|
@@ -39334,6 +41093,7 @@ var CSharpCredit = class {
|
|
|
39334
41093
|
const kinds = [];
|
|
39335
41094
|
if (INERT_WHEN_ALPHANUMERIC.has(type)) kinds.push("allowlist", "numeric");
|
|
39336
41095
|
if (type === "ssrf") kinds.push("host");
|
|
41096
|
+
if (type === "open_redirect") kinds.push("localUrl");
|
|
39337
41097
|
const proven = /* @__PURE__ */ new Set();
|
|
39338
41098
|
if (kinds.length === 0) return proven;
|
|
39339
41099
|
const scopeStart = this.methodAt(sinkLine)?.start_line ?? 1;
|
|
@@ -39509,7 +41269,8 @@ var InterproceduralPass = class {
|
|
|
39509
41269
|
const csCredit = language === "csharp" && typeof ctx.code === "string" ? new CSharpCredit(ctx.code, graph.ir.types.flatMap((t) => t.methods)) : null;
|
|
39510
41270
|
if (sinks.length > 0) {
|
|
39511
41271
|
const interProc = analyzeInterprocedural(graph, sources, sinks, sanitizers, {
|
|
39512
|
-
taintedVariables: constProp.tainted
|
|
41272
|
+
taintedVariables: constProp.tainted,
|
|
41273
|
+
sourceCode: typeof ctx.code === "string" ? ctx.code : void 0
|
|
39513
41274
|
});
|
|
39514
41275
|
for (const sink of interProc.propagatedSinks) {
|
|
39515
41276
|
if (sink.type === "external_taint_escape") continue;
|
|
@@ -39576,6 +41337,16 @@ var InterproceduralPass = class {
|
|
|
39576
41337
|
}
|
|
39577
41338
|
}
|
|
39578
41339
|
}
|
|
41340
|
+
appendCalleeSourceCallerSinkFlows(
|
|
41341
|
+
graph,
|
|
41342
|
+
sources,
|
|
41343
|
+
sinks,
|
|
41344
|
+
interProc,
|
|
41345
|
+
additionalFlows,
|
|
41346
|
+
language === "java" ? ctx.code : void 0,
|
|
41347
|
+
language === "java" ? constProp : void 0,
|
|
41348
|
+
language === "java" || language === "javascript" || language === "typescript" ? ctx.code : void 0
|
|
41349
|
+
);
|
|
39579
41350
|
const taintBridges = findTaintBridges(interProc);
|
|
39580
41351
|
interprocedural = {
|
|
39581
41352
|
tainted_methods: Array.from(interProc.taintedMethods),
|
|
@@ -39597,7 +41368,8 @@ var InterproceduralPass = class {
|
|
|
39597
41368
|
return { additionalSinks, additionalFlows, interprocedural };
|
|
39598
41369
|
}
|
|
39599
41370
|
const interProc = analyzeInterprocedural(graph, fallbackSources, [], sanitizers, {
|
|
39600
|
-
taintedVariables: constProp.tainted
|
|
41371
|
+
taintedVariables: constProp.tainted,
|
|
41372
|
+
sourceCode: typeof ctx.code === "string" ? ctx.code : void 0
|
|
39601
41373
|
});
|
|
39602
41374
|
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)) : [];
|
|
39603
41375
|
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))));
|
|
@@ -39701,6 +41473,401 @@ var InterproceduralPass = class {
|
|
|
39701
41473
|
return { additionalSinks: filteredAdditionalSinks, additionalFlows: filteredAdditionalFlows, interprocedural };
|
|
39702
41474
|
}
|
|
39703
41475
|
};
|
|
41476
|
+
function assigneeIsConstPropClean(constProp, method, variable) {
|
|
41477
|
+
if (!method) return false;
|
|
41478
|
+
const scoped = `${method}:${variable}`;
|
|
41479
|
+
if (!constProp.symbols.has(scoped)) return false;
|
|
41480
|
+
if (constProp.tainted.has(scoped)) return false;
|
|
41481
|
+
for (const t of constProp.tainted) {
|
|
41482
|
+
if (t.startsWith(`${method}:`) && t.endsWith(`:${variable}`)) return false;
|
|
41483
|
+
}
|
|
41484
|
+
if (constProp.sanitizedVarUncovered?.has(scoped)) return false;
|
|
41485
|
+
return true;
|
|
41486
|
+
}
|
|
41487
|
+
function constPropTaints(constProp, method, variable) {
|
|
41488
|
+
if (constProp.tainted.has(`${method}:${variable}`)) return true;
|
|
41489
|
+
for (const t of constProp.tainted) {
|
|
41490
|
+
if (t.startsWith(`${method}:`) && t.endsWith(`:${variable}`)) return true;
|
|
41491
|
+
}
|
|
41492
|
+
return false;
|
|
41493
|
+
}
|
|
41494
|
+
function callArgumentIsConstPropTainted(graph, constProp, method, line) {
|
|
41495
|
+
if (!method) return false;
|
|
41496
|
+
for (const call of graph.ir.calls) {
|
|
41497
|
+
if (call.location.line !== line) continue;
|
|
41498
|
+
for (const arg of call.arguments) {
|
|
41499
|
+
const names = arg.variable ? [arg.variable] : (arg.expression ?? "").match(/[A-Za-z_]\w*/g) ?? [];
|
|
41500
|
+
if (names.some((n) => constPropTaints(constProp, method, n))) return true;
|
|
41501
|
+
}
|
|
41502
|
+
}
|
|
41503
|
+
return false;
|
|
41504
|
+
}
|
|
41505
|
+
function calleeReturnsTaintedContainer(constProp, code, startLine, endLine) {
|
|
41506
|
+
const lines = code.split("\n");
|
|
41507
|
+
for (let l = startLine; l <= endLine; l++) {
|
|
41508
|
+
const m = /^\s*return\s+([A-Za-z_]\w*)\s*;/.exec(lines[l - 1] ?? "");
|
|
41509
|
+
if (!m) continue;
|
|
41510
|
+
if ((constProp.taintedArrayElements.get(m[1])?.size ?? 0) > 0) return true;
|
|
41511
|
+
if ((constProp.taintedCollections.get(m[1])?.size ?? 0) > 0) return true;
|
|
41512
|
+
}
|
|
41513
|
+
return false;
|
|
41514
|
+
}
|
|
41515
|
+
var DEAD_BRANCH_CHECKED_SINKS = /* @__PURE__ */ new Set([
|
|
41516
|
+
"sql_injection",
|
|
41517
|
+
"trust_boundary",
|
|
41518
|
+
"path_traversal",
|
|
41519
|
+
"ldap_injection",
|
|
41520
|
+
"xpath_injection"
|
|
41521
|
+
]);
|
|
41522
|
+
function calleeSourceReachesReturn(graph, code, startLine, endLine, sourceLine) {
|
|
41523
|
+
const lines = code.split("\n");
|
|
41524
|
+
const returnLines = /* @__PURE__ */ new Set();
|
|
41525
|
+
for (let l = startLine; l <= endLine; l++) {
|
|
41526
|
+
if (/^\s*return\b/.test(lines[l - 1] ?? "")) returnLines.add(l);
|
|
41527
|
+
}
|
|
41528
|
+
if (returnLines.size === 0) return true;
|
|
41529
|
+
if (returnLines.has(sourceLine)) return true;
|
|
41530
|
+
const inRange = (l) => l >= startLine && l <= endLine;
|
|
41531
|
+
const ends = (l) => /[;{}]\s*$/.test((lines[l - 1] ?? "").replace(/\/\/.*$/, "").trimEnd());
|
|
41532
|
+
const statementStart = (l) => {
|
|
41533
|
+
let s = l;
|
|
41534
|
+
while (s > startLine && !ends(s - 1) && (lines[s - 2] ?? "").trim() !== "") s--;
|
|
41535
|
+
return s;
|
|
41536
|
+
};
|
|
41537
|
+
const reached = new Set(
|
|
41538
|
+
graph.ir.dfg.defs.filter((d) => d.line === sourceLine && d.kind === "local").map((d) => d.id)
|
|
41539
|
+
);
|
|
41540
|
+
if (reached.size === 0) return true;
|
|
41541
|
+
let changed = true;
|
|
41542
|
+
while (changed) {
|
|
41543
|
+
changed = false;
|
|
41544
|
+
for (const u of graph.ir.dfg.uses) {
|
|
41545
|
+
if (u.def_id === null || !reached.has(u.def_id) || !inRange(u.line)) continue;
|
|
41546
|
+
const stmt = statementStart(u.line);
|
|
41547
|
+
if (returnLines.has(u.line) || returnLines.has(stmt)) return true;
|
|
41548
|
+
for (const d of graph.ir.dfg.defs) {
|
|
41549
|
+
if ((d.line === u.line || d.line === stmt) && d.kind === "local" && !reached.has(d.id)) {
|
|
41550
|
+
reached.add(d.id);
|
|
41551
|
+
changed = true;
|
|
41552
|
+
}
|
|
41553
|
+
}
|
|
41554
|
+
const base = storeBase(lines[stmt - 1] ?? "");
|
|
41555
|
+
if (base && base !== u.variable) {
|
|
41556
|
+
for (const b of graph.ir.dfg.uses) {
|
|
41557
|
+
if ((b.line === u.line || b.line === stmt) && b.variable === base && b.def_id !== null && !reached.has(b.def_id)) {
|
|
41558
|
+
reached.add(b.def_id);
|
|
41559
|
+
changed = true;
|
|
41560
|
+
}
|
|
41561
|
+
}
|
|
41562
|
+
}
|
|
41563
|
+
}
|
|
41564
|
+
}
|
|
41565
|
+
return false;
|
|
41566
|
+
}
|
|
41567
|
+
function storeBase(line) {
|
|
41568
|
+
const m = /^\s*([A-Za-z_]\w*)\s*(?:\[[^\]=]*\]\s*)+=(?!=)/.exec(line) ?? /^\s*([A-Za-z_]\w*)\s*\.\s*[A-Za-z_]\w*\s*=(?!=)/.exec(line);
|
|
41569
|
+
if (!m || m[1] === "this") return null;
|
|
41570
|
+
return m[1];
|
|
41571
|
+
}
|
|
41572
|
+
function appendCalleeSourceCallerSinkFlows(graph, sources, sinks, interProc, additionalFlows, fileCode, constProp, returnReachCode) {
|
|
41573
|
+
const types = graph.ir.types ?? [];
|
|
41574
|
+
for (const edge of interProc.callEdges) {
|
|
41575
|
+
const callee = interProc.methodNodes.get(edge.calleeMethod);
|
|
41576
|
+
if (!callee) continue;
|
|
41577
|
+
const calleeSources = sources.filter(
|
|
41578
|
+
(s) => s.line >= callee.startLine && s.line <= callee.endLine && (!returnReachCode || s.type === "interprocedural_param" || calleeSourceReachesReturn(graph, returnReachCode, callee.startLine, callee.endLine, s.line))
|
|
41579
|
+
);
|
|
41580
|
+
if (calleeSources.length === 0) continue;
|
|
41581
|
+
const assignee = graph.ir.dfg.defs.find(
|
|
41582
|
+
(d) => d.line === edge.callLine && d.kind === "local"
|
|
41583
|
+
);
|
|
41584
|
+
if (!assignee?.variable) continue;
|
|
41585
|
+
if (constProp && callArgumentIsConstPropTainted(graph, constProp, edge.callerMethod, edge.callLine) && assigneeIsConstPropClean(constProp, edge.callerMethod, assignee.variable) && !(fileCode && calleeReturnsTaintedContainer(constProp, fileCode, callee.startLine, callee.endLine))) {
|
|
41586
|
+
continue;
|
|
41587
|
+
}
|
|
41588
|
+
const derivedLocals = localsDerivedFromAssignee(
|
|
41589
|
+
graph,
|
|
41590
|
+
assignee.variable,
|
|
41591
|
+
assignee.line
|
|
41592
|
+
);
|
|
41593
|
+
for (const sink of sinks) {
|
|
41594
|
+
if (sink.type === "external_taint_escape") continue;
|
|
41595
|
+
if (sink.line <= edge.callLine) continue;
|
|
41596
|
+
if (enclosingMethodName(types, sink.line) !== edge.callerMethod) continue;
|
|
41597
|
+
const sinkVar = sinkVariableConsumingDerived(graph, sink, derivedLocals);
|
|
41598
|
+
if (!sinkVar) continue;
|
|
41599
|
+
if (additionalFlows.some((f) => f.source_line === calleeSources[0].line && f.sink_line === sink.line)) {
|
|
41600
|
+
continue;
|
|
41601
|
+
}
|
|
41602
|
+
const source = calleeSources[0];
|
|
41603
|
+
if (fileCode && source.type === "interprocedural_param" && source.variable && DEAD_BRANCH_CHECKED_SINKS.has(sink.type) && interproceduralParamReachIsDeadBranchOnly(
|
|
41604
|
+
fileCode,
|
|
41605
|
+
callee.startLine,
|
|
41606
|
+
callee.endLine,
|
|
41607
|
+
source.variable,
|
|
41608
|
+
assignee.variable
|
|
41609
|
+
)) {
|
|
41610
|
+
continue;
|
|
41611
|
+
}
|
|
41612
|
+
if (fileCode && HELPER_RETURN_GATED_SINKS.has(sink.type) && calleeSources.every(
|
|
41613
|
+
(s) => (s.type === "interprocedural_param" || s.type === "plugin_param") && !!s.variable
|
|
41614
|
+
) && !calleeReturnMayCarryParam(
|
|
41615
|
+
fileCode,
|
|
41616
|
+
callee.startLine,
|
|
41617
|
+
callee.endLine,
|
|
41618
|
+
calleeSources.map((s) => s.variable)
|
|
41619
|
+
)) {
|
|
41620
|
+
continue;
|
|
41621
|
+
}
|
|
41622
|
+
additionalFlows.push({
|
|
41623
|
+
source_line: source.line,
|
|
41624
|
+
sink_line: sink.line,
|
|
41625
|
+
source_type: source.type,
|
|
41626
|
+
sink_type: sink.type,
|
|
41627
|
+
path: [
|
|
41628
|
+
{ variable: source.location, line: source.line, type: "source" },
|
|
41629
|
+
{ variable: assignee.variable, line: edge.callLine, type: "use" },
|
|
41630
|
+
{ variable: sinkVar, line: sink.line, type: "sink" }
|
|
41631
|
+
],
|
|
41632
|
+
confidence: sink.confidence * source.confidence * 0.85,
|
|
41633
|
+
sanitized: false
|
|
41634
|
+
});
|
|
41635
|
+
}
|
|
41636
|
+
}
|
|
41637
|
+
}
|
|
41638
|
+
function interproceduralParamReachIsDeadBranchOnly(code, startLine, endLine, paramName, localName) {
|
|
41639
|
+
if (paramName === localName) return false;
|
|
41640
|
+
const lines = code.split("\n");
|
|
41641
|
+
const slice = lines.slice(startLine - 1, endLine);
|
|
41642
|
+
const sliceText = slice.join("\n");
|
|
41643
|
+
const dead = computeDeadJavaBranchLines(slice);
|
|
41644
|
+
const onLivePaths = buildJavaTaintedVars(sliceText, /* @__PURE__ */ new Set([paramName]), dead);
|
|
41645
|
+
const ifDeadLinesCount = buildJavaTaintedVars(sliceText, /* @__PURE__ */ new Set([paramName]), /* @__PURE__ */ new Set());
|
|
41646
|
+
return ifDeadLinesCount.has(localName) && !onLivePaths.has(localName);
|
|
41647
|
+
}
|
|
41648
|
+
var HELPER_RETURN_GATED_SINKS = /* @__PURE__ */ new Set([
|
|
41649
|
+
"sql_injection",
|
|
41650
|
+
"trust_boundary",
|
|
41651
|
+
"command_injection",
|
|
41652
|
+
"path_traversal",
|
|
41653
|
+
// #976: the same helper shapes feed LDAP and XPath sinks (OWASP ldapi/xpathi).
|
|
41654
|
+
"ldap_injection",
|
|
41655
|
+
"xpath_injection"
|
|
41656
|
+
]);
|
|
41657
|
+
function calleeReturnMayCarryParam(code, startLine, endLine, sourceVars) {
|
|
41658
|
+
const raw = code.split("\n").slice(startLine - 1, endLine);
|
|
41659
|
+
const paramNames = [...sourceVars, ...javaMethodParamNames(raw)];
|
|
41660
|
+
const dead = computeDeadJavaBranchLines(raw);
|
|
41661
|
+
const inlined = /* @__PURE__ */ new Set();
|
|
41662
|
+
const slice = joinWrappedStatements(raw, inlined);
|
|
41663
|
+
const text = slice.join("\n");
|
|
41664
|
+
const seeds = new Set(paramNames);
|
|
41665
|
+
const mutated = /* @__PURE__ */ new Set();
|
|
41666
|
+
let live = new Set(seeds);
|
|
41667
|
+
for (let round = 0; round < 8; round++) {
|
|
41668
|
+
live = /* @__PURE__ */ new Set([...seeds, ...buildJavaTaintedVars(text, seeds, dead, { trackSlots: true }).keys()]);
|
|
41669
|
+
let grew = false;
|
|
41670
|
+
for (let i2 = 0; i2 < slice.length; i2++) {
|
|
41671
|
+
if (dead.has(i2)) continue;
|
|
41672
|
+
for (const call of slice[i2].matchAll(/([A-Za-z_]\w*)\s*\.\s*[A-Za-z_]\w*\s*\(([^;]*)\)/g)) {
|
|
41673
|
+
if (live.has(call[1])) continue;
|
|
41674
|
+
const args2 = call[2].replace(/"(?:[^"\\]|\\.)*"/g, " ").match(/[\p{L}\p{N}_]+/gu) ?? [];
|
|
41675
|
+
if (args2.some((t) => live.has(t))) {
|
|
41676
|
+
seeds.add(call[1]);
|
|
41677
|
+
mutated.add(call[1]);
|
|
41678
|
+
grew = true;
|
|
41679
|
+
}
|
|
41680
|
+
}
|
|
41681
|
+
const store = /^\s*([A-Za-z_]\w*)\s*(?:(?:\[[^\]=]*\]\s*)+|\.\s*[A-Za-z_]\w*\s*)=(?!=)\s*(.*?);?\s*$/.exec(slice[i2]);
|
|
41682
|
+
if (store && store[1] !== "this" && !live.has(store[1])) {
|
|
41683
|
+
const rhs = store[2].replace(/"(?:[^"\\]|\\.)*"/g, " ").match(/[\p{L}\p{N}_]+/gu) ?? [];
|
|
41684
|
+
if (rhs.some((t) => live.has(t))) {
|
|
41685
|
+
seeds.add(store[1]);
|
|
41686
|
+
mutated.add(store[1]);
|
|
41687
|
+
grew = true;
|
|
41688
|
+
}
|
|
41689
|
+
}
|
|
41690
|
+
}
|
|
41691
|
+
if (!grew) break;
|
|
41692
|
+
}
|
|
41693
|
+
let sawReturn = false;
|
|
41694
|
+
for (let i2 = 0; i2 < slice.length; i2++) {
|
|
41695
|
+
if (dead.has(i2) || !/^\s*return\b/.test(slice[i2])) continue;
|
|
41696
|
+
const m = /^\s*return\b\s*(.*?)\s*;\s*(?:\/\/.*)?$/.exec(slice[i2]);
|
|
41697
|
+
if (!m) return true;
|
|
41698
|
+
sawReturn = true;
|
|
41699
|
+
const expr = m[1];
|
|
41700
|
+
const bare = /^[A-Za-z_]\w*$/.test(expr) ? expr : null;
|
|
41701
|
+
if (bare && mutated.has(bare)) return true;
|
|
41702
|
+
if (bare && live.has(bare)) {
|
|
41703
|
+
const def = mustReachingAssignment(slice, dead, i2, bare, inlined);
|
|
41704
|
+
if (!def) return true;
|
|
41705
|
+
const upTo = slice.slice(0, def.line);
|
|
41706
|
+
upTo.push(`__helperReturn = ${def.rhs};`);
|
|
41707
|
+
const atDef = buildJavaTaintedVars(upTo.join("\n"), seeds, dead, { trackSlots: true });
|
|
41708
|
+
if (atDef.has("__helperReturn")) return true;
|
|
41709
|
+
continue;
|
|
41710
|
+
}
|
|
41711
|
+
const idents = expr.replace(/"(?:[^"\\]|\\.)*"/g, " ").replace(/'(?:[^'\\]|\\.)'/g, " ").match(/[\p{L}\p{N}_]+/gu) ?? [];
|
|
41712
|
+
if (idents.some((t) => live.has(t))) return true;
|
|
41713
|
+
}
|
|
41714
|
+
return !sawReturn;
|
|
41715
|
+
}
|
|
41716
|
+
function javaMethodParamNames(lines) {
|
|
41717
|
+
const header = lines.join("\n").split("{")[0];
|
|
41718
|
+
const open = header.indexOf("(");
|
|
41719
|
+
if (open < 0) return [];
|
|
41720
|
+
let depth = 0;
|
|
41721
|
+
let end = -1;
|
|
41722
|
+
for (let k = open; k < header.length; k++) {
|
|
41723
|
+
if (header[k] === "(") depth++;
|
|
41724
|
+
else if (header[k] === ")" && --depth === 0) {
|
|
41725
|
+
end = k;
|
|
41726
|
+
break;
|
|
41727
|
+
}
|
|
41728
|
+
}
|
|
41729
|
+
if (end < 0) return [];
|
|
41730
|
+
const names = [];
|
|
41731
|
+
let angle = 0;
|
|
41732
|
+
let piece = "";
|
|
41733
|
+
for (const c of header.slice(open + 1, end) + ",") {
|
|
41734
|
+
if (c === "<") angle++;
|
|
41735
|
+
else if (c === ">") angle--;
|
|
41736
|
+
if (c === "," && angle === 0) {
|
|
41737
|
+
const m = /([A-Za-z_]\w*)\s*(?:\[\s*\])*\s*$/.exec(piece.trim());
|
|
41738
|
+
if (m) names.push(m[1]);
|
|
41739
|
+
piece = "";
|
|
41740
|
+
} else piece += c;
|
|
41741
|
+
}
|
|
41742
|
+
return names;
|
|
41743
|
+
}
|
|
41744
|
+
function joinWrappedStatements(lines, inlined) {
|
|
41745
|
+
const out2 = [...lines];
|
|
41746
|
+
const ends = /[;{}:]\s*(?:\/\/.*)?$/;
|
|
41747
|
+
const header = /^\s*(?:if|else|for|while|do|switch|case|default|try|catch|finally|synchronized)\b|^\s*@|^\s*(?:\/\/|\/?\*)/;
|
|
41748
|
+
for (let i2 = 0; i2 < out2.length; i2++) {
|
|
41749
|
+
const line = out2[i2];
|
|
41750
|
+
if (line.trim() === "" || ends.test(line) || header.test(line)) continue;
|
|
41751
|
+
let joined = line;
|
|
41752
|
+
let j = i2 + 1;
|
|
41753
|
+
for (; j < out2.length && j < i2 + 15; j++) {
|
|
41754
|
+
joined += " " + out2[j].trim();
|
|
41755
|
+
if (ends.test(out2[j])) break;
|
|
41756
|
+
}
|
|
41757
|
+
if (j >= out2.length || j >= i2 + 15) continue;
|
|
41758
|
+
out2[i2] = joined;
|
|
41759
|
+
for (let k = i2 + 1; k <= j; k++) out2[k] = "";
|
|
41760
|
+
i2 = j;
|
|
41761
|
+
}
|
|
41762
|
+
return out2.map((line, i2) => {
|
|
41763
|
+
const body2 = inlineControlBody(line);
|
|
41764
|
+
if (body2 !== line) inlined.add(i2);
|
|
41765
|
+
return body2;
|
|
41766
|
+
});
|
|
41767
|
+
}
|
|
41768
|
+
function inlineControlBody(line) {
|
|
41769
|
+
let rest = line;
|
|
41770
|
+
const indent = /^\s*/.exec(line)[0];
|
|
41771
|
+
for (let guard = 0; guard < 4; guard++) {
|
|
41772
|
+
const t = rest.trimStart();
|
|
41773
|
+
const elseM = /^(?:\}\s*)?else\b\s*/.exec(t);
|
|
41774
|
+
if (elseM && !/^(?:\}\s*)?else\s+if\b/.test(t)) {
|
|
41775
|
+
rest = t.slice(elseM[0].length);
|
|
41776
|
+
continue;
|
|
41777
|
+
}
|
|
41778
|
+
const head = /^(?:\}\s*)?(?:else\s+)?(?:if|for|while)\s*\(/.exec(t);
|
|
41779
|
+
if (!head) break;
|
|
41780
|
+
let depth = 1;
|
|
41781
|
+
let k = head[0].length;
|
|
41782
|
+
for (; k < t.length && depth > 0; k++) {
|
|
41783
|
+
if (t[k] === "(") depth++;
|
|
41784
|
+
else if (t[k] === ")") depth--;
|
|
41785
|
+
}
|
|
41786
|
+
if (depth !== 0) return line;
|
|
41787
|
+
rest = t.slice(k);
|
|
41788
|
+
}
|
|
41789
|
+
const body2 = rest.trim();
|
|
41790
|
+
if (body2 === "" || body2 === rest.trim() && body2 === line.trim() || body2.startsWith("{")) return line;
|
|
41791
|
+
return indent + body2;
|
|
41792
|
+
}
|
|
41793
|
+
function mustReachingAssignment(slice, dead, retLine, name2, inlined) {
|
|
41794
|
+
const depth = [];
|
|
41795
|
+
let d = 0;
|
|
41796
|
+
for (const line of slice) {
|
|
41797
|
+
depth.push(d);
|
|
41798
|
+
const code = line.replace(/"(?:[^"\\]|\\.)*"/g, '""').replace(/'(?:[^'\\]|\\.)'/g, "''").replace(/\/\/.*$/, "");
|
|
41799
|
+
for (const c of code) {
|
|
41800
|
+
if (c === "{") d++;
|
|
41801
|
+
else if (c === "}") d--;
|
|
41802
|
+
}
|
|
41803
|
+
}
|
|
41804
|
+
const target = depth[retLine];
|
|
41805
|
+
const esc = name2.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
41806
|
+
const assign = new RegExp(`^\\s*(?:(?:final\\s+)?[A-Za-z_][\\w.]*(?:\\s*<[^>]*>)?(?:\\s*\\[\\s*\\])*\\s+)?${esc}\\s*=\\s*(.+?);\\s*(?://.*)?$`);
|
|
41807
|
+
const mentionsAssign = new RegExp(`(?<![\\w.])${esc}\\s*=(?!=)`);
|
|
41808
|
+
for (let j = retLine - 1; j >= 0; j--) {
|
|
41809
|
+
if (depth[j] < target) return null;
|
|
41810
|
+
if (dead.has(j)) continue;
|
|
41811
|
+
if (!mentionsAssign.test(slice[j])) continue;
|
|
41812
|
+
if (depth[j] > target || inlined.has(j)) return null;
|
|
41813
|
+
const m = assign.exec(slice[j]);
|
|
41814
|
+
if (!m) return null;
|
|
41815
|
+
return { line: j, rhs: m[1] };
|
|
41816
|
+
}
|
|
41817
|
+
return null;
|
|
41818
|
+
}
|
|
41819
|
+
function localsDerivedFromAssignee(graph, seedVar, seedLine) {
|
|
41820
|
+
const defs = graph.ir.dfg.defs;
|
|
41821
|
+
const chains = graph.ir.dfg.chains ?? [];
|
|
41822
|
+
const seedDefs = defs.filter(
|
|
41823
|
+
(d) => d.variable === seedVar && d.line === seedLine && d.kind === "local"
|
|
41824
|
+
);
|
|
41825
|
+
if (seedDefs.length === 0) return /* @__PURE__ */ new Set([seedVar]);
|
|
41826
|
+
const defIds = new Set(seedDefs.map((d) => d.id));
|
|
41827
|
+
const frontier = seedDefs.map((d) => d.id);
|
|
41828
|
+
const visited = new Set(frontier);
|
|
41829
|
+
while (frontier.length > 0) {
|
|
41830
|
+
const cur = frontier.shift();
|
|
41831
|
+
for (const ch of chains) {
|
|
41832
|
+
if (ch.from_def !== cur || visited.has(ch.to_def)) continue;
|
|
41833
|
+
visited.add(ch.to_def);
|
|
41834
|
+
defIds.add(ch.to_def);
|
|
41835
|
+
frontier.push(ch.to_def);
|
|
41836
|
+
}
|
|
41837
|
+
}
|
|
41838
|
+
const names = /* @__PURE__ */ new Set([seedVar]);
|
|
41839
|
+
for (const d of defs) {
|
|
41840
|
+
if (d.variable && defIds.has(d.id)) names.add(d.variable);
|
|
41841
|
+
}
|
|
41842
|
+
return names;
|
|
41843
|
+
}
|
|
41844
|
+
function sinkVariableConsumingDerived(graph, sink, derived) {
|
|
41845
|
+
for (const u of graph.usesAtLine(sink.line)) {
|
|
41846
|
+
if (u.variable && derived.has(u.variable)) return u.variable;
|
|
41847
|
+
}
|
|
41848
|
+
for (const call of graph.callsByLine.get(sink.line) ?? []) {
|
|
41849
|
+
for (const arg of call.arguments ?? []) {
|
|
41850
|
+
if (arg.variable && derived.has(arg.variable)) return arg.variable;
|
|
41851
|
+
if (arg.expression) {
|
|
41852
|
+
for (const v of derived) {
|
|
41853
|
+
const re = new RegExp(`\\b${v.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`);
|
|
41854
|
+
if (re.test(arg.expression)) return v;
|
|
41855
|
+
}
|
|
41856
|
+
}
|
|
41857
|
+
}
|
|
41858
|
+
}
|
|
41859
|
+
return void 0;
|
|
41860
|
+
}
|
|
41861
|
+
function enclosingMethodName(types, line) {
|
|
41862
|
+
for (const type of types) {
|
|
41863
|
+
for (const method of type.methods) {
|
|
41864
|
+
if (line >= method.start_line && line <= method.end_line) {
|
|
41865
|
+
return method.name;
|
|
41866
|
+
}
|
|
41867
|
+
}
|
|
41868
|
+
}
|
|
41869
|
+
return null;
|
|
41870
|
+
}
|
|
39704
41871
|
function csharpParamReachesSink(code, method, taintedArgs, sink, credit) {
|
|
39705
41872
|
const lines = code.split(/\r?\n/);
|
|
39706
41873
|
const params = taintedArgs.length > 0 ? method.parameters.filter((p) => taintedArgs.includes(p.position)) : method.parameters;
|
|
@@ -40441,12 +42608,26 @@ var ConstantPropagationPass = class {
|
|
|
40441
42608
|
}
|
|
40442
42609
|
}
|
|
40443
42610
|
}
|
|
40444
|
-
|
|
42611
|
+
const result = analyzeConstantPropagation(this.tree, code, {
|
|
40445
42612
|
sanitizerMethods: taintMatcher.sanitizerMethods,
|
|
40446
42613
|
taintedParameters
|
|
40447
42614
|
});
|
|
42615
|
+
if (ctx.language === "java") pruneDeadChains(ctx, result.unreachableLines);
|
|
42616
|
+
return result;
|
|
40448
42617
|
}
|
|
40449
42618
|
};
|
|
42619
|
+
function pruneDeadChains(ctx, unreachable) {
|
|
42620
|
+
if (unreachable.size === 0) return;
|
|
42621
|
+
const dfg = ctx.graph.ir.dfg;
|
|
42622
|
+
if (!dfg.chains || dfg.chains.length === 0) return;
|
|
42623
|
+
const lines = ctx.code.split("\n");
|
|
42624
|
+
const dead = /* @__PURE__ */ new Set();
|
|
42625
|
+
for (const d of dfg.defs) {
|
|
42626
|
+
if (unreachable.has(d.line) && !/\?[^?.:]*:/.test(lines[d.line - 1] ?? "")) dead.add(d.id);
|
|
42627
|
+
}
|
|
42628
|
+
if (dead.size === 0) return;
|
|
42629
|
+
dfg.chains = dfg.chains.filter((c) => !dead.has(c.from_def) && !dead.has(c.to_def));
|
|
42630
|
+
}
|
|
40450
42631
|
|
|
40451
42632
|
// src/analysis/passes/source-semantics-pass.ts
|
|
40452
42633
|
var DEMO_PATH_RE = /(?:^|\/)(?:demo|example|examples|samples|integration-tests|integration_tests)(?:\/|$)/i;
|
|
@@ -40933,13 +43114,123 @@ function argvFirstLiteralIsShell(lineText) {
|
|
|
40933
43114
|
const base = m[1].split(/[\\/]/).pop().replace(/\.exe$/i, "").toLowerCase();
|
|
40934
43115
|
return SHELL_PROGRAMS.has(base);
|
|
40935
43116
|
}
|
|
40936
|
-
function
|
|
43117
|
+
function javaLocalInitRhsBeforeLine(varName, beforeLine, methodStart, methodEnd, sourceLines) {
|
|
43118
|
+
const declAssign = new RegExp(
|
|
43119
|
+
`^\\s*(?:final\\s+)?[\\w<>,\\s\\[\\]]+\\s+${escapeReSf(varName)}\\s*=\\s*(.+?)\\s*;\\s*(?://.*)?$`
|
|
43120
|
+
);
|
|
43121
|
+
const reassign = new RegExp(`^\\s*${escapeReSf(varName)}\\s*=\\s*(.+?)\\s*;\\s*(?://.*)?$`);
|
|
43122
|
+
let lastRhs;
|
|
43123
|
+
for (let l = methodStart; l < beforeLine && l <= methodEnd; l++) {
|
|
43124
|
+
const line = (sourceLines[l - 1] ?? "").trim();
|
|
43125
|
+
const m = declAssign.exec(line) ?? reassign.exec(line);
|
|
43126
|
+
if (m) lastRhs = m[1].trim();
|
|
43127
|
+
}
|
|
43128
|
+
return lastRhs;
|
|
43129
|
+
}
|
|
43130
|
+
function callArgLooksLikeShellArgv(expr, probePrefix) {
|
|
43131
|
+
return argvFirstLiteralIsShell(`${probePrefix}${expr}`);
|
|
43132
|
+
}
|
|
43133
|
+
function parseSimpleJavaCall(expr) {
|
|
43134
|
+
const trimmed = expr.trim();
|
|
43135
|
+
const m = /^([\w][\w.]*)\s*\(/.exec(trimmed);
|
|
43136
|
+
if (!m) return null;
|
|
43137
|
+
const head = m[1];
|
|
43138
|
+
const dot = head.lastIndexOf(".");
|
|
43139
|
+
if (dot < 0) return { method: head };
|
|
43140
|
+
return { qualifier: head.slice(0, dot), method: head.slice(dot + 1) };
|
|
43141
|
+
}
|
|
43142
|
+
function javaMethodBodyReturnLooksLikeShellArgv(methodStart, methodEnd, sourceLines) {
|
|
43143
|
+
for (let l = methodStart; l <= methodEnd; l++) {
|
|
43144
|
+
const line = (sourceLines[l - 1] ?? "").trim();
|
|
43145
|
+
const ret = /\breturn\s+(.+?)\s*;/.exec(line);
|
|
43146
|
+
if (!ret) continue;
|
|
43147
|
+
if (callArgLooksLikeShellArgv(ret[1].trim(), "new ProcessBuilder(")) return true;
|
|
43148
|
+
}
|
|
43149
|
+
return false;
|
|
43150
|
+
}
|
|
43151
|
+
function javaResolveCalleeMethodLines(methodName, qualifier, refLine, types, sourceLines, ctx) {
|
|
43152
|
+
const enclosing = types.find((t) => refLine >= t.start_line && refLine <= t.end_line);
|
|
43153
|
+
const typeName = qualifier ? qualifier.includes(".") ? qualifier.split(".").pop() : qualifier : enclosing?.name;
|
|
43154
|
+
if (!typeName) return void 0;
|
|
43155
|
+
const tryType = (t, lines) => {
|
|
43156
|
+
const mm = t.methods.find((m) => m.name === methodName);
|
|
43157
|
+
if (!mm) return void 0;
|
|
43158
|
+
return { start: mm.start_line, end: mm.end_line, lines };
|
|
43159
|
+
};
|
|
43160
|
+
if (ctx?.projectGraph && ctx.sourceLinesByFile) {
|
|
43161
|
+
for (const fp of ctx.projectGraph.filePaths) {
|
|
43162
|
+
const ir = ctx.projectGraph.getIR(fp);
|
|
43163
|
+
if (!ir) continue;
|
|
43164
|
+
const t = ir.types.find((tt) => tt.name === typeName);
|
|
43165
|
+
if (!t) continue;
|
|
43166
|
+
const lines = ctx.sourceLinesByFile.get(fp);
|
|
43167
|
+
if (!lines) continue;
|
|
43168
|
+
const hit = tryType(t, lines);
|
|
43169
|
+
if (hit) return hit;
|
|
43170
|
+
}
|
|
43171
|
+
}
|
|
43172
|
+
const local = types.find((t) => t.name === typeName);
|
|
43173
|
+
if (local) return tryType(local, sourceLines);
|
|
43174
|
+
return void 0;
|
|
43175
|
+
}
|
|
43176
|
+
function javaExpressionLooksLikeShellArgv(expr, refLine, types, sourceLines, ctx) {
|
|
43177
|
+
if (callArgLooksLikeShellArgv(expr, "new ProcessBuilder(")) return true;
|
|
43178
|
+
const parsed = parseSimpleJavaCall(expr);
|
|
43179
|
+
if (!parsed) return false;
|
|
43180
|
+
const body2 = javaResolveCalleeMethodLines(
|
|
43181
|
+
parsed.method,
|
|
43182
|
+
parsed.qualifier,
|
|
43183
|
+
refLine,
|
|
43184
|
+
types,
|
|
43185
|
+
sourceLines,
|
|
43186
|
+
ctx
|
|
43187
|
+
);
|
|
43188
|
+
if (!body2) return false;
|
|
43189
|
+
return javaMethodBodyReturnLooksLikeShellArgv(body2.start, body2.end, body2.lines);
|
|
43190
|
+
}
|
|
43191
|
+
function javaFieldShellArgvWrittenBeforeLine(fieldName, beforeLine, methodStart, methodEnd, sourceLines, types, ctx) {
|
|
43192
|
+
const cap = fieldName.charAt(0).toUpperCase() + fieldName.slice(1);
|
|
43193
|
+
const beanSetter = new RegExp(`\\bset${escapeReSf(cap)}\\s*\\((.+)\\)\\s*;?\\s*$`);
|
|
43194
|
+
const fieldAssign = new RegExp(`^\\s*(?:this\\.)?${escapeReSf(fieldName)}\\s*=\\s*(.+?)\\s*;\\s*(?://.*)?$`);
|
|
43195
|
+
for (let l = methodStart; l < beforeLine && l <= methodEnd; l++) {
|
|
43196
|
+
const line = (sourceLines[l - 1] ?? "").trim();
|
|
43197
|
+
const sm = beanSetter.exec(line);
|
|
43198
|
+
if (sm && javaExpressionLooksLikeShellArgv(sm[1].trim(), l, types, sourceLines, ctx)) {
|
|
43199
|
+
return true;
|
|
43200
|
+
}
|
|
43201
|
+
const fm = fieldAssign.exec(line);
|
|
43202
|
+
if (fm && callArgLooksLikeShellArgv(fm[1].trim(), "new ProcessBuilder(")) return true;
|
|
43203
|
+
}
|
|
43204
|
+
return false;
|
|
43205
|
+
}
|
|
43206
|
+
function sameFileCallerPassesShellArgv(paramName, methodName, sinkLine, types, calls, sourceLines) {
|
|
40937
43207
|
if (!methodName) return false;
|
|
40938
43208
|
for (const t of types) {
|
|
40939
43209
|
const m = t.methods.find((mm) => mm.name === methodName && sinkLine >= mm.start_line && sinkLine <= mm.end_line);
|
|
40940
43210
|
if (!m) continue;
|
|
40941
43211
|
const pos = m.parameters.findIndex((p) => p.name === paramName);
|
|
40942
|
-
if (pos < 0)
|
|
43212
|
+
if (pos < 0) {
|
|
43213
|
+
const isField = t.fields?.some((f) => f.name === paramName);
|
|
43214
|
+
if (!isField) return false;
|
|
43215
|
+
return calls.some((c) => {
|
|
43216
|
+
if (c.method_name !== methodName) return false;
|
|
43217
|
+
if (c.receiver != null && c.receiver !== "this") return false;
|
|
43218
|
+
if (c.location.line < t.start_line || c.location.line > t.end_line) return false;
|
|
43219
|
+
if (c.arguments.length !== m.parameters.length) return false;
|
|
43220
|
+
const callerMethod = t.methods.find(
|
|
43221
|
+
(mm) => c.location.line >= mm.start_line && c.location.line <= mm.end_line
|
|
43222
|
+
);
|
|
43223
|
+
if (!callerMethod) return false;
|
|
43224
|
+
return javaFieldShellArgvWrittenBeforeLine(
|
|
43225
|
+
paramName,
|
|
43226
|
+
c.location.line,
|
|
43227
|
+
callerMethod.start_line,
|
|
43228
|
+
callerMethod.end_line,
|
|
43229
|
+
sourceLines,
|
|
43230
|
+
types
|
|
43231
|
+
);
|
|
43232
|
+
});
|
|
43233
|
+
}
|
|
40943
43234
|
return calls.some((c) => {
|
|
40944
43235
|
if (c.method_name !== methodName) return false;
|
|
40945
43236
|
if (c.receiver != null && c.receiver !== "this") return false;
|
|
@@ -40947,8 +43238,30 @@ function sameFileCallerPassesShellArgv(paramName, methodName, sinkLine, types, c
|
|
|
40947
43238
|
if (c.arguments.length !== m.parameters.length) return false;
|
|
40948
43239
|
const shadowed = types.some((u) => u !== t && u.start_line >= t.start_line && u.end_line <= t.end_line && (u.start_line > t.start_line || u.end_line < t.end_line) && c.location.line >= u.start_line && c.location.line <= u.end_line && u.methods.some((um) => um.name === methodName && um.parameters.length === c.arguments.length));
|
|
40949
43240
|
if (shadowed) return false;
|
|
40950
|
-
const expr = c.arguments[pos]?.expression;
|
|
40951
|
-
|
|
43241
|
+
const expr = (c.arguments[pos]?.expression ?? "").trim();
|
|
43242
|
+
if (!expr) return false;
|
|
43243
|
+
if (javaExpressionLooksLikeShellArgv(expr, c.location.line, types, sourceLines)) {
|
|
43244
|
+
return true;
|
|
43245
|
+
}
|
|
43246
|
+
const argVar = c.arguments[pos]?.variable;
|
|
43247
|
+
if (argVar && expr === argVar && !/[.(]/.test(expr)) {
|
|
43248
|
+
const callerMethod = t.methods.find(
|
|
43249
|
+
(mm) => c.location.line >= mm.start_line && c.location.line <= mm.end_line
|
|
43250
|
+
);
|
|
43251
|
+
if (callerMethod) {
|
|
43252
|
+
const rhs = javaLocalInitRhsBeforeLine(
|
|
43253
|
+
argVar,
|
|
43254
|
+
c.location.line,
|
|
43255
|
+
callerMethod.start_line,
|
|
43256
|
+
callerMethod.end_line,
|
|
43257
|
+
sourceLines
|
|
43258
|
+
);
|
|
43259
|
+
if (rhs && javaExpressionLooksLikeShellArgv(rhs, c.location.line, types, sourceLines)) {
|
|
43260
|
+
return true;
|
|
43261
|
+
}
|
|
43262
|
+
}
|
|
43263
|
+
}
|
|
43264
|
+
return false;
|
|
40952
43265
|
});
|
|
40953
43266
|
}
|
|
40954
43267
|
return false;
|
|
@@ -41002,13 +43315,44 @@ var HTML_CONTENT_TYPE_RE = /text\/html|TEXT_HTML/;
|
|
|
41002
43315
|
var FETCH_GLOBAL_RECEIVER_RE = /(?:^|[^.\w])(?:window|globalThis|self|global)\s*\.\s*fetch\s*\(/;
|
|
41003
43316
|
var FETCH_MEMBER_RECEIVER_RE = /[\w$)\]]\s*\.\s*fetch\s*\(/;
|
|
41004
43317
|
var NOSQL_ARRAY_METHODS = /* @__PURE__ */ new Set(["find", "filter", "some", "every", "findIndex", "findLast"]);
|
|
43318
|
+
var SHELL_PROGRAM = /(?:^|[\\/])(?:sh|bash|zsh|dash|ksh|fish|cmd(?:\.exe)?|powershell(?:\.exe)?|pwsh|node|python3?|perl|ruby|php|osascript|env)$/i;
|
|
41005
43319
|
var FUNCTION_FIRST_ARG_RE = /\.\s*(?:find|filter|some|every|findIndex|findLast)\s*\(\s*(?:async\s+)?(?:function\b|(?:\([^()]*\)|[A-Za-z_$][\w$]*)\s*=>)/;
|
|
43320
|
+
var NAMED_ARRAY_PREDICATE_RE = /([A-Za-z_$][\w$]*)\s*\.\s*(find|filter|some|every|findIndex|findLast)\s*\(\s*([A-Za-z_$][\w$]*)\s*\)/;
|
|
43321
|
+
function isDeclaredFunctionName(name2, lines) {
|
|
43322
|
+
const n = name2.replace(/[$]/g, "\\$");
|
|
43323
|
+
const decls = [
|
|
43324
|
+
new RegExp(`\\bfunction\\s+${n}\\s*[(<]`),
|
|
43325
|
+
new RegExp(`\\b(?:const|let|var)\\s+${n}\\s*(?::[^=]*)?=\\s*(?:async\\s+)?(?:function\\b|\\(|[A-Za-z_$][\\w$]*\\s*=>)`)
|
|
43326
|
+
];
|
|
43327
|
+
return lines.some((l) => decls.some((re) => re.test(l)));
|
|
43328
|
+
}
|
|
43329
|
+
function isDeclaredArrayName(name2, lines) {
|
|
43330
|
+
const n = name2.replace(/[$]/g, "\\$");
|
|
43331
|
+
const re = new RegExp(
|
|
43332
|
+
`\\b${n}\\s*(?:\\??\\s*:\\s*(?:readonly\\s+)?(?:[\\w$.<>,\\s]+\\[\\]|(?:Readonly)?Array\\s*<)|(?::[^=;]*)?=\\s*(?:\\[|new\\s+Array\\b|Array\\.(?:from|of)\\b))`
|
|
43333
|
+
);
|
|
43334
|
+
return lines.some((l) => re.test(l));
|
|
43335
|
+
}
|
|
41006
43336
|
var ORM_BUILDER_KEY_RE = /[{,]\s*(?:where|select|populate|include|orderBy|relations|attributes)\s*:/;
|
|
41007
43337
|
var BROWSER_COMPONENT_EXT_RE = /\.(?:jsx|tsx|vue|svelte)$/;
|
|
41008
43338
|
var CLIENT_SIGNAL_RE = /["']use client["']|\buse(?:State|Effect|Ref|Callback|Memo|Context|Reducer|LayoutEffect)\s*\(|\b(?:window|document|localStorage|sessionStorage|navigator)\s*\.|\son(?:Click|Change|Submit|Input|KeyDown|KeyUp|MouseOver|Focus|Blur)\s*=/;
|
|
41009
43339
|
var SERVER_SIGNAL_RE = /["']use server["']|\b(?:getServerSideProps|getStaticProps|getStaticPaths)\b|from\s+["']next\/server["']|\bNext(?:Api)?(?:Request|Response)\b|from\s+["'](?:node:)?(?:fs|child_process|http|https|net|dns|dgram)["']|\bexport\s+(?:default\s+)?(?:async\s+)?function\s+handler\s*\(/;
|
|
41010
43340
|
var FIXED_HOST_TEMPLATE_RE = /`https?:\/\/[^/${}\s`]+[/`]/;
|
|
41011
43341
|
var BASH_FIXED_HOST_URL_RE = /^(?:https?|ftp):\/\/[A-Za-z0-9.-]+(?::\d+)?\//;
|
|
43342
|
+
var RUST_FIXED_HOST_FORMAT_RE = /format!\(\s*"https?:\/\/[^"{}]+\/\{\}"/;
|
|
43343
|
+
function rustSsrfRequestUsesFixedHostFormat(code, sinkLine) {
|
|
43344
|
+
const lines = code.split("\n");
|
|
43345
|
+
const sinkText = lines[sinkLine - 1] ?? "";
|
|
43346
|
+
const argMatch = sinkText.match(/(?:reqwest::)?get\s*\(\s*&?(\w+)/);
|
|
43347
|
+
if (!argMatch) return false;
|
|
43348
|
+
const varName = argMatch[1];
|
|
43349
|
+
const assignRe = new RegExp(`\\blet\\s+${escapeRegex2(varName)}\\s*=\\s*format!`);
|
|
43350
|
+
for (let i2 = sinkLine - 2; i2 >= Math.max(0, sinkLine - 20); i2--) {
|
|
43351
|
+
const line = lines[i2] ?? "";
|
|
43352
|
+
if (assignRe.test(line) && RUST_FIXED_HOST_FORMAT_RE.test(line)) return true;
|
|
43353
|
+
}
|
|
43354
|
+
return false;
|
|
43355
|
+
}
|
|
41012
43356
|
function literalEndsInitializer(code, end) {
|
|
41013
43357
|
let i2 = end;
|
|
41014
43358
|
let crossedNewline = false;
|
|
@@ -41180,7 +43524,9 @@ function isUnwrittenLocalMapKeyRead(code, source) {
|
|
|
41180
43524
|
if (!read) return false;
|
|
41181
43525
|
const [, recv, key] = read;
|
|
41182
43526
|
const ctorRe = new RegExp(
|
|
41183
|
-
|
|
43527
|
+
// `new HashMap<>()` or the qualified `new java.util.HashMap<>()` (OWASP
|
|
43528
|
+
// BenchmarkJava writes the qualified form throughout).
|
|
43529
|
+
`\\b${recv}\\s*=\\s*new\\s+(?:java\\.util\\.(?:concurrent\\.)?)?(?:Hash|Tree|LinkedHash|ConcurrentHash|Concurrent|Identity|Weak)?Map\\s*(?:<[^>]*>)?\\s*\\(`
|
|
41184
43530
|
);
|
|
41185
43531
|
if (!lines.some((l) => ctorRe.test(l))) return false;
|
|
41186
43532
|
const escapeRe2 = new RegExp(`\\w\\s*\\([^)]*(?<![\\w.])${recv}(?![\\w.])[^)]*\\)`);
|
|
@@ -41190,26 +43536,46 @@ function isUnwrittenLocalMapKeyRead(code, source) {
|
|
|
41190
43536
|
if (escapeRe2.test(stripped)) return false;
|
|
41191
43537
|
}
|
|
41192
43538
|
const putRe = new RegExp(`\\b${recv}\\s*\\.\\s*put\\s*\\(\\s*"${key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}"`);
|
|
41193
|
-
if (lines.some((l) => putRe.test(l))) return
|
|
43539
|
+
if (lines.some((l) => putRe.test(l))) return isLiteralOnlyLocalMapKey(lines, recv, key);
|
|
41194
43540
|
return true;
|
|
41195
43541
|
}
|
|
41196
|
-
function
|
|
41197
|
-
const
|
|
41198
|
-
const literalPut = new RegExp(
|
|
41199
|
-
`\\b${recv}\\s*\\.\\s*put\\s*\\(\\s*(?:"(?:[^"\\\\]|\\\\.)*"|[A-Za-z_][\\w.]*)\\s*,\\s*"(?:[^"\\\\]|\\\\.)*"\\s*\\)`,
|
|
41200
|
-
"g"
|
|
41201
|
-
);
|
|
43542
|
+
function isLiteralOnlyLocalMapKey(lines, recv, key) {
|
|
43543
|
+
const escapedKey = key.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
41202
43544
|
const otherMutator = new RegExp(
|
|
41203
43545
|
`\\b${recv}\\s*\\.\\s*(?:putAll|putIfAbsent|compute|computeIfAbsent|computeIfPresent|merge|replace|replaceAll|entrySet|values)\\s*\\(`
|
|
41204
43546
|
);
|
|
41205
|
-
|
|
41206
|
-
|
|
43547
|
+
if (lines.some((l) => otherMutator.test(l))) return false;
|
|
43548
|
+
const keyPut = new RegExp(
|
|
43549
|
+
`\\b${recv}\\s*\\.\\s*put\\s*\\(\\s*"${escapedKey}"\\s*,\\s*"(?:[^"\\\\]|\\\\.)*"\\s*\\)`
|
|
43550
|
+
);
|
|
43551
|
+
const anyKeyPut = new RegExp(`\\b${recv}\\s*\\.\\s*put\\s*\\(\\s*"${escapedKey}"`);
|
|
43552
|
+
let putsForKey = 0;
|
|
43553
|
+
let literalPutsForKey = 0;
|
|
41207
43554
|
for (const l of lines) {
|
|
41208
|
-
|
|
41209
|
-
|
|
41210
|
-
literalPuts += (l.match(literalPut) ?? []).length;
|
|
43555
|
+
putsForKey += (l.match(anyKeyPut) ?? []).length;
|
|
43556
|
+
literalPutsForKey += (l.match(keyPut) ?? []).length;
|
|
41211
43557
|
}
|
|
41212
|
-
return
|
|
43558
|
+
return putsForKey > 0 && putsForKey === literalPutsForKey;
|
|
43559
|
+
}
|
|
43560
|
+
function isJsDisguisedCacheDbInputRead(code, source) {
|
|
43561
|
+
if (source.type !== "db_input") return false;
|
|
43562
|
+
const loc = source.location ?? "";
|
|
43563
|
+
if (!/\.cache\.get\s*\(/i.test(loc) && !/\bcache\.get\s*\(/i.test(loc)) return false;
|
|
43564
|
+
const lines = code.split("\n");
|
|
43565
|
+
const lineText = lines[source.line - 1] ?? "";
|
|
43566
|
+
if (/\w+\.cache\.get\s*\(/.test(lineText)) return true;
|
|
43567
|
+
const read = /\b([A-Za-z_]\w*)\s*\.\s*get\s*\(/.exec(lineText);
|
|
43568
|
+
if (!read) return false;
|
|
43569
|
+
const recv = read[1];
|
|
43570
|
+
if (recv !== "cache") return false;
|
|
43571
|
+
const mapCtor = new RegExp(
|
|
43572
|
+
`\\b${recv}\\s*=\\s*new\\s+(?:Hash|Tree|LinkedHash|ConcurrentHash|Concurrent|Identity|Weak)?Map\\s*(?:<[^>]*>)?\\s*\\(`
|
|
43573
|
+
);
|
|
43574
|
+
if (lines.some((l) => mapCtor.test(l))) return true;
|
|
43575
|
+
const redisClient = new RegExp(
|
|
43576
|
+
`\\b${recv}\\s*=\\s*(?:await\\s+)?(?:redis\\.)?createClient\\s*\\(`
|
|
43577
|
+
);
|
|
43578
|
+
return !lines.some((l) => redisClient.test(l));
|
|
41213
43579
|
}
|
|
41214
43580
|
function csharpContentServesHtml(call) {
|
|
41215
43581
|
if (call.receiver !== null && call.receiver !== "this" && call.receiver !== "base") return false;
|
|
@@ -41217,8 +43583,8 @@ function csharpContentServesHtml(call) {
|
|
|
41217
43583
|
if (contentType === void 0) return true;
|
|
41218
43584
|
const literal = /^@?"([^"]*)"$/.exec(contentType);
|
|
41219
43585
|
if (literal) return /^\s*(?:text\/html|text\/xml|application\/xml|[\w.-]+\/[\w.-]+\+xml)\b/i.test(literal[1]);
|
|
41220
|
-
const
|
|
41221
|
-
if (
|
|
43586
|
+
const named2 = /^(?:System\s*\.\s*Net\s*\.\s*Mime\s*\.\s*)?MediaTypeNames\s*\.\s*(Text|Application)\s*\.\s*(\w+)$/.exec(contentType);
|
|
43587
|
+
if (named2) return named2[2] === "Html" || named2[2] === "Xml";
|
|
41222
43588
|
return true;
|
|
41223
43589
|
}
|
|
41224
43590
|
function csharpContentCallInheritsHelper(call, types, sourceLines) {
|
|
@@ -41385,7 +43751,7 @@ function findEnclosingMethodFromIr(types, sinkLine) {
|
|
|
41385
43751
|
return null;
|
|
41386
43752
|
}
|
|
41387
43753
|
function splitJavaConcatTokens(rhs) {
|
|
41388
|
-
const
|
|
43754
|
+
const tokens2 = [];
|
|
41389
43755
|
let cur = "";
|
|
41390
43756
|
let depth = 0;
|
|
41391
43757
|
let inString = false;
|
|
@@ -41422,7 +43788,7 @@ function splitJavaConcatTokens(rhs) {
|
|
|
41422
43788
|
continue;
|
|
41423
43789
|
}
|
|
41424
43790
|
if (ch === "+" && depth === 0) {
|
|
41425
|
-
|
|
43791
|
+
tokens2.push(cur.trim());
|
|
41426
43792
|
cur = "";
|
|
41427
43793
|
i2++;
|
|
41428
43794
|
continue;
|
|
@@ -41430,8 +43796,8 @@ function splitJavaConcatTokens(rhs) {
|
|
|
41430
43796
|
cur += ch;
|
|
41431
43797
|
i2++;
|
|
41432
43798
|
}
|
|
41433
|
-
if (cur.trim())
|
|
41434
|
-
return
|
|
43799
|
+
if (cur.trim()) tokens2.push(cur.trim());
|
|
43800
|
+
return tokens2;
|
|
41435
43801
|
}
|
|
41436
43802
|
function isImplicitlyAnchoredAllowlistRegex(re) {
|
|
41437
43803
|
if (re === "") return false;
|
|
@@ -41536,7 +43902,7 @@ var SinkFilterPass = class {
|
|
|
41536
43902
|
const executableSources = ctx.code && ctx.language ? mergedSources.filter(
|
|
41537
43903
|
(s) => !isNonExecutableSourceLine(ctx.code, s.line, ctx.language)
|
|
41538
43904
|
) : mergedSources;
|
|
41539
|
-
const sources = ctx.code ? executableSources.filter((s) => !isUnwrittenLocalMapKeyRead(ctx.code, s)) : executableSources;
|
|
43905
|
+
const sources = ctx.code ? executableSources.filter((s) => !isUnwrittenLocalMapKeyRead(ctx.code, s)).filter((s) => !isJsDisguisedCacheDbInputRead(ctx.code, s)) : executableSources;
|
|
41540
43906
|
const sinks = [...taintMatcher.sinks];
|
|
41541
43907
|
for (const s of langSources.additionalSinks) {
|
|
41542
43908
|
const springReturn = s.type === "xss" && typeof s.location === "string" && s.location.startsWith("Spring handler returns HTML");
|
|
@@ -41844,7 +44210,7 @@ var SinkFilterPass = class {
|
|
|
41844
44210
|
const varName = arg0.variable ?? "";
|
|
41845
44211
|
if (varName !== "" && argExpr === varName && !/[(.]/.test(argExpr)) {
|
|
41846
44212
|
const t = resolveIdentifierType(varName, ctorCall.in_method, irTypes);
|
|
41847
|
-
if (isArgvContainerType(t) && !sameFileCallerPassesShellArgv(varName, ctorCall.in_method, ctorCall.location.line, irTypes, irCalls)) {
|
|
44213
|
+
if (isArgvContainerType(t) && !sameFileCallerPassesShellArgv(varName, ctorCall.in_method, ctorCall.location.line, irTypes, irCalls, sourceLines)) {
|
|
41848
44214
|
return false;
|
|
41849
44215
|
}
|
|
41850
44216
|
}
|
|
@@ -42027,11 +44393,11 @@ var SinkFilterPass = class {
|
|
|
42027
44393
|
rhs = sqlVar;
|
|
42028
44394
|
}
|
|
42029
44395
|
if (!rhs) return true;
|
|
42030
|
-
const
|
|
42031
|
-
if (
|
|
44396
|
+
const tokens2 = splitJavaConcatTokens(rhs);
|
|
44397
|
+
if (tokens2.length < 2) return true;
|
|
42032
44398
|
let hasPlaceholder = false;
|
|
42033
44399
|
const methodCallNames = [];
|
|
42034
|
-
for (const tk of
|
|
44400
|
+
for (const tk of tokens2) {
|
|
42035
44401
|
if (/^"(?:[^"\\]|\\.)*"$/.test(tk)) {
|
|
42036
44402
|
if (tk.includes("?")) hasPlaceholder = true;
|
|
42037
44403
|
continue;
|
|
@@ -42088,13 +44454,44 @@ var SinkFilterPass = class {
|
|
|
42088
44454
|
return !FETCH_MEMBER_RECEIVER_RE.test(sinkLineText);
|
|
42089
44455
|
});
|
|
42090
44456
|
}
|
|
44457
|
+
if (["javascript", "typescript"].includes(language)) {
|
|
44458
|
+
const lines = ctx.code.split("\n");
|
|
44459
|
+
const FIXED_PROGRAM_EXEC = /* @__PURE__ */ new Set(["spawn", "spawnSync", "execFile", "execFileSync"]);
|
|
44460
|
+
filtered = filtered.filter((sink) => {
|
|
44461
|
+
if (sink.type !== "command_injection" || !FIXED_PROGRAM_EXEC.has(sink.method ?? "")) return true;
|
|
44462
|
+
let stmt = lines[sink.line - 1] ?? "";
|
|
44463
|
+
for (let k = 0; k < 8 && !/\)\s*;?\s*$/.test(stmt.replace(/\/\/.*$/, "")); k++) {
|
|
44464
|
+
stmt += " " + (lines[sink.line + k] ?? "").trim();
|
|
44465
|
+
}
|
|
44466
|
+
const call = new RegExp(`\\b${sink.method}\\s*\\(\\s*([^,)]+)`).exec(stmt);
|
|
44467
|
+
if (!call) return true;
|
|
44468
|
+
const program = call[1].trim();
|
|
44469
|
+
const literal = /^(['"`])([^'"`$]*)\1$/.exec(program);
|
|
44470
|
+
const fixed = program === "process.execPath" || literal !== null && !SHELL_PROGRAM.test(literal[2]);
|
|
44471
|
+
if (!fixed) return true;
|
|
44472
|
+
if (/\bshell\s*:\s*(?!false\b)/.test(stmt)) return true;
|
|
44473
|
+
if (/['"`]-(?:e|p|-eval|-print)['"`]/.test(stmt)) return true;
|
|
44474
|
+
return false;
|
|
44475
|
+
});
|
|
44476
|
+
}
|
|
42091
44477
|
if (["javascript", "typescript"].includes(language)) {
|
|
42092
44478
|
const sourceLines = ctx.code.split("\n");
|
|
42093
44479
|
filtered = filtered.filter((sink) => {
|
|
42094
44480
|
if (sink.type !== "nosql_injection") return true;
|
|
42095
44481
|
if (!NOSQL_ARRAY_METHODS.has(sink.method ?? "")) return true;
|
|
42096
|
-
|
|
42097
|
-
|
|
44482
|
+
let sinkLineText = sourceLines[sink.line - 1] ?? "";
|
|
44483
|
+
for (let k = 0; k < 3 && /\(\s*$/.test(sinkLineText); k++) {
|
|
44484
|
+
sinkLineText += " " + (sourceLines[sink.line + k] ?? "").trim();
|
|
44485
|
+
}
|
|
44486
|
+
if (FUNCTION_FIRST_ARG_RE.test(sinkLineText)) return false;
|
|
44487
|
+
const named2 = NAMED_ARRAY_PREDICATE_RE.exec(sinkLineText);
|
|
44488
|
+
if (named2) {
|
|
44489
|
+
const [, receiver, method, arg] = named2;
|
|
44490
|
+
if (NOSQL_ARRAY_METHODS.has(method) && (isDeclaredFunctionName(arg, sourceLines) || isDeclaredArrayName(receiver, sourceLines))) {
|
|
44491
|
+
return false;
|
|
44492
|
+
}
|
|
44493
|
+
}
|
|
44494
|
+
return true;
|
|
42098
44495
|
});
|
|
42099
44496
|
}
|
|
42100
44497
|
if (["javascript", "typescript"].includes(language)) {
|
|
@@ -42211,6 +44608,12 @@ var SinkFilterPass = class {
|
|
|
42211
44608
|
return bodyCalls.length === 0 || !bodyCalls.every(rustBodyDeclaresNonHtmlType);
|
|
42212
44609
|
});
|
|
42213
44610
|
}
|
|
44611
|
+
if (language === "rust") {
|
|
44612
|
+
filtered = filtered.filter((sink) => {
|
|
44613
|
+
if (sink.type !== "ssrf") return true;
|
|
44614
|
+
return !rustSsrfRequestUsesFixedHostFormat(ctx.code, sink.line);
|
|
44615
|
+
});
|
|
44616
|
+
}
|
|
42214
44617
|
if (language === "bash") {
|
|
42215
44618
|
const sourceLines = ctx.code.split("\n");
|
|
42216
44619
|
filtered = filtered.filter((sink) => {
|
|
@@ -42733,7 +45136,9 @@ function filterCleanVariableSinks(sinks, calls, taintedVars, symbols, dfg, sanit
|
|
|
42733
45136
|
return sinks.filter((sink) => {
|
|
42734
45137
|
const callsAtSink = callsByLine.get(sink.line) ?? [];
|
|
42735
45138
|
const isInSynchronizedBlock = synchronizedLines?.has(sink.line) ?? false;
|
|
42736
|
-
const relevantCalls = sink.method ? callsAtSink.filter(
|
|
45139
|
+
const relevantCalls = sink.method ? callsAtSink.filter(
|
|
45140
|
+
(c) => c.method_name === sink.method && (sink.callColumn === void 0 || c.location.column === sink.callColumn)
|
|
45141
|
+
) : callsAtSink;
|
|
42737
45142
|
const trustArgPositions = language !== "bash" && language !== "shell";
|
|
42738
45143
|
for (const call of relevantCalls) {
|
|
42739
45144
|
let allArgsAreClean = true;
|
|
@@ -43498,19 +45903,59 @@ function rustAttributesAbove(lines, startLine) {
|
|
|
43498
45903
|
continue;
|
|
43499
45904
|
}
|
|
43500
45905
|
if (t === "" || t.startsWith("//")) continue;
|
|
45906
|
+
if (out2.length > 0) break;
|
|
43501
45907
|
break;
|
|
43502
45908
|
}
|
|
43503
45909
|
return out2;
|
|
43504
45910
|
}
|
|
45911
|
+
function isModuleLevelFunction(method, lines) {
|
|
45912
|
+
const first = lines[method.start_line - 1] ?? "";
|
|
45913
|
+
return !/^\s/.test(first);
|
|
45914
|
+
}
|
|
45915
|
+
function jsTsExportBinding(exportName, lines) {
|
|
45916
|
+
const esc = exportName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
45917
|
+
const text = lines.join("\n");
|
|
45918
|
+
const first = lines.find((l) => /^\s*(?:export|function|const|async)/.test(l)) ?? "";
|
|
45919
|
+
if (/^export\s+(?:default\s+)?(?:async\s+)?(?:function\b|(?:const|let|var)\s+)/.test(first.trimStart()) && new RegExp(`\\b${esc}\\b`).test(first)) {
|
|
45920
|
+
return true;
|
|
45921
|
+
}
|
|
45922
|
+
if (new RegExp(`(?:^|\\n)\\s*export\\s*\\{[^}]*\\b${esc}\\b`).test(text)) return true;
|
|
45923
|
+
if (new RegExp(`(?:^|[^\\w$.])(?:module\\s*\\.\\s*)?exports\\s*\\.\\s*${esc}\\s*=`).test(text)) return true;
|
|
45924
|
+
if (new RegExp(`module\\s*\\.\\s*exports\\s*=\\s*\\{[^}]*\\b${esc}\\b`).test(text)) return true;
|
|
45925
|
+
return false;
|
|
45926
|
+
}
|
|
45927
|
+
var CHANNEL_EXPORT_HANDLER_NAMES = /* @__PURE__ */ new Set([
|
|
45928
|
+
"handle",
|
|
45929
|
+
"getUser",
|
|
45930
|
+
"onMessage",
|
|
45931
|
+
"onWebhook",
|
|
45932
|
+
"resolveUser",
|
|
45933
|
+
"sse"
|
|
45934
|
+
]);
|
|
45935
|
+
var CHANNEL_HANDLER_PARAM = /^(event|req|request|ctx|context|message|payload|topic|id|user|_|args|info)$/;
|
|
45936
|
+
function hasChannelHandlerParamSignature(method) {
|
|
45937
|
+
if (method.parameters.length === 0) return false;
|
|
45938
|
+
return method.parameters.some((p) => CHANNEL_HANDLER_PARAM.test(p.name));
|
|
45939
|
+
}
|
|
45940
|
+
function isChannelExportedHandler(method, language, lines) {
|
|
45941
|
+
if (language !== "javascript" && language !== "typescript") return false;
|
|
45942
|
+
if (!isModuleLevelFunction(method, lines)) return false;
|
|
45943
|
+
if (!CHANNEL_EXPORT_HANDLER_NAMES.has(method.name)) return false;
|
|
45944
|
+
if (!hasChannelHandlerParamSignature(method)) return false;
|
|
45945
|
+
return jsTsExportBinding(method.name, lines);
|
|
45946
|
+
}
|
|
43505
45947
|
function isLambdaEntryPoint(method, language, lines) {
|
|
43506
45948
|
const names = method.parameters.map((p) => p.name);
|
|
43507
45949
|
const first = lines[method.start_line - 1] ?? "";
|
|
43508
|
-
if (
|
|
45950
|
+
if (!isModuleLevelFunction(method, lines)) return false;
|
|
43509
45951
|
if (language === "python") {
|
|
43510
45952
|
return method.name === "lambda_handler" && names.length === 2 && names[0] === "event" && names[1] === "context";
|
|
43511
45953
|
}
|
|
43512
45954
|
if (language !== "javascript" && language !== "typescript") return false;
|
|
43513
45955
|
if (method.name !== "handler") return false;
|
|
45956
|
+
if (names.length === 1 && names[0] === "event") {
|
|
45957
|
+
return jsTsExportBinding("handler", lines) || /^export\s+(?:default\s+)?(?:async\s+)?(?:function\b|(?:const|let|var)\s+handler\b)/.test(first);
|
|
45958
|
+
}
|
|
43514
45959
|
if (names.length < 2 || names.length > 3 || names[0] !== "event" || names[1] !== "context") return false;
|
|
43515
45960
|
if (names.length === 3 && names[2] !== "callback") return false;
|
|
43516
45961
|
if (/^export\s+(?:default\s+)?(?:async\s+)?(?:function\b|(?:const|let|var)\s+handler\b)/.test(first)) return true;
|
|
@@ -43520,6 +45965,7 @@ function isLambdaEntryPoint(method, language, lines) {
|
|
|
43520
45965
|
function isFrameworkHandler(method, language, lines) {
|
|
43521
45966
|
if (method.annotations.some((a) => ROUTE_ANNOTATION.test(a))) return true;
|
|
43522
45967
|
if (isLambdaEntryPoint(method, language, lines)) return true;
|
|
45968
|
+
if (isChannelExportedHandler(method, language, lines)) return true;
|
|
43523
45969
|
if (language === "rust") {
|
|
43524
45970
|
if (rustAttributesAbove(lines, method.start_line).some((a) => RUST_ROUTE_ATTR.test(a))) return true;
|
|
43525
45971
|
if (method.return_type && RUST_HANDLER_RETURN.test(method.return_type)) return true;
|
|
@@ -43535,6 +45981,11 @@ function isReactHtmlComponent(m, f, lines) {
|
|
|
43535
45981
|
const sig = lines[m.start_line - 1] ?? "";
|
|
43536
45982
|
return /\bfunction\s+[A-Z][A-Za-z0-9]*\s*\(\s*\{/.test(sig);
|
|
43537
45983
|
}
|
|
45984
|
+
function isRustDieselSqlParamFlow(f, lines) {
|
|
45985
|
+
if (f.source_type !== "interprocedural_param" || f.sink_type !== "sql_injection") return false;
|
|
45986
|
+
const sinkLine = lines[f.sink_line - 1] ?? "";
|
|
45987
|
+
return /\b(?:sql_query|raw_sql)\s*\(/.test(sinkLine);
|
|
45988
|
+
}
|
|
43538
45989
|
function isPythonYamlLoadParamDeser(f, lines) {
|
|
43539
45990
|
if (f.source_type !== "interprocedural_param" || f.sink_type !== "deserialization") return false;
|
|
43540
45991
|
const head = f.path[0]?.variable;
|
|
@@ -43664,8 +46115,8 @@ var ParamSourceFlowGatePass = class {
|
|
|
43664
46115
|
const viaReceiver = !isCtor && !!owner && owner.name !== "<module>";
|
|
43665
46116
|
const feeds = (pos) => fed.params.has(`${viaReceiver ? "m" : "f"}:${callee}:${pos}`);
|
|
43666
46117
|
const head = f.path[0]?.variable;
|
|
43667
|
-
const
|
|
43668
|
-
if (
|
|
46118
|
+
const named2 = m.parameters.findIndex((p) => p.name === head);
|
|
46119
|
+
if (named2 >= 0) return feeds(named2);
|
|
43669
46120
|
for (const s of sources) {
|
|
43670
46121
|
if (s.line !== f.source_line || s.type !== "interprocedural_param") continue;
|
|
43671
46122
|
if (FIELD_CARRIED_SOURCE.test(s.location ?? "")) {
|
|
@@ -43683,7 +46134,7 @@ var ParamSourceFlowGatePass = class {
|
|
|
43683
46134
|
let keep = true;
|
|
43684
46135
|
if (f.source_type === "interprocedural_param" && !realSourceLines.has(f.source_line)) {
|
|
43685
46136
|
const m = enclosingMethod(methods, f.source_line);
|
|
43686
|
-
keep = m !== void 0 && (isHandler(m) || fedByRealSource(f, m) || isReactHtmlComponent(m, f, lines) || ctx.language === "python" && isPythonYamlLoadParamDeser(f, lines));
|
|
46137
|
+
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));
|
|
43687
46138
|
}
|
|
43688
46139
|
if (keep) flows[w++] = f;
|
|
43689
46140
|
else {
|
|
@@ -44359,6 +46810,32 @@ function indexJavaLocalAssignments(code) {
|
|
|
44359
46810
|
}
|
|
44360
46811
|
return index;
|
|
44361
46812
|
}
|
|
46813
|
+
function goCalleeBaseName(callee) {
|
|
46814
|
+
const dot = callee.lastIndexOf(".");
|
|
46815
|
+
return dot === -1 ? callee : callee.slice(dot + 1);
|
|
46816
|
+
}
|
|
46817
|
+
function goConstantHelperCalleeOnLine(line) {
|
|
46818
|
+
const m = line.match(/:=\s*([\w.]+)\s*\(/) ?? line.match(/\bvar\s+\w+\s*=\s*([\w.]+)\s*\(/);
|
|
46819
|
+
if (!m) return null;
|
|
46820
|
+
return goCalleeBaseName(m[1]);
|
|
46821
|
+
}
|
|
46822
|
+
function goConstantHelperCalleeFromLines(lines, lineNumber) {
|
|
46823
|
+
const direct = goConstantHelperCalleeOnLine(lines[lineNumber - 1] ?? "");
|
|
46824
|
+
if (direct) return direct;
|
|
46825
|
+
const cur = lines[lineNumber - 1] ?? "";
|
|
46826
|
+
const partial = cur.match(/:=\s*([\w.]+)\s*$/) ?? cur.match(/\bvar\s+\w+\s*=\s*([\w.]+)\s*$/);
|
|
46827
|
+
if (partial) {
|
|
46828
|
+
const next = (lines[lineNumber] ?? "").trimStart();
|
|
46829
|
+
if (next.startsWith("(")) return goCalleeBaseName(partial[1]);
|
|
46830
|
+
}
|
|
46831
|
+
if (!cur.includes(":=") && !/\bvar\s+\w+\s*=/.test(cur)) return null;
|
|
46832
|
+
if (cur.includes("(")) return null;
|
|
46833
|
+
for (let i2 = lineNumber + 1; i2 <= Math.min(lines.length, lineNumber + 4); i2++) {
|
|
46834
|
+
const m = (lines[i2 - 1] ?? "").match(/^\s*([\w.]+)\s*\(/);
|
|
46835
|
+
if (m) return goCalleeBaseName(m[1]);
|
|
46836
|
+
}
|
|
46837
|
+
return null;
|
|
46838
|
+
}
|
|
44362
46839
|
function makeConstPropVeto(constProp, graph, sources, code, language, sanitizers) {
|
|
44363
46840
|
const lines = typeof code === "string" ? code.split("\n") : [];
|
|
44364
46841
|
const selfReassign = /* @__PURE__ */ new Map();
|
|
@@ -44454,8 +46931,8 @@ function makeConstPropVeto(constProp, graph, sources, code, language, sanitizers
|
|
|
44454
46931
|
if (d.line === sourceLine && sources.some((s) => s.line === sourceLine && !CONTAINER_READ_SOURCES.has(s.type))) {
|
|
44455
46932
|
if (step.line === sinkLine && !constProp.tainted.has(fpLookup)) {
|
|
44456
46933
|
for (let ln = sourceLine; ln <= sinkLine; ln++) {
|
|
44457
|
-
const
|
|
44458
|
-
if (
|
|
46934
|
+
const callee = goConstantHelperCalleeFromLines(lines, ln);
|
|
46935
|
+
if (callee && constProp.constantReturningMethods?.has(callee)) {
|
|
44459
46936
|
return true;
|
|
44460
46937
|
}
|
|
44461
46938
|
}
|
|
@@ -44658,7 +47135,17 @@ var TaintPropagationPass = class {
|
|
|
44658
47135
|
if (isFP) continue;
|
|
44659
47136
|
pushIfNew(f);
|
|
44660
47137
|
}
|
|
44661
|
-
const paramFlows = detectParameterSinkFlows(
|
|
47138
|
+
const paramFlows = detectParameterSinkFlows(
|
|
47139
|
+
types,
|
|
47140
|
+
calls,
|
|
47141
|
+
sources,
|
|
47142
|
+
sinks,
|
|
47143
|
+
constProp.unreachableLines,
|
|
47144
|
+
constProp.tainted,
|
|
47145
|
+
ctx.code,
|
|
47146
|
+
ctx.language,
|
|
47147
|
+
graph.ir.meta.file
|
|
47148
|
+
) ?? [];
|
|
44662
47149
|
for (const f of paramFlows) {
|
|
44663
47150
|
pushIfNew(f);
|
|
44664
47151
|
}
|
|
@@ -44733,6 +47220,22 @@ var TaintPropagationPass = class {
|
|
|
44733
47220
|
if (sanitizedNames.has(sourceVar) && coversFlow(sourceVar)) return false;
|
|
44734
47221
|
return true;
|
|
44735
47222
|
});
|
|
47223
|
+
if (ctx.language === "csharp") {
|
|
47224
|
+
finalFlows = finalFlows.filter(
|
|
47225
|
+
(f) => !shouldGateCSharpPatPermsLibraryParamFlow(
|
|
47226
|
+
f,
|
|
47227
|
+
sources,
|
|
47228
|
+
sinks,
|
|
47229
|
+
types,
|
|
47230
|
+
{
|
|
47231
|
+
language: ctx.language,
|
|
47232
|
+
types,
|
|
47233
|
+
filePath: graph.ir.meta.file,
|
|
47234
|
+
calls
|
|
47235
|
+
}
|
|
47236
|
+
)
|
|
47237
|
+
);
|
|
47238
|
+
}
|
|
44736
47239
|
if (sanitizers && sanitizers.length > 0) {
|
|
44737
47240
|
const sanitizersByLine = /* @__PURE__ */ new Map();
|
|
44738
47241
|
for (const san of sanitizers) {
|
|
@@ -45125,7 +47628,7 @@ function detectJsModuleScopeFlows(code, sources, sinks, unreachableLines) {
|
|
|
45125
47628
|
for (const line of lines) {
|
|
45126
47629
|
const stripped = line.replace(/\s+$/, "");
|
|
45127
47630
|
if (!stripped || /^[ \t]/.test(line)) continue;
|
|
45128
|
-
const m = stripped.match(/^(?:let|var|const)\s+([A-Za-z_$][\w$]*)\b/);
|
|
47631
|
+
const m = stripped.match(/^(?:export\s+)?(?:let|var|const)\s+([A-Za-z_$][\w$]*)\b/);
|
|
45129
47632
|
if (m) moduleVars.add(m[1]);
|
|
45130
47633
|
}
|
|
45131
47634
|
if (moduleVars.size === 0) return flows;
|
|
@@ -45141,7 +47644,9 @@ function detectJsModuleScopeFlows(code, sources, sinks, unreachableLines) {
|
|
|
45141
47644
|
const line = lines[i2];
|
|
45142
47645
|
if (unreachableLines.has(i2 + 1)) continue;
|
|
45143
47646
|
for (const lhs of moduleVars) {
|
|
45144
|
-
const declRe = new RegExp(
|
|
47647
|
+
const declRe = new RegExp(
|
|
47648
|
+
`\\b(?:export\\s+)?(?:let|const|var)\\s+${lhs.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`
|
|
47649
|
+
);
|
|
45145
47650
|
if (declRe.test(line)) continue;
|
|
45146
47651
|
const m = line.match(
|
|
45147
47652
|
new RegExp(`\\b${lhs.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\s*=\\s*([^;]+)`)
|
|
@@ -45263,6 +47768,16 @@ function isTaintedInMethod(taintedVars, varName, scopedName, fieldNames, isField
|
|
|
45263
47768
|
}
|
|
45264
47769
|
return true;
|
|
45265
47770
|
}
|
|
47771
|
+
function mapGetLiteralKeyFromExpr(expr) {
|
|
47772
|
+
const m = expr.match(/\b([A-Za-z_]\w*)\s*\.\s*get\s*\(\s*"([^"]*)"\s*\)/);
|
|
47773
|
+
return m ? { map: m[1], key: m[2] } : null;
|
|
47774
|
+
}
|
|
47775
|
+
function isMapLiteralKeyTainted(constProp, mapName, key, inMethod) {
|
|
47776
|
+
const scoped = inMethod ? `${inMethod}:${mapName}` : mapName;
|
|
47777
|
+
const keys = constProp.taintedCollections.get(mapName) ?? constProp.taintedCollections.get(scoped);
|
|
47778
|
+
if (!keys || keys.size === 0) return false;
|
|
47779
|
+
return keys.has(key) || keys.has("*");
|
|
47780
|
+
}
|
|
45266
47781
|
function detectCollectionFlows(calls, sources, sinks, constProp, code, types, graph) {
|
|
45267
47782
|
const taintedVars = constProp.tainted;
|
|
45268
47783
|
const unreachableLines = constProp.unreachableLines;
|
|
@@ -45305,7 +47820,23 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
|
|
|
45305
47820
|
);
|
|
45306
47821
|
const bareFieldRead = fieldNames.has(varName) && expr === varName && !methodHasLocalDecl(code, call.in_method, varName, call.location.line);
|
|
45307
47822
|
const isFieldUse = explicitField || bareFieldRead;
|
|
45308
|
-
|
|
47823
|
+
const mapKeyRead = mapGetLiteralKeyFromExpr(expr);
|
|
47824
|
+
let argTainted = isTaintedInMethod(
|
|
47825
|
+
taintedVars,
|
|
47826
|
+
varName,
|
|
47827
|
+
scopedName,
|
|
47828
|
+
fieldNames,
|
|
47829
|
+
isFieldUse
|
|
47830
|
+
);
|
|
47831
|
+
if (mapKeyRead && mapKeyRead.map === varName) {
|
|
47832
|
+
argTainted = isMapLiteralKeyTainted(
|
|
47833
|
+
constProp,
|
|
47834
|
+
varName,
|
|
47835
|
+
mapKeyRead.key,
|
|
47836
|
+
call.in_method
|
|
47837
|
+
);
|
|
47838
|
+
}
|
|
47839
|
+
if (argTainted) {
|
|
45309
47840
|
const source = pickScopedSource(sources, sink.line, call.in_method ?? null, types, varName);
|
|
45310
47841
|
if (source) {
|
|
45311
47842
|
if (source.variable && source.variable !== varName && source.in_method && call.in_method && source.in_method !== call.in_method) {
|
|
@@ -45340,12 +47871,23 @@ function detectCollectionFlows(calls, sources, sinks, constProp, code, types, gr
|
|
|
45340
47871
|
{ method: "peek", re: /(\w+)\.peek\(/ },
|
|
45341
47872
|
{ method: "toArray", re: /(\w+)\.toArray\(/ }
|
|
45342
47873
|
];
|
|
45343
|
-
for (const { re } of collectionPatterns) {
|
|
47874
|
+
for (const { method, re } of collectionPatterns) {
|
|
45344
47875
|
const match = expr.match(re);
|
|
45345
47876
|
if (match) {
|
|
45346
47877
|
const collectionVar = match[1];
|
|
45347
47878
|
const scopedCollection = call.in_method ? `${call.in_method}:${collectionVar}` : collectionVar;
|
|
45348
|
-
|
|
47879
|
+
const mapKey = method === "get" ? mapGetLiteralKeyFromExpr(expr) : null;
|
|
47880
|
+
let collectionTainted = taintedVars.has(collectionVar) || taintedVars.has(scopedCollection);
|
|
47881
|
+
if (mapKey && mapKey.map === collectionVar) {
|
|
47882
|
+
collectionTainted = isMapLiteralKeyTainted(
|
|
47883
|
+
constProp,
|
|
47884
|
+
collectionVar,
|
|
47885
|
+
mapKey.key,
|
|
47886
|
+
call.in_method
|
|
47887
|
+
);
|
|
47888
|
+
}
|
|
47889
|
+
if (!collectionTainted) continue;
|
|
47890
|
+
{
|
|
45349
47891
|
const source = pickScopedSource(sources, sink.line, call.in_method ?? null, types, collectionVar);
|
|
45350
47892
|
if (source) {
|
|
45351
47893
|
if (source.variable && source.variable !== collectionVar && source.in_method && call.in_method && source.in_method !== call.in_method) {
|
|
@@ -45422,6 +47964,39 @@ function detectArrayElementFlows(calls, sources, sinks, taintedArrayElements, un
|
|
|
45422
47964
|
}
|
|
45423
47965
|
return flows;
|
|
45424
47966
|
}
|
|
47967
|
+
function csharpPatPermsDirectParamSink(sink, paramVar) {
|
|
47968
|
+
const method = (sink.method ?? "").replace(/^.*\./, "");
|
|
47969
|
+
if (method !== "FileStream") return false;
|
|
47970
|
+
const code = sink.code ?? "";
|
|
47971
|
+
if (!code) return true;
|
|
47972
|
+
const escaped = paramVar.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
47973
|
+
return new RegExp(`\\bFileStream\\s*\\(\\s*${escaped}\\b`).test(code);
|
|
47974
|
+
}
|
|
47975
|
+
function shouldGateCSharpPatPermsLibraryParamFlow(flow, sources, sinks, types, ctx) {
|
|
47976
|
+
if (flow.source_type !== "interprocedural_param" || flow.sink_type !== "path_traversal") {
|
|
47977
|
+
return false;
|
|
47978
|
+
}
|
|
47979
|
+
const srcVar = flow.path?.[0]?.variable;
|
|
47980
|
+
const sinkVar = flow.path?.[flow.path.length - 1]?.variable;
|
|
47981
|
+
if (!srcVar || srcVar !== sinkVar) return false;
|
|
47982
|
+
const sink = sinks.find(
|
|
47983
|
+
(s) => s.line === flow.sink_line && s.type === "path_traversal"
|
|
47984
|
+
);
|
|
47985
|
+
if (!sink || !csharpPatPermsDirectParamSink(sink, srcVar)) return false;
|
|
47986
|
+
const src = sources.find(
|
|
47987
|
+
(s) => s.line === flow.source_line && s.type === "interprocedural_param"
|
|
47988
|
+
);
|
|
47989
|
+
const methodName = src?.in_method;
|
|
47990
|
+
if (!methodName) return false;
|
|
47991
|
+
const enclosingType = types.find((t) => t.methods.some((m) => m.name === methodName));
|
|
47992
|
+
const enclosingMethod2 = enclosingType?.methods.find((m) => m.name === methodName);
|
|
47993
|
+
return shouldGateInterproceduralParam(
|
|
47994
|
+
flow.source_type,
|
|
47995
|
+
enclosingMethod2,
|
|
47996
|
+
enclosingType,
|
|
47997
|
+
ctx
|
|
47998
|
+
);
|
|
47999
|
+
}
|
|
45425
48000
|
function compoundArgParamNames(expression, paramNames) {
|
|
45426
48001
|
const stripped = expression.replace(/(['"`])(?:\\.|(?!\1).)*\1/g, (m) => " ".repeat(m.length));
|
|
45427
48002
|
const matched = [];
|
|
@@ -45435,7 +48010,7 @@ function compoundArgParamNames(expression, paramNames) {
|
|
|
45435
48010
|
}
|
|
45436
48011
|
return matched;
|
|
45437
48012
|
}
|
|
45438
|
-
function detectParameterSinkFlows(types, calls, sources, sinks, unreachableLines, tainted, code) {
|
|
48013
|
+
function detectParameterSinkFlows(types, calls, sources, sinks, unreachableLines, tainted, code, language, filePath) {
|
|
45439
48014
|
const flows = [];
|
|
45440
48015
|
const paramSourcesByMethod = /* @__PURE__ */ new Map();
|
|
45441
48016
|
for (const source of sources) {
|
|
@@ -45476,6 +48051,20 @@ function detectParameterSinkFlows(types, calls, sources, sinks, unreachableLines
|
|
|
45476
48051
|
for (const varName of varNames) {
|
|
45477
48052
|
const paramSource = methodParamSources.get(varName);
|
|
45478
48053
|
if (paramSource) {
|
|
48054
|
+
if (language === "csharp" && paramSource.type === "interprocedural_param" && sink.type === "path_traversal" && csharpPatPermsDirectParamSink(sink, varName)) {
|
|
48055
|
+
const enclosingType = types.find(
|
|
48056
|
+
(t) => t.methods.some((m) => m.name === methodName)
|
|
48057
|
+
);
|
|
48058
|
+
const enclosingMethod2 = enclosingType?.methods.find((m) => m.name === methodName);
|
|
48059
|
+
if (shouldGateInterproceduralParam(
|
|
48060
|
+
paramSource.type,
|
|
48061
|
+
enclosingMethod2,
|
|
48062
|
+
enclosingType,
|
|
48063
|
+
{ language, types, filePath, calls }
|
|
48064
|
+
)) {
|
|
48065
|
+
continue;
|
|
48066
|
+
}
|
|
48067
|
+
}
|
|
45479
48068
|
const exists = flows.some((f) => f.source_line === paramSource.line && f.sink_line === sink.line && f.sink_type === sink.type);
|
|
45480
48069
|
if (!exists) {
|
|
45481
48070
|
if (typeof code === "string" && isReassignedToLiteralBetween(code, varName, paramSource.line, sink.line, unreachableLines)) {
|
|
@@ -46470,9 +49059,18 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
|
|
|
46470
49059
|
if (!prev || s.line < prev.line) realSourceByVar.set(s.variable, s);
|
|
46471
49060
|
}
|
|
46472
49061
|
for (const [varName, derivedLine] of derived) {
|
|
46473
|
-
if (!varName
|
|
49062
|
+
if (!varName) continue;
|
|
46474
49063
|
const owner = methodAt(derivedLine);
|
|
46475
49064
|
const fieldAlias = isDeclaredField(derivedLine, varName);
|
|
49065
|
+
if (existingVars.has(varName)) {
|
|
49066
|
+
if (!fieldAlias) continue;
|
|
49067
|
+
const stubIdx = sourcesWithVar.findIndex(
|
|
49068
|
+
(s) => s.variable === varName && s.type === "interprocedural_param"
|
|
49069
|
+
);
|
|
49070
|
+
if (stubIdx < 0) continue;
|
|
49071
|
+
sourcesWithVar.splice(stubIdx, 1);
|
|
49072
|
+
existingVars.delete(varName);
|
|
49073
|
+
}
|
|
46476
49074
|
let scopedAnchor = anchor;
|
|
46477
49075
|
if (owner) {
|
|
46478
49076
|
let best;
|
|
@@ -47807,7 +50405,7 @@ var ResourceLeakPass = class {
|
|
|
47807
50405
|
for (const call of graph.ir.calls) {
|
|
47808
50406
|
const name2 = call.method_name;
|
|
47809
50407
|
const isConstructor = call.is_constructor === true && RESOURCE_CTORS.has(name2);
|
|
47810
|
-
const isFactory = !call.is_constructor && RESOURCE_FACTORY_METHODS.has(name2);
|
|
50408
|
+
const isFactory = !call.is_constructor && RESOURCE_FACTORY_METHODS.has(name2) && (name2 !== "open" || !!call.receiver || graph.ir.meta.language === "python");
|
|
47811
50409
|
if (!isConstructor && !isFactory) continue;
|
|
47812
50410
|
const openLine = call.location.line;
|
|
47813
50411
|
const defs = graph.defsAtLine(openLine);
|
|
@@ -51831,10 +54429,28 @@ var InsecureCookiePass = class {
|
|
|
51831
54429
|
* unassigned `new Cookie(...)` only looks at that statement, so another
|
|
51832
54430
|
* cookie's setter cannot cover it.
|
|
51833
54431
|
*/
|
|
54432
|
+
/** Cookie variable assigned to this `new Cookie(...)` call site (per-cookie, #595). */
|
|
54433
|
+
javaCookieVarName(code, call) {
|
|
54434
|
+
const lines = code.split("\n");
|
|
54435
|
+
const idx = (call.location.line ?? 1) - 1;
|
|
54436
|
+
const line = lines[idx] ?? "";
|
|
54437
|
+
const sameLine = /\b([A-Za-z_]\w*)\s*=\s*new\s+(?:[\w.]+\.)?Cookie\b/.exec(line);
|
|
54438
|
+
if (sameLine?.[1]) return sameLine[1];
|
|
54439
|
+
if (/\bnew\s+(?:[\w.]+\.)?Cookie\s*\(/.test(line)) {
|
|
54440
|
+
for (let i2 = idx - 1; i2 >= Math.max(0, idx - 4); i2--) {
|
|
54441
|
+
const prev = (lines[i2] ?? "").trimEnd();
|
|
54442
|
+
const splitAssign = /\b([A-Za-z_]\w*)\s*=\s*$/.exec(prev);
|
|
54443
|
+
if (splitAssign?.[1]) return splitAssign[1];
|
|
54444
|
+
const prevSame = /\b([A-Za-z_]\w*)\s*=\s*new\s+(?:[\w.]+\.)?Cookie\b/.exec(prev);
|
|
54445
|
+
if (prevSame?.[1]) return prevSame[1];
|
|
54446
|
+
}
|
|
54447
|
+
}
|
|
54448
|
+
return void 0;
|
|
54449
|
+
}
|
|
51834
54450
|
javaCookieSetterTrue(code, call, setter) {
|
|
51835
|
-
const
|
|
51836
|
-
const
|
|
51837
|
-
const varName =
|
|
54451
|
+
const lines = code.split("\n");
|
|
54452
|
+
const line = lines[(call.location.line ?? 1) - 1] ?? "";
|
|
54453
|
+
const varName = this.javaCookieVarName(code, call);
|
|
51838
54454
|
const re = varName ? new RegExp(`\\b${varName}\\.${setter}\\s*\\(\\s*true\\s*\\)`) : new RegExp(`\\.${setter}\\s*\\(\\s*true\\s*\\)`);
|
|
51839
54455
|
return re.test(varName ? code : line);
|
|
51840
54456
|
}
|
|
@@ -52917,6 +55533,9 @@ var WeakRandomPass = class {
|
|
|
52917
55533
|
if (method === "random" && (receiver === "Math" || receiver.endsWith(".Math"))) {
|
|
52918
55534
|
return "Math.random";
|
|
52919
55535
|
}
|
|
55536
|
+
if (this.jsIsModuleScopedCryptoRandomUuid(call, ctx)) {
|
|
55537
|
+
return "crypto.randomUUID (module scope)";
|
|
55538
|
+
}
|
|
52920
55539
|
return null;
|
|
52921
55540
|
}
|
|
52922
55541
|
if (language === "go") {
|
|
@@ -52954,6 +55573,26 @@ var WeakRandomPass = class {
|
|
|
52954
55573
|
* file (i.e. `math/rand` imported unaliased; `crypto/rand` is either not
|
|
52955
55574
|
* imported or imported under an alias).
|
|
52956
55575
|
*/
|
|
55576
|
+
/**
|
|
55577
|
+
* Module-scoped `crypto.randomUUID()` / `randomUUID()` — entropy fixed at load.
|
|
55578
|
+
*/
|
|
55579
|
+
jsIsModuleScopedCryptoRandomUuid(call, ctx) {
|
|
55580
|
+
if (call.method_name !== "randomUUID") return false;
|
|
55581
|
+
if (call.in_method != null && call.in_method !== "") return false;
|
|
55582
|
+
const receiver = call.receiver ?? "";
|
|
55583
|
+
if (receiver === "crypto" || receiver.endsWith(".crypto")) return true;
|
|
55584
|
+
if (!receiver) {
|
|
55585
|
+
const imports = ctx.graph.ir.imports ?? [];
|
|
55586
|
+
return imports.some((imp) => {
|
|
55587
|
+
const pkg = imp.from_package ?? "";
|
|
55588
|
+
if (pkg !== "crypto" && pkg !== "node:crypto") return false;
|
|
55589
|
+
const name2 = imp.imported_name ?? imp.alias ?? "";
|
|
55590
|
+
const alias = imp.alias ?? imp.imported_name ?? "";
|
|
55591
|
+
return name2 === "randomUUID" || alias === "randomUUID";
|
|
55592
|
+
});
|
|
55593
|
+
}
|
|
55594
|
+
return false;
|
|
55595
|
+
}
|
|
52957
55596
|
goMathRandIsActive(ctx) {
|
|
52958
55597
|
const imports = ctx.graph.ir.imports ?? [];
|
|
52959
55598
|
let mathRandUnaliased = false;
|
|
@@ -54265,6 +56904,13 @@ var PY_HTTP_RECEIVERS = /* @__PURE__ */ new Set([
|
|
|
54265
56904
|
var VERIFY_FALSE_RE = /\bverify\s*=\s*False\b/;
|
|
54266
56905
|
var REJECT_UNAUTHORIZED_FALSE_RE = /\brejectUnauthorized\s*:\s*false\b/;
|
|
54267
56906
|
var INSECURE_SKIP_VERIFY_TRUE_RE = /\bInsecureSkipVerify\s*:\s*true\b/;
|
|
56907
|
+
var GO_X509_VERIFY_CALL_RE = /\.Verify\s*\(/;
|
|
56908
|
+
var GO_INTERMEDIATE_DENYLIST_GUARD_RE = /\b(denylist|denyList|deny_list|blocklist|blockList|blockedIntermediate|blocked_intermediate|deniedIntermediate|deniedIntermediates|denied_intermediate|isDeniedIntermediate|intermediateDenylist|intermediate_denylist)\b/i;
|
|
56909
|
+
function goSourceWithoutComments(code) {
|
|
56910
|
+
let s = code.replace(/\/\*[\s\S]*?\*\//g, " ");
|
|
56911
|
+
s = s.replace(/\/\/[^\n]*/g, " ");
|
|
56912
|
+
return s;
|
|
56913
|
+
}
|
|
54268
56914
|
var HOSTNAME_LAMBDA_TRUE_RE = /\(\s*\w+\s*,\s*\w+\s*\)\s*->\s*true\b/;
|
|
54269
56915
|
var CS_CERT_CALLBACK_TRUE_RE = /\b(ServerCertificateValidationCallback|ServerCertificateCustomValidationCallback|RemoteCertificateValidationCallback)\s*(?:\+?=|\()\s*(?:\([^)]*\)|\w+)\s*=>\s*(?:true\b|\{\s*return\s+true\b)/;
|
|
54270
56916
|
var CS_DANGEROUS_ACCEPT_RE = /\bDangerousAcceptAnyServerCertificateValidator\b/;
|
|
@@ -54273,6 +56919,14 @@ var ALLOW_ALL_HOSTNAME_VERIFIERS = /* @__PURE__ */ new Set([
|
|
|
54273
56919
|
"new AllowAllHostnameVerifier()",
|
|
54274
56920
|
"new NoopHostnameVerifier()"
|
|
54275
56921
|
]);
|
|
56922
|
+
var JS_CHECK_SERVER_IDENTITY_NOP_RE = /\bcheckServerIdentity\s*:\s*(?:async\s*)?\([^)]*\)\s*=>\s*(?:undefined|null)\b/;
|
|
56923
|
+
var JS_CHECK_SERVER_IDENTITY_NOP_FN_RE = /\bcheckServerIdentity\s*:\s*function\s*\([^)]*\)\s*\{\s*return\s+(?:undefined|null)\s*;?\s*\}/;
|
|
56924
|
+
var JS_CHECK_SERVER_IDENTITY_DECL_RE = /\bfunction\s+checkServerIdentity\s*\([^)]*\)\s*\{/g;
|
|
56925
|
+
var JS_LOOSE_IP_HOST_STRIP_RE = /\.replace\s*\(\s*\/\[\^\\d\.\]\\]\//;
|
|
56926
|
+
var JS_CHECK_SERVER_IDENTITY_LOOSE_BODY_RE = /(?:looseIp\s*\(|\.replace\s*\(\s*\/\[\^\\d\.\]\\]\/)[\s\S]*?return\s+undefined\b/;
|
|
56927
|
+
var JS_NFKC_NORMALIZE_RE = /\.normalize\s*\(\s*['"]NFKC['"]\s*\)/i;
|
|
56928
|
+
var JS_SUBJECT_ALT_NAME_RE = /\bsubjectaltname\b|\bsubjectAltName\b|\baltNames\b|\bDNS:\b|\bIP Address:/i;
|
|
56929
|
+
var JS_ISSUER_CHAIN_WALK_RE = /\bissuerCertificate\b/;
|
|
54276
56930
|
var TlsVerifyDisabledPass = class {
|
|
54277
56931
|
name = "tls-verify-disabled";
|
|
54278
56932
|
category = "security";
|
|
@@ -54387,6 +57041,18 @@ var TlsVerifyDisabledPass = class {
|
|
|
54387
57041
|
});
|
|
54388
57042
|
}
|
|
54389
57043
|
}
|
|
57044
|
+
if (/\bx509\./.test(code) && /\bVerifyOptions\b/.test(code) && GO_X509_VERIFY_CALL_RE.test(code) && !GO_INTERMEDIATE_DENYLIST_GUARD_RE.test(goSourceWithoutComments(code))) {
|
|
57045
|
+
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
57046
|
+
if (GO_X509_VERIFY_CALL_RE.test(lines[i2])) {
|
|
57047
|
+
out2.push({
|
|
57048
|
+
line: i2 + 1,
|
|
57049
|
+
pattern: "x509.Verify without intermediate denylist",
|
|
57050
|
+
api: "x509.Certificate.Verify"
|
|
57051
|
+
});
|
|
57052
|
+
break;
|
|
57053
|
+
}
|
|
57054
|
+
}
|
|
57055
|
+
}
|
|
54390
57056
|
}
|
|
54391
57057
|
if (language === "python") {
|
|
54392
57058
|
for (let i2 = 0; i2 < lines.length; i2++) {
|
|
@@ -54410,6 +57076,35 @@ var TlsVerifyDisabledPass = class {
|
|
|
54410
57076
|
api: "process.env"
|
|
54411
57077
|
});
|
|
54412
57078
|
}
|
|
57079
|
+
if (JS_CHECK_SERVER_IDENTITY_NOP_RE.test(l) || JS_CHECK_SERVER_IDENTITY_NOP_FN_RE.test(l)) {
|
|
57080
|
+
out2.push({
|
|
57081
|
+
line: i2 + 1,
|
|
57082
|
+
pattern: "checkServerIdentity => undefined",
|
|
57083
|
+
api: "tls.connect / https.request options"
|
|
57084
|
+
});
|
|
57085
|
+
}
|
|
57086
|
+
}
|
|
57087
|
+
const m = JS_CHECK_SERVER_IDENTITY_NOP_RE.exec(code) ?? JS_CHECK_SERVER_IDENTITY_NOP_FN_RE.exec(code);
|
|
57088
|
+
if (m && m.index !== void 0) {
|
|
57089
|
+
const line = code.slice(0, m.index).split("\n").length;
|
|
57090
|
+
const dupKey = `${line}-checkServerIdentity => undefined`;
|
|
57091
|
+
if (!out2.some((o) => `${o.line}-${o.pattern}` === dupKey)) {
|
|
57092
|
+
out2.push({
|
|
57093
|
+
line,
|
|
57094
|
+
pattern: "checkServerIdentity => undefined",
|
|
57095
|
+
api: "tls.connect / https.request options"
|
|
57096
|
+
});
|
|
57097
|
+
}
|
|
57098
|
+
}
|
|
57099
|
+
for (const weak of this.detectWeakCheckServerIdentityCallbacks(code)) {
|
|
57100
|
+
const dupKey = `${weak.line}-${weak.pattern}`;
|
|
57101
|
+
if (!out2.some((o) => `${o.line}-${o.pattern}` === dupKey)) {
|
|
57102
|
+
out2.push({
|
|
57103
|
+
line: weak.line,
|
|
57104
|
+
pattern: weak.pattern,
|
|
57105
|
+
api: "checkServerIdentity (custom)"
|
|
57106
|
+
});
|
|
57107
|
+
}
|
|
54413
57108
|
}
|
|
54414
57109
|
}
|
|
54415
57110
|
if (language === "csharp") {
|
|
@@ -54429,16 +57124,90 @@ var TlsVerifyDisabledPass = class {
|
|
|
54429
57124
|
}
|
|
54430
57125
|
return out2;
|
|
54431
57126
|
}
|
|
57127
|
+
/** Standalone and inline `checkServerIdentity` with weak identity checks. */
|
|
57128
|
+
detectWeakCheckServerIdentityCallbacks(code) {
|
|
57129
|
+
const hits = [];
|
|
57130
|
+
const fileHasDenylist = GO_INTERMEDIATE_DENYLIST_GUARD_RE.test(code);
|
|
57131
|
+
const declRe = new RegExp(JS_CHECK_SERVER_IDENTITY_DECL_RE.source, "g");
|
|
57132
|
+
let match;
|
|
57133
|
+
while ((match = declRe.exec(code)) !== null) {
|
|
57134
|
+
const openBrace = code.indexOf("{", match.index);
|
|
57135
|
+
if (openBrace < 0) continue;
|
|
57136
|
+
const body2 = this.sliceBalancedBraces(code, openBrace);
|
|
57137
|
+
if (!body2) continue;
|
|
57138
|
+
const prelude = code.slice(Math.max(0, match.index - 800), match.index);
|
|
57139
|
+
const line = code.slice(0, match.index).split("\n").length;
|
|
57140
|
+
const weak = this.classifyWeakCheckServerIdentityBody(
|
|
57141
|
+
body2,
|
|
57142
|
+
prelude,
|
|
57143
|
+
fileHasDenylist
|
|
57144
|
+
);
|
|
57145
|
+
if (weak) hits.push({ line, pattern: weak });
|
|
57146
|
+
}
|
|
57147
|
+
const inlineRe = /\bcheckServerIdentity\s*:\s*(?:async\s*)?function\s*\([^)]*\)\s*\{/g;
|
|
57148
|
+
while ((match = inlineRe.exec(code)) !== null) {
|
|
57149
|
+
const openBrace = code.indexOf("{", match.index);
|
|
57150
|
+
if (openBrace < 0) continue;
|
|
57151
|
+
const body2 = this.sliceBalancedBraces(code, openBrace);
|
|
57152
|
+
if (!body2) continue;
|
|
57153
|
+
const prelude = code.slice(Math.max(0, match.index - 800), match.index);
|
|
57154
|
+
const line = code.slice(0, match.index).split("\n").length;
|
|
57155
|
+
const weak = this.classifyWeakCheckServerIdentityBody(
|
|
57156
|
+
body2,
|
|
57157
|
+
prelude,
|
|
57158
|
+
fileHasDenylist
|
|
57159
|
+
);
|
|
57160
|
+
if (weak) hits.push({ line, pattern: weak });
|
|
57161
|
+
}
|
|
57162
|
+
return hits;
|
|
57163
|
+
}
|
|
57164
|
+
classifyWeakCheckServerIdentityBody(body2, prelude, fileHasDenylist) {
|
|
57165
|
+
if (!/\breturn\s+undefined\b/.test(body2)) return null;
|
|
57166
|
+
const loose = JS_LOOSE_IP_HOST_STRIP_RE.test(body2) || JS_LOOSE_IP_HOST_STRIP_RE.test(prelude) || /\blooseIp\s*\(/.test(body2);
|
|
57167
|
+
if (loose && JS_CHECK_SERVER_IDENTITY_LOOSE_BODY_RE.test(body2)) {
|
|
57168
|
+
return "checkServerIdentity loose host parse => undefined";
|
|
57169
|
+
}
|
|
57170
|
+
const nfkc = JS_NFKC_NORMALIZE_RE.test(body2) || JS_NFKC_NORMALIZE_RE.test(prelude);
|
|
57171
|
+
if (nfkc && /\breturn\s+undefined\b/.test(body2)) {
|
|
57172
|
+
return "checkServerIdentity NFKC host normalize => undefined";
|
|
57173
|
+
}
|
|
57174
|
+
if (JS_SUBJECT_ALT_NAME_RE.test(body2) && /\breturn\s+undefined\b/.test(body2)) {
|
|
57175
|
+
return "checkServerIdentity DNS SAN / IP match => undefined";
|
|
57176
|
+
}
|
|
57177
|
+
if (JS_ISSUER_CHAIN_WALK_RE.test(body2) && !fileHasDenylist && /\breturn\s+undefined\b/.test(body2)) {
|
|
57178
|
+
return "checkServerIdentity issuer chain without denylist => undefined";
|
|
57179
|
+
}
|
|
57180
|
+
return null;
|
|
57181
|
+
}
|
|
57182
|
+
sliceBalancedBraces(code, openIndex) {
|
|
57183
|
+
if (code[openIndex] !== "{") return null;
|
|
57184
|
+
let depth = 0;
|
|
57185
|
+
for (let i2 = openIndex; i2 < code.length; i2++) {
|
|
57186
|
+
const ch = code[i2];
|
|
57187
|
+
if (ch === "{") depth++;
|
|
57188
|
+
else if (ch === "}") {
|
|
57189
|
+
depth--;
|
|
57190
|
+
if (depth === 0) return code.slice(openIndex, i2 + 1);
|
|
57191
|
+
}
|
|
57192
|
+
}
|
|
57193
|
+
return null;
|
|
57194
|
+
}
|
|
54432
57195
|
fixFor(language, pattern) {
|
|
54433
57196
|
if (pattern.includes("InsecureSkipVerify")) {
|
|
54434
57197
|
return "Remove `InsecureSkipVerify: true` \u2014 let Go verify the cert. If you need to trust a private CA, set `RootCAs` to a `*x509.CertPool` containing that CA.";
|
|
54435
57198
|
}
|
|
57199
|
+
if (pattern.includes("x509.Verify without intermediate denylist")) {
|
|
57200
|
+
return "Before calling `x509.Certificate.Verify`, check the chain (including intermediates) against your blocked-CA / denylist policy. Relying on PKIX verification alone accepts chains that include revoked or blocked intermediates.";
|
|
57201
|
+
}
|
|
54436
57202
|
if (pattern.includes("verify=False")) {
|
|
54437
57203
|
return "Remove `verify=False`. To trust a private CA, pass `verify='/path/to/ca.pem'`.";
|
|
54438
57204
|
}
|
|
54439
57205
|
if (pattern.includes("rejectUnauthorized")) {
|
|
54440
57206
|
return "Remove `rejectUnauthorized: false`. To trust a private CA, set the `ca` option to the CA cert(s). Never disable TLS verification globally.";
|
|
54441
57207
|
}
|
|
57208
|
+
if (pattern.includes("checkServerIdentity")) {
|
|
57209
|
+
return "Implement `checkServerIdentity` to compare the certificate to the intended hostname (or remove the override). Returning `undefined` accepts the connection; loose host/IP folding before that check enables MITM.";
|
|
57210
|
+
}
|
|
54442
57211
|
if (pattern.includes("NODE_TLS_REJECT_UNAUTHORIZED")) {
|
|
54443
57212
|
return "Remove the `NODE_TLS_REJECT_UNAUTHORIZED=0` assignment \u2014 it globally disables TLS verification for every outbound HTTPS request.";
|
|
54444
57213
|
}
|
|
@@ -56410,6 +59179,36 @@ function boundedMakeDefIds(defs, code, language) {
|
|
|
56410
59179
|
return out2;
|
|
56411
59180
|
}
|
|
56412
59181
|
|
|
59182
|
+
// src/analysis/comment-lines.ts
|
|
59183
|
+
function makeCommentOnlyLineTest(root, code) {
|
|
59184
|
+
const lines = code.split("\n");
|
|
59185
|
+
const cache = /* @__PURE__ */ new Map();
|
|
59186
|
+
return (line) => {
|
|
59187
|
+
const hit = cache.get(line);
|
|
59188
|
+
if (hit !== void 0) return hit;
|
|
59189
|
+
let result = false;
|
|
59190
|
+
const text = lines[line - 1];
|
|
59191
|
+
if (text !== void 0) {
|
|
59192
|
+
const first = text.search(/\S/);
|
|
59193
|
+
if (first >= 0) {
|
|
59194
|
+
const end = text.trimEnd().length;
|
|
59195
|
+
const node = root.descendantForPosition({ row: line - 1, column: first });
|
|
59196
|
+
let n = node;
|
|
59197
|
+
while (n && !/comment/.test(n.type) && n.startPosition.row === line - 1 && n.startPosition.column === first && n.parent) {
|
|
59198
|
+
n = n.parent;
|
|
59199
|
+
}
|
|
59200
|
+
if (n && /comment/.test(n.type)) {
|
|
59201
|
+
const startsBefore = n.startPosition.row < line - 1 || n.startPosition.row === line - 1 && n.startPosition.column <= first;
|
|
59202
|
+
const endsAfter = n.endPosition.row > line - 1 || n.endPosition.row === line - 1 && n.endPosition.column >= end;
|
|
59203
|
+
result = startsBefore && endsAfter;
|
|
59204
|
+
}
|
|
59205
|
+
}
|
|
59206
|
+
}
|
|
59207
|
+
cache.set(line, result);
|
|
59208
|
+
return result;
|
|
59209
|
+
};
|
|
59210
|
+
}
|
|
59211
|
+
|
|
56413
59212
|
// src/analyzer.ts
|
|
56414
59213
|
var initialized = false;
|
|
56415
59214
|
async function initAnalyzer(options = {}) {
|
|
@@ -56633,10 +59432,24 @@ function neutralizeOverlongLines(code) {
|
|
|
56633
59432
|
}
|
|
56634
59433
|
return { code: out2, dropped };
|
|
56635
59434
|
}
|
|
59435
|
+
var AnalysisTimeoutError = class extends Error {
|
|
59436
|
+
file;
|
|
59437
|
+
elapsedMs;
|
|
59438
|
+
phase;
|
|
59439
|
+
constructor(file, elapsedMs, phase) {
|
|
59440
|
+
super(`analysis of ${file} timed out after ${elapsedMs}ms (at ${phase})`);
|
|
59441
|
+
this.name = "AnalysisTimeoutError";
|
|
59442
|
+
this.file = file;
|
|
59443
|
+
this.elapsedMs = elapsedMs;
|
|
59444
|
+
this.phase = phase;
|
|
59445
|
+
}
|
|
59446
|
+
};
|
|
56636
59447
|
async function analyze(code, filePath, language, options = {}) {
|
|
56637
59448
|
if (!initialized) {
|
|
56638
59449
|
await initAnalyzer(options);
|
|
56639
59450
|
}
|
|
59451
|
+
const fileTimeoutMs = options.fileTimeoutMs ?? 0;
|
|
59452
|
+
const fileDeadline = fileTimeoutMs > 0 ? Date.now() + fileTimeoutMs : 0;
|
|
56640
59453
|
if (language === "html" || language === "vue") {
|
|
56641
59454
|
return analyzeMarkupFile(code, filePath, options, language);
|
|
56642
59455
|
}
|
|
@@ -56671,6 +59484,9 @@ async function analyze(code, filePath, language, options = {}) {
|
|
|
56671
59484
|
const tree = await parse(code, parseGrammar);
|
|
56672
59485
|
phaseEnd("parse", tParse);
|
|
56673
59486
|
try {
|
|
59487
|
+
if (fileDeadline > 0 && Date.now() > fileDeadline) {
|
|
59488
|
+
throw new AnalysisTimeoutError(filePath, Date.now() - (fileDeadline - fileTimeoutMs), "parse");
|
|
59489
|
+
}
|
|
56674
59490
|
logger.trace("Parsed AST", { rootNodeType: tree.rootNode.type });
|
|
56675
59491
|
const tParseStatus = phaseStart();
|
|
56676
59492
|
const parseStatus = extractParseStatus(tree);
|
|
@@ -56723,7 +59539,8 @@ async function analyze(code, filePath, language, options = {}) {
|
|
|
56723
59539
|
const imports = extractImports(tree, language, nodeCache);
|
|
56724
59540
|
phaseEnd("extractImports", tImports);
|
|
56725
59541
|
const tExports = phaseStart();
|
|
56726
|
-
|
|
59542
|
+
if (options.declarationDetail && (language === "typescript" || language === "javascript")) enrichTsDeclarations(tree, types);
|
|
59543
|
+
const exports = (options.declarationDetail && (language === "typescript" || language === "javascript") ? extractTsExports(types) : null) ?? extractExports(types);
|
|
56727
59544
|
phaseEnd("extractExports", tExports);
|
|
56728
59545
|
const tCFG = phaseStart();
|
|
56729
59546
|
const cfg = buildCFG(tree, language, nodeCache);
|
|
@@ -56844,7 +59661,14 @@ async function analyze(code, filePath, language, options = {}) {
|
|
|
56844
59661
|
if (!disabledPasses.has("unrestricted-file-upload")) pipeline.add(new UnrestrictedFileUploadPass());
|
|
56845
59662
|
if (!disabledPasses.has("missing-sanitizer-gate")) pipeline.add(new MissingSanitizerGatePass());
|
|
56846
59663
|
if (!disabledPasses.has("insecure-deserialization-config")) pipeline.add(new InsecureDeserializationConfigPass());
|
|
56847
|
-
const { results, findings } = pipeline.run(
|
|
59664
|
+
const { results, findings } = pipeline.run(
|
|
59665
|
+
graph,
|
|
59666
|
+
code,
|
|
59667
|
+
language,
|
|
59668
|
+
config,
|
|
59669
|
+
options.resources,
|
|
59670
|
+
fileDeadline > 0 ? { deadline: fileDeadline, onExpired: (phase) => new AnalysisTimeoutError(filePath, Date.now() - (fileDeadline - fileTimeoutMs), phase) } : void 0
|
|
59671
|
+
);
|
|
56848
59672
|
const sinkFilter = results.get("sink-filter");
|
|
56849
59673
|
const interProc = results.get("interprocedural");
|
|
56850
59674
|
const taint = {
|
|
@@ -56865,6 +59689,12 @@ async function analyze(code, filePath, language, options = {}) {
|
|
|
56865
59689
|
taint.flows = [...taint.flows ?? [], ...constructionFlows];
|
|
56866
59690
|
}
|
|
56867
59691
|
}
|
|
59692
|
+
const isCommentOnlyLine = makeCommentOnlyLineTest(tree.rootNode, code);
|
|
59693
|
+
taint.sinks = taint.sinks.filter((s) => !isCommentOnlyLine(s.line));
|
|
59694
|
+
taint.sources = taint.sources.filter((s) => !isCommentOnlyLine(s.line));
|
|
59695
|
+
if (taint.flows) {
|
|
59696
|
+
taint.flows = taint.flows.filter((f) => !isCommentOnlyLine(f.sink_line) && !isCommentOnlyLine(f.source_line));
|
|
59697
|
+
}
|
|
56868
59698
|
if (taint.flows && taint.flows.length > 0 && taint.sinks.length > 0) {
|
|
56869
59699
|
const sinkTagsByKey = /* @__PURE__ */ new Map();
|
|
56870
59700
|
for (const s of taint.sinks) {
|
|
@@ -56893,7 +59723,10 @@ async function analyze(code, filePath, language, options = {}) {
|
|
|
56893
59723
|
unresolvedItems: unresolved.length
|
|
56894
59724
|
});
|
|
56895
59725
|
emitFindingsInstrumentation(filePath, findings, taint);
|
|
56896
|
-
const
|
|
59726
|
+
const codeFindings = findings.filter(
|
|
59727
|
+
(f) => f.category !== "security" || f.line <= 1 || !isCommentOnlyLine(f.line)
|
|
59728
|
+
);
|
|
59729
|
+
const verifiedFindings = applyConfidenceFilter(codeFindings, options.includeSpeculative === true);
|
|
56897
59730
|
const downgradedFindings = applyLibraryApiSurfaceDowngrade(verifiedFindings);
|
|
56898
59731
|
const profiledFindings = applyProjectProfileTransform(
|
|
56899
59732
|
downgradedFindings,
|