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
@@ -10459,9 +10459,46 @@ function processStatement2(stmt, startDefId, startUseId, scopeStack, isJavaScrip
10459
10459
  case "try_statement":
10460
10460
  case "try_with_resources_statement": {
10461
10461
  if (isJavaScript) {
10462
- const stmtUses = extractUses(stmt, useId, scopeStack, isJavaScript);
10463
- uses.push(...stmtUses.uses);
10464
- useId = stmtUses.nextId;
10462
+ const tryBody = stmt.childForFieldName("body");
10463
+ if (tryBody) {
10464
+ const r = processStatement2(tryBody, defId, useId, scopeStack, isJavaScript);
10465
+ defs.push(...r.defs);
10466
+ uses.push(...r.uses);
10467
+ defId = r.nextDefId;
10468
+ useId = r.nextUseId;
10469
+ }
10470
+ const handler = stmt.childForFieldName("handler");
10471
+ if (handler) {
10472
+ scopeStack.push(/* @__PURE__ */ new Map());
10473
+ const param = handler.childForFieldName("parameter");
10474
+ if (param) {
10475
+ const paramDefs = param.type === "identifier" ? [{ id: defId, variable: getNodeText(param), line: param.startPosition.row + 1, column: param.startPosition.column, kind: "local" }] : extractDestructuringDefs(param, defId);
10476
+ for (const def of paramDefs) {
10477
+ defs.push(def);
10478
+ currentScope(scopeStack).set(def.variable, def.id);
10479
+ markDeclared(currentScope(scopeStack), def.variable);
10480
+ defId++;
10481
+ }
10482
+ }
10483
+ const handlerBody = handler.childForFieldName("body");
10484
+ if (handlerBody) {
10485
+ const r = processStatement2(handlerBody, defId, useId, scopeStack, isJavaScript);
10486
+ defs.push(...r.defs);
10487
+ uses.push(...r.uses);
10488
+ defId = r.nextDefId;
10489
+ useId = r.nextUseId;
10490
+ }
10491
+ carryBranchDefsOut(scopeStack.pop(), scopeStack, false);
10492
+ }
10493
+ const finalizer6 = stmt.childForFieldName("finalizer");
10494
+ const finallyBody = finalizer6?.childForFieldName("body");
10495
+ if (finallyBody) {
10496
+ const r = processStatement2(finallyBody, defId, useId, scopeStack, isJavaScript);
10497
+ defs.push(...r.defs);
10498
+ uses.push(...r.uses);
10499
+ defId = r.nextDefId;
10500
+ useId = r.nextUseId;
10501
+ }
10465
10502
  break;
10466
10503
  }
10467
10504
  scopeStack.push(/* @__PURE__ */ new Map());
@@ -11862,6 +11899,46 @@ function extractGoAddressableVarName(node) {
11862
11899
  return null;
11863
11900
  }
11864
11901
 
11902
+ // src/analysis/js-helper-return.ts
11903
+ function jsHelperReturnsNoParam(sourceCode, rawName) {
11904
+ if (!/^[A-Za-z_$][\w$]*$/.test(rawName)) return false;
11905
+ const name2 = rawName.replace(/\$/g, "\\$");
11906
+ const decls = [...sourceCode.matchAll(new RegExp(`\\bfunction\\s+${name2}\\s*\\(([^)]*)\\)\\s*\\{`, "g"))];
11907
+ if (decls.length !== 1) return false;
11908
+ if (new RegExp(`(?:const|let|var)\\s+${name2}\\s*=`).test(sourceCode)) return false;
11909
+ const open = (decls[0].index ?? 0) + decls[0][0].length - 1;
11910
+ let depth = 0;
11911
+ let close = -1;
11912
+ for (let i2 = open; i2 < sourceCode.length; i2++) {
11913
+ const ch = sourceCode[i2];
11914
+ if (ch === "{") depth++;
11915
+ else if (ch === "}" && --depth === 0) {
11916
+ close = i2;
11917
+ break;
11918
+ }
11919
+ }
11920
+ if (close < 0) return false;
11921
+ const body2 = sourceCode.slice(open + 1, close).replace(/\/\/.*$/gm, "");
11922
+ if (/\bfunction\b|=>/.test(body2)) return false;
11923
+ const literal = /^(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`[^`$]*`|-?\d+(?:\.\d+)?|true|false|null)$/;
11924
+ const returns = [...body2.matchAll(/\breturn\b\s*([^;]*);?/g)].map((m) => m[1].trim());
11925
+ if (returns.length === 0) return false;
11926
+ for (const expr of returns) {
11927
+ if (literal.test(expr)) continue;
11928
+ const slot = /^([A-Za-z_$][\w$]*)\s*\[\s*(\d+)\s*\]$/.exec(expr);
11929
+ if (!slot) return false;
11930
+ const arr = slot[1].replace(/\$/g, "\\$");
11931
+ const declRe = new RegExp(`(?:const|let|var)\\s+${arr}\\s*=\\s*\\[([^\\]]*)\\]\\s*;?`);
11932
+ const d = declRe.exec(body2);
11933
+ if (!d) return false;
11934
+ if (new RegExp(`\\b${arr}\\s*(?:\\[[^\\]]*\\]\\s*=(?!=)|\\.\\s*(?:push|unshift|splice|shift|pop|reverse|sort|fill|copyWithin)\\s*\\()`).test(body2)) return false;
11935
+ const elems = d[1].split(",").map((e) => e.trim());
11936
+ const el = elems[Number(slot[2])];
11937
+ if (el === void 0 || !literal.test(el)) return false;
11938
+ }
11939
+ return true;
11940
+ }
11941
+
11865
11942
  // src/analysis/literal-expression.ts
11866
11943
  function isProvablyLiteralExpression(expr) {
11867
11944
  let e = (expr ?? "").trim();
@@ -13627,7 +13704,7 @@ var DEFAULT_SINKS = [
13627
13704
  { method: "renderHTML", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13628
13705
  { method: "parseHTML", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13629
13706
  // HTML sanitizer/validator sinks (AntiSamy, OWASP HTML Sanitizer, etc.)
13630
- { method: "scan", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13707
+ { method: "scan", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
13631
13708
  { method: "isValid", class: "SafeHtmlValidator", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13632
13709
  { method: "sanitize", class: "PolicyFactory", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13633
13710
  { method: "validate", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0] },
@@ -13643,8 +13720,8 @@ var DEFAULT_SINKS = [
13643
13720
  { method: "writeAttribute", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0, 1] },
13644
13721
  // AntiSamy specific (SAX filters)
13645
13722
  { method: "startElement", class: "MagicSAXFilter", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0, 1, 2] },
13646
- { method: "scan", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13647
- { method: "scan", class: "AntiSamySAXScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13723
+ { method: "scan", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
13724
+ { method: "scan", class: "AntiSamySAXScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
13648
13725
  // Hibernate Validator
13649
13726
  { method: "getFragmentAsDocument", class: "SafeHtmlValidator", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13650
13727
  // JSPWiki specific
@@ -13694,15 +13771,15 @@ var DEFAULT_SINKS = [
13694
13771
  { method: "getValidListItem", class: "DefaultValidator", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0, 1] },
13695
13772
  { method: "isValidURI", class: "DefaultValidator", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0, 1] },
13696
13773
  // AntiSamy test/processing methods
13697
- { method: "scriptAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13698
- { method: "imgAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13699
- { method: "hrefAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13700
- { method: "cssAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13701
- { method: "IllegalXML", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13702
- { method: "testIssue2", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13703
- { method: "issue41", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13704
- { method: "testGithubIssue151", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13705
- { method: "processStyleTag", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13774
+ { method: "scriptAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13775
+ { method: "imgAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13776
+ { method: "hrefAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13777
+ { method: "cssAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13778
+ { method: "IllegalXML", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13779
+ { method: "testIssue2", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13780
+ { method: "issue41", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13781
+ { method: "testGithubIssue151", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13782
+ { method: "processStyleTag", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
13706
13783
  // JSON Sanitizer
13707
13784
  { method: "sanitizeString", class: "JsonSanitizer", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13708
13785
  { method: "testIssue13", class: "JsonSanitizerTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
@@ -14528,16 +14605,16 @@ var DEFAULT_SINKS = [
14528
14605
  { method: "parse", class: "sax", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0] },
14529
14606
  { method: "XMLParser", class: "lxml", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0] },
14530
14607
  // Python LDAP Injection
14531
- { method: "search", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
14532
- { method: "search_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
14533
- { method: "search_ext", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
14534
- { method: "search_ext_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
14608
+ { method: "search", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
14609
+ { method: "search_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
14610
+ { method: "search_ext", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
14611
+ { method: "search_ext_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
14535
14612
  // ldap3 library (different API from python-ldap)
14536
- { method: "search", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 1] },
14537
- { method: "extend", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
14538
- { method: "modify", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
14539
- { method: "add", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
14540
- { method: "delete", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
14613
+ { method: "search", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 1], languages: ["python"] },
14614
+ { method: "extend", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
14615
+ { method: "modify", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
14616
+ { method: "add", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
14617
+ { method: "delete", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
14541
14618
  // Python Trust Boundary (CWE-501)
14542
14619
  // The vulnerability is storing untrusted data in session that gets trusted later
14543
14620
  { method: "__setitem__", class: "session", type: "trust_boundary", cwe: "CWE-501", severity: "medium", arg_positions: [1] },
@@ -14628,7 +14705,7 @@ var DEFAULT_SINKS = [
14628
14705
  { method: "put", class: "VelocityContext", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [1] },
14629
14706
  { method: "setVariable", class: "Context", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [1] },
14630
14707
  // HTML sanitizer bypass markers (known CVE patterns)
14631
- { method: "clean", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0] },
14708
+ { method: "clean", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0], languages: ["java"] },
14632
14709
  { method: "getValidSafeHTML", class: "ESAPI", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0] },
14633
14710
  // NOTE (cognium-dev#270): `HttpServletRequest`/`HttpSession.getAttribute()`
14634
14711
  // were registered here as xss sinks to model "attribute reflection XSS", but
@@ -16576,7 +16653,14 @@ function findSources(calls, types, patterns, sourceLines, language, imports) {
16576
16653
  }
16577
16654
  const propertyPatterns = patterns.filter((p) => p.property && p.object && p.property_tainted);
16578
16655
  const hasPropertyPatterns = propertyPatterns.length > 0;
16656
+ const jsCode = (language === "javascript" || language === "typescript") && sourceLines ? sourceLines.join("\n") : void 0;
16657
+ const noParamHelper = /* @__PURE__ */ new Map();
16579
16658
  for (const call of calls) {
16659
+ if (jsCode !== void 0 && !call.receiver) {
16660
+ let drop = noParamHelper.get(call.method_name);
16661
+ if (drop === void 0) noParamHelper.set(call.method_name, drop = jsHelperReturnsNoParam(jsCode, call.method_name));
16662
+ if (drop) continue;
16663
+ }
16580
16664
  for (const arg of call.arguments) {
16581
16665
  if (arg.expression) {
16582
16666
  const taintCheck = isJavaScriptTaintedArgument(arg.expression, hasPropertyPatterns ? patterns : void 0);
@@ -17347,8 +17431,29 @@ function isRegexReceiver(receiver, sourceLines) {
17347
17431
  if (r.startsWith("/") && /\/[a-z]*$/.test(r)) return true;
17348
17432
  if (/^(?:new\s+)?RegExp\s*\(/.test(r)) return true;
17349
17433
  if (!/^[A-Za-z_$][\w$]*$/.test(r) || !sourceLines) return false;
17350
- const decl = new RegExp(`(?:const|let|var)\\s+${escapeRe(r)}\\s*=\\s*(?:/|(?:new\\s+)?RegExp\\s*\\()`);
17351
- return sourceLines.some((l) => decl.test(l));
17434
+ const n = escapeRe(r);
17435
+ const decl = new RegExp(`(?:const|let|var)\\s+${n}\\s*(?::\\s*RegExp\\s*)?=\\s*(?:/|(?:new\\s+)?RegExp\\s*\\()`);
17436
+ if (sourceLines.some((l) => decl.test(l))) return true;
17437
+ const wrapped = new RegExp(`(?:const|let|var)\\s+${n}\\s*(?::\\s*RegExp\\s*)?=\\s*$`);
17438
+ const typed = new RegExp(`\\b${n}\\s*[?!]?\\s*:\\s*RegExp\\b`);
17439
+ return sourceLines.some((l, i2) => typed.test(l) || wrapped.test(l) && /^\s*(?:\/|(?:new\s+)?RegExp\s*\()/.test(sourceLines[i2 + 1] ?? ""));
17440
+ }
17441
+ var DB_TYPE_NAME = /(?:connection|database|\bdb\b|db$|^db|pool|client|knex|sql|statement|prisma|sequelize|repository|transaction|query|store)/i;
17442
+ function isTypedNonDbReceiver(receiver, sourceLines) {
17443
+ const raw = (receiver ?? "").trim();
17444
+ if (!raw || !sourceLines) return false;
17445
+ const lastDot = raw.lastIndexOf(".");
17446
+ const name2 = (lastDot >= 0 ? raw.slice(lastDot + 1) : raw).trim();
17447
+ if (!/^[A-Za-z_$][\w$]*$/.test(name2) || DB_TYPE_NAME.test(name2)) return false;
17448
+ 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*[;,)=]`);
17449
+ let typed;
17450
+ for (const l of sourceLines) {
17451
+ const m = decl.exec(l);
17452
+ if (!m) continue;
17453
+ if (typed !== void 0 && typed !== m[1]) return false;
17454
+ typed = m[1];
17455
+ }
17456
+ return typed !== void 0 && !DB_TYPE_NAME.test(typed) && !/^(?:any|unknown|object)$/.test(typed);
17352
17457
  }
17353
17458
  function isNavigationReceiverName(receiver) {
17354
17459
  const r = (receiver ?? "").trim();
@@ -17385,7 +17490,10 @@ function isDeclaredFunctionReference(arg, sourceLines) {
17385
17490
  // const connect = () => / function / async () =>
17386
17491
  new RegExp(
17387
17492
  `\\b(?:const|let|var)\\s+${n}\\s*=\\s*(?:async\\s+)?(?:function\\b|\\(|[A-Za-z_$][\\w$]*\\s*=>)`
17388
- )
17493
+ ),
17494
+ // A Promise executor's resolve / reject: `new Promise((r) => setTimeout(r, ms))`,
17495
+ // the sleep idiom (dogfood 2026-10-31, controldeck harness).
17496
+ 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*[,)])`)
17389
17497
  ];
17390
17498
  return sourceLines.some((l) => decls.some((re) => re.test(l)));
17391
17499
  }
@@ -17646,7 +17754,10 @@ function findSinks(calls, patterns, typeHierarchy, language, sourceLines, types)
17646
17754
  if ((pattern.type === "command_injection" || pattern.type === "sql_injection") && call.method_name === "exec" && (language === "javascript" || language === "typescript") && isRegexReceiver(call.receiver, sourceLines)) {
17647
17755
  continue;
17648
17756
  }
17649
- if (pattern.type === "sql_injection" && call.method_name === "get" && pattern.class === "Connection" && (language === "javascript" || language === "typescript") && isInMemoryMapGetReceiver(call.receiver, sourceLines)) {
17757
+ if (pattern.type === "sql_injection" && call.method_name === "get" && pattern.class === "Connection" && (language === "javascript" || language === "typescript") && (isInMemoryMapGetReceiver(call.receiver, sourceLines) || isTypedNonDbReceiver(call.receiver, sourceLines))) {
17758
+ continue;
17759
+ }
17760
+ if (call.method_name === "get" && (language === "javascript" || language === "typescript") && isInMemoryMapGetReceiver(call.receiver, sourceLines)) {
17650
17761
  continue;
17651
17762
  }
17652
17763
  if (pattern.type === "code_injection" && language === "python" && call.method_name === "compile" && call.receiver && call.receiver !== "builtins") {
@@ -10393,9 +10393,46 @@ function processStatement2(stmt, startDefId, startUseId, scopeStack, isJavaScrip
10393
10393
  case "try_statement":
10394
10394
  case "try_with_resources_statement": {
10395
10395
  if (isJavaScript) {
10396
- const stmtUses = extractUses(stmt, useId, scopeStack, isJavaScript);
10397
- uses.push(...stmtUses.uses);
10398
- useId = stmtUses.nextId;
10396
+ const tryBody = stmt.childForFieldName("body");
10397
+ if (tryBody) {
10398
+ const r = processStatement2(tryBody, defId, useId, scopeStack, isJavaScript);
10399
+ defs.push(...r.defs);
10400
+ uses.push(...r.uses);
10401
+ defId = r.nextDefId;
10402
+ useId = r.nextUseId;
10403
+ }
10404
+ const handler = stmt.childForFieldName("handler");
10405
+ if (handler) {
10406
+ scopeStack.push(/* @__PURE__ */ new Map());
10407
+ const param = handler.childForFieldName("parameter");
10408
+ if (param) {
10409
+ const paramDefs = param.type === "identifier" ? [{ id: defId, variable: getNodeText(param), line: param.startPosition.row + 1, column: param.startPosition.column, kind: "local" }] : extractDestructuringDefs(param, defId);
10410
+ for (const def of paramDefs) {
10411
+ defs.push(def);
10412
+ currentScope(scopeStack).set(def.variable, def.id);
10413
+ markDeclared(currentScope(scopeStack), def.variable);
10414
+ defId++;
10415
+ }
10416
+ }
10417
+ const handlerBody = handler.childForFieldName("body");
10418
+ if (handlerBody) {
10419
+ const r = processStatement2(handlerBody, defId, useId, scopeStack, isJavaScript);
10420
+ defs.push(...r.defs);
10421
+ uses.push(...r.uses);
10422
+ defId = r.nextDefId;
10423
+ useId = r.nextUseId;
10424
+ }
10425
+ carryBranchDefsOut(scopeStack.pop(), scopeStack, false);
10426
+ }
10427
+ const finalizer6 = stmt.childForFieldName("finalizer");
10428
+ const finallyBody = finalizer6?.childForFieldName("body");
10429
+ if (finallyBody) {
10430
+ const r = processStatement2(finallyBody, defId, useId, scopeStack, isJavaScript);
10431
+ defs.push(...r.defs);
10432
+ uses.push(...r.uses);
10433
+ defId = r.nextDefId;
10434
+ useId = r.nextUseId;
10435
+ }
10399
10436
  break;
10400
10437
  }
10401
10438
  scopeStack.push(/* @__PURE__ */ new Map());
@@ -11796,6 +11833,46 @@ function extractGoAddressableVarName(node) {
11796
11833
  return null;
11797
11834
  }
11798
11835
 
11836
+ // src/analysis/js-helper-return.ts
11837
+ function jsHelperReturnsNoParam(sourceCode, rawName) {
11838
+ if (!/^[A-Za-z_$][\w$]*$/.test(rawName)) return false;
11839
+ const name2 = rawName.replace(/\$/g, "\\$");
11840
+ const decls = [...sourceCode.matchAll(new RegExp(`\\bfunction\\s+${name2}\\s*\\(([^)]*)\\)\\s*\\{`, "g"))];
11841
+ if (decls.length !== 1) return false;
11842
+ if (new RegExp(`(?:const|let|var)\\s+${name2}\\s*=`).test(sourceCode)) return false;
11843
+ const open = (decls[0].index ?? 0) + decls[0][0].length - 1;
11844
+ let depth = 0;
11845
+ let close = -1;
11846
+ for (let i2 = open; i2 < sourceCode.length; i2++) {
11847
+ const ch = sourceCode[i2];
11848
+ if (ch === "{") depth++;
11849
+ else if (ch === "}" && --depth === 0) {
11850
+ close = i2;
11851
+ break;
11852
+ }
11853
+ }
11854
+ if (close < 0) return false;
11855
+ const body2 = sourceCode.slice(open + 1, close).replace(/\/\/.*$/gm, "");
11856
+ if (/\bfunction\b|=>/.test(body2)) return false;
11857
+ const literal = /^(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|`[^`$]*`|-?\d+(?:\.\d+)?|true|false|null)$/;
11858
+ const returns = [...body2.matchAll(/\breturn\b\s*([^;]*);?/g)].map((m) => m[1].trim());
11859
+ if (returns.length === 0) return false;
11860
+ for (const expr of returns) {
11861
+ if (literal.test(expr)) continue;
11862
+ const slot = /^([A-Za-z_$][\w$]*)\s*\[\s*(\d+)\s*\]$/.exec(expr);
11863
+ if (!slot) return false;
11864
+ const arr = slot[1].replace(/\$/g, "\\$");
11865
+ const declRe = new RegExp(`(?:const|let|var)\\s+${arr}\\s*=\\s*\\[([^\\]]*)\\]\\s*;?`);
11866
+ const d = declRe.exec(body2);
11867
+ if (!d) return false;
11868
+ if (new RegExp(`\\b${arr}\\s*(?:\\[[^\\]]*\\]\\s*=(?!=)|\\.\\s*(?:push|unshift|splice|shift|pop|reverse|sort|fill|copyWithin)\\s*\\()`).test(body2)) return false;
11869
+ const elems = d[1].split(",").map((e) => e.trim());
11870
+ const el = elems[Number(slot[2])];
11871
+ if (el === void 0 || !literal.test(el)) return false;
11872
+ }
11873
+ return true;
11874
+ }
11875
+
11799
11876
  // src/analysis/literal-expression.ts
11800
11877
  function isProvablyLiteralExpression(expr) {
11801
11878
  let e = (expr ?? "").trim();
@@ -13561,7 +13638,7 @@ var DEFAULT_SINKS = [
13561
13638
  { method: "renderHTML", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13562
13639
  { method: "parseHTML", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13563
13640
  // HTML sanitizer/validator sinks (AntiSamy, OWASP HTML Sanitizer, etc.)
13564
- { method: "scan", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13641
+ { method: "scan", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
13565
13642
  { method: "isValid", class: "SafeHtmlValidator", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13566
13643
  { method: "sanitize", class: "PolicyFactory", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13567
13644
  { method: "validate", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0] },
@@ -13577,8 +13654,8 @@ var DEFAULT_SINKS = [
13577
13654
  { method: "writeAttribute", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0, 1] },
13578
13655
  // AntiSamy specific (SAX filters)
13579
13656
  { method: "startElement", class: "MagicSAXFilter", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0, 1, 2] },
13580
- { method: "scan", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13581
- { method: "scan", class: "AntiSamySAXScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13657
+ { method: "scan", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
13658
+ { method: "scan", class: "AntiSamySAXScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
13582
13659
  // Hibernate Validator
13583
13660
  { method: "getFragmentAsDocument", class: "SafeHtmlValidator", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13584
13661
  // JSPWiki specific
@@ -13628,15 +13705,15 @@ var DEFAULT_SINKS = [
13628
13705
  { method: "getValidListItem", class: "DefaultValidator", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0, 1] },
13629
13706
  { method: "isValidURI", class: "DefaultValidator", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0, 1] },
13630
13707
  // AntiSamy test/processing methods
13631
- { method: "scriptAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13632
- { method: "imgAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13633
- { method: "hrefAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13634
- { method: "cssAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13635
- { method: "IllegalXML", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13636
- { method: "testIssue2", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13637
- { method: "issue41", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13638
- { method: "testGithubIssue151", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
13639
- { method: "processStyleTag", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13708
+ { method: "scriptAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13709
+ { method: "imgAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13710
+ { method: "hrefAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13711
+ { method: "cssAttacks", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13712
+ { method: "IllegalXML", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13713
+ { method: "testIssue2", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13714
+ { method: "issue41", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13715
+ { method: "testGithubIssue151", class: "AntiSamyTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [], languages: ["java"] },
13716
+ { method: "processStyleTag", class: "AntiSamyDOMScanner", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0], languages: ["java"] },
13640
13717
  // JSON Sanitizer
13641
13718
  { method: "sanitizeString", class: "JsonSanitizer", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [0] },
13642
13719
  { method: "testIssue13", class: "JsonSanitizerTest", type: "xss", cwe: "CWE-79", severity: "high", arg_positions: [] },
@@ -14462,16 +14539,16 @@ var DEFAULT_SINKS = [
14462
14539
  { method: "parse", class: "sax", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0] },
14463
14540
  { method: "XMLParser", class: "lxml", type: "xxe", cwe: "CWE-611", severity: "high", arg_positions: [0] },
14464
14541
  // Python LDAP Injection
14465
- { method: "search", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
14466
- { method: "search_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
14467
- { method: "search_ext", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
14468
- { method: "search_ext_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2] },
14542
+ { method: "search", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
14543
+ { method: "search_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
14544
+ { method: "search_ext", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
14545
+ { method: "search_ext_s", class: "ldap", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 2], languages: ["python"] },
14469
14546
  // ldap3 library (different API from python-ldap)
14470
- { method: "search", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 1] },
14471
- { method: "extend", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
14472
- { method: "modify", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
14473
- { method: "add", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
14474
- { method: "delete", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0] },
14547
+ { method: "search", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0, 1], languages: ["python"] },
14548
+ { method: "extend", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
14549
+ { method: "modify", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
14550
+ { method: "add", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
14551
+ { method: "delete", class: "Connection", type: "ldap_injection", cwe: "CWE-90", severity: "high", arg_positions: [0], languages: ["python"] },
14475
14552
  // Python Trust Boundary (CWE-501)
14476
14553
  // The vulnerability is storing untrusted data in session that gets trusted later
14477
14554
  { method: "__setitem__", class: "session", type: "trust_boundary", cwe: "CWE-501", severity: "medium", arg_positions: [1] },
@@ -14562,7 +14639,7 @@ var DEFAULT_SINKS = [
14562
14639
  { method: "put", class: "VelocityContext", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [1] },
14563
14640
  { method: "setVariable", class: "Context", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [1] },
14564
14641
  // HTML sanitizer bypass markers (known CVE patterns)
14565
- { method: "clean", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0] },
14642
+ { method: "clean", class: "AntiSamy", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0], languages: ["java"] },
14566
14643
  { method: "getValidSafeHTML", class: "ESAPI", type: "xss", cwe: "CWE-79", severity: "medium", arg_positions: [0] },
14567
14644
  // NOTE (cognium-dev#270): `HttpServletRequest`/`HttpSession.getAttribute()`
14568
14645
  // were registered here as xss sinks to model "attribute reflection XSS", but
@@ -16510,7 +16587,14 @@ function findSources(calls, types, patterns, sourceLines, language, imports) {
16510
16587
  }
16511
16588
  const propertyPatterns = patterns.filter((p) => p.property && p.object && p.property_tainted);
16512
16589
  const hasPropertyPatterns = propertyPatterns.length > 0;
16590
+ const jsCode = (language === "javascript" || language === "typescript") && sourceLines ? sourceLines.join("\n") : void 0;
16591
+ const noParamHelper = /* @__PURE__ */ new Map();
16513
16592
  for (const call of calls) {
16593
+ if (jsCode !== void 0 && !call.receiver) {
16594
+ let drop = noParamHelper.get(call.method_name);
16595
+ if (drop === void 0) noParamHelper.set(call.method_name, drop = jsHelperReturnsNoParam(jsCode, call.method_name));
16596
+ if (drop) continue;
16597
+ }
16514
16598
  for (const arg of call.arguments) {
16515
16599
  if (arg.expression) {
16516
16600
  const taintCheck = isJavaScriptTaintedArgument(arg.expression, hasPropertyPatterns ? patterns : void 0);
@@ -17281,8 +17365,29 @@ function isRegexReceiver(receiver, sourceLines) {
17281
17365
  if (r.startsWith("/") && /\/[a-z]*$/.test(r)) return true;
17282
17366
  if (/^(?:new\s+)?RegExp\s*\(/.test(r)) return true;
17283
17367
  if (!/^[A-Za-z_$][\w$]*$/.test(r) || !sourceLines) return false;
17284
- const decl = new RegExp(`(?:const|let|var)\\s+${escapeRe(r)}\\s*=\\s*(?:/|(?:new\\s+)?RegExp\\s*\\()`);
17285
- return sourceLines.some((l) => decl.test(l));
17368
+ const n = escapeRe(r);
17369
+ const decl = new RegExp(`(?:const|let|var)\\s+${n}\\s*(?::\\s*RegExp\\s*)?=\\s*(?:/|(?:new\\s+)?RegExp\\s*\\()`);
17370
+ if (sourceLines.some((l) => decl.test(l))) return true;
17371
+ const wrapped = new RegExp(`(?:const|let|var)\\s+${n}\\s*(?::\\s*RegExp\\s*)?=\\s*$`);
17372
+ const typed = new RegExp(`\\b${n}\\s*[?!]?\\s*:\\s*RegExp\\b`);
17373
+ return sourceLines.some((l, i2) => typed.test(l) || wrapped.test(l) && /^\s*(?:\/|(?:new\s+)?RegExp\s*\()/.test(sourceLines[i2 + 1] ?? ""));
17374
+ }
17375
+ var DB_TYPE_NAME = /(?:connection|database|\bdb\b|db$|^db|pool|client|knex|sql|statement|prisma|sequelize|repository|transaction|query|store)/i;
17376
+ function isTypedNonDbReceiver(receiver, sourceLines) {
17377
+ const raw = (receiver ?? "").trim();
17378
+ if (!raw || !sourceLines) return false;
17379
+ const lastDot = raw.lastIndexOf(".");
17380
+ const name2 = (lastDot >= 0 ? raw.slice(lastDot + 1) : raw).trim();
17381
+ if (!/^[A-Za-z_$][\w$]*$/.test(name2) || DB_TYPE_NAME.test(name2)) return false;
17382
+ 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*[;,)=]`);
17383
+ let typed;
17384
+ for (const l of sourceLines) {
17385
+ const m = decl.exec(l);
17386
+ if (!m) continue;
17387
+ if (typed !== void 0 && typed !== m[1]) return false;
17388
+ typed = m[1];
17389
+ }
17390
+ return typed !== void 0 && !DB_TYPE_NAME.test(typed) && !/^(?:any|unknown|object)$/.test(typed);
17286
17391
  }
17287
17392
  function isNavigationReceiverName(receiver) {
17288
17393
  const r = (receiver ?? "").trim();
@@ -17319,7 +17424,10 @@ function isDeclaredFunctionReference(arg, sourceLines) {
17319
17424
  // const connect = () => / function / async () =>
17320
17425
  new RegExp(
17321
17426
  `\\b(?:const|let|var)\\s+${n}\\s*=\\s*(?:async\\s+)?(?:function\\b|\\(|[A-Za-z_$][\\w$]*\\s*=>)`
17322
- )
17427
+ ),
17428
+ // A Promise executor's resolve / reject: `new Promise((r) => setTimeout(r, ms))`,
17429
+ // the sleep idiom (dogfood 2026-10-31, controldeck harness).
17430
+ 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*[,)])`)
17323
17431
  ];
17324
17432
  return sourceLines.some((l) => decls.some((re) => re.test(l)));
17325
17433
  }
@@ -17580,7 +17688,10 @@ function findSinks(calls, patterns, typeHierarchy, language, sourceLines, types)
17580
17688
  if ((pattern.type === "command_injection" || pattern.type === "sql_injection") && call.method_name === "exec" && (language === "javascript" || language === "typescript") && isRegexReceiver(call.receiver, sourceLines)) {
17581
17689
  continue;
17582
17690
  }
17583
- if (pattern.type === "sql_injection" && call.method_name === "get" && pattern.class === "Connection" && (language === "javascript" || language === "typescript") && isInMemoryMapGetReceiver(call.receiver, sourceLines)) {
17691
+ if (pattern.type === "sql_injection" && call.method_name === "get" && pattern.class === "Connection" && (language === "javascript" || language === "typescript") && (isInMemoryMapGetReceiver(call.receiver, sourceLines) || isTypedNonDbReceiver(call.receiver, sourceLines))) {
17692
+ continue;
17693
+ }
17694
+ if (call.method_name === "get" && (language === "javascript" || language === "typescript") && isInMemoryMapGetReceiver(call.receiver, sourceLines)) {
17584
17695
  continue;
17585
17696
  }
17586
17697
  if (pattern.type === "code_injection" && language === "python" && call.method_name === "compile" && call.receiver && call.receiver !== "builtins") {
@@ -666,14 +666,53 @@ function processStatement(stmt, startDefId, startUseId, scopeStack, isJavaScript
666
666
  }
667
667
  case 'try_statement':
668
668
  case 'try_with_resources_statement': {
669
- // Java only (JavaScript's `try` keeps the default below: uses only).
670
- // Before this case a Java `try` recorded uses only, so no local declared
671
- // in a try body, catch or finally — nor a try-with-resources resource —
672
- // had a def, and nothing used inside or after it had a reaching def.
669
+ // Before this case a `try` recorded uses only, so no local declared in a
670
+ // try body, catch or finally — nor a try-with-resources resource — had a
671
+ // def, and nothing used inside or after it had a reaching def.
673
672
  if (isJavaScript) {
674
- const stmtUses = extractUses(stmt, useId, scopeStack, isJavaScript);
675
- uses.push(...stmtUses.uses);
676
- useId = stmtUses.nextId;
673
+ // JavaScript / TypeScript: `try { } catch (e | { pattern }) { } finally { }`
674
+ const tryBody = stmt.childForFieldName('body');
675
+ if (tryBody) {
676
+ const r = processStatement(tryBody, defId, useId, scopeStack, isJavaScript);
677
+ defs.push(...r.defs);
678
+ uses.push(...r.uses);
679
+ defId = r.nextDefId;
680
+ useId = r.nextUseId;
681
+ }
682
+ const handler = stmt.childForFieldName('handler');
683
+ if (handler) {
684
+ scopeStack.push(new Map());
685
+ const param = handler.childForFieldName('parameter');
686
+ if (param) {
687
+ const paramDefs = param.type === 'identifier'
688
+ ? [{ id: defId, variable: getNodeText(param), line: param.startPosition.row + 1, column: param.startPosition.column, kind: 'local' }]
689
+ : extractDestructuringDefs(param, defId);
690
+ for (const def of paramDefs) {
691
+ defs.push(def);
692
+ currentScope(scopeStack).set(def.variable, def.id);
693
+ markDeclared(currentScope(scopeStack), def.variable);
694
+ defId++;
695
+ }
696
+ }
697
+ const handlerBody = handler.childForFieldName('body');
698
+ if (handlerBody) {
699
+ const r = processStatement(handlerBody, defId, useId, scopeStack, isJavaScript);
700
+ defs.push(...r.defs);
701
+ uses.push(...r.uses);
702
+ defId = r.nextDefId;
703
+ useId = r.nextUseId;
704
+ }
705
+ carryBranchDefsOut(scopeStack.pop(), scopeStack, false);
706
+ }
707
+ const finalizer = stmt.childForFieldName('finalizer');
708
+ const finallyBody = finalizer?.childForFieldName('body');
709
+ if (finallyBody) {
710
+ const r = processStatement(finallyBody, defId, useId, scopeStack, isJavaScript);
711
+ defs.push(...r.defs);
712
+ uses.push(...r.uses);
713
+ defId = r.nextDefId;
714
+ useId = r.nextUseId;
715
+ }
677
716
  break;
678
717
  }
679
718
  // Resources are scoped to the statement: visible in the body, gone after it.