circle-ir 4.23.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 +18 -5
- package/dist/analysis/config-loader.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 +1414 -33
- 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 +687 -4
- 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 +40 -1
- 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 +11388 -8828
- package/dist/core/circle-ir-core.cjs +307 -27
- package/dist/core/circle-ir-core.js +307 -27
- 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.)
|
|
@@ -15969,9 +16159,11 @@ var DEFAULT_SANITIZERS = [
|
|
|
15969
16159
|
// Type coercion (removes string-based injections)
|
|
15970
16160
|
// Sprint 29 (#113): include external_taint_escape — a numeric cast cannot
|
|
15971
16161
|
// carry an unvalidated string payload across a function boundary.
|
|
15972
|
-
|
|
15973
|
-
|
|
15974
|
-
{ 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"] },
|
|
15975
16167
|
// Sprint 29 (#113): bounds-clamp Math.min / Math.max — when used to bound
|
|
15976
16168
|
// a numeric/size value (e.g. `Math.min(size, MAX_BYTES)`), the result is
|
|
15977
16169
|
// safely bounded and cannot resource-exhaust downstream. Only suppress
|
|
@@ -15999,6 +16191,8 @@ var DEFAULT_SANITIZERS = [
|
|
|
15999
16191
|
// SQL - parameterized queries (mysql, pg)
|
|
16000
16192
|
{ method: "escape", class: "mysql", removes: ["sql_injection"] },
|
|
16001
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"] },
|
|
16002
16196
|
{ method: "format", class: "mysql", removes: ["sql_injection"] },
|
|
16003
16197
|
// MongoDB - sanitization
|
|
16004
16198
|
{ method: "sanitize", class: "mongo", removes: ["nosql_injection"] },
|
|
@@ -16243,7 +16437,7 @@ var DEFAULT_SANITIZERS = [
|
|
|
16243
16437
|
// Java UUID parse — UUID.fromString rejects non-UUID strings
|
|
16244
16438
|
{ method: "fromString", class: "UUID", removes: ["sql_injection", "command_injection", "path_traversal", "code_injection"] },
|
|
16245
16439
|
// JavaScript numeric coercion (Number/parseInt/parseFloat already covered above; add path_traversal/code_injection)
|
|
16246
|
-
{ 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"] },
|
|
16247
16441
|
// Go numeric parse — strconv.Atoi, ParseInt, ParseFloat, ParseUint, ParseBool
|
|
16248
16442
|
{ method: "Atoi", class: "strconv", removes: ["sql_injection", "command_injection", "path_traversal", "code_injection"] },
|
|
16249
16443
|
{ method: "ParseInt", class: "strconv", removes: ["sql_injection", "command_injection", "path_traversal", "code_injection"] },
|
|
@@ -16320,6 +16514,12 @@ var DEFAULT_SINK_SEMANTICS = [
|
|
|
16320
16514
|
real_class: "jdk_internal",
|
|
16321
16515
|
overrides: ["code_injection"],
|
|
16322
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)"
|
|
16323
16523
|
}
|
|
16324
16524
|
];
|
|
16325
16525
|
function getDefaultConfig() {
|
|
@@ -17420,6 +17620,7 @@ function isSafeJSChildProcessCall(call, pattern, language) {
|
|
|
17420
17620
|
if (m !== "spawn" && m !== "spawnSync" && m !== "execFile" && m !== "execFileSync") return false;
|
|
17421
17621
|
const programArg = call.arguments.find((a) => a.position === 0);
|
|
17422
17622
|
if (!programArg) return false;
|
|
17623
|
+
if (call.arguments.some((a) => SHELL_OPTION_ON.test(a.expression ?? ""))) return false;
|
|
17423
17624
|
let program;
|
|
17424
17625
|
if (programArg.literal !== null && programArg.literal !== void 0) {
|
|
17425
17626
|
program = String(programArg.literal).split("/").pop() ?? String(programArg.literal);
|
|
@@ -17428,6 +17629,7 @@ function isSafeJSChildProcessCall(call, pattern, language) {
|
|
|
17428
17629
|
if (!(expr.startsWith('"') || expr.startsWith("`") || expr.startsWith("'"))) {
|
|
17429
17630
|
return false;
|
|
17430
17631
|
}
|
|
17632
|
+
if (expr.startsWith("`") && expr.includes("${")) return false;
|
|
17431
17633
|
const stripped = expr.slice(1, -1);
|
|
17432
17634
|
program = stripped.split("/").pop() ?? stripped;
|
|
17433
17635
|
}
|
|
@@ -17836,6 +18038,10 @@ function isTypedNonDbReceiver(receiver, sourceLines) {
|
|
|
17836
18038
|
}
|
|
17837
18039
|
return typed !== void 0 && !DB_TYPE_NAME.test(typed) && !/^(?:any|unknown|object)$/.test(typed);
|
|
17838
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
|
+
}
|
|
17839
18045
|
function isNavigationReceiverName(receiver) {
|
|
17840
18046
|
const r = (receiver ?? "").trim();
|
|
17841
18047
|
if (!r) return false;
|
|
@@ -17881,14 +18087,15 @@ function isJsMapTypedReceiver(receiver, sourceLines) {
|
|
|
17881
18087
|
const raw = (receiver ?? "").trim();
|
|
17882
18088
|
if (!raw || !sourceLines) return false;
|
|
17883
18089
|
const lastDot = raw.lastIndexOf(".");
|
|
17884
|
-
|
|
18090
|
+
let r = (lastDot >= 0 ? raw.slice(lastDot + 1) : raw).trim();
|
|
18091
|
+
if (r.startsWith("#")) r = r.slice(1);
|
|
17885
18092
|
if (!/^[A-Za-z_$][\w$]*$/.test(r)) return false;
|
|
17886
18093
|
const n = escapeRe(r);
|
|
17887
18094
|
const mapCtor = new RegExp(
|
|
17888
|
-
`\\b
|
|
18095
|
+
`\\b#?${n}\\s*(?::[^=;]*)?=\\s*new\\s+(?:Weak)?Map\\s*(?:<.*>)?\\s*\\(`
|
|
17889
18096
|
);
|
|
17890
18097
|
const mapType = new RegExp(
|
|
17891
|
-
`\\b
|
|
18098
|
+
`\\b#?${n}\\s*\\??\\s*:\\s*(?:Readonly)?(?:Weak)?Map\\s*<`
|
|
17892
18099
|
);
|
|
17893
18100
|
return sourceLines.some((l) => mapCtor.test(l) || mapType.test(l));
|
|
17894
18101
|
}
|
|
@@ -17897,7 +18104,8 @@ function isInMemoryMapGetReceiver(receiver, sourceLines) {
|
|
|
17897
18104
|
if (!raw || !sourceLines) return false;
|
|
17898
18105
|
if (/\.properties$/i.test(raw)) return true;
|
|
17899
18106
|
const lastDot = raw.lastIndexOf(".");
|
|
17900
|
-
|
|
18107
|
+
let r = (lastDot >= 0 ? raw.slice(lastDot + 1) : raw).trim();
|
|
18108
|
+
if (r.startsWith("#")) r = r.slice(1);
|
|
17901
18109
|
if (/^(properties|memoryCache)$/i.test(r)) return true;
|
|
17902
18110
|
return isJsMapTypedReceiver(receiver, sourceLines);
|
|
17903
18111
|
}
|
|
@@ -18192,6 +18400,9 @@ function findSinks(calls, patterns, typeHierarchy, language, sourceLines, types)
|
|
|
18192
18400
|
if ((pattern.type === "command_injection" || pattern.type === "sql_injection") && call.method_name === "exec" && (language === "javascript" || language === "typescript") && isRegexReceiver(call.receiver, sourceLines)) {
|
|
18193
18401
|
continue;
|
|
18194
18402
|
}
|
|
18403
|
+
if (pattern.type === "sql_injection" && call.method_name === "query" && (language === "javascript" || language === "typescript") && isRequestObjectReceiver(call.receiver)) {
|
|
18404
|
+
continue;
|
|
18405
|
+
}
|
|
18195
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))) {
|
|
18196
18407
|
continue;
|
|
18197
18408
|
}
|
|
@@ -18260,6 +18471,8 @@ function matchesSourcePattern(call, pattern, language, types, imports) {
|
|
|
18260
18471
|
return false;
|
|
18261
18472
|
}
|
|
18262
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;
|
|
18263
18476
|
} else if (!receiverMightBeClass(call.receiver, pattern.class)) {
|
|
18264
18477
|
return false;
|
|
18265
18478
|
}
|
|
@@ -18442,6 +18655,8 @@ var SAFE_RECEIVERS_BY_METHOD = {
|
|
|
18442
18655
|
"saml",
|
|
18443
18656
|
"oidc"
|
|
18444
18657
|
]),
|
|
18658
|
+
// ES template tag `String.raw` — not SQL (Knex/Objection `.raw(sql)` keeps sinking).
|
|
18659
|
+
raw: /* @__PURE__ */ new Set(["string"]),
|
|
18445
18660
|
// add() is extremely generic — safe on collections, UI containers, builders, etc.
|
|
18446
18661
|
add: /* @__PURE__ */ new Set([
|
|
18447
18662
|
"list",
|
|
@@ -19143,6 +19358,23 @@ function findSanitizers(calls, types, patterns, sourceLines, language) {
|
|
|
19143
19358
|
sanitizes: removes
|
|
19144
19359
|
});
|
|
19145
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
|
+
}
|
|
19146
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();
|
|
19147
19379
|
for (const call of calls) {
|
|
19148
19380
|
if (sanitizerMethods.has(call.method_name)) {
|
|
@@ -19238,7 +19470,7 @@ function findPythonNoopHelpers(types, sourceLines) {
|
|
|
19238
19470
|
function isPythonNoopBody(method, sourceLines) {
|
|
19239
19471
|
if (method.parameters.length === 0) return false;
|
|
19240
19472
|
const text = sourceLines.slice(method.start_line - 1, method.end_line).join("\n");
|
|
19241
|
-
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);
|
|
19242
19474
|
if (!header) return false;
|
|
19243
19475
|
const body2 = text.slice(header[0].length).replace(/#.*$/gm, "").trim();
|
|
19244
19476
|
const m = /^return\s+([^\n;]+)$/.exec(body2);
|
|
@@ -19267,7 +19499,7 @@ function findGoNoopHelpers(types, sourceLines) {
|
|
|
19267
19499
|
function isGoNoopBody(method, sourceLines) {
|
|
19268
19500
|
if (method.parameters.length === 0) return false;
|
|
19269
19501
|
const text = sourceLines.slice(method.start_line - 1, method.end_line).join("\n");
|
|
19270
|
-
const header = /^\s*func\s+\w+\s*\(([^()]*)\)\s
|
|
19502
|
+
const header = /^\s*func\s+\w+\s*\(([^()]*)\)\s*(?:(?:\([\w.\[\]*, ]*\)|[\w.\[\]*,](?:[\w.\[\]*, ]*[\w.\[\]*,])?)\s*)?\{/.exec(text);
|
|
19271
19503
|
if (!header) return false;
|
|
19272
19504
|
const close = text.lastIndexOf("}");
|
|
19273
19505
|
if (close < header[0].length) return false;
|
|
@@ -19444,6 +19676,7 @@ var CodeGraph = class {
|
|
|
19444
19676
|
* `re.MatchString(x)`) (#568)
|
|
19445
19677
|
* - a lookup in a constant table the file never writes (`T[req.query.k]`)
|
|
19446
19678
|
* (#667)
|
|
19679
|
+
* - a read of Hono bindings, `c.env` or a member below it
|
|
19447
19680
|
*/
|
|
19448
19681
|
taintBarrierDefIds = /* @__PURE__ */ new Set();
|
|
19449
19682
|
constructor(ir) {
|
|
@@ -19950,6 +20183,43 @@ function propagateTaint(graphOrDfg, callsOrSources, sourcesOrSinks, sinksOrSanit
|
|
|
19950
20183
|
return { taintedVars, flows: deduped, reachableSinks };
|
|
19951
20184
|
}
|
|
19952
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
|
+
}
|
|
19953
20223
|
function isCompleteConditionHeader(code) {
|
|
19954
20224
|
if (!code) return false;
|
|
19955
20225
|
const m = /^(?:\}\s*)?(?:else\s+)?(?:if|while)\s*\(/.exec(code);
|
|
@@ -20003,6 +20273,12 @@ function lineDefinitionLacksUse(lineCode, variable, via) {
|
|
|
20003
20273
|
const rhs = lineCode.slice(m.index + m[0].length, end);
|
|
20004
20274
|
return !new RegExp(String.raw`(?<![.\w$])${via.replace(/\$/g, "\\$")}(?![\w$])`).test(rhs);
|
|
20005
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
|
+
}
|
|
20006
20282
|
function findInitialTaint(sources, callsByLine, defsByLine, chainsByFromDef, jsLike = false, lineText) {
|
|
20007
20283
|
const tainted = [];
|
|
20008
20284
|
for (const source of sources) {
|
|
@@ -20023,8 +20299,10 @@ function findInitialTaint(sources, callsByLine, defsByLine, chainsByFromDef, jsL
|
|
|
20023
20299
|
}
|
|
20024
20300
|
}
|
|
20025
20301
|
}
|
|
20302
|
+
const consumedParams = jsLike ? paramsConsumedBySourceCall(source, defsOnLine, callsByLine.get(source.line)) : null;
|
|
20026
20303
|
for (const def of defsOnLine) {
|
|
20027
20304
|
if (seedable && !seedable.has(def.id)) continue;
|
|
20305
|
+
if (consumedParams?.has(def.variable)) continue;
|
|
20028
20306
|
if ((source.type === "interprocedural_param" || PARAM_SCOPED_SOURCE_RE.test(source.location ?? "")) && source.variable && def.kind === "param" && def.variable !== source.variable) {
|
|
20029
20307
|
continue;
|
|
20030
20308
|
}
|
|
@@ -20045,7 +20323,9 @@ function findInitialTaint(sources, callsByLine, defsByLine, chainsByFromDef, jsL
|
|
|
20045
20323
|
const nextCode = lineText && !source.variable ? lineText(source.line + 1)?.trim() : void 0;
|
|
20046
20324
|
const nextMulti = !!nextCode && hasSecondStatement(nextCode);
|
|
20047
20325
|
const sourceLineNames = [...new Set(defsOnLine.map((d) => d.variable))];
|
|
20326
|
+
const nextCatchNames = jsLike ? catchBindingNames(lineText?.(source.line + 1)?.trim()) : null;
|
|
20048
20327
|
for (const def of defsNextLine) {
|
|
20328
|
+
if (nextCatchNames?.has(def.variable)) continue;
|
|
20049
20329
|
const callsOnSourceLine = callsByLine.get(source.line) ?? [];
|
|
20050
20330
|
if (callsOnSourceLine.length > 0) {
|
|
20051
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"}
|