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
@@ -1 +1 @@
1
- {"version":3,"file":"taint-matcher.d.ts","sourceRoot":"","sources":["../../src/analysis/taint-matcher.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAgB,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAkB,KAAK,EAAwB,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG9K,OAAO,KAAK,EAAE,WAAW,EAAiB,WAAW,EAAoB,MAAM,oBAAoB,CAAC;AACpG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AA2F7E,wBAAgB,YAAY,CAC1B,KAAK,EAAE,QAAQ,EAAE,EACjB,KAAK,EAAE,QAAQ,EAAE,EACjB,MAAM,GAAE,WAAgC,EACxC,aAAa,CAAC,EAAE,qBAAqB,EACrC,QAAQ,CAAC,EAAE,iBAAiB,EAC5B,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,GAClC,KAAK,CAYP;AAqBD;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,SAAS,GAC7C,OAAO,CAST;AA0JD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,WAAW,EAAE,EACtB,KAAK,EAAE,SAAS,EAAE,EAClB,IAAI,EAAE,MAAM,GACX,IAAI,CAYN;AAu+GD;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,WAAW,GACnB,OAAO,CAET"}
1
+ {"version":3,"file":"taint-matcher.d.ts","sourceRoot":"","sources":["../../src/analysis/taint-matcher.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAgB,QAAQ,EAAE,QAAQ,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAkB,KAAK,EAAwB,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAG9K,OAAO,KAAK,EAAE,WAAW,EAAiB,WAAW,EAAoB,MAAM,oBAAoB,CAAC;AACpG,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AA2F7E,wBAAgB,YAAY,CAC1B,KAAK,EAAE,QAAQ,EAAE,EACjB,KAAK,EAAE,QAAQ,EAAE,EACjB,MAAM,GAAE,WAAgC,EACxC,aAAa,CAAC,EAAE,qBAAqB,EACrC,QAAQ,CAAC,EAAE,iBAAiB,EAC5B,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,aAAa,CAAC,UAAU,CAAC,GAClC,KAAK,CAYP;AAqBD;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,aAAa,CAAC,UAAU,CAAC,GAAG,SAAS,GAC7C,OAAO,CAST;AA0JD;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,EAAE,WAAW,EAAE,EACtB,KAAK,EAAE,SAAS,EAAE,EAClB,IAAI,EAAE,MAAM,GACX,IAAI,CAYN;AAqiHD;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,WAAW,GACnB,OAAO,CAET"}
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * Matches method calls and annotations against taint configurations.
5
5
  */
6
+ import { jsHelperReturnsNoParam } from './js-helper-return.js';
6
7
  import { javaWikiTagInheritedContextReceiver } from './passes/language-sources-pass.js';
7
8
  import { DOM_ASSIGNMENT_SINK_METHODS, isProvablyLiteralExpression } from './literal-expression.js';
8
9
  import { getDefaultConfig } from './config-loader.js';
@@ -505,7 +506,19 @@ function findSources(calls, types, patterns, sourceLines, language, imports) {
505
506
  // Get property-based source patterns
506
507
  const propertyPatterns = patterns.filter(p => p.property && p.object && p.property_tainted);
507
508
  const hasPropertyPatterns = propertyPatterns.length > 0;
509
+ const jsCode = (language === 'javascript' || language === 'typescript') && sourceLines ? sourceLines.join('\n') : undefined;
510
+ const noParamHelper = new Map();
508
511
  for (const call of calls) {
512
+ // #992: a request value passed to a same-file helper that returns none of
513
+ // its parameters (`pick(req.query.x)` → `return ['safe', x][0]`) is not a
514
+ // source at this call.
515
+ if (jsCode !== undefined && !call.receiver) {
516
+ let drop = noParamHelper.get(call.method_name);
517
+ if (drop === undefined)
518
+ noParamHelper.set(call.method_name, drop = jsHelperReturnsNoParam(jsCode, call.method_name));
519
+ if (drop)
520
+ continue;
521
+ }
509
522
  for (const arg of call.arguments) {
510
523
  if (arg.expression) {
511
524
  const taintCheck = isJavaScriptTaintedArgument(arg.expression, hasPropertyPatterns ? patterns : undefined);
@@ -1784,8 +1797,49 @@ function isRegexReceiver(receiver, sourceLines) {
1784
1797
  return true;
1785
1798
  if (!/^[A-Za-z_$][\w$]*$/.test(r) || !sourceLines)
1786
1799
  return false;
1787
- const decl = new RegExp(`(?:const|let|var)\\s+${escapeRe(r)}\\s*=\\s*(?:/|(?:new\\s+)?RegExp\\s*\\()`);
1788
- return sourceLines.some(l => decl.test(l));
1800
+ const n = escapeRe(r);
1801
+ const decl = new RegExp(`(?:const|let|var)\\s+${n}\\s*(?::\\s*RegExp\\s*)?=\\s*(?:/|(?:new\\s+)?RegExp\\s*\\()`);
1802
+ if (sourceLines.some(l => decl.test(l)))
1803
+ return true;
1804
+ // The literal on the next line (`const METHOD_DECL =\n /…/;`, dogfood
1805
+ // 2026-10-31: cognium-ai juliet-method-scope.ts `METHOD_DECL.exec(line)` was
1806
+ // a command_injection), or a `: RegExp` annotation with no initializer here.
1807
+ const wrapped = new RegExp(`(?:const|let|var)\\s+${n}\\s*(?::\\s*RegExp\\s*)?=\\s*$`);
1808
+ const typed = new RegExp(`\\b${n}\\s*[?!]?\\s*:\\s*RegExp\\b`);
1809
+ return sourceLines.some((l, i) => typed.test(l) ||
1810
+ (wrapped.test(l) && /^\s*(?:\/|(?:new\s+)?RegExp\s*\()/.test(sourceLines[i + 1] ?? '')));
1811
+ }
1812
+ /**
1813
+ * cognium-dev#985 follow-up (dogfood 2026-10-31) — the receiver's last property
1814
+ * is declared in this file with an explicit type that names no database
1815
+ * (`private backend: CacheBackend` → `this.backend.get(key)`). That is positive
1816
+ * evidence the `.get` is not sqlite's `db.get(sql)`; an untyped or DB-looking
1817
+ * declaration (`db: Database`, `pool: Pool`, `conn: Connection`) keeps the sink.
1818
+ */
1819
+ const DB_TYPE_NAME = /(?:connection|database|\bdb\b|db$|^db|pool|client|knex|sql|statement|prisma|sequelize|repository|transaction|query|store)/i;
1820
+ function isTypedNonDbReceiver(receiver, sourceLines) {
1821
+ const raw = (receiver ?? '').trim();
1822
+ if (!raw || !sourceLines)
1823
+ return false;
1824
+ const lastDot = raw.lastIndexOf('.');
1825
+ const name = (lastDot >= 0 ? raw.slice(lastDot + 1) : raw).trim();
1826
+ if (!/^[A-Za-z_$][\w$]*$/.test(name) || DB_TYPE_NAME.test(name))
1827
+ return false;
1828
+ // A `this.x` receiver is the class field: read only field declarations
1829
+ // (`private backend: CacheBackend;`), not same-named parameters or literals.
1830
+ const decl = raw.startsWith('this.')
1831
+ ? new RegExp(`^\\s*(?:(?:private|protected|public|readonly|static|declare)\\s+)+${escapeRe(name)}\\s*[?!]?\\s*:\\s*([A-Za-z_$][\\w$]*)\\s*[;=]`)
1832
+ : new RegExp(`\\b${escapeRe(name)}\\s*\\??\\s*:\\s*([A-Za-z_$][\\w$]*)\\s*[;,)=]`);
1833
+ let typed;
1834
+ for (const l of sourceLines) {
1835
+ const m = decl.exec(l);
1836
+ if (!m)
1837
+ continue;
1838
+ if (typed !== undefined && typed !== m[1])
1839
+ return false; // two declarations disagree
1840
+ typed = m[1];
1841
+ }
1842
+ return typed !== undefined && !DB_TYPE_NAME.test(typed) && !/^(?:any|unknown|object)$/.test(typed);
1789
1843
  }
1790
1844
  /**
1791
1845
  * cognium-dev#1000 — is this receiver named like a navigation object
@@ -1882,6 +1936,9 @@ function isDeclaredFunctionReference(arg, sourceLines) {
1882
1936
  new RegExp(`\\bfunction\\s+${n}\\s*\\(`),
1883
1937
  // const connect = () => / function / async () =>
1884
1938
  new RegExp(`\\b(?:const|let|var)\\s+${n}\\s*=\\s*(?:async\\s+)?(?:function\\b|\\(|[A-Za-z_$][\\w$]*\\s*=>)`),
1939
+ // A Promise executor's resolve / reject: `new Promise((r) => setTimeout(r, ms))`,
1940
+ // the sleep idiom (dogfood 2026-10-31, controldeck harness).
1941
+ 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*[,)])`),
1885
1942
  ];
1886
1943
  return sourceLines.some(l => decls.some(re => re.test(l)));
1887
1944
  }
@@ -2512,6 +2569,15 @@ function findSinks(calls, patterns, typeHierarchy, language, sourceLines, types)
2512
2569
  if (pattern.type === 'sql_injection' &&
2513
2570
  call.method_name === 'get' &&
2514
2571
  pattern.class === 'Connection' &&
2572
+ (language === 'javascript' || language === 'typescript') &&
2573
+ (isInMemoryMapGetReceiver(call.receiver, sourceLines) ||
2574
+ isTypedNonDbReceiver(call.receiver, sourceLines))) {
2575
+ continue;
2576
+ }
2577
+ // Dogfood 2026-10-31: the same Map evidence holds for every `.get`
2578
+ // sink, not just SQL — `tps.get(path)` with `tps: ReadonlyMap<…>`
2579
+ // matched `https.get` (SSRF) through the receiver-name heuristic.
2580
+ if (call.method_name === 'get' &&
2515
2581
  (language === 'javascript' || language === 'typescript') &&
2516
2582
  isInMemoryMapGetReceiver(call.receiver, sourceLines)) {
2517
2583
  continue;