# 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 ([[raw/dedsecops.com/xxe-as-a-dast-finding-in-band-error-based-and-out-of-band-confirmation-14210|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 ([[raw/cheatsheetseries.owasp.org/xml-external-entity-prevention-owasp-cheat-sheet-series-2059|OWASP XXE Prevention Cheat Sheet]], [[raw/vicytech.com/parsers-should-not-fetch-files-xxe-hardening-guide-after-cisco-broadwo-14648|Parsers Should Not Fetch Files]]): - **DocumentBuilderFactory / SAXParserFactory:** set `http://apache.org/xml/features/disallow-doctype-decl` = true and enable `FEATURE_SECURE_PROCESSING`; keep XInclude off. If a DTD is required, disable external general entities, external parameter entities, and `load-external-dtd`. - **XMLInputFactory (StAX):** `SUPPORT_DTD` = false and `IS_SUPPORTING_EXTERNAL_ENTITIES` = false. - **TransformerFactory / SchemaFactory / Validator:** set `ACCESS_EXTERNAL_DTD`, `ACCESS_EXTERNAL_SCHEMA`, `ACCESS_EXTERNAL_STYLESHEET` to empty string — schema validation and XSLT resolve entities too. JVM-wide, the matching `javax.xml.accessExternalDTD`/`...Schema`/`...Stylesheet` system properties were the recommended Struts CVE-2025-68493 mitigation ([[raw/sangfor.com/xxe-in-apache-struts-cve-2025-68493-3131|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) ([[raw/kearikan.com/apache-roller-xxe-in-atompub-entry-parsing-15488|Apache Roller AtomPub XXE]]). - Never feed untrusted XML to **`java.beans.XMLDecoder`** — blocking entities doesn't remove its deserialization risk ([[raw/cheatsheetseries.owasp.org/xml-external-entity-prevention-owasp-cheat-sheet-series-2059|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`, `XPathBuilder` handed the payload to `javax.xml.xpath`, which built its own `DocumentBuilder` with JDK defaults, so a DOCTYPE refused on Camel's hardened default document type was accepted and external entities resolved. Choosing `InputSource` for streaming silently chose a weaker parser ([[raw/camel.apache.org/apache-camel-cve-2026-85250-15823|Apache Camel CVE-2026-85250]]). - **Validation is not hardening.** PMD's `TestSchemaParser.newDocumentBuilder` enabled 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) ([[raw/github.com/pmd-local-file-reads-through-xxe-in-rule-tests-15825|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) ([[raw/github.com/eclipse-aas4j-3-0-1-xmlschemavalidator-xxe-cve-2026-127031-14501|Eclipse AAS4J XmlSchemaValidator XXE]]). ## .NET Safety is version-gated at **4.5.2**: - `XmlDocument`, `XmlTextReader`, `XPathNavigator` are **unsafe before 4.5.2** (their `XmlResolver` must be set to null); safe by default at ≥4.5.2. - `XmlReader`/`XmlDictionaryReader`/`XmlNodeReader` and `XDocument`/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 ([[raw/cheatsheetseries.owasp.org/xml-external-entity-prevention-owasp-cheat-sheet-series-2059|OWASP XXE Prevention Cheat Sheet]]). Legacy .NET defaults are exactly why OOXML upload parsers are XXE sinks ([[raw/infosecwriteups.com/the-file-that-answered-back-xxe-hidden-in-cell-a2-10182|XXE Hidden in Cell A2]]). ## PHP / libxml2 Since **libxml 2.9.0**, entity substitution is off by default ([[raw/cheatsheetseries.owasp.org/xml-external-entity-prevention-owasp-cheat-sheet-series-2059|OWASP XXE Prevention Cheat Sheet]]). - Do **not** pass `LIBXML_NOENT`, `LIBXML_DTDLOAD`, or `LIBXML_DTDVALID` on untrusted XML — any of these re-enables the class (Symfony `XmlUtils::parse()` `validateOnParse=true`, CVE-2026-45071, enabled DTD validation and let `file://` entities resolve before doctype rejection) ([[raw/symfony.com/symfony-config-xmlutils-parse-xxe-via-validateonparse-13205|Symfony Config XmlUtils::parse XXE]]). - In libxml2 directly, ensure `XML_PARSE_NOENT` and `XML_PARSE_DTDLOAD` are 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** — passing `null` directly is **not** equivalent and does not block loading (per PHP's own advisory) ([[raw/cheatsheetseries.owasp.org/xml-external-entity-prevention-owasp-cheat-sheet-series-2059|OWASP XXE Prevention Cheat Sheet]]). - Internal entity expansion (quadratic/billion-laughs DoS) is **not** blocked by 2.9+ defaults — bound expansion separately ([[raw/github.com/phpspreadsheet-xmlscanner-bypass-via-iso-2022-escapes-allows-xxe-12615|PhpSpreadsheet ISO-2022 Bypass]]). ## Python Built-in parsers use **Expat**, which doesn't access files/network by default ([[raw/cheatsheetseries.owasp.org/xml-external-entity-prevention-owasp-cheat-sheet-series-2059|OWASP XXE Prevention Cheat Sheet]]). Measured defaults ([[raw/dedsecops.com/xxe-as-a-dast-finding-in-band-error-based-and-out-of-band-confirmation-14210|XXE as a DAST Finding]]): - `xml.etree.ElementTree`, `minidom`, `xml.sax` expand internal entities, resolve no external entity by default. A SAX finding hinges on whether `feature_external_ges` was turned on (that one switch enables file read); `feature_external_pes` can't even be enabled on Expat. - **lxml:** from version **5.0** the default is `resolve_entities='internal'` (was `True` before 5.0 — pre-5.0 code reads external entities by default). That 5.0 change covered only the normal XML and HTML parsers: **`iterparse()` and `ETCompatXMLParser()` kept `resolve_entities=True` until lxml 6.1**, so default use of either read local files (GHSA-vfmq-68hx-4jfw); on older versions pass `resolve_entities='internal'` or `False` explicitly ([[raw/github.com/lxml-default-iterparse-etcompatxmlparser-allows-xxe-to-local-files-15827|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 measured `LIBXML_FEATURES`. Set `resolve_entities=False`, `no_network=True`, DTD loading off; `etree.iterparse()` insecurely configured was CVE-2025-6984 in langchain-community ([[raw/security.snyk.io/xxe-injection-in-langchain-community-cve-2025-6984-4624|langchain-community XXE]]). lxml's default parser read Tandoor Recipes' `.env` via an XML importer ([[raw/github.com/tandoor-recipes-xxe-local-file-read-via-lxml-and-ssrf-in-importer-12618|Tandoor Recipes lxml XXE]]). - Use **defusedxml** for untrusted XML; set `forbid_dtd=True` where available. Keep input size and decompressed size bounded independently (`xmlrpc` is 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:** `sax` 1.4.1 (strict) and `fast-xml-parser` 5.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 (`libxmljs` wraps libxml2 and can be configured unsafely) ([[raw/dedsecops.com/xxe-as-a-dast-finding-in-band-error-based-and-out-of-band-confirmation-14210|XXE as a DAST Finding]]). - **Ruby/Nokogiri:** default parse options are safe, but enabling `DTDLOAD`/`DTDVALID`/`NOENT` on untrusted XML is dangerous; on **JRuby** the `NONET` option 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) ([[raw/github.com/jruby-nonet-bypassed-for-external-dtds-and-entities-14049|JRuby NONET Bypass]]). - **C/C++:** libxml2 — don't set `XML_PARSE_NOENT`/`XML_PARSE_DTDLOAD`; Xerces-C++ — `setDisableDefaultEntityResolution(true)` or `XMLUni::fgXercesDisableDefaultEntityResolution` ([[raw/cheatsheetseries.owasp.org/xml-external-entity-prevention-owasp-cheat-sheet-series-2059|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 ([[raw/vicytech.com/parsers-should-not-fetch-files-xxe-hardening-guide-after-cisco-broadwo-14648|Parsers Should Not Fetch Files]]). - **Same hardened factory everywhere** — one forgotten `DocumentBuilder` in a utility class undoes the rest, and so does a library that builds its own parser on an alternate code path (Camel XPath with `InputSource`). - **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 ([[raw/kearikan.com/apache-roller-xxe-in-atompub-entry-parsing-15488|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 ([[raw/dedsecops.com/xxe-as-a-dast-finding-in-band-error-based-and-out-of-band-confirmation-14210|XXE as a DAST Finding]]). ## Related - [[XML External Entity Injection]] - [[Blind XXE]] - [[XXE via File Uploads]] - [[XInclude Attacks]] ## Sources - [[raw/camel.apache.org/apache-camel-cve-2026-85250-15823|Apache Camel CVE-2026-85250]] - [[raw/cheatsheetseries.owasp.org/xml-external-entity-prevention-owasp-cheat-sheet-series-2059|XML External Entity Prevention Cheat Sheet | OWASP]] - [[raw/cloudmersive.medium.com/how-to-protect-text-input-from-xml-external-entity-xxe-attacks-using-p-467|Protecting Input from XXE using Python]] - [[raw/dedsecops.com/xxe-as-a-dast-finding-in-band-error-based-and-out-of-band-confirmation-14210|XXE as a DAST Finding]] - [[raw/github.com/eclipse-aas4j-3-0-1-xmlschemavalidator-xxe-cve-2026-127031-14501|Eclipse AAS4J XmlSchemaValidator XXE]] - [[raw/github.com/jruby-nonet-bypassed-for-external-dtds-and-entities-14049|JRuby NONET Bypassed for External DTDs]] - [[raw/github.com/lxml-default-iterparse-etcompatxmlparser-allows-xxe-to-local-files-15827|lxml: default iterparse()/ETCompatXMLParser() allows XXE to local files]] - [[raw/github.com/phpspreadsheet-xmlscanner-bypass-via-iso-2022-escapes-allows-xxe-12615|PhpSpreadsheet XmlScanner bypass via ISO-2022 escapes allows XXE]] - [[raw/github.com/pmd-local-file-reads-through-xxe-in-rule-tests-15825|PMD: local file reads through XXE in rule tests]] - [[raw/github.com/tandoor-recipes-xxe-local-file-read-via-lxml-and-ssrf-in-importer-12618|Tandoor Recipes lxml XXE]] - [[raw/infosecwriteups.com/the-file-that-answered-back-xxe-hidden-in-cell-a2-10182|The File That Answered Back — XXE Hidden in Cell A2]] - [[raw/invadel.com/xxe-injection-how-it-works-and-how-to-fix-it-13890|XXE Injection: How It Works and How to Fix It]] - [[raw/kearikan.com/apache-roller-xxe-in-atompub-entry-parsing-15488|Apache Roller AtomPub XXE]] - [[raw/sangfor.com/xxe-in-apache-struts-cve-2025-68493-3131|XXE in Apache Struts CVE-2025-68493]] - [[raw/security.snyk.io/xxe-injection-in-langchain-community-cve-2025-6984-4624|XXE in langchain-community (CVE-2025-6984)]] - [[raw/symfony.com/symfony-config-xmlutils-parse-xxe-via-validateonparse-13205|Symfony Config XmlUtils::parse XXE]] - [[raw/vicytech.com/parsers-should-not-fetch-files-xxe-hardening-guide-after-cisco-broadwo-14648|Parsers Should Not Fetch Files: XXE Hardening Guide]]