circle-ir 4.18.1 → 4.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/analysis/config-loader.js +22 -22
  2. package/dist/analysis/config-loader.js.map +1 -1
  3. package/dist/analysis/interprocedural.d.ts +6 -0
  4. package/dist/analysis/interprocedural.d.ts.map +1 -1
  5. package/dist/analysis/interprocedural.js +53 -6
  6. package/dist/analysis/interprocedural.js.map +1 -1
  7. package/dist/analysis/js-helper-return.d.ts +12 -0
  8. package/dist/analysis/js-helper-return.d.ts.map +1 -0
  9. package/dist/analysis/js-helper-return.js +64 -0
  10. package/dist/analysis/js-helper-return.js.map +1 -0
  11. package/dist/analysis/passes/interprocedural-pass.d.ts.map +1 -1
  12. package/dist/analysis/passes/interprocedural-pass.js +8 -6
  13. package/dist/analysis/passes/interprocedural-pass.js.map +1 -1
  14. package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
  15. package/dist/analysis/passes/language-sources-pass.js +40 -1
  16. package/dist/analysis/passes/language-sources-pass.js.map +1 -1
  17. package/dist/analysis/passes/resource-leak-pass.d.ts.map +1 -1
  18. package/dist/analysis/passes/resource-leak-pass.js +5 -1
  19. package/dist/analysis/passes/resource-leak-pass.js.map +1 -1
  20. package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
  21. package/dist/analysis/passes/sink-filter-pass.js +38 -1
  22. package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
  23. package/dist/analysis/taint-matcher.d.ts.map +1 -1
  24. package/dist/analysis/taint-matcher.js +68 -2
  25. package/dist/analysis/taint-matcher.js.map +1 -1
  26. package/dist/browser/circle-ir.js +229 -41
  27. package/dist/core/circle-ir-core.cjs +140 -29
  28. package/dist/core/circle-ir-core.js +140 -29
  29. package/dist/core/extractors/dfg.js +46 -7
  30. package/dist/core/extractors/dfg.js.map +1 -1
  31. package/dist/resolution/cross-file.d.ts +2 -0
  32. package/dist/resolution/cross-file.d.ts.map +1 -1
  33. package/dist/resolution/cross-file.js +22 -0
  34. package/dist/resolution/cross-file.js.map +1 -1
  35. package/package.json +1 -1
@@ -10413,9 +10413,46 @@ function processStatement2(stmt, startDefId, startUseId, scopeStack, isJavaScrip
10413
10413
  case "try_statement":
10414
10414
  case "try_with_resources_statement": {
10415
10415
  if (isJavaScript) {
10416
- const stmtUses = extractUses(stmt, useId, scopeStack, isJavaScript);
10417
- uses.push(...stmtUses.uses);
10418
- useId = stmtUses.nextId;
10416
+ const tryBody = stmt.childForFieldName("body");
10417
+ if (tryBody) {
10418
+ const r = processStatement2(tryBody, defId, useId, scopeStack, isJavaScript);
10419
+ defs.push(...r.defs);
10420
+ uses.push(...r.uses);
10421
+ defId = r.nextDefId;
10422
+ useId = r.nextUseId;
10423
+ }
10424
+ const handler = stmt.childForFieldName("handler");
10425
+ if (handler) {
10426
+ scopeStack.push(/* @__PURE__ */ new Map());
10427
+ const param = handler.childForFieldName("parameter");
10428
+ if (param) {
10429
+ const paramDefs = param.type === "identifier" ? [{ id: defId, variable: getNodeText(param), line: param.startPosition.row + 1, column: param.startPosition.column, kind: "local" }] : extractDestructuringDefs(param, defId);
10430
+ for (const def of paramDefs) {
10431
+ defs.push(def);
10432
+ currentScope(scopeStack).set(def.variable, def.id);
10433
+ markDeclared(currentScope(scopeStack), def.variable);
10434
+ defId++;
10435
+ }
10436
+ }
10437
+ const handlerBody = handler.childForFieldName("body");
10438
+ if (handlerBody) {
10439
+ const r = processStatement2(handlerBody, defId, useId, scopeStack, isJavaScript);
10440
+ defs.push(...r.defs);
10441
+ uses.push(...r.uses);
10442
+ defId = r.nextDefId;
10443
+ useId = r.nextUseId;
10444
+ }
10445
+ carryBranchDefsOut(scopeStack.pop(), scopeStack, false);
10446
+ }
10447
+ const finalizer6 = stmt.childForFieldName("finalizer");
10448
+ const finallyBody = finalizer6?.childForFieldName("body");
10449
+ if (finallyBody) {
10450
+ const r = processStatement2(finallyBody, defId, useId, scopeStack, isJavaScript);
10451
+ defs.push(...r.defs);
10452
+ uses.push(...r.uses);
10453
+ defId = r.nextDefId;
10454
+ useId = r.nextUseId;
10455
+ }
10419
10456
  break;
10420
10457
  }
10421
10458
  scopeStack.push(/* @__PURE__ */ new Map());
@@ -14022,7 +14059,7 @@ var DEFAULT_SINKS = [
14022
14059
  { method: "renderHTML", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
14023
14060
  { method: "parseHTML", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
14024
14061
  // HTML sanitizer/validator sinks (AntiSamy, OWASP HTML Sanitizer, etc.)
14025
- { method: "scan", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
14062
+ { method: "scan", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
14026
14063
  { method: "isValid", class: "SafeHtmlValidator", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
14027
14064
  { method: "sanitize", class: "PolicyFactory", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
14028
14065
  { method: "validate", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0] },
@@ -14038,8 +14075,8 @@ var DEFAULT_SINKS = [
14038
14075
  { method: "writeAttribute", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0, 1] },
14039
14076
  // AntiSamy specific (SAX filters)
14040
14077
  { method: "startElement", class: "MagicSAXFilter", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0, 1, 2] },
14041
- { method: "scan", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
14042
- { method: "scan", class: "AntiSamySAXScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
14078
+ { method: "scan", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
14079
+ { method: "scan", class: "AntiSamySAXScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
14043
14080
  // Hibernate Validator
14044
14081
  { method: "getFragmentAsDocument", class: "SafeHtmlValidator", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
14045
14082
  // JSPWiki specific
@@ -14089,15 +14126,15 @@ var DEFAULT_SINKS = [
14089
14126
  { method: "getValidListItem", class: "DefaultValidator", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0, 1] },
14090
14127
  { method: "isValidURI", class: "DefaultValidator", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0, 1] },
14091
14128
  // AntiSamy test/processing methods
14092
- { method: "scriptAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
14093
- { method: "imgAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
14094
- { method: "hrefAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
14095
- { method: "cssAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
14096
- { method: "IllegalXML", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
14097
- { method: "testIssue2", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
14098
- { method: "issue41", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
14099
- { method: "testGithubIssue151", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
14100
- { method: "processStyleTag", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
14129
+ { method: "scriptAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
14130
+ { method: "imgAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
14131
+ { method: "hrefAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
14132
+ { method: "cssAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
14133
+ { method: "IllegalXML", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
14134
+ { method: "testIssue2", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
14135
+ { method: "issue41", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
14136
+ { method: "testGithubIssue151", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
14137
+ { method: "processStyleTag", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
14101
14138
  // JSON Sanitizer
14102
14139
  { method: "sanitizeString", class: "JsonSanitizer", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
14103
14140
  { method: "testIssue13", class: "JsonSanitizerTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
@@ -14923,16 +14960,16 @@ var DEFAULT_SINKS = [
14923
14960
  { method: "parse", class: "sax", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0] },
14924
14961
  { method: "XMLParser", class: "lxml", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0] },
14925
14962
  // Python LDAP Injection
14926
- { method: "search", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
14927
- { method: "search_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
14928
- { method: "search_ext", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
14929
- { method: "search_ext_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
14963
+ { method: "search", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
14964
+ { method: "search_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
14965
+ { method: "search_ext", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
14966
+ { method: "search_ext_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
14930
14967
  // ldap3 library (different API from python-ldap)
14931
- { method: "search", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 1] },
14932
- { method: "extend", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
14933
- { method: "modify", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
14934
- { method: "add", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
14935
- { method: "delete", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
14968
+ { method: "search", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 1], languages: ["python"] },
14969
+ { method: "extend", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
14970
+ { method: "modify", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
14971
+ { method: "add", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
14972
+ { method: "delete", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
14936
14973
  // Python Trust Boundary (CWE-501)
14937
14974
  // The vulnerability is storing untrusted data in session that gets trusted later
14938
14975
  { method: "__setitem__", class: "session", type: "trust_boundary", cwe: "CWE-501", severity: "medium", arg_positions: [1] },
@@ -15023,7 +15060,7 @@ var DEFAULT_SINKS = [
15023
15060
  { method: "put", class: "VelocityContext", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [1] },
15024
15061
  { method: "setVariable", class: "Context", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [1] },
15025
15062
  // HTML sanitizer bypass markers (known CVE patterns)
15026
- { method: "clean", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0] },
15063
+ { method: "clean", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0], languages: ["java"] },
15027
15064
  { method: "getValidSafeHTML", class: "ESAPI", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0] },
15028
15065
  // NOTE (cognium-dev#270): `HttpServletRequest`/`HttpSession.getAttribute()`
15029
15066
  // were registered here as xss sinks to model "attribute reflection XSS", but
@@ -16415,6 +16452,46 @@ var DEFAULT_HEADER_RULES = [
16415
16452
  }
16416
16453
  ];
16417
16454
 
16455
+ // src/analysis/js-helper-return.ts
16456
+ function jsHelperReturnsNoParam(sourceCode, rawName) {
16457
+ if (!/^[A-Za-z_$][\w$]*$/.test(rawName)) return false;
16458
+ const name2 = rawName.replace(/\$/g, "\\$");
16459
+ const decls = [...sourceCode.matchAll(new RegExp(`\\bfunction\\s+${name2}\\s*\\(([^)]*)\\)\\s*\\{`, "g"))];
16460
+ if (decls.length !== 1) return false;
16461
+ if (new RegExp(`(?:const|let|var)\\s+${name2}\\s*=`).test(sourceCode)) return false;
16462
+ const open = (decls[0].index ?? 0) + decls[0][0].length - 1;
16463
+ let depth = 0;
16464
+ let close = -1;
16465
+ for (let i2 = open; i2 < sourceCode.length; i2++) {
16466
+ const ch = sourceCode[i2];
16467
+ if (ch === "{") depth++;
16468
+ else if (ch === "}" && --depth === 0) {
16469
+ close = i2;
16470
+ break;
16471
+ }
16472
+ }
16473
+ if (close < 0) return false;
16474
+ const body2 = sourceCode.slice(open + 1, close).replace(/\/\/.*$/gm, "");
16475
+ if (/\bfunction\b|=>/.test(body2)) return false;
16476
+ const literal = /^(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`[^`$]*`|-?\d+(?:\.\d+)?|true|false|null)$/;
16477
+ const returns = [...body2.matchAll(/\breturn\b\s*([^;]*);?/g)].map((m) => m[1].trim());
16478
+ if (returns.length === 0) return false;
16479
+ for (const expr of returns) {
16480
+ if (literal.test(expr)) continue;
16481
+ const slot = /^([A-Za-z_$][\w$]*)\s*\[\s*(\d+)\s*\]$/.exec(expr);
16482
+ if (!slot) return false;
16483
+ const arr = slot[1].replace(/\$/g, "\\$");
16484
+ const declRe = new RegExp(`(?:const|let|var)\\s+${arr}\\s*=\\s*\\[([^\\]]*)\\]\\s*;?`);
16485
+ const d = declRe.exec(body2);
16486
+ if (!d) return false;
16487
+ if (new RegExp(`\\b${arr}\\s*(?:\\[[^\\]]*\\]\\s*=(?!=)|\\.\\s*(?:push|unshift|splice|shift|pop|reverse|sort|fill|copyWithin)\\s*\\()`).test(body2)) return false;
16488
+ const elems = d[1].split(",").map((e) => e.trim());
16489
+ const el = elems[Number(slot[2])];
16490
+ if (el === void 0 || !literal.test(el)) return false;
16491
+ }
16492
+ return true;
16493
+ }
16494
+
16418
16495
  // src/analysis/literal-expression.ts
16419
16496
  function isProvablyLiteralExpression(expr) {
16420
16497
  let e = (expr ?? "").trim();
@@ -19208,12 +19285,37 @@ function classifyCSharpLambdaParam(raw) {
19208
19285
  if (baseType === "string") return { type: "http_param", name: name2, via: "string param" };
19209
19286
  return null;
19210
19287
  }
19288
+ var REQUEST_FIELD_TYPES = {
19289
+ query: "http_param",
19290
+ params: "http_param",
19291
+ body: "http_body",
19292
+ headers: "http_header",
19293
+ cookies: "http_cookie"
19294
+ };
19295
+ function destructuredRequestPatterns(sourceCode) {
19296
+ const out2 = [];
19297
+ const seen = /* @__PURE__ */ new Set();
19298
+ for (const m of sourceCode.matchAll(/[(,]\s*\{([^{}]*)\}\s*:\s*(?:express\.)?Request\b/g)) {
19299
+ for (const part of m[1].split(",")) {
19300
+ const bind = /^\s*(\w+)\s*(?::\s*(\w+))?\s*(?:=[^,]*)?$/.exec(part);
19301
+ if (!bind) continue;
19302
+ const field = bind[1];
19303
+ const local = bind[2] ?? bind[1];
19304
+ const type = REQUEST_FIELD_TYPES[field];
19305
+ if (!type || seen.has(local)) continue;
19306
+ seen.add(local);
19307
+ out2.push({ pattern: new RegExp(`(?<![\\w.])${local}\\s*[.[]`), type });
19308
+ }
19309
+ }
19310
+ return out2;
19311
+ }
19211
19312
  function findJavaScriptAssignmentSources(sourceCode, language) {
19212
19313
  if (!["javascript", "typescript"].includes(language)) return [];
19213
19314
  const sources = [];
19214
19315
  const lines = sourceCode.split("\n");
19215
19316
  const isRouteHandler2 = /export\s+(?:async\s+)?(?:function\s+(?:GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS|loader|action)\b|const\s+(?:GET|POST|PUT|PATCH|DELETE|loader|action)\b)/.test(sourceCode) && /\{[^}]*\bparams\b[^}]*\}/.test(sourceCode);
19216
- const patterns = isRouteHandler2 ? [...JS_TAINTED_PATTERNS, { pattern: /\bparams\s*[.[]/, type: "http_path" }] : JS_TAINTED_PATTERNS;
19317
+ const patterns = isRouteHandler2 ? [...JS_TAINTED_PATTERNS, { pattern: /\bparams\s*[.[]/, type: "http_path" }] : [...JS_TAINTED_PATTERNS];
19318
+ patterns.push(...destructuredRequestPatterns(sourceCode));
19217
19319
  const lookupTables = constLookupTables(sourceCode, language);
19218
19320
  const assignmentRe2 = /(?:(?:var|let|const)\s+(\w+)\s*:\s*[^=;]+?\s*=(?![>=])|(?:(?:var|let|const)\s+)?(\w+)\s*=)\s*/g;
19219
19321
  const rhsOwnStmt = /^(?:"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`|[^;}"'`])*/;
@@ -19231,6 +19333,8 @@ function findJavaScriptAssignmentSources(sourceCode, language) {
19231
19333
  rhs = rhsOwnStmt.exec(rhs)?.[0] ?? rhs;
19232
19334
  }
19233
19335
  if (isConstTableLookup(rhs, lookupTables)) continue;
19336
+ const wholeCall = /^\s*([A-Za-z_$][\w$]*)\s*\(.*\)\s*;?\s*$/.exec(rhs);
19337
+ if (wholeCall && jsHelperReturnsNoParam(sourceCode, wholeCall[1])) continue;
19234
19338
  for (const { pattern, type } of patterns) {
19235
19339
  if (pattern.test(rhs)) {
19236
19340
  const alreadyExists = sources.some((s) => s.line === lineNumber && s.type === type && s.variable === varName);
@@ -27575,7 +27679,14 @@ function findSources(calls, types, patterns, sourceLines, language, imports) {
27575
27679
  }
27576
27680
  const propertyPatterns = patterns.filter((p) => p.property && p.object && p.property_tainted);
27577
27681
  const hasPropertyPatterns = propertyPatterns.length > 0;
27682
+ const jsCode = (language === "javascript" || language === "typescript") && sourceLines ? sourceLines.join("\n") : void 0;
27683
+ const noParamHelper = /* @__PURE__ */ new Map();
27578
27684
  for (const call of calls) {
27685
+ if (jsCode !== void 0 && !call.receiver) {
27686
+ let drop = noParamHelper.get(call.method_name);
27687
+ if (drop === void 0) noParamHelper.set(call.method_name, drop = jsHelperReturnsNoParam(jsCode, call.method_name));
27688
+ if (drop) continue;
27689
+ }
27579
27690
  for (const arg of call.arguments) {
27580
27691
  if (arg.expression) {
27581
27692
  const taintCheck = isJavaScriptTaintedArgument(arg.expression, hasPropertyPatterns ? patterns : void 0);
@@ -28346,8 +28457,29 @@ function isRegexReceiver(receiver, sourceLines) {
28346
28457
  if (r.startsWith("/") && /\/[a-z]*$/.test(r)) return true;
28347
28458
  if (/^(?:new\s+)?RegExp\s*\(/.test(r)) return true;
28348
28459
  if (!/^[A-Za-z_$][\w$]*$/.test(r) || !sourceLines) return false;
28349
- const decl = new RegExp(`(?:const|let|var)\\s+${escapeRe(r)}\\s*=\\s*(?:/|(?:new\\s+)?RegExp\\s*\\()`);
28350
- return sourceLines.some((l) => decl.test(l));
28460
+ const n = escapeRe(r);
28461
+ const decl = new RegExp(`(?:const|let|var)\\s+${n}\\s*(?::\\s*RegExp\\s*)?=\\s*(?:/|(?:new\\s+)?RegExp\\s*\\()`);
28462
+ if (sourceLines.some((l) => decl.test(l))) return true;
28463
+ const wrapped = new RegExp(`(?:const|let|var)\\s+${n}\\s*(?::\\s*RegExp\\s*)?=\\s*$`);
28464
+ const typed = new RegExp(`\\b${n}\\s*[?!]?\\s*:\\s*RegExp\\b`);
28465
+ return sourceLines.some((l, i2) => typed.test(l) || wrapped.test(l) && /^\s*(?:\/|(?:new\s+)?RegExp\s*\()/.test(sourceLines[i2 + 1] ?? ""));
28466
+ }
28467
+ var DB_TYPE_NAME = /(?:connection|database|\bdb\b|db$|^db|pool|client|knex|sql|statement|prisma|sequelize|repository|transaction|query|store)/i;
28468
+ function isTypedNonDbReceiver(receiver, sourceLines) {
28469
+ const raw = (receiver ?? "").trim();
28470
+ if (!raw || !sourceLines) return false;
28471
+ const lastDot = raw.lastIndexOf(".");
28472
+ const name2 = (lastDot >= 0 ? raw.slice(lastDot + 1) : raw).trim();
28473
+ if (!/^[A-Za-z_$][\w$]*$/.test(name2) || DB_TYPE_NAME.test(name2)) return false;
28474
+ const decl = raw.startsWith("this.") ? new RegExp(`^\\s*(?:(?:private|protected|public|readonly|static|declare)\\s+)+${escapeRe(name2)}\\s*[?!]?\\s*:\\s*([A-Za-z_$][\\w$]*)\\s*[;=]`) : new RegExp(`\\b${escapeRe(name2)}\\s*\\??\\s*:\\s*([A-Za-z_$][\\w$]*)\\s*[;,)=]`);
28475
+ let typed;
28476
+ for (const l of sourceLines) {
28477
+ const m = decl.exec(l);
28478
+ if (!m) continue;
28479
+ if (typed !== void 0 && typed !== m[1]) return false;
28480
+ typed = m[1];
28481
+ }
28482
+ return typed !== void 0 && !DB_TYPE_NAME.test(typed) && !/^(?:any|unknown|object)$/.test(typed);
28351
28483
  }
28352
28484
  function isNavigationReceiverName(receiver) {
28353
28485
  const r = (receiver ?? "").trim();
@@ -28384,7 +28516,10 @@ function isDeclaredFunctionReference(arg, sourceLines) {
28384
28516
  // const connect = () => / function / async () =>
28385
28517
  new RegExp(
28386
28518
  `\\b(?:const|let|var)\\s+${n}\\s*=\\s*(?:async\\s+)?(?:function\\b|\\(|[A-Za-z_$][\\w$]*\\s*=>)`
28387
- )
28519
+ ),
28520
+ // A Promise executor's resolve / reject: `new Promise((r) => setTimeout(r, ms))`,
28521
+ // the sleep idiom (dogfood 2026-10-31, controldeck harness).
28522
+ new RegExp(`\\bnew\\s+Promise\\s*(?:<[^>]*>)?\\s*\\(\\s*(?:async\\s+)?(?:\\(\\s*(?:[A-Za-z_$][\\w$]*\\s*,\\s*)?${n}\\s*[,)]|${n}\\s*=>|function\\s*\\(\\s*(?:[A-Za-z_$][\\w$]*\\s*,\\s*)?${n}\\s*[,)])`)
28388
28523
  ];
28389
28524
  return sourceLines.some((l) => decls.some((re) => re.test(l)));
28390
28525
  }
@@ -28645,7 +28780,10 @@ function findSinks(calls, patterns, typeHierarchy, language, sourceLines, types)
28645
28780
  if ((pattern.type === "command_injection" || pattern.type === "sql_injection") && call.method_name === "exec" && (language === "javascript" || language === "typescript") && isRegexReceiver(call.receiver, sourceLines)) {
28646
28781
  continue;
28647
28782
  }
28648
- if (pattern.type === "sql_injection" && call.method_name === "get" && pattern.class === "Connection" && (language === "javascript" || language === "typescript") && isInMemoryMapGetReceiver(call.receiver, sourceLines)) {
28783
+ if (pattern.type === "sql_injection" && call.method_name === "get" && pattern.class === "Connection" && (language === "javascript" || language === "typescript") && (isInMemoryMapGetReceiver(call.receiver, sourceLines) || isTypedNonDbReceiver(call.receiver, sourceLines))) {
28784
+ continue;
28785
+ }
28786
+ if (call.method_name === "get" && (language === "javascript" || language === "typescript") && isInMemoryMapGetReceiver(call.receiver, sourceLines)) {
28649
28787
  continue;
28650
28788
  }
28651
28789
  if (pattern.type === "code_injection" && language === "python" && call.method_name === "compile" && call.receiver && call.receiver !== "builtins") {
@@ -32624,7 +32762,9 @@ function analyzeInterprocedural(graphOrTypes, callsOrSources, dfgOrSinks, source
32624
32762
  const calls = graph.ir.calls;
32625
32763
  const declaredTypeNames = new Set(types.map((t) => t.name));
32626
32764
  const methodNodes = buildMethodNodes(types);
32627
- const callEdges = buildCallEdges(calls, methodNodes, types);
32765
+ const lang = graph.ir.meta.language;
32766
+ const collectionReceiver = (lang === "typescript" || lang === "javascript") && typeof options.sourceCode === "string" ? makeBuiltinCollectionReceiverTest(options.sourceCode) : null;
32767
+ const callEdges = buildCallEdges(calls, methodNodes, types, collectionReceiver);
32628
32768
  const taintedMethods = /* @__PURE__ */ new Set();
32629
32769
  const taintedReturns = /* @__PURE__ */ new Map();
32630
32770
  for (const source of sources) {
@@ -32860,8 +33000,9 @@ function analyzeInterprocedural(graphOrTypes, callsOrSources, dfgOrSinks, source
32860
33000
  }
32861
33001
  }
32862
33002
  }
32863
- const resolvedCalleeFqn = resolveMethodCall2(call, methodNodes, types);
32864
- const targetMethod = resolvedCalleeFqn ? methodNodes.byFqn.get(resolvedCalleeFqn) : getMethodNode(methodNodes, call.method_name);
33003
+ const builtinReceiver = collectionReceiver !== null && collectionReceiver(call.receiver);
33004
+ const resolvedCalleeFqn = builtinReceiver ? null : resolveMethodCall2(call, methodNodes, types);
33005
+ const targetMethod = builtinReceiver ? void 0 : resolvedCalleeFqn ? methodNodes.byFqn.get(resolvedCalleeFqn) : getMethodNode(methodNodes, call.method_name);
32865
33006
  if (!targetMethod) {
32866
33007
  if (taintedArgPositions.length > 0 && !collectionMethods.has(call.method_name) && !sanitizerMethods.has(call.method_name) && !safeUtilityMethods.has(call.method_name) && !ormQueryBuilderMethods.has(call.method_name)) {
32867
33008
  const isBash = graph.ir.meta.language === "bash";
@@ -33070,9 +33211,29 @@ function resolveMethodCall2(call, methodNodes, types) {
33070
33211
  }
33071
33212
  return null;
33072
33213
  }
33073
- function buildCallEdges(calls, methodNodes, types) {
33214
+ function makeBuiltinCollectionReceiverTest(sourceCode) {
33215
+ const memo = /* @__PURE__ */ new Map();
33216
+ return (receiver) => {
33217
+ const raw = (receiver ?? "").trim();
33218
+ const m = /^(?:this\.)?([A-Za-z_$][\w$]*)$/.exec(raw);
33219
+ if (!m || raw === "this") return false;
33220
+ const name2 = m[1];
33221
+ const hit = memo.get(name2);
33222
+ if (hit !== void 0) return hit;
33223
+ const n = name2.replace(/[$]/g, "\\$&");
33224
+ const coll = "(?:Readonly)?(?:Weak)?(?:Map|Set)";
33225
+ const ctor = new RegExp(`(?<![\\w$.])${n}\\s*(?::[^=;]*)?=\\s*new\\s+(?:Weak)?(?:Map|Set)\\s*(?:<[^;]*>)?\\s*\\(`);
33226
+ const typed = new RegExp(`(?<![\\w$.])${n}\\s*[?!]?\\s*:\\s*${coll}\\s*<`);
33227
+ const thisCtor = new RegExp(`\\bthis\\.${n}\\s*=\\s*new\\s+(?:Weak)?(?:Map|Set)\\s*(?:<[^;]*>)?\\s*\\(`);
33228
+ const result = ctor.test(sourceCode) || typed.test(sourceCode) || thisCtor.test(sourceCode);
33229
+ memo.set(name2, result);
33230
+ return result;
33231
+ };
33232
+ }
33233
+ function buildCallEdges(calls, methodNodes, types, collectionReceiver = null) {
33074
33234
  const edges = [];
33075
33235
  for (const call of calls) {
33236
+ if (collectionReceiver !== null && collectionReceiver(call.receiver)) continue;
33076
33237
  const resolvedFqn = resolveMethodCall2(call, methodNodes, types);
33077
33238
  if (!resolvedFqn) continue;
33078
33239
  const callerMethod = call.in_method;
@@ -41108,7 +41269,8 @@ var InterproceduralPass = class {
41108
41269
  const csCredit = language === "csharp" && typeof ctx.code === "string" ? new CSharpCredit(ctx.code, graph.ir.types.flatMap((t) => t.methods)) : null;
41109
41270
  if (sinks.length > 0) {
41110
41271
  const interProc = analyzeInterprocedural(graph, sources, sinks, sanitizers, {
41111
- taintedVariables: constProp.tainted
41272
+ taintedVariables: constProp.tainted,
41273
+ sourceCode: typeof ctx.code === "string" ? ctx.code : void 0
41112
41274
  });
41113
41275
  for (const sink of interProc.propagatedSinks) {
41114
41276
  if (sink.type === "external_taint_escape") continue;
@@ -41182,7 +41344,8 @@ var InterproceduralPass = class {
41182
41344
  interProc,
41183
41345
  additionalFlows,
41184
41346
  language === "java" ? ctx.code : void 0,
41185
- language === "java" ? constProp : void 0
41347
+ language === "java" ? constProp : void 0,
41348
+ language === "java" || language === "javascript" || language === "typescript" ? ctx.code : void 0
41186
41349
  );
41187
41350
  const taintBridges = findTaintBridges(interProc);
41188
41351
  interprocedural = {
@@ -41205,7 +41368,8 @@ var InterproceduralPass = class {
41205
41368
  return { additionalSinks, additionalFlows, interprocedural };
41206
41369
  }
41207
41370
  const interProc = analyzeInterprocedural(graph, fallbackSources, [], sanitizers, {
41208
- taintedVariables: constProp.tainted
41371
+ taintedVariables: constProp.tainted,
41372
+ sourceCode: typeof ctx.code === "string" ? ctx.code : void 0
41209
41373
  });
41210
41374
  const cleared = ctx.hasResult("taint-matcher") ? ctx.getResult("taint-matcher").sinks.filter((s) => s.method && !sinks.some((k) => k.line === s.line && k.method === s.method)) : [];
41211
41375
  const isClearedCall = (esc) => cleared.some((s) => s.line === esc.line && s.method === esc.method && (!s.argPositions?.length || !esc.argPositions?.length || esc.argPositions.every((p) => s.argPositions.includes(p))));
@@ -41405,13 +41569,13 @@ function storeBase(line) {
41405
41569
  if (!m || m[1] === "this") return null;
41406
41570
  return m[1];
41407
41571
  }
41408
- function appendCalleeSourceCallerSinkFlows(graph, sources, sinks, interProc, additionalFlows, fileCode, constProp) {
41572
+ function appendCalleeSourceCallerSinkFlows(graph, sources, sinks, interProc, additionalFlows, fileCode, constProp, returnReachCode) {
41409
41573
  const types = graph.ir.types ?? [];
41410
41574
  for (const edge of interProc.callEdges) {
41411
41575
  const callee = interProc.methodNodes.get(edge.calleeMethod);
41412
41576
  if (!callee) continue;
41413
41577
  const calleeSources = sources.filter(
41414
- (s) => s.line >= callee.startLine && s.line <= callee.endLine && (!fileCode || s.type === "interprocedural_param" || calleeSourceReachesReturn(graph, fileCode, callee.startLine, callee.endLine, s.line))
41578
+ (s) => s.line >= callee.startLine && s.line <= callee.endLine && (!returnReachCode || s.type === "interprocedural_param" || calleeSourceReachesReturn(graph, returnReachCode, callee.startLine, callee.endLine, s.line))
41415
41579
  );
41416
41580
  if (calleeSources.length === 0) continue;
41417
41581
  const assignee = graph.ir.dfg.defs.find(
@@ -43151,6 +43315,7 @@ var HTML_CONTENT_TYPE_RE = /text\/html|TEXT_HTML/;
43151
43315
  var FETCH_GLOBAL_RECEIVER_RE = /(?:^|[^.\w])(?:window|globalThis|self|global)\s*\.\s*fetch\s*\(/;
43152
43316
  var FETCH_MEMBER_RECEIVER_RE = /[\w$)\]]\s*\.\s*fetch\s*\(/;
43153
43317
  var NOSQL_ARRAY_METHODS = /* @__PURE__ */ new Set(["find", "filter", "some", "every", "findIndex", "findLast"]);
43318
+ var SHELL_PROGRAM = /(?:^|[\\/])(?:sh|bash|zsh|dash|ksh|fish|cmd(?:\.exe)?|powershell(?:\.exe)?|pwsh|node|python3?|perl|ruby|php|osascript|env)$/i;
43154
43319
  var FUNCTION_FIRST_ARG_RE = /\.\s*(?:find|filter|some|every|findIndex|findLast)\s*\(\s*(?:async\s+)?(?:function\b|(?:\([^()]*\)|[A-Za-z_$][\w$]*)\s*=>)/;
43155
43320
  var NAMED_ARRAY_PREDICATE_RE = /([A-Za-z_$][\w$]*)\s*\.\s*(find|filter|some|every|findIndex|findLast)\s*\(\s*([A-Za-z_$][\w$]*)\s*\)/;
43156
43321
  function isDeclaredFunctionName(name2, lines) {
@@ -44289,12 +44454,35 @@ var SinkFilterPass = class {
44289
44454
  return !FETCH_MEMBER_RECEIVER_RE.test(sinkLineText);
44290
44455
  });
44291
44456
  }
44457
+ if (["javascript", "typescript"].includes(language)) {
44458
+ const lines = ctx.code.split("\n");
44459
+ const FIXED_PROGRAM_EXEC = /* @__PURE__ */ new Set(["spawn", "spawnSync", "execFile", "execFileSync"]);
44460
+ filtered = filtered.filter((sink) => {
44461
+ if (sink.type !== "command_injection" || !FIXED_PROGRAM_EXEC.has(sink.method ?? "")) return true;
44462
+ let stmt = lines[sink.line - 1] ?? "";
44463
+ for (let k = 0; k < 8 && !/\)\s*;?\s*$/.test(stmt.replace(/\/\/.*$/, "")); k++) {
44464
+ stmt += " " + (lines[sink.line + k] ?? "").trim();
44465
+ }
44466
+ const call = new RegExp(`\\b${sink.method}\\s*\\(\\s*([^,)]+)`).exec(stmt);
44467
+ if (!call) return true;
44468
+ const program = call[1].trim();
44469
+ const literal = /^(['"`])([^'"`$]*)\1$/.exec(program);
44470
+ const fixed = program === "process.execPath" || literal !== null && !SHELL_PROGRAM.test(literal[2]);
44471
+ if (!fixed) return true;
44472
+ if (/\bshell\s*:\s*(?!false\b)/.test(stmt)) return true;
44473
+ if (/['"`]-(?:e|p|-eval|-print)['"`]/.test(stmt)) return true;
44474
+ return false;
44475
+ });
44476
+ }
44292
44477
  if (["javascript", "typescript"].includes(language)) {
44293
44478
  const sourceLines = ctx.code.split("\n");
44294
44479
  filtered = filtered.filter((sink) => {
44295
44480
  if (sink.type !== "nosql_injection") return true;
44296
44481
  if (!NOSQL_ARRAY_METHODS.has(sink.method ?? "")) return true;
44297
- const sinkLineText = sourceLines[sink.line - 1] ?? "";
44482
+ let sinkLineText = sourceLines[sink.line - 1] ?? "";
44483
+ for (let k = 0; k < 3 && /\(\s*$/.test(sinkLineText); k++) {
44484
+ sinkLineText += " " + (sourceLines[sink.line + k] ?? "").trim();
44485
+ }
44298
44486
  if (FUNCTION_FIRST_ARG_RE.test(sinkLineText)) return false;
44299
44487
  const named2 = NAMED_ARRAY_PREDICATE_RE.exec(sinkLineText);
44300
44488
  if (named2) {
@@ -50217,7 +50405,7 @@ var ResourceLeakPass = class {
50217
50405
  for (const call of graph.ir.calls) {
50218
50406
  const name2 = call.method_name;
50219
50407
  const isConstructor = call.is_constructor === true && RESOURCE_CTORS.has(name2);
50220
- const isFactory = !call.is_constructor && RESOURCE_FACTORY_METHODS.has(name2);
50408
+ const isFactory = !call.is_constructor && RESOURCE_FACTORY_METHODS.has(name2) && (name2 !== "open" || !!call.receiver || graph.ir.meta.language === "python");
50221
50409
  if (!isConstructor && !isFactory) continue;
50222
50410
  const openLine = call.location.line;
50223
50411
  const defs = graph.defsAtLine(openLine);