circle-ir 4.22.0 → 4.24.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/configs/sink-semantics.json +6 -0
- package/dist/analysis/config-loader.d.ts.map +1 -1
- package/dist/analysis/config-loader.js +24 -5
- package/dist/analysis/config-loader.js.map +1 -1
- package/dist/analysis/constant-propagation/patterns.d.ts +16 -8
- package/dist/analysis/constant-propagation/patterns.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/patterns.js +18 -9
- package/dist/analysis/constant-propagation/patterns.js.map +1 -1
- package/dist/analysis/findings.d.ts +8 -1
- package/dist/analysis/findings.d.ts.map +1 -1
- package/dist/analysis/findings.js +67 -5
- package/dist/analysis/findings.js.map +1 -1
- package/dist/analysis/hono-env.d.ts +24 -0
- package/dist/analysis/hono-env.d.ts.map +1 -0
- package/dist/analysis/hono-env.js +105 -0
- package/dist/analysis/hono-env.js.map +1 -0
- package/dist/analysis/html/html-extractor.d.ts +6 -0
- package/dist/analysis/html/html-extractor.d.ts.map +1 -1
- package/dist/analysis/html/html-extractor.js +16 -0
- package/dist/analysis/html/html-extractor.js.map +1 -1
- package/dist/analysis/interprocedural.d.ts.map +1 -1
- package/dist/analysis/interprocedural.js +51 -2
- package/dist/analysis/interprocedural.js.map +1 -1
- package/dist/analysis/js-helper-return.d.ts +7 -0
- package/dist/analysis/js-helper-return.d.ts.map +1 -1
- package/dist/analysis/js-helper-return.js +165 -0
- package/dist/analysis/js-helper-return.js.map +1 -1
- package/dist/analysis/js-spawn-argv.d.ts +34 -0
- package/dist/analysis/js-spawn-argv.d.ts.map +1 -0
- package/dist/analysis/js-spawn-argv.js +156 -0
- package/dist/analysis/js-spawn-argv.js.map +1 -0
- package/dist/analysis/maven-declared.d.ts.map +1 -1
- package/dist/analysis/maven-declared.js +5 -1
- package/dist/analysis/maven-declared.js.map +1 -1
- package/dist/analysis/passes/cli-main-reflection-suppress-pass.d.ts +1 -1
- package/dist/analysis/passes/cli-main-reflection-suppress-pass.d.ts.map +1 -1
- package/dist/analysis/passes/cli-main-reflection-suppress-pass.js +3 -1
- package/dist/analysis/passes/cli-main-reflection-suppress-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 +2 -1
- package/dist/analysis/passes/cross-file-pass.js.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.d.ts.map +1 -1
- package/dist/analysis/passes/interprocedural-pass.js +113 -2
- package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
- package/dist/analysis/passes/language-sources-pass.d.ts +15 -0
- package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
- package/dist/analysis/passes/language-sources-pass.js +1551 -119
- package/dist/analysis/passes/language-sources-pass.js.map +1 -1
- package/dist/analysis/passes/module-side-effect-pass.d.ts +9 -0
- package/dist/analysis/passes/module-side-effect-pass.d.ts.map +1 -1
- package/dist/analysis/passes/module-side-effect-pass.js +30 -3
- package/dist/analysis/passes/module-side-effect-pass.js.map +1 -1
- package/dist/analysis/passes/orphan-module-pass.d.ts +6 -1
- package/dist/analysis/passes/orphan-module-pass.d.ts.map +1 -1
- package/dist/analysis/passes/orphan-module-pass.js +6 -1
- package/dist/analysis/passes/orphan-module-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 +2 -1
- package/dist/analysis/passes/param-source-flow-gate-pass.js.map +1 -1
- package/dist/analysis/passes/scan-secrets-pass.d.ts +8 -0
- package/dist/analysis/passes/scan-secrets-pass.d.ts.map +1 -1
- package/dist/analysis/passes/scan-secrets-pass.js +78 -10
- package/dist/analysis/passes/scan-secrets-pass.js.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.d.ts +17 -0
- package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.js +691 -7
- package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.d.ts +19 -0
- package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.js +116 -12
- package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
- package/dist/analysis/require-entry-path.d.ts +4 -1
- package/dist/analysis/require-entry-path.d.ts.map +1 -1
- package/dist/analysis/require-entry-path.js +150 -7
- package/dist/analysis/require-entry-path.js.map +1 -1
- package/dist/analysis/rules.d.ts +7 -0
- package/dist/analysis/rules.d.ts.map +1 -1
- package/dist/analysis/rules.js +65 -0
- package/dist/analysis/rules.js.map +1 -1
- package/dist/analysis/sbom.d.ts +32 -4
- package/dist/analysis/sbom.d.ts.map +1 -1
- package/dist/analysis/sbom.js +57 -19
- package/dist/analysis/sbom.js.map +1 -1
- package/dist/analysis/taint-matcher.d.ts.map +1 -1
- package/dist/analysis/taint-matcher.js +85 -8
- package/dist/analysis/taint-matcher.js.map +1 -1
- package/dist/analysis/taint-propagation.d.ts +7 -0
- package/dist/analysis/taint-propagation.d.ts.map +1 -1
- package/dist/analysis/taint-propagation.js +84 -0
- package/dist/analysis/taint-propagation.js.map +1 -1
- package/dist/analysis/test-to-production-taint-gate.d.ts.map +1 -1
- package/dist/analysis/test-to-production-taint-gate.js +6 -2
- package/dist/analysis/test-to-production-taint-gate.js.map +1 -1
- package/dist/analyzer.d.ts +30 -5
- package/dist/analyzer.d.ts.map +1 -1
- package/dist/analyzer.js +93 -13
- package/dist/analyzer.js.map +1 -1
- package/dist/browser/circle-ir.js +11477 -8820
- package/dist/core/circle-ir-core.cjs +351 -28
- package/dist/core/circle-ir-core.js +351 -28
- package/dist/core/extractors/calls.d.ts.map +1 -1
- package/dist/core/extractors/calls.js +83 -1
- package/dist/core/extractors/calls.js.map +1 -1
- package/dist/core/extractors/meta.d.ts +3 -2
- package/dist/core/extractors/meta.d.ts.map +1 -1
- package/dist/core/extractors/meta.js +3 -2
- package/dist/core/extractors/meta.js.map +1 -1
- package/dist/core/extractors/runtime-registrations.js +5 -2
- package/dist/core/extractors/runtime-registrations.js.map +1 -1
- package/dist/core/extractors/types.d.ts +3 -2
- package/dist/core/extractors/types.d.ts.map +1 -1
- package/dist/core/extractors/types.js +22 -20
- package/dist/core/extractors/types.js.map +1 -1
- package/dist/core/index.d.ts +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/parser.d.ts +11 -6
- package/dist/core/parser.d.ts.map +1 -1
- package/dist/core/parser.js +29 -5
- package/dist/core/parser.js.map +1 -1
- package/dist/core/partial-parse-recovery.d.ts +26 -0
- package/dist/core/partial-parse-recovery.d.ts.map +1 -0
- package/dist/core/partial-parse-recovery.js +129 -0
- package/dist/core/partial-parse-recovery.js.map +1 -0
- package/dist/graph/code-graph.d.ts +1 -0
- package/dist/graph/code-graph.d.ts.map +1 -1
- package/dist/graph/code-graph.js +1 -0
- package/dist/graph/code-graph.js.map +1 -1
- package/dist/graph/import-graph.d.ts +14 -4
- package/dist/graph/import-graph.d.ts.map +1 -1
- package/dist/graph/import-graph.js +72 -9
- package/dist/graph/import-graph.js.map +1 -1
- package/dist/graph-facts/dead-code.d.ts +2 -0
- package/dist/graph-facts/dead-code.d.ts.map +1 -1
- package/dist/graph-facts/dead-code.js +126 -1
- package/dist/graph-facts/dead-code.js.map +1 -1
- package/dist/graph-facts/index.d.ts +1 -1
- package/dist/graph-facts/index.d.ts.map +1 -1
- package/dist/graph-facts/index.js +1 -1
- package/dist/graph-facts/index.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/languages/plugins/javascript.d.ts.map +1 -1
- package/dist/languages/plugins/javascript.js +1 -1
- package/dist/languages/plugins/javascript.js.map +1 -1
- package/dist/languages/registry.d.ts.map +1 -1
- package/dist/languages/registry.js +12 -0
- package/dist/languages/registry.js.map +1 -1
- package/dist/navigation/index.d.ts +1 -1
- package/dist/navigation/index.d.ts.map +1 -1
- package/dist/navigation/index.js.map +1 -1
- package/dist/navigation/navigation-index.js +3 -1
- package/dist/navigation/navigation-index.js.map +1 -1
- package/dist/navigation/python-graph.d.ts +3 -1
- package/dist/navigation/python-graph.d.ts.map +1 -1
- package/dist/navigation/python-graph.js +236 -23
- package/dist/navigation/python-graph.js.map +1 -1
- package/dist/navigation/ts-call-edges.d.ts +18 -0
- package/dist/navigation/ts-call-edges.d.ts.map +1 -1
- package/dist/navigation/ts-call-edges.js +207 -18
- package/dist/navigation/ts-call-edges.js.map +1 -1
- package/dist/path-set/path-set.d.ts +5 -2
- package/dist/path-set/path-set.d.ts.map +1 -1
- package/dist/path-set/path-set.js +4 -1
- package/dist/path-set/path-set.js.map +1 -1
- package/dist/resolution/cross-file.d.ts +12 -0
- package/dist/resolution/cross-file.d.ts.map +1 -1
- package/dist/resolution/cross-file.js +357 -3
- package/dist/resolution/cross-file.js.map +1 -1
- package/dist/stable-ids/ts-parse-errors.d.ts +2 -0
- package/dist/stable-ids/ts-parse-errors.d.ts.map +1 -1
- package/dist/stable-ids/ts-parse-errors.js +43 -1
- package/dist/stable-ids/ts-parse-errors.js.map +1 -1
- package/dist/types/config.d.ts +2 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/index.d.ts +74 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/docs/SPEC.md +1 -1
- package/package.json +2 -2
|
@@ -4277,7 +4277,7 @@ init_parser();
|
|
|
4277
4277
|
function extractMeta(code, tree, filePath, language) {
|
|
4278
4278
|
const loc = countLinesOfCode(code);
|
|
4279
4279
|
const hash = computeHash(code);
|
|
4280
|
-
const pkg = extractPackage(tree, language);
|
|
4280
|
+
const pkg = tree ? extractPackage(tree, language) : null;
|
|
4281
4281
|
return {
|
|
4282
4282
|
circle_ir: "3.0",
|
|
4283
4283
|
file: filePath,
|
|
@@ -4581,19 +4581,6 @@ function extractJavaTypes(tree, cache, options) {
|
|
|
4581
4581
|
types.push(extractEnumInfo(enumDecl));
|
|
4582
4582
|
}
|
|
4583
4583
|
if (!options?.navigationTypes) return types;
|
|
4584
|
-
for (const enumDecl of enums) {
|
|
4585
|
-
const info2 = types.find(
|
|
4586
|
-
(t) => t.kind === "enum" && t.start_line === enumDecl.startPosition.row + 1 && t.name === getIdentifier(enumDecl, "name")
|
|
4587
|
-
);
|
|
4588
|
-
const body2 = enumDecl.childForFieldName("body");
|
|
4589
|
-
if (!info2 || !body2) continue;
|
|
4590
|
-
for (let i2 = 0; i2 < body2.childCount; i2++) {
|
|
4591
|
-
const decls = body2.child(i2);
|
|
4592
|
-
if (decls?.type !== "enum_body_declarations") continue;
|
|
4593
|
-
info2.methods.push(...extractMethods(decls));
|
|
4594
|
-
info2.fields.push(...extractFields(decls));
|
|
4595
|
-
}
|
|
4596
|
-
}
|
|
4597
4584
|
const methodsByStart = /* @__PURE__ */ new Map();
|
|
4598
4585
|
for (const t of types) {
|
|
4599
4586
|
for (const m of t.methods) methodsByStart.set(`${m.start_line}:${m.name}`, m);
|
|
@@ -5541,6 +5528,11 @@ function extractEnumInfo(node) {
|
|
|
5541
5528
|
const body2 = node.childForFieldName("body");
|
|
5542
5529
|
const methods = body2 ? extractMethods(body2) : [];
|
|
5543
5530
|
const fields = body2 ? extractFields(body2) : [];
|
|
5531
|
+
for (const decls of body2?.children ?? []) {
|
|
5532
|
+
if (decls?.type !== "enum_body_declarations") continue;
|
|
5533
|
+
methods.push(...extractMethods(decls));
|
|
5534
|
+
fields.push(...extractFields(decls));
|
|
5535
|
+
}
|
|
5544
5536
|
const pkg = extractPackageFromAncestors(node);
|
|
5545
5537
|
return {
|
|
5546
5538
|
name: name2,
|
|
@@ -5568,6 +5560,13 @@ function extractMethods(body2) {
|
|
|
5568
5560
|
if (child.type === "method_declaration" || child.type === "constructor_declaration") {
|
|
5569
5561
|
methods.push(extractMethodInfo(child, precedingComment));
|
|
5570
5562
|
precedingComment = null;
|
|
5563
|
+
} else if (child.type === "compact_constructor_declaration") {
|
|
5564
|
+
const info2 = extractMethodInfo(child, precedingComment);
|
|
5565
|
+
const rec = body2.parent?.type === "record_declaration" ? body2.parent : null;
|
|
5566
|
+
const params = rec?.childForFieldName("parameters");
|
|
5567
|
+
if (params) info2.parameters = extractParameters(params);
|
|
5568
|
+
methods.push(info2);
|
|
5569
|
+
precedingComment = null;
|
|
5571
5570
|
} else {
|
|
5572
5571
|
precedingComment = null;
|
|
5573
5572
|
}
|
|
@@ -5575,7 +5574,7 @@ function extractMethods(body2) {
|
|
|
5575
5574
|
return methods;
|
|
5576
5575
|
}
|
|
5577
5576
|
function extractMethodInfo(node, precedingComment = null) {
|
|
5578
|
-
const isConstructor = node.type === "constructor_declaration";
|
|
5577
|
+
const isConstructor = node.type === "constructor_declaration" || node.type === "compact_constructor_declaration";
|
|
5579
5578
|
const name2 = getIdentifier(node, "name") ?? (isConstructor ? "<init>" : "unknown");
|
|
5580
5579
|
const returnTypeNode = node.childForFieldName("type");
|
|
5581
5580
|
const returnType = returnTypeNode ? getNodeText(returnTypeNode) : isConstructor ? null : "void";
|
|
@@ -6260,6 +6259,10 @@ function extractCalls(tree, cache, language, options = {}) {
|
|
|
6260
6259
|
calls.push(callInfo);
|
|
6261
6260
|
}
|
|
6262
6261
|
}
|
|
6262
|
+
for (const ref of getNodesFromCache(tree.rootNode, "method_reference", cache)) {
|
|
6263
|
+
const callInfo = extractMethodReference(ref, context);
|
|
6264
|
+
if (callInfo) calls.push(callInfo);
|
|
6265
|
+
}
|
|
6263
6266
|
if (typed) {
|
|
6264
6267
|
for (const inv of getNodesFromCache(tree.rootNode, "explicit_constructor_invocation", cache)) {
|
|
6265
6268
|
const callInfo = extractExplicitConstructorInvocation(inv, context);
|
|
@@ -7371,6 +7374,47 @@ function extractObjectCreation(node, context, typed = false) {
|
|
|
7371
7374
|
resolution
|
|
7372
7375
|
};
|
|
7373
7376
|
}
|
|
7377
|
+
function extractMethodReference(node, context) {
|
|
7378
|
+
const target = node.namedChildren[0];
|
|
7379
|
+
if (!target) return null;
|
|
7380
|
+
const isNew = node.children.some((c) => c?.type === "new");
|
|
7381
|
+
if (isNew && target.type === "array_type") return null;
|
|
7382
|
+
const location = { line: node.startPosition.row + 1, column: node.startPosition.column };
|
|
7383
|
+
const inMethod = findEnclosingMethod(node);
|
|
7384
|
+
const written = getNodeText(target);
|
|
7385
|
+
if (isNew) {
|
|
7386
|
+
const { simpleName: simpleName2, fqn: fqn2 } = resolveFqn(stripGenerics(written), context);
|
|
7387
|
+
return {
|
|
7388
|
+
method_name: written,
|
|
7389
|
+
receiver: null,
|
|
7390
|
+
receiver_type: simpleName2,
|
|
7391
|
+
receiver_type_fqn: fqn2,
|
|
7392
|
+
arguments: [],
|
|
7393
|
+
location,
|
|
7394
|
+
in_method: inMethod,
|
|
7395
|
+
reference_form: "constructor",
|
|
7396
|
+
resolved: true,
|
|
7397
|
+
resolution: { status: "resolved", target: `${written}.<init>` }
|
|
7398
|
+
};
|
|
7399
|
+
}
|
|
7400
|
+
const nameNode = node.namedChildren[node.namedChildCount - 1];
|
|
7401
|
+
if (!nameNode || nameNode.type !== "identifier" || nameNode === target) return null;
|
|
7402
|
+
const methodName = getNodeText(nameNode);
|
|
7403
|
+
const { resolved, resolution } = resolveMethodCall(methodName, written, context);
|
|
7404
|
+
const { simpleName, fqn } = resolveReceiverType(stripGenerics(written), context);
|
|
7405
|
+
return {
|
|
7406
|
+
method_name: methodName,
|
|
7407
|
+
receiver: written,
|
|
7408
|
+
receiver_type: simpleName,
|
|
7409
|
+
receiver_type_fqn: fqn,
|
|
7410
|
+
arguments: [],
|
|
7411
|
+
location,
|
|
7412
|
+
in_method: inMethod,
|
|
7413
|
+
reference_form: target.type === "super" ? "super" : "method",
|
|
7414
|
+
resolved,
|
|
7415
|
+
resolution
|
|
7416
|
+
};
|
|
7417
|
+
}
|
|
7374
7418
|
var JAVA_TYPE_DECLARATIONS = /* @__PURE__ */ new Set(["class_declaration", "interface_declaration", "enum_declaration", "record_declaration"]);
|
|
7375
7419
|
function extractExplicitConstructorInvocation(node, context) {
|
|
7376
7420
|
const kind = node.childForFieldName("constructor")?.type;
|
|
@@ -7776,6 +7820,21 @@ function findEnclosingMethod(node) {
|
|
|
7776
7820
|
}
|
|
7777
7821
|
return "<init>";
|
|
7778
7822
|
}
|
|
7823
|
+
return findEnclosingFieldInitializer(node);
|
|
7824
|
+
}
|
|
7825
|
+
function findEnclosingFieldInitializer(node) {
|
|
7826
|
+
for (let cur = node, parent = node.parent; parent; cur = parent, parent = parent.parent) {
|
|
7827
|
+
if (parent.type === "constant_declaration") return "<clinit>";
|
|
7828
|
+
if (parent.type === "enum_constant") {
|
|
7829
|
+
return cur.type === "argument_list" ? "<clinit>" : null;
|
|
7830
|
+
}
|
|
7831
|
+
if (parent.type === "field_declaration") {
|
|
7832
|
+
const body2 = parent.parent?.type;
|
|
7833
|
+
if (body2 !== "class_body" && body2 !== "enum_body_declarations") return null;
|
|
7834
|
+
const modifiers = parent.namedChildren.find((c) => c?.type === "modifiers");
|
|
7835
|
+
return modifiers?.children.some((c) => c?.type === "static") ? "<clinit>" : "<init>";
|
|
7836
|
+
}
|
|
7837
|
+
}
|
|
7779
7838
|
return null;
|
|
7780
7839
|
}
|
|
7781
7840
|
function resolveMethodCall(methodName, receiver, context) {
|
|
@@ -8167,7 +8226,8 @@ function extractPythonLiteral(node) {
|
|
|
8167
8226
|
return null;
|
|
8168
8227
|
}
|
|
8169
8228
|
}
|
|
8170
|
-
|
|
8229
|
+
const m = /^[rRbBuUfF]{0,2}("""|'''|"|')([\s\S]*)\1$/.exec(text);
|
|
8230
|
+
return m ? m[2] : text;
|
|
8171
8231
|
}
|
|
8172
8232
|
return text;
|
|
8173
8233
|
}
|
|
@@ -12186,6 +12246,9 @@ function runsArgvAsCommand(program) {
|
|
|
12186
12246
|
return ARG_EXECUTING_PROGRAMS.has(base);
|
|
12187
12247
|
}
|
|
12188
12248
|
|
|
12249
|
+
// src/analysis/js-spawn-argv.ts
|
|
12250
|
+
var SHELL_OPTION_ON = /\bshell\s*:(?!\s*false\b)/;
|
|
12251
|
+
|
|
12189
12252
|
// src/analysis/js-helper-return.ts
|
|
12190
12253
|
function jsHelperReturnsNoParam(sourceCode, rawName) {
|
|
12191
12254
|
if (!/^[A-Za-z_$][\w$]*$/.test(rawName)) return false;
|
|
@@ -12225,6 +12288,126 @@ function jsHelperReturnsNoParam(sourceCode, rawName) {
|
|
|
12225
12288
|
}
|
|
12226
12289
|
return true;
|
|
12227
12290
|
}
|
|
12291
|
+
var NUMERIC_CALL = /^(?:Number|parseInt|parseFloat|Number\.parseInt|Number\.parseFloat|Math\.[A-Za-z]+)\s*\(/;
|
|
12292
|
+
var NUMERIC_LITERAL = /^-?(?:\d[\d_]*(?:\.\d+)?|0[xX][0-9a-fA-F]+)$/;
|
|
12293
|
+
function closeAt(text, open) {
|
|
12294
|
+
let depth = 0;
|
|
12295
|
+
for (let i2 = open; i2 < text.length; i2++) {
|
|
12296
|
+
const ch = text[i2];
|
|
12297
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
12298
|
+
let j = i2 + 1;
|
|
12299
|
+
for (; j < text.length && text[j] !== ch; j++) if (text[j] === "\\") j++;
|
|
12300
|
+
i2 = j;
|
|
12301
|
+
continue;
|
|
12302
|
+
}
|
|
12303
|
+
if (ch === "(" || ch === "[" || ch === "{") depth++;
|
|
12304
|
+
else if ((ch === ")" || ch === "]" || ch === "}") && --depth === 0) return i2;
|
|
12305
|
+
}
|
|
12306
|
+
return -1;
|
|
12307
|
+
}
|
|
12308
|
+
function splitTernary(expr) {
|
|
12309
|
+
let depth = 0;
|
|
12310
|
+
let q = -1;
|
|
12311
|
+
let nested = 0;
|
|
12312
|
+
for (let i2 = 0; i2 < expr.length; i2++) {
|
|
12313
|
+
const ch = expr[i2];
|
|
12314
|
+
if (ch === '"' || ch === "'" || ch === "`") {
|
|
12315
|
+
let j = i2 + 1;
|
|
12316
|
+
for (; j < expr.length && expr[j] !== ch; j++) if (expr[j] === "\\") j++;
|
|
12317
|
+
i2 = j;
|
|
12318
|
+
continue;
|
|
12319
|
+
}
|
|
12320
|
+
if (ch === "(" || ch === "[" || ch === "{") depth++;
|
|
12321
|
+
else if (ch === ")" || ch === "]" || ch === "}") depth--;
|
|
12322
|
+
else if (depth === 0 && ch === "?" && expr[i2 + 1] !== "." && expr[i2 + 1] !== "?") {
|
|
12323
|
+
if (q < 0) q = i2;
|
|
12324
|
+
else nested++;
|
|
12325
|
+
} else if (depth === 0 && ch === ":" && q >= 0) {
|
|
12326
|
+
if (nested > 0) {
|
|
12327
|
+
nested--;
|
|
12328
|
+
continue;
|
|
12329
|
+
}
|
|
12330
|
+
return [expr.slice(q + 1, i2).trim(), expr.slice(i2 + 1).trim()];
|
|
12331
|
+
}
|
|
12332
|
+
}
|
|
12333
|
+
return null;
|
|
12334
|
+
}
|
|
12335
|
+
function isNumericExpr(expr, body2, params, depth) {
|
|
12336
|
+
let e = expr.trim();
|
|
12337
|
+
if (e.endsWith("number")) {
|
|
12338
|
+
const head = e.slice(0, -"number".length).trimEnd();
|
|
12339
|
+
if (head.length < e.length - "number".length && /\sas$/.test(head)) e = head.slice(0, -2).trimEnd();
|
|
12340
|
+
}
|
|
12341
|
+
while (e.startsWith("(") && closeAt(e, 0) === e.length - 1) e = e.slice(1, -1).trim();
|
|
12342
|
+
if (e === "" || depth > 4) return false;
|
|
12343
|
+
if (NUMERIC_LITERAL.test(e)) return true;
|
|
12344
|
+
const call = NUMERIC_CALL.exec(e);
|
|
12345
|
+
if (call) return closeAt(e, call[0].length - 1) === e.length - 1;
|
|
12346
|
+
if (/^\+\s*[A-Za-z_$][\w$.]*$/.test(e)) return true;
|
|
12347
|
+
const tern = splitTernary(e);
|
|
12348
|
+
if (tern) return tern.every((t) => isNumericExpr(t, body2, params, depth + 1));
|
|
12349
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(e) || params.has(e)) return false;
|
|
12350
|
+
return localIsNumeric(e, body2, params, depth);
|
|
12351
|
+
}
|
|
12352
|
+
function stripBlockComments(text) {
|
|
12353
|
+
let out2 = "";
|
|
12354
|
+
let i2 = 0;
|
|
12355
|
+
for (; ; ) {
|
|
12356
|
+
const open = text.indexOf("/*", i2);
|
|
12357
|
+
const close = open < 0 ? -1 : text.indexOf("*/", open + 2);
|
|
12358
|
+
if (close < 0) return out2 + text.slice(i2);
|
|
12359
|
+
out2 += text.slice(i2, open);
|
|
12360
|
+
i2 = close + 2;
|
|
12361
|
+
}
|
|
12362
|
+
}
|
|
12363
|
+
function localIsNumeric(name2, body2, params, depth) {
|
|
12364
|
+
const esc = name2.replace(/\$/g, "\\$");
|
|
12365
|
+
if (!new RegExp(`\\b(?:const|let|var)\\s+${esc}\\b`).test(body2)) return false;
|
|
12366
|
+
if (new RegExp(`\\b(?:const|let|var)\\s*[{[][^=;]*(?<![\\w$])${esc}(?![\\w$])`).test(body2)) return false;
|
|
12367
|
+
if (new RegExp(`\\b(?:const|let|var)\\s+${esc}\\s+(?:of|in)\\b`).test(body2)) return false;
|
|
12368
|
+
const write = new RegExp(`(?<![\\w$.])${esc}\\s*(?::\\s*number\\s*)?(\\*\\*=|[-*/%]=|\\+=|\\?\\?=|\\|\\|=|&&=|=(?![=>])|\\+\\+|--)`, "g");
|
|
12369
|
+
let writes = 0;
|
|
12370
|
+
for (const m of body2.matchAll(write)) {
|
|
12371
|
+
writes++;
|
|
12372
|
+
const op = m[1];
|
|
12373
|
+
if (op === "++" || op === "--" || /^(?:\*\*|[-*/%])=$/.test(op)) continue;
|
|
12374
|
+
const rhs = /^[^;\n]*/.exec(body2.slice(m.index + m[0].length))[0];
|
|
12375
|
+
if (!isNumericExpr(rhs, body2, params, depth + 1)) return false;
|
|
12376
|
+
}
|
|
12377
|
+
return writes > 0;
|
|
12378
|
+
}
|
|
12379
|
+
function jsHelperReturnsNumber(sourceCode, rawName) {
|
|
12380
|
+
if (!/^[A-Za-z_$][\w$]*$/.test(rawName)) return false;
|
|
12381
|
+
const name2 = rawName.replace(/\$/g, "\\$");
|
|
12382
|
+
const decl = new RegExp(
|
|
12383
|
+
`\\bfunction\\s+${name2}\\s*(?:<[^>]*>)?\\s*\\(([^)]*)\\)[^{]*\\{|\\bconst\\s+${name2}\\s*=\\s*(?:async\\s+)?(?:function\\s*)?\\(([^)]*)\\)[^{=]*(?:=>\\s*)?\\{`,
|
|
12384
|
+
"g"
|
|
12385
|
+
);
|
|
12386
|
+
const decls = [...sourceCode.matchAll(decl)];
|
|
12387
|
+
if (decls.length !== 1) return false;
|
|
12388
|
+
if (new RegExp(`\\b(?:let|var)\\s+${name2}\\s*=|(?<![\\w$.])${name2}\\s*=(?![=>])[^=]`).test(
|
|
12389
|
+
sourceCode.slice(0, decls[0].index) + sourceCode.slice(decls[0].index + decls[0][0].length)
|
|
12390
|
+
)) return false;
|
|
12391
|
+
const open = decls[0].index + decls[0][0].length - 1;
|
|
12392
|
+
const close = closeAt(sourceCode, open);
|
|
12393
|
+
if (close < 0) return false;
|
|
12394
|
+
const body2 = stripBlockComments(sourceCode.slice(open + 1, close)).split("\n").map((l) => {
|
|
12395
|
+
const c = l.indexOf("//");
|
|
12396
|
+
return c < 0 ? l : l.slice(0, c);
|
|
12397
|
+
}).join("\n");
|
|
12398
|
+
if (/\bfunction\b|=>|\byield\b/.test(body2)) return false;
|
|
12399
|
+
const params = new Set(
|
|
12400
|
+
(decls[0][1] ?? decls[0][2] ?? "").split(",").map((p) => /^\s*(?:\.\.\.)?([A-Za-z_$][\w$]*)/.exec(p)?.[1]).filter((p) => !!p)
|
|
12401
|
+
);
|
|
12402
|
+
let returns = 0;
|
|
12403
|
+
for (const m of body2.matchAll(/\breturn\b([^;\n}]*)/g)) {
|
|
12404
|
+
returns++;
|
|
12405
|
+
const after = body2.slice(m.index + m[0].length);
|
|
12406
|
+
if (after.startsWith("\n") && !/^\s*(?:[}A-Za-z_$]|$)/.test(after)) return false;
|
|
12407
|
+
if (!isNumericExpr(m[1], body2, params, 0)) return false;
|
|
12408
|
+
}
|
|
12409
|
+
return returns > 0;
|
|
12410
|
+
}
|
|
12228
12411
|
|
|
12229
12412
|
// src/analysis/literal-expression.ts
|
|
12230
12413
|
function isProvablyLiteralExpression(expr) {
|
|
@@ -12594,6 +12777,10 @@ function jsChainTextAt(sourceLines, line, column) {
|
|
|
12594
12777
|
}
|
|
12595
12778
|
|
|
12596
12779
|
// src/analysis/passes/language-sources-pass.ts
|
|
12780
|
+
var JAVA_LITERAL_RHS_RE = /^(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)'|-?\d[\w.]*|true|false|null)$/;
|
|
12781
|
+
var JAVA_NON_THROWING_STMT_RE = new RegExp(
|
|
12782
|
+
`^(?:final\\s+)?(?:[A-Za-z_][\\w.]*(?:<[^;=()]*>)?(?:\\s*\\[\\s*\\])*\\s+)?[A-Za-z_]\\w*\\s*=\\s*(?:${JAVA_LITERAL_RHS_RE.source.slice(1, -1)})\\s*;$`
|
|
12783
|
+
);
|
|
12597
12784
|
var JINJA_LITERAL_ARG_RE_FRAG = `(?:"[^"\\\\]*"|'[^'\\\\]*')`;
|
|
12598
12785
|
var JINJA_SAFE_RTS_RE = new RegExp(
|
|
12599
12786
|
`^(?:flask\\.|jinja2\\.)?render_template_string\\s*\\(\\s*${JINJA_LITERAL_ARG_RE_FRAG}\\s*[,)]`
|
|
@@ -13999,7 +14186,10 @@ var DEFAULT_SINKS = [
|
|
|
13999
14186
|
{ method: "handleDiv", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14000
14187
|
{ method: "handleImage", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14001
14188
|
{ method: "handleLink", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14002
|
-
{ method: "render", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14189
|
+
{ method: "render", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
|
|
14190
|
+
// Python Jinja/Mako template `.render()` — keep separate from the Java wiki
|
|
14191
|
+
// row so a classless match does not fire on JS/TS locals named `render` (#1432).
|
|
14192
|
+
{ method: "render", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["python"] },
|
|
14003
14193
|
{ method: "renderHTML", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14004
14194
|
{ method: "parseHTML", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
|
|
14005
14195
|
// HTML sanitizer/validator sinks (AntiSamy, OWASP HTML Sanitizer, etc.)
|
|
@@ -14179,6 +14369,8 @@ var DEFAULT_SINKS = [
|
|
|
14179
14369
|
{ method: "eval", class: "ScriptContext", type: "code_injection", cwe: "CWE-94", severity: "critical", arg_positions: [0] },
|
|
14180
14370
|
// Dynamic class loading (can lead to RCE)
|
|
14181
14371
|
{ method: "forName", class: "Class", type: "code_injection", cwe: "CWE-94", severity: "high", arg_positions: [0] },
|
|
14372
|
+
// Attacker-chosen class names used for reflective instantiation (yamlbeans CVE-2023-24621, cognium-dev#1290)
|
|
14373
|
+
{ method: "forName", class: "Class", type: "deserialization", cwe: "CWE-502", severity: "critical", arg_positions: [0], languages: ["java"] },
|
|
14182
14374
|
{ method: "loadClass", class: "ClassLoader", type: "code_injection", cwe: "CWE-94", severity: "high", arg_positions: [0] },
|
|
14183
14375
|
{ method: "defineClass", class: "ClassLoader", type: "code_injection", cwe: "CWE-94", severity: "critical", arg_positions: [0, 1] },
|
|
14184
14376
|
{ method: "newInstance", class: "Class", type: "code_injection", cwe: "CWE-94", severity: "high", arg_positions: [] },
|
|
@@ -15914,6 +16106,10 @@ var DEFAULT_SANITIZERS = [
|
|
|
15914
16106
|
// Log Injection sanitizers
|
|
15915
16107
|
{ method: "replace", removes: ["log_injection"] },
|
|
15916
16108
|
// Used to remove newlines/control chars
|
|
16109
|
+
// JSON.stringify escapes CR/LF (and every other control character) inside a
|
|
16110
|
+
// string, so a log entry cannot be split. Log injection only: the output still
|
|
16111
|
+
// carries `<`, quotes and shell/SQL metacharacters.
|
|
16112
|
+
{ method: "stringify", class: "JSON", removes: ["log_injection"] },
|
|
15917
16113
|
// LDAP Injection
|
|
15918
16114
|
{ method: "encodeForLDAP", removes: ["ldap_injection"] },
|
|
15919
16115
|
{ method: "encodeForDN", removes: ["ldap_injection"] },
|
|
@@ -15963,9 +16159,11 @@ var DEFAULT_SANITIZERS = [
|
|
|
15963
16159
|
// Type coercion (removes string-based injections)
|
|
15964
16160
|
// Sprint 29 (#113): include external_taint_escape — a numeric cast cannot
|
|
15965
16161
|
// carry an unvalidated string payload across a function boundary.
|
|
15966
|
-
|
|
15967
|
-
|
|
15968
|
-
{ method: "
|
|
16162
|
+
// #1305 E2: a number has no CR/LF, so it cannot split or forge a log entry: log_injection too.
|
|
16163
|
+
// (Still not size-sensitive consumers: a parsed number is attacker-chosen.)
|
|
16164
|
+
{ method: "parseInt", removes: ["sql_injection", "nosql_injection", "command_injection", "xss", "external_taint_escape", "path_traversal", "code_injection", "log_injection"] },
|
|
16165
|
+
{ method: "parseFloat", removes: ["sql_injection", "nosql_injection", "command_injection", "external_taint_escape", "path_traversal", "code_injection", "log_injection"] },
|
|
16166
|
+
{ method: "Number", removes: ["sql_injection", "nosql_injection", "command_injection", "external_taint_escape", "path_traversal", "code_injection", "log_injection"] },
|
|
15969
16167
|
// Sprint 29 (#113): bounds-clamp Math.min / Math.max — when used to bound
|
|
15970
16168
|
// a numeric/size value (e.g. `Math.min(size, MAX_BYTES)`), the result is
|
|
15971
16169
|
// safely bounded and cannot resource-exhaust downstream. Only suppress
|
|
@@ -15993,6 +16191,8 @@ var DEFAULT_SANITIZERS = [
|
|
|
15993
16191
|
// SQL - parameterized queries (mysql, pg)
|
|
15994
16192
|
{ method: "escape", class: "mysql", removes: ["sql_injection"] },
|
|
15995
16193
|
{ method: "escapeId", class: "mysql", removes: ["sql_injection"] },
|
|
16194
|
+
// BenchProctor express_ts safe ORDER BY (cognium-dev#1332): escapeIdentifier wrapper before concat query
|
|
16195
|
+
{ method: "escapeIdentifier", removes: ["sql_injection", "external_taint_escape"] },
|
|
15996
16196
|
{ method: "format", class: "mysql", removes: ["sql_injection"] },
|
|
15997
16197
|
// MongoDB - sanitization
|
|
15998
16198
|
{ method: "sanitize", class: "mongo", removes: ["nosql_injection"] },
|
|
@@ -16237,7 +16437,7 @@ var DEFAULT_SANITIZERS = [
|
|
|
16237
16437
|
// Java UUID parse — UUID.fromString rejects non-UUID strings
|
|
16238
16438
|
{ method: "fromString", class: "UUID", removes: ["sql_injection", "command_injection", "path_traversal", "code_injection"] },
|
|
16239
16439
|
// JavaScript numeric coercion (Number/parseInt/parseFloat already covered above; add path_traversal/code_injection)
|
|
16240
|
-
{ method: "BigInt", removes: ["sql_injection", "nosql_injection", "command_injection", "path_traversal", "code_injection"] },
|
|
16440
|
+
{ method: "BigInt", removes: ["sql_injection", "nosql_injection", "command_injection", "path_traversal", "code_injection", "log_injection"] },
|
|
16241
16441
|
// Go numeric parse — strconv.Atoi, ParseInt, ParseFloat, ParseUint, ParseBool
|
|
16242
16442
|
{ method: "Atoi", class: "strconv", removes: ["sql_injection", "command_injection", "path_traversal", "code_injection"] },
|
|
16243
16443
|
{ method: "ParseInt", class: "strconv", removes: ["sql_injection", "command_injection", "path_traversal", "code_injection"] },
|
|
@@ -16314,6 +16514,12 @@ var DEFAULT_SINK_SEMANTICS = [
|
|
|
16314
16514
|
real_class: "jdk_internal",
|
|
16315
16515
|
overrides: ["code_injection"],
|
|
16316
16516
|
note: "java.lang.invoke.MethodHandle \u2014 JDK-internal"
|
|
16517
|
+
},
|
|
16518
|
+
{
|
|
16519
|
+
signature: "Class#forName",
|
|
16520
|
+
real_class: "jdk_reflection",
|
|
16521
|
+
overrides: ["deserialization"],
|
|
16522
|
+
note: "User-controlled Class.forName is CWE-94 code_injection; drop CWE-502 duplicate (#1349)"
|
|
16317
16523
|
}
|
|
16318
16524
|
];
|
|
16319
16525
|
function getDefaultConfig() {
|
|
@@ -16325,6 +16531,40 @@ function getDefaultConfig() {
|
|
|
16325
16531
|
};
|
|
16326
16532
|
}
|
|
16327
16533
|
|
|
16534
|
+
// src/types/index.ts
|
|
16535
|
+
var SINK_TYPES = [
|
|
16536
|
+
"sql_injection",
|
|
16537
|
+
"nosql_injection",
|
|
16538
|
+
"command_injection",
|
|
16539
|
+
"path_traversal",
|
|
16540
|
+
"xss",
|
|
16541
|
+
"xxe",
|
|
16542
|
+
"deserialization",
|
|
16543
|
+
"ldap_injection",
|
|
16544
|
+
"xpath_injection",
|
|
16545
|
+
"ssrf",
|
|
16546
|
+
"open_redirect",
|
|
16547
|
+
"code_injection",
|
|
16548
|
+
"log_injection",
|
|
16549
|
+
"redos",
|
|
16550
|
+
"format_string",
|
|
16551
|
+
"crlf",
|
|
16552
|
+
"mass_assignment",
|
|
16553
|
+
"mybatis_mapper_call",
|
|
16554
|
+
"weak_random",
|
|
16555
|
+
"weak_hash",
|
|
16556
|
+
"weak_crypto",
|
|
16557
|
+
"insecure_cookie",
|
|
16558
|
+
"trust_boundary",
|
|
16559
|
+
"cache_poisoning",
|
|
16560
|
+
"prompt_injection",
|
|
16561
|
+
"insecure_storage",
|
|
16562
|
+
"prototype_pollution",
|
|
16563
|
+
"regex_dos",
|
|
16564
|
+
"unsafe_memory",
|
|
16565
|
+
"external_taint_escape"
|
|
16566
|
+
];
|
|
16567
|
+
|
|
16328
16568
|
// src/analysis/constant-propagation/patterns.ts
|
|
16329
16569
|
var TAINT_PATTERNS = [
|
|
16330
16570
|
// HTTP Sources (Servlet API)
|
|
@@ -16554,7 +16794,10 @@ var HTML_CONTEXT_ENCODER_METHODS = /* @__PURE__ */ new Set([
|
|
|
16554
16794
|
"htmlEscapeDecimal",
|
|
16555
16795
|
"htmlEscapeHex"
|
|
16556
16796
|
]);
|
|
16557
|
-
var
|
|
16797
|
+
var HTML_CONTEXT_ENCODER_COVERED_SINKS = /* @__PURE__ */ new Set(["xss", "external_taint_escape"]);
|
|
16798
|
+
var HTML_CONTEXT_ENCODER_UNCOVERED_SINKS = new Set(
|
|
16799
|
+
SINK_TYPES.filter((t) => !HTML_CONTEXT_ENCODER_COVERED_SINKS.has(t))
|
|
16800
|
+
);
|
|
16558
16801
|
var ANTI_SANITIZER_METHODS = /* @__PURE__ */ new Set([
|
|
16559
16802
|
// URL decoding (reverses URL encoding)
|
|
16560
16803
|
"decode",
|
|
@@ -17377,6 +17620,7 @@ function isSafeJSChildProcessCall(call, pattern, language) {
|
|
|
17377
17620
|
if (m !== "spawn" && m !== "spawnSync" && m !== "execFile" && m !== "execFileSync") return false;
|
|
17378
17621
|
const programArg = call.arguments.find((a) => a.position === 0);
|
|
17379
17622
|
if (!programArg) return false;
|
|
17623
|
+
if (call.arguments.some((a) => SHELL_OPTION_ON.test(a.expression ?? ""))) return false;
|
|
17380
17624
|
let program;
|
|
17381
17625
|
if (programArg.literal !== null && programArg.literal !== void 0) {
|
|
17382
17626
|
program = String(programArg.literal).split("/").pop() ?? String(programArg.literal);
|
|
@@ -17385,6 +17629,7 @@ function isSafeJSChildProcessCall(call, pattern, language) {
|
|
|
17385
17629
|
if (!(expr.startsWith('"') || expr.startsWith("`") || expr.startsWith("'"))) {
|
|
17386
17630
|
return false;
|
|
17387
17631
|
}
|
|
17632
|
+
if (expr.startsWith("`") && expr.includes("${")) return false;
|
|
17388
17633
|
const stripped = expr.slice(1, -1);
|
|
17389
17634
|
program = stripped.split("/").pop() ?? stripped;
|
|
17390
17635
|
}
|
|
@@ -17793,6 +18038,10 @@ function isTypedNonDbReceiver(receiver, sourceLines) {
|
|
|
17793
18038
|
}
|
|
17794
18039
|
return typed !== void 0 && !DB_TYPE_NAME.test(typed) && !/^(?:any|unknown|object)$/.test(typed);
|
|
17795
18040
|
}
|
|
18041
|
+
var REQUEST_OBJECT_RECEIVERS = /* @__PURE__ */ new Set(["req", "request", "c.req", "ctx.req", "ctx.request", "this.req"]);
|
|
18042
|
+
function isRequestObjectReceiver(receiver) {
|
|
18043
|
+
return REQUEST_OBJECT_RECEIVERS.has((receiver ?? "").trim());
|
|
18044
|
+
}
|
|
17796
18045
|
function isNavigationReceiverName(receiver) {
|
|
17797
18046
|
const r = (receiver ?? "").trim();
|
|
17798
18047
|
if (!r) return false;
|
|
@@ -17838,14 +18087,15 @@ function isJsMapTypedReceiver(receiver, sourceLines) {
|
|
|
17838
18087
|
const raw = (receiver ?? "").trim();
|
|
17839
18088
|
if (!raw || !sourceLines) return false;
|
|
17840
18089
|
const lastDot = raw.lastIndexOf(".");
|
|
17841
|
-
|
|
18090
|
+
let r = (lastDot >= 0 ? raw.slice(lastDot + 1) : raw).trim();
|
|
18091
|
+
if (r.startsWith("#")) r = r.slice(1);
|
|
17842
18092
|
if (!/^[A-Za-z_$][\w$]*$/.test(r)) return false;
|
|
17843
18093
|
const n = escapeRe(r);
|
|
17844
18094
|
const mapCtor = new RegExp(
|
|
17845
|
-
`\\b
|
|
18095
|
+
`\\b#?${n}\\s*(?::[^=;]*)?=\\s*new\\s+(?:Weak)?Map\\s*(?:<.*>)?\\s*\\(`
|
|
17846
18096
|
);
|
|
17847
18097
|
const mapType = new RegExp(
|
|
17848
|
-
`\\b
|
|
18098
|
+
`\\b#?${n}\\s*\\??\\s*:\\s*(?:Readonly)?(?:Weak)?Map\\s*<`
|
|
17849
18099
|
);
|
|
17850
18100
|
return sourceLines.some((l) => mapCtor.test(l) || mapType.test(l));
|
|
17851
18101
|
}
|
|
@@ -17854,7 +18104,8 @@ function isInMemoryMapGetReceiver(receiver, sourceLines) {
|
|
|
17854
18104
|
if (!raw || !sourceLines) return false;
|
|
17855
18105
|
if (/\.properties$/i.test(raw)) return true;
|
|
17856
18106
|
const lastDot = raw.lastIndexOf(".");
|
|
17857
|
-
|
|
18107
|
+
let r = (lastDot >= 0 ? raw.slice(lastDot + 1) : raw).trim();
|
|
18108
|
+
if (r.startsWith("#")) r = r.slice(1);
|
|
17858
18109
|
if (/^(properties|memoryCache)$/i.test(r)) return true;
|
|
17859
18110
|
return isJsMapTypedReceiver(receiver, sourceLines);
|
|
17860
18111
|
}
|
|
@@ -18149,6 +18400,9 @@ function findSinks(calls, patterns, typeHierarchy, language, sourceLines, types)
|
|
|
18149
18400
|
if ((pattern.type === "command_injection" || pattern.type === "sql_injection") && call.method_name === "exec" && (language === "javascript" || language === "typescript") && isRegexReceiver(call.receiver, sourceLines)) {
|
|
18150
18401
|
continue;
|
|
18151
18402
|
}
|
|
18403
|
+
if (pattern.type === "sql_injection" && call.method_name === "query" && (language === "javascript" || language === "typescript") && isRequestObjectReceiver(call.receiver)) {
|
|
18404
|
+
continue;
|
|
18405
|
+
}
|
|
18152
18406
|
if (pattern.type === "sql_injection" && call.method_name === "get" && pattern.class === "Connection" && (language === "javascript" || language === "typescript") && (isInMemoryMapGetReceiver(call.receiver, sourceLines) || isTypedNonDbReceiver(call.receiver, sourceLines))) {
|
|
18153
18407
|
continue;
|
|
18154
18408
|
}
|
|
@@ -18217,6 +18471,8 @@ function matchesSourcePattern(call, pattern, language, types, imports) {
|
|
|
18217
18471
|
return false;
|
|
18218
18472
|
}
|
|
18219
18473
|
} else if (language === "java" && types && imports && call.receiver && pattern.class && javaWikiTagInheritedContextReceiver(call.receiver, pattern.class, call, types, imports)) {
|
|
18474
|
+
} else if (language === "java" && pattern.type === "db_input" && pattern.class === "ResultSet" && call.receiver_type && call.receiver_type !== "var" && !/(?:ResultSet|RowSet)$/.test(call.receiver_type)) {
|
|
18475
|
+
return false;
|
|
18220
18476
|
} else if (!receiverMightBeClass(call.receiver, pattern.class)) {
|
|
18221
18477
|
return false;
|
|
18222
18478
|
}
|
|
@@ -18399,6 +18655,8 @@ var SAFE_RECEIVERS_BY_METHOD = {
|
|
|
18399
18655
|
"saml",
|
|
18400
18656
|
"oidc"
|
|
18401
18657
|
]),
|
|
18658
|
+
// ES template tag `String.raw` — not SQL (Knex/Objection `.raw(sql)` keeps sinking).
|
|
18659
|
+
raw: /* @__PURE__ */ new Set(["string"]),
|
|
18402
18660
|
// add() is extremely generic — safe on collections, UI containers, builders, etc.
|
|
18403
18661
|
add: /* @__PURE__ */ new Set([
|
|
18404
18662
|
"list",
|
|
@@ -19100,6 +19358,23 @@ function findSanitizers(calls, types, patterns, sourceLines, language) {
|
|
|
19100
19358
|
sanitizes: removes
|
|
19101
19359
|
});
|
|
19102
19360
|
}
|
|
19361
|
+
if (sourceLines && (language === "javascript" || language === "typescript" || language === "tsx")) {
|
|
19362
|
+
const numericRemoves = patterns.find((p) => p.method === "Number" && !p.class)?.removes ?? [];
|
|
19363
|
+
const jsCode = sourceLines.join("\n");
|
|
19364
|
+
const numericHelper = /* @__PURE__ */ new Map();
|
|
19365
|
+
for (const call of calls) {
|
|
19366
|
+
if (call.receiver || wrapperSanitizers.has(call.method_name) || numericRemoves.length === 0) continue;
|
|
19367
|
+
let numeric = numericHelper.get(call.method_name);
|
|
19368
|
+
if (numeric === void 0) numericHelper.set(call.method_name, numeric = jsHelperReturnsNumber(jsCode, call.method_name));
|
|
19369
|
+
if (!numeric) continue;
|
|
19370
|
+
sanitizers.push({
|
|
19371
|
+
type: "derived_wrapper",
|
|
19372
|
+
method: formatSanitizerMethod(call),
|
|
19373
|
+
line: call.location.line,
|
|
19374
|
+
sanitizes: [...numericRemoves]
|
|
19375
|
+
});
|
|
19376
|
+
}
|
|
19377
|
+
}
|
|
19103
19378
|
const noopLocalHelpers = !sourceLines ? /* @__PURE__ */ new Set() : language === "java" ? findJavaNoopHelpers(types, sourceLines) : language === "python" ? findPythonNoopHelpers(types, sourceLines) : language === "go" ? findGoNoopHelpers(types, sourceLines) : language === "javascript" || language === "typescript" || language === "tsx" ? findJsNoopHelpers(types, sourceLines) : /* @__PURE__ */ new Set();
|
|
19104
19379
|
for (const call of calls) {
|
|
19105
19380
|
if (sanitizerMethods.has(call.method_name)) {
|
|
@@ -19195,7 +19470,7 @@ function findPythonNoopHelpers(types, sourceLines) {
|
|
|
19195
19470
|
function isPythonNoopBody(method, sourceLines) {
|
|
19196
19471
|
if (method.parameters.length === 0) return false;
|
|
19197
19472
|
const text = sourceLines.slice(method.start_line - 1, method.end_line).join("\n");
|
|
19198
|
-
const header = /^\s*(?:async\s+)?def\s+\w+\s*\(([^()]*)\)\s*(?:->\s*[\w.\[\], ]
|
|
19473
|
+
const header = /^\s*(?:async\s+)?def\s+\w+\s*\(([^()]*)\)\s*(?:->\s*[\w.\[\],](?:[\w.\[\], ]*[\w.\[\],])?\s*)?:/.exec(text);
|
|
19199
19474
|
if (!header) return false;
|
|
19200
19475
|
const body2 = text.slice(header[0].length).replace(/#.*$/gm, "").trim();
|
|
19201
19476
|
const m = /^return\s+([^\n;]+)$/.exec(body2);
|
|
@@ -19224,7 +19499,7 @@ function findGoNoopHelpers(types, sourceLines) {
|
|
|
19224
19499
|
function isGoNoopBody(method, sourceLines) {
|
|
19225
19500
|
if (method.parameters.length === 0) return false;
|
|
19226
19501
|
const text = sourceLines.slice(method.start_line - 1, method.end_line).join("\n");
|
|
19227
|
-
const header = /^\s*func\s+\w+\s*\(([^()]*)\)\s
|
|
19502
|
+
const header = /^\s*func\s+\w+\s*\(([^()]*)\)\s*(?:(?:\([\w.\[\]*, ]*\)|[\w.\[\]*,](?:[\w.\[\]*, ]*[\w.\[\]*,])?)\s*)?\{/.exec(text);
|
|
19228
19503
|
if (!header) return false;
|
|
19229
19504
|
const close = text.lastIndexOf("}");
|
|
19230
19505
|
if (close < header[0].length) return false;
|
|
@@ -19401,6 +19676,7 @@ var CodeGraph = class {
|
|
|
19401
19676
|
* `re.MatchString(x)`) (#568)
|
|
19402
19677
|
* - a lookup in a constant table the file never writes (`T[req.query.k]`)
|
|
19403
19678
|
* (#667)
|
|
19679
|
+
* - a read of Hono bindings, `c.env` or a member below it
|
|
19404
19680
|
*/
|
|
19405
19681
|
taintBarrierDefIds = /* @__PURE__ */ new Set();
|
|
19406
19682
|
constructor(ir) {
|
|
@@ -19907,6 +20183,43 @@ function propagateTaint(graphOrDfg, callsOrSources, sourcesOrSinks, sinksOrSanit
|
|
|
19907
20183
|
return { taintedVars, flows: deduped, reachableSinks };
|
|
19908
20184
|
}
|
|
19909
20185
|
var PARAM_SCOPED_SOURCE_RE = /^(?:GraphQL \w+\.\w+ resolver args|Express handler destructured request) /;
|
|
20186
|
+
var IDENT_START = /[A-Za-z_$]/;
|
|
20187
|
+
var IDENT_PART = /[\w$]/;
|
|
20188
|
+
var WORD_CHAR = /\w/;
|
|
20189
|
+
var isSpace = (ch) => ch.trim() === "";
|
|
20190
|
+
function calledMethodInLocation(location) {
|
|
20191
|
+
for (let at = location.indexOf("()"); at >= 0; at = location.indexOf("()", at + 1)) {
|
|
20192
|
+
const after = at + 2;
|
|
20193
|
+
if (after < location.length) {
|
|
20194
|
+
let w = after;
|
|
20195
|
+
while (w < location.length && isSpace(location[w])) w++;
|
|
20196
|
+
if (w === after || location.slice(w, w + 2) !== "in" || WORD_CHAR.test(location[w + 2] ?? "")) continue;
|
|
20197
|
+
}
|
|
20198
|
+
let end = at;
|
|
20199
|
+
while (end > 0 && isSpace(location[end - 1])) end--;
|
|
20200
|
+
let start2 = end;
|
|
20201
|
+
while (start2 > 0 && IDENT_PART.test(location[start2 - 1])) start2--;
|
|
20202
|
+
while (start2 < end && !IDENT_START.test(location[start2])) start2++;
|
|
20203
|
+
if (start2 < end) return location.slice(start2, end);
|
|
20204
|
+
}
|
|
20205
|
+
return void 0;
|
|
20206
|
+
}
|
|
20207
|
+
function paramsConsumedBySourceCall(source, defsOnLine, calls) {
|
|
20208
|
+
if (source.type === "interprocedural_param" || !calls) return null;
|
|
20209
|
+
const method = source.method ?? calledMethodInLocation(source.location ?? "");
|
|
20210
|
+
if (!method) return null;
|
|
20211
|
+
const params = defsOnLine.filter((d) => d.kind === "param" && /^[A-Za-z_$][\w$]*$/.test(d.variable));
|
|
20212
|
+
if (params.length === 0) return null;
|
|
20213
|
+
const out2 = /* @__PURE__ */ new Set();
|
|
20214
|
+
for (const call of calls) {
|
|
20215
|
+
if (call.method_name !== method) continue;
|
|
20216
|
+
for (const p of params) {
|
|
20217
|
+
const re = new RegExp(String.raw`(?<![.\w$])${p.variable.replace(/\$/g, "\\$")}(?![\w$])`);
|
|
20218
|
+
if (call.arguments.some((a) => re.test(a.expression))) out2.add(p.variable);
|
|
20219
|
+
}
|
|
20220
|
+
}
|
|
20221
|
+
return out2.size > 0 ? out2 : null;
|
|
20222
|
+
}
|
|
19910
20223
|
function isCompleteConditionHeader(code) {
|
|
19911
20224
|
if (!code) return false;
|
|
19912
20225
|
const m = /^(?:\}\s*)?(?:else\s+)?(?:if|while)\s*\(/.exec(code);
|
|
@@ -19960,6 +20273,12 @@ function lineDefinitionLacksUse(lineCode, variable, via) {
|
|
|
19960
20273
|
const rhs = lineCode.slice(m.index + m[0].length, end);
|
|
19961
20274
|
return !new RegExp(String.raw`(?<![.\w$])${via.replace(/\$/g, "\\$")}(?![\w$])`).test(rhs);
|
|
19962
20275
|
}
|
|
20276
|
+
function catchBindingNames(code) {
|
|
20277
|
+
const m = code ? /^(?:\}\s*)?catch\s*\(([^)]*)\)/.exec(code) : null;
|
|
20278
|
+
if (!m) return /* @__PURE__ */ new Set();
|
|
20279
|
+
const binding = /^\s*[{[]/.test(m[1]) ? m[1] : m[1].split(":")[0];
|
|
20280
|
+
return new Set(binding.match(/[A-Za-z_$][\w$]*/g) ?? []);
|
|
20281
|
+
}
|
|
19963
20282
|
function findInitialTaint(sources, callsByLine, defsByLine, chainsByFromDef, jsLike = false, lineText) {
|
|
19964
20283
|
const tainted = [];
|
|
19965
20284
|
for (const source of sources) {
|
|
@@ -19980,8 +20299,10 @@ function findInitialTaint(sources, callsByLine, defsByLine, chainsByFromDef, jsL
|
|
|
19980
20299
|
}
|
|
19981
20300
|
}
|
|
19982
20301
|
}
|
|
20302
|
+
const consumedParams = jsLike ? paramsConsumedBySourceCall(source, defsOnLine, callsByLine.get(source.line)) : null;
|
|
19983
20303
|
for (const def of defsOnLine) {
|
|
19984
20304
|
if (seedable && !seedable.has(def.id)) continue;
|
|
20305
|
+
if (consumedParams?.has(def.variable)) continue;
|
|
19985
20306
|
if ((source.type === "interprocedural_param" || PARAM_SCOPED_SOURCE_RE.test(source.location ?? "")) && source.variable && def.kind === "param" && def.variable !== source.variable) {
|
|
19986
20307
|
continue;
|
|
19987
20308
|
}
|
|
@@ -20002,7 +20323,9 @@ function findInitialTaint(sources, callsByLine, defsByLine, chainsByFromDef, jsL
|
|
|
20002
20323
|
const nextCode = lineText && !source.variable ? lineText(source.line + 1)?.trim() : void 0;
|
|
20003
20324
|
const nextMulti = !!nextCode && hasSecondStatement(nextCode);
|
|
20004
20325
|
const sourceLineNames = [...new Set(defsOnLine.map((d) => d.variable))];
|
|
20326
|
+
const nextCatchNames = jsLike ? catchBindingNames(lineText?.(source.line + 1)?.trim()) : null;
|
|
20005
20327
|
for (const def of defsNextLine) {
|
|
20328
|
+
if (nextCatchNames?.has(def.variable)) continue;
|
|
20006
20329
|
const callsOnSourceLine = callsByLine.get(source.line) ?? [];
|
|
20007
20330
|
if (callsOnSourceLine.length > 0) {
|
|
20008
20331
|
if (source.variable && def.variable !== source.variable) continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calls.d.ts","sourceRoot":"","sources":["../../../src/core/extractors/calls.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAQ,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAgC,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAA2D,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AA8EvG;;;;;GAKG;AACH;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC7C;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,IAAI,EACV,KAAK,CAAC,EAAE,SAAS,EACjB,QAAQ,CAAC,EAAE,MAAM,EACjB,OAAO,GAAE,qBAA0B,GAClC,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"calls.d.ts","sourceRoot":"","sources":["../../../src/core/extractors/calls.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAQ,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,KAAK,EAAE,QAAQ,EAAgC,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAA2D,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AA8EvG;;;;;GAKG;AACH;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;;OAKG;IACH,qBAAqB,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;CAC7C;AAED,wBAAgB,YAAY,CAC1B,IAAI,EAAE,IAAI,EACV,KAAK,CAAC,EAAE,SAAS,EACjB,QAAQ,CAAC,EAAE,MAAM,EACjB,OAAO,GAAE,qBAA0B,GAClC,QAAQ,EAAE,CA0EZ"}
|