circle-ir 4.22.0 → 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.
- package/dist/analysis/config-loader.d.ts.map +1 -1
- package/dist/analysis/config-loader.js +6 -0
- package/dist/analysis/config-loader.js.map +1 -1
- package/dist/analysis/constant-propagation/patterns.d.ts +16 -8
- package/dist/analysis/constant-propagation/patterns.d.ts.map +1 -1
- package/dist/analysis/constant-propagation/patterns.js +18 -9
- package/dist/analysis/constant-propagation/patterns.js.map +1 -1
- package/dist/analysis/passes/language-sources-pass.d.ts.map +1 -1
- package/dist/analysis/passes/language-sources-pass.js +51 -0
- package/dist/analysis/passes/language-sources-pass.js.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.d.ts.map +1 -1
- package/dist/analysis/passes/sink-filter-pass.js +4 -3
- package/dist/analysis/passes/sink-filter-pass.js.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.d.ts.map +1 -1
- package/dist/analysis/passes/taint-propagation-pass.js +76 -11
- package/dist/analysis/passes/taint-propagation-pass.js.map +1 -1
- package/dist/browser/circle-ir.js +105 -8
- package/dist/core/circle-ir-core.cjs +44 -1
- package/dist/core/circle-ir-core.js +44 -1
- package/package.json +1 -1
|
@@ -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;
|
|
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
|
-
|
|
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
|
// ---------------------------------------------------------------------------
|