circle-ir 4.21.1 → 4.23.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 (65) hide show
  1. package/dist/analysis/config-loader.d.ts.map +1 -1
  2. package/dist/analysis/config-loader.js +12 -0
  3. package/dist/analysis/config-loader.js.map +1 -1
  4. package/dist/analysis/constant-propagation/patterns.d.ts +16 -8
  5. package/dist/analysis/constant-propagation/patterns.d.ts.map +1 -1
  6. package/dist/analysis/constant-propagation/patterns.js +18 -9
  7. package/dist/analysis/constant-propagation/patterns.js.map +1 -1
  8. package/dist/analysis/findings.d.ts.map +1 -1
  9. package/dist/analysis/findings.js +14 -6
  10. package/dist/analysis/findings.js.map +1 -1
  11. package/dist/analysis/passes/_js-crypto-binding.d.ts +53 -0
  12. package/dist/analysis/passes/_js-crypto-binding.d.ts.map +1 -0
  13. package/dist/analysis/passes/_js-crypto-binding.js +123 -0
  14. package/dist/analysis/passes/_js-crypto-binding.js.map +1 -0
  15. package/dist/analysis/passes/hardcoded-secret-argument-pass.d.ts +85 -0
  16. package/dist/analysis/passes/hardcoded-secret-argument-pass.d.ts.map +1 -0
  17. package/dist/analysis/passes/hardcoded-secret-argument-pass.js +351 -0
  18. package/dist/analysis/passes/hardcoded-secret-argument-pass.js.map +1 -0
  19. package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
  20. package/dist/analysis/passes/language-sources-pass.js +53 -2
  21. package/dist/analysis/passes/language-sources-pass.js.map +1 -1
  22. package/dist/analysis/passes/missing-auth-middleware-pass.d.ts +56 -0
  23. package/dist/analysis/passes/missing-auth-middleware-pass.d.ts.map +1 -0
  24. package/dist/analysis/passes/missing-auth-middleware-pass.js +255 -0
  25. package/dist/analysis/passes/missing-auth-middleware-pass.js.map +1 -0
  26. package/dist/analysis/passes/prototype-pollution-pass.d.ts +78 -0
  27. package/dist/analysis/passes/prototype-pollution-pass.d.ts.map +1 -0
  28. package/dist/analysis/passes/prototype-pollution-pass.js +736 -0
  29. package/dist/analysis/passes/prototype-pollution-pass.js.map +1 -0
  30. package/dist/analysis/passes/redos-regex-literal-pass.d.ts +106 -0
  31. package/dist/analysis/passes/redos-regex-literal-pass.d.ts.map +1 -0
  32. package/dist/analysis/passes/redos-regex-literal-pass.js +637 -0
  33. package/dist/analysis/passes/redos-regex-literal-pass.js.map +1 -0
  34. package/dist/analysis/passes/scan-secrets-pass.d.ts +3 -0
  35. package/dist/analysis/passes/scan-secrets-pass.d.ts.map +1 -1
  36. package/dist/analysis/passes/scan-secrets-pass.js +3 -3
  37. package/dist/analysis/passes/scan-secrets-pass.js.map +1 -1
  38. package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
  39. package/dist/analysis/passes/sink-filter-pass.js +4 -3
  40. package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
  41. package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
  42. package/dist/analysis/passes/taint-propagation-pass.js +100 -11
  43. package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
  44. package/dist/analysis/passes/weak-crypto-pass.d.ts.map +1 -1
  45. package/dist/analysis/passes/weak-crypto-pass.js +7 -1
  46. package/dist/analysis/passes/weak-crypto-pass.js.map +1 -1
  47. package/dist/analysis/passes/weak-hash-pass.d.ts.map +1 -1
  48. package/dist/analysis/passes/weak-hash-pass.js +7 -1
  49. package/dist/analysis/passes/weak-hash-pass.js.map +1 -1
  50. package/dist/analysis/passes/weak-password-hash-pass.d.ts.map +1 -1
  51. package/dist/analysis/passes/weak-password-hash-pass.js +7 -1
  52. package/dist/analysis/passes/weak-password-hash-pass.js.map +1 -1
  53. package/dist/analyzer.d.ts.map +1 -1
  54. package/dist/analyzer.js +12 -0
  55. package/dist/analyzer.js.map +1 -1
  56. package/dist/browser/circle-ir.js +1834 -154
  57. package/dist/core/circle-ir-core.cjs +114 -80
  58. package/dist/core/circle-ir-core.js +114 -80
  59. package/dist/core/extractors/imports.js +18 -1
  60. package/dist/core/extractors/imports.js.map +1 -1
  61. package/dist/types/index.d.ts +5 -0
  62. package/dist/types/index.d.ts.map +1 -1
  63. package/dist/wasm/web-tree-sitter.wasm +0 -0
  64. package/docs/SPEC.md +1 -0
  65. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"taint-propagation-pass.d.ts","sourceRoot":"","sources":["../../../src/analysis/passes/taint-propagation-pass.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAe9E,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB;AAkmBD,qBAAa,oBAAqB,YAAW,YAAY,CAAC,0BAA0B,CAAC;IACnF,QAAQ,CAAC,IAAI,uBAAuB;IACpC,QAAQ,CAAC,QAAQ,EAAG,UAAU,CAAU;IAExC,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,0BAA0B,CAm0BhD;CACF;AA2vDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA6FnE"}
1
+ {"version":3,"file":"taint-propagation-pass.d.ts","sourceRoot":"","sources":["../../../src/analysis/passes/taint-propagation-pass.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAe9E,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB;AA+nBD,qBAAa,oBAAqB,YAAW,YAAY,CAAC,0BAA0B,CAAC;IACnF,QAAQ,CAAC,IAAI,uBAAuB;IACpC,QAAQ,CAAC,QAAQ,EAAG,UAAU,CAAU;IAExC,GAAG,CAAC,GAAG,EAAE,WAAW,GAAG,0BAA0B,CAw0BhD;CACF;AAmyDD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA6FnE"}
@@ -473,6 +473,20 @@ function goConstantHelperCalleeFromLines(lines, lineNumber) {
473
473
  }
474
474
  return null;
475
475
  }
476
+ /**
477
+ * Whether `step` is a variable produced by an HTML-context encoder
478
+ * that does not clean `sinkType` (#589 `sanitizedVarUncovered`, scoped
479
+ * `method:var`; a bare name looks up only its own method).
480
+ */
481
+ function encoderLeavesSinkUncovered(constProp, graph, step, sinkType) {
482
+ const unc = constProp.sanitizedVarUncovered;
483
+ if (!unc || unc.size === 0)
484
+ return false;
485
+ if (step.variable.includes(':'))
486
+ return !!unc.get(step.variable)?.has(sinkType);
487
+ const method = methodAtLine(graph, step.line);
488
+ return !!unc.get(method ? `${method}:${step.variable}` : step.variable)?.has(sinkType);
489
+ }
476
490
  function makeConstPropVeto(constProp, graph, sources, code, language, sanitizers) {
477
491
  const lines = typeof code === 'string' ? code.split('\n') : [];
478
492
  const selfReassign = new Map();
@@ -505,7 +519,7 @@ function makeConstPropVeto(constProp, graph, sources, code, language, sanitizers
505
519
  const use = (graph.usesByLine.get(line) ?? []).find(u => u.variable === v && u.def_id != null);
506
520
  return use ? graph.defById.get(use.def_id) : undefined;
507
521
  };
508
- return (step, sourceLine, sinkLine, sinkType) => {
522
+ return (step, sourceLine, sinkLine, sinkType, encodedUpstream) => {
509
523
  // cognium-dev#1198 — heap-field stamped sources are not in constProp.tainted.
510
524
  if (step.variable.includes('.') &&
511
525
  sources.some((s) => s.variable === step.variable &&
@@ -523,6 +537,12 @@ function makeConstPropVeto(constProp, graph, sources, code, language, sanitizers
523
537
  return false;
524
538
  if (r.reason !== 'variable_not_tainted')
525
539
  return true;
540
+ // An earlier step is the output of an HTML-context encoder
541
+ // that does not clean this sink type (`sql = "…" + encodeForHTML(p)`).
542
+ // const-prop's "not tainted" for a value derived from it is that encoder's
543
+ // credit, which does not apply here.
544
+ if (encodedUpstream)
545
+ return false;
526
546
  if (r.reason === 'variable_not_tainted' &&
527
547
  language === 'java' &&
528
548
  method &&
@@ -699,9 +719,15 @@ export class TaintPropagationPass {
699
719
  const verifiedFlows = propagationResult.flows.filter(flow => {
700
720
  if (constProp.unreachableLines.has(flow.sink.line))
701
721
  return false;
722
+ // Once the path passes a variable whose HTML-context encoder
723
+ // leaves this sink type uncovered, later steps are not vetoed as
724
+ // "not tainted" (see `encodedUpstream` in makeConstPropVeto).
725
+ let encodedUpstream = false;
702
726
  for (const step of flow.path) {
703
- if (isVetoed(step, flow.source.line, flow.sink.line, flow.sink.type))
727
+ if (isVetoed(step, flow.source.line, flow.sink.line, flow.sink.type, encodedUpstream))
704
728
  return false;
729
+ if (!encodedUpstream)
730
+ encodedUpstream = encoderLeavesSinkUncovered(constProp, graph, step, flow.sink.type);
705
731
  }
706
732
  if (isCorrelatedPredicateFP(constProp, flow))
707
733
  return false;
@@ -1627,18 +1653,57 @@ function isInJavaSanitizedMethod(code, types, sinkLine, sinkType) {
1627
1653
  return true;
1628
1654
  }
1629
1655
  if (sinkType === 'xxe') {
1630
- // DocumentBuilderFactory / SAXParserFactory / XMLInputFactory hardening.
1631
- // Any one of these features suffices per the OWASP XXE cheatsheet.
1632
- const setFeatureRe = /\.setFeature\s*\(\s*"(?:[^"]*disallow-doctype-decl|[^"]*external-general-entities|[^"]*external-parameter-entities|[^"]*load-external-dtd)"/;
1633
- if (setFeatureRe.test(body))
1634
- return true;
1635
- // setProperty variant for XMLInputFactory: `XMLInputFactory.SUPPORT_DTD`.
1636
- if (/\.setProperty\s*\([^,]*SUPPORT_DTD[^,]*,\s*false\s*\)/.test(body))
1637
- return true;
1638
- return false;
1656
+ return isHardenedXmlFactory(body);
1639
1657
  }
1640
1658
  return false;
1641
1659
  }
1660
+ /**
1661
+ * cognium-dev#1291 / #1293 follow-up — does this Java method body harden an XML
1662
+ * factory against XXE? One table shared by every factory kind (DocumentBuilder,
1663
+ * SAXParser, XMLInputFactory, TransformerFactory, SchemaFactory, XMLReader).
1664
+ *
1665
+ * Hardened when ANY of these appears in the body:
1666
+ * 1. setFeature("…disallow-doctype-decl | external-general-entities |
1667
+ * external-parameter-entities | load-external-dtd", …) — a string literal.
1668
+ * 2. setProperty(…SUPPORT_DTD…, false) — XMLInputFactory.
1669
+ * 3. set{Attribute,Property}(…ACCESS_EXTERNAL_{DTD,STYLESHEET,SCHEMA}…, "")
1670
+ * or the literal "http://javax.xml.XMLConstants/property/accessExternal…"
1671
+ * URI, with the value argument checked to be the EMPTY STRING. Covers both
1672
+ * the direct `tf.setAttribute(NAME, "")` form and a wrapper call such as
1673
+ * angus-mail's `setAttribute(tf, NAME, "")`.
1674
+ *
1675
+ * FEATURE_SECURE_PROCESSING is deliberately NOT accepted: on its own it does not
1676
+ * stop external entity or DTD resolution (JAXP). A non-empty access value such
1677
+ * as "all" or "file" is NOT hardening and must not match (#1293 regression: it
1678
+ * cleared `ACCESS_EXTERNAL_DTD="all"` because it never checked the value).
1679
+ *
1680
+ * Limits (unchanged from the prior recognizer): matching is textual and
1681
+ * method-scoped — it does not verify the hardened factory is the one used at the
1682
+ * sink, and an occurrence inside a comment or a log string is not excluded (the
1683
+ * accessExternal* URI itself contains "//", so cheap comment-stripping would
1684
+ * corrupt it).
1685
+ */
1686
+ function isHardenedXmlFactory(body) {
1687
+ // (1) Feature flags that disable DTD / external-entity processing.
1688
+ const setFeatureRe = /\.setFeature\s*\(\s*"(?:[^"]*disallow-doctype-decl|[^"]*external-general-entities|[^"]*external-parameter-entities|[^"]*load-external-dtd)"/;
1689
+ if (setFeatureRe.test(body))
1690
+ return true;
1691
+ // (2) XMLInputFactory SUPPORT_DTD = false.
1692
+ if (/\.setProperty\s*\([^,]*SUPPORT_DTD[^,]*,\s*false\s*\)/.test(body))
1693
+ return true;
1694
+ // (3) External-access lockdown set to the empty string. The name (XMLConstants
1695
+ // constant or literal property URI) is matched only when the value argument is
1696
+ // the empty string, so a non-empty value like "all"/"file" is not credited.
1697
+ // A permissive value on ANY external-access attribute (e.g. ACCESS_EXTERNAL_DTD
1698
+ // = "all" alongside ACCESS_EXTERNAL_STYLESHEET = "") vetoes the credit — the
1699
+ // open vector is still exploitable, so the method is not treated as hardened.
1700
+ const accessName = '(?:ACCESS_EXTERNAL_(?:DTD|STYLESHEET|SCHEMA)\\b|"https?:\\/\\/javax\\.xml\\.XMLConstants\\/property\\/accessExternal(?:DTD|Stylesheet|Schema)")';
1701
+ const emptyExternalAccessRe = new RegExp(`${accessName}\\s*,\\s*""`);
1702
+ const permissiveExternalAccessRe = new RegExp(`${accessName}\\s*,\\s*"[^"]+"`);
1703
+ if (emptyExternalAccessRe.test(body) && !permissiveExternalAccessRe.test(body))
1704
+ return true;
1705
+ return false;
1706
+ }
1642
1707
  // ---------------------------------------------------------------------------
1643
1708
  // Helpers (moved verbatim from analyzer.ts)
1644
1709
  // ---------------------------------------------------------------------------
@@ -3435,6 +3500,25 @@ function sinkNestedInJsTsParseArgs(lineText, sinkMethod) {
3435
3500
  }
3436
3501
  return false;
3437
3502
  }
3503
+ /**
3504
+ * For a source and a `redos` sink on the same line: the source's expression
3505
+ * (`req.query.p` from `req.query.p in handler`) is inside a call argument at
3506
+ * one of the sink's pattern positions. Sources tagged with an LHS variable
3507
+ * (`re = RegExp(...)`) carry no expression and do not qualify.
3508
+ */
3509
+ function redosColocatedInPatternArg(source, sink, calls) {
3510
+ if (source.variable)
3511
+ return false;
3512
+ const loc = source.location ?? '';
3513
+ const at = loc.indexOf(' in ');
3514
+ const expr = (at >= 0 ? loc.slice(0, at) : loc).trim();
3515
+ if (expr.length < 3)
3516
+ return false;
3517
+ const positions = sink.argPositions && sink.argPositions.length > 0 ? sink.argPositions : [0];
3518
+ return calls.some(c => c.location.line === sink.line &&
3519
+ c.method_name === sink.method &&
3520
+ c.arguments.some(a => positions.includes(a.position) && (a.expression ?? '').includes(expr)));
3521
+ }
3438
3522
  function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachableLines, tainted, code, language, types) {
3439
3523
  const flows = [];
3440
3524
  // #472 — Go function ranges for the same-function gate below. Returns the
@@ -4857,6 +4941,11 @@ function detectExpressionScanFlows(calls, sources, sinks, sanitizers, unreachabl
4857
4941
  // JSDoc for the per-sink policy).
4858
4942
  if (!sourceSemanticsAllowed(source, sink.type))
4859
4943
  continue;
4944
+ // A colocated request value reaches a `redos` sink only as the pattern
4945
+ // argument: `new RegExp(req.query.p)`, not `req.query.p.match(/x/)` or
4946
+ // Java `request.getParameter("x").matches("[a-z]+")`.
4947
+ if (sink.type === 'redos' && !redosColocatedInPatternArg(source, sink, calls))
4948
+ continue;
4860
4949
  // cognium-dev#1156 — sink nested only inside `.parse(` args (same line).
4861
4950
  const colocLineText = sink.code ?? '';
4862
4951
  if (colocLineText &&