XXE Parser Defaults and Hardening
Per-language XML parser behavior: which libraries resolve external entities by default, which don’t, and the exact settings that close the gap — because in XXE the dangerous property is a default, not a call site.
Why defaults decide everything
XXE is “entirely a function of which option bits are set”; higher-level bindings differ only in which bits they set for you (XXE as a DAST Finding). Measured against current versions, most parsers at their defaults parse a DOCTYPE and expand internal entities but refuse external resolution — which is why a finding built only on “DOCTYPE processed” is a common false positive, and why the exact library version must be cited. Two anti-patterns recur: a flag flipped on by a wrapper, and a parser whose “harden” call covers only part of the surface.
Java
The highest-risk ecosystem — rich parser zoo, verbose error strings, and many wrappers. Core JAXP controls (OWASP XXE Prevention Cheat Sheet, Parsers Should Not Fetch Files):
- DocumentBuilderFactory / SAXParserFactory: set
http://apache.org/xml/features/disallow-doctype-decl= true and enableFEATURE_SECURE_PROCESSING; keep XInclude off. If a DTD is required, disable external general entities, external parameter entities, andload-external-dtd. - XMLInputFactory (StAX):
SUPPORT_DTD= false andIS_SUPPORTING_EXTERNAL_ENTITIES= false. - TransformerFactory / SchemaFactory / Validator: set
ACCESS_EXTERNAL_DTD,ACCESS_EXTERNAL_SCHEMA,ACCESS_EXTERNAL_STYLESHEETto empty string — schema validation and XSLT resolve entities too. JVM-wide, the matchingjavax.xml.accessExternalDTD/...Schema/...Stylesheetsystem properties were the recommended Struts CVE-2025-68493 mitigation (Apache Struts XWork XXE). - Wrappers replace your resolver: dom4j (
SAXReader), JDOM (SAXBuilder), commons-digester (Digester) all swap the underlying reader’s entity resolver — harden through the wrapper’s own API, not the raw reader. setExpandEntityReferences(false)is not a fix — on JDOM2 2.0.6.1 it only disables external general entities, leaving parameter entities and external DTD subsets live (Apache Roller CVE-2026-105153) (Apache Roller AtomPub XXE).- Never feed untrusted XML to
java.beans.XMLDecoder— blocking entities doesn’t remove its deserialization risk (OWASP XXE Prevention Cheat Sheet). - Per-path parser construction. Apache Camel CVE-2026-85250 (CWE-611, fixed 4.18.5 / 4.22.x; 4.14.x EOL unfixed): with
documentType=InputSource,XPathBuilderhanded the payload tojavax.xml.xpath, which built its ownDocumentBuilderwith JDK defaults, so a DOCTYPE refused on Camel’s hardened default document type was accepted and external entities resolved. ChoosingInputSourcefor streaming silently chose a weaker parser (Apache Camel CVE-2026-85250). - Validation is not hardening. PMD’s
TestSchemaParser.newDocumentBuilderenabled schema validation but never disabled DTDs or external entities; a crafted rule-tests XML read a local file into the test description, which became a JUnit dynamic test name and leaked through CI build logs (GHSA-9hm5-r2r7-hjcq) (PMD rule-test XXE). - JAXB unmarshalling resolves external entities unless fed a hardened StAX reader — IBM ApplinX (CVE-2026-92877), Eclipse AAS4J (CVE-2026-127031) (Eclipse AAS4J XmlSchemaValidator XXE).
.NET
Safety is version-gated at 4.5.2:
XmlDocument,XmlTextReader,XPathNavigatorare unsafe before 4.5.2 (theirXmlResolvermust be set to null); safe by default at ≥4.5.2.XmlReader/XmlDictionaryReader/XmlNodeReaderandXDocument/LINQ-to-XML are safe by default, and at ≥4.5.2 won’t even process an inline DTD unless you explicitly re-enable it.- ASP.NET must also set
<httpRuntime targetFramework="4.5.2+"/>— omitting the tag reverts to unsafe-by-default regardless of the actual framework (OWASP XXE Prevention Cheat Sheet). Legacy .NET defaults are exactly why OOXML upload parsers are XXE sinks (XXE Hidden in Cell A2).
PHP / libxml2
Since libxml 2.9.0, entity substitution is off by default (OWASP XXE Prevention Cheat Sheet).
- Do not pass
LIBXML_NOENT,LIBXML_DTDLOAD, orLIBXML_DTDVALIDon untrusted XML — any of these re-enables the class (SymfonyXmlUtils::parse()validateOnParse=true, CVE-2026-45071, enabled DTD validation and letfile://entities resolve before doctype rejection) (Symfony Config XmlUtils::parse XXE). - In libxml2 directly, ensure
XML_PARSE_NOENTandXML_PARSE_DTDLOADare unset. The substitute-entities bit alone enables general-entity file reads; DTD-load adds external DTDs. - To reject external entities, install a
libxml_set_external_entity_loader()callback that returns null — passingnulldirectly is not equivalent and does not block loading (per PHP’s own advisory) (OWASP XXE Prevention Cheat Sheet). - Internal entity expansion (quadratic/billion-laughs DoS) is not blocked by 2.9+ defaults — bound expansion separately (PhpSpreadsheet ISO-2022 Bypass).
Python
Built-in parsers use Expat, which doesn’t access files/network by default (OWASP XXE Prevention Cheat Sheet). Measured defaults (XXE as a DAST Finding):
xml.etree.ElementTree,minidom,xml.saxexpand internal entities, resolve no external entity by default. A SAX finding hinges on whetherfeature_external_geswas turned on (that one switch enables file read);feature_external_pescan’t even be enabled on Expat.- lxml: from version 5.0 the default is
resolve_entities='internal'(wasTruebefore 5.0 — pre-5.0 code reads external entities by default). That 5.0 change covered only the normal XML and HTML parsers:iterparse()andETCompatXMLParser()keptresolve_entities=Trueuntil lxml 6.1, so default use of either read local files (GHSA-vfmq-68hx-4jfw); on older versions passresolve_entities='internal'orFalseexplicitly (lxml iterparse XXE). The default still loads local external parameter entities (a DTD fragment on disk), and network access depends on whether the linked libxml2 was built with HTTP support — cite the measuredLIBXML_FEATURES. Setresolve_entities=False,no_network=True, DTD loading off;etree.iterparse()insecurely configured was CVE-2025-6984 in langchain-community (langchain-community XXE). lxml’s default parser read Tandoor Recipes’.envvia an XML importer (Tandoor Recipes lxml XXE). - Use defusedxml for untrusted XML; set
forbid_dtd=Truewhere available. Keep input size and decompressed size bounded independently (xmlrpcis decompression-bomb-prone). XInclude is a separate file-read path — don’t run the XInclude step on untrusted input.
Node.js, Ruby, C/C++
- Node:
sax1.4.1 (strict) andfast-xml-parser5.2.5 do not resolve external entities by default (“External entities are not supported”) — but this is “not by default here,” not a guarantee for every Node XML library (libxmljswraps libxml2 and can be configured unsafely) (XXE as a DAST Finding). - Ruby/Nokogiri: default parse options are safe, but enabling
DTDLOAD/DTDVALID/NOENTon untrusted XML is dangerous; on JRuby theNONEToption was bypassed for short-form IPv4 hosts (http://127.1/) and absolute paths — SSRF to external DTDs/entities (GHSA-v995-44v6-5fqm, fixed Nokogiri 1.19.5) (JRuby NONET Bypass). - C/C++: libxml2 — don’t set
XML_PARSE_NOENT/XML_PARSE_DTDLOAD; Xerces-C++ —setDisableDefaultEntityResolution(true)orXMLUni::fgXercesDisableDefaultEntityResolution(OWASP XXE Prevention Cheat Sheet).
Cross-cutting principles
- Fail closed — if a parser doesn’t support a security setting, stop rather than parse partly hardened (Parsers Should Not Fetch Files).
- Same hardened factory everywhere — one forgotten
DocumentBuilderin a utility class undoes the rest, and so does a library that builds its own parser on an alternate code path (Camel XPath withInputSource). - Dev tooling parses untrusted XML too — test-fixture XML from a pull request runs in CI with access to runner secrets (PMD).
- Parse before auth is the worst case — SAML/SOAP/provisioning parsers that run before permission checks turn any default-on parser into a pre-auth bug (Apache Roller AtomPub XXE).
- SAST caveat — model XXE as parser construction/use with DTD or external-entity options enabled on untrusted data; crediting a denylist “sanitizer” it doesn’t actually protect is the classic false result (XXE as a DAST Finding).
Related
Sources
- Apache Camel CVE-2026-85250 · original
- XML External Entity Prevention Cheat Sheet | OWASP · original
- Protecting Input from XXE using Python · original
- XXE as a DAST Finding · original
- Eclipse AAS4J XmlSchemaValidator XXE · original
- JRuby NONET Bypassed for External DTDs · original
- lxml: default iterparse()/ETCompatXMLParser() allows XXE to local files · original
- PhpSpreadsheet XmlScanner bypass via ISO-2022 escapes allows XXE · original
- PMD: local file reads through XXE in rule tests · original
- Tandoor Recipes lxml XXE · original
- The File That Answered Back — XXE Hidden in Cell A2 · original
- XXE Injection: How It Works and How to Fix It · original
- Apache Roller AtomPub XXE · original
- XXE in Apache Struts CVE-2025-68493 · original
- XXE in langchain-community (CVE-2025-6984) · original
- Symfony Config XmlUtils::parse XXE · original
- Parsers Should Not Fetch Files: XXE Hardening Guide · original