Lesson 16 of 20 · 16m
XXE: the parser reads your filesystem
External entities turn any XML-ish input — SAML, docx, SVG — into file read plus SSRF, and the disabling flags differ per stack.
Hand an XML parser <!DOCTYPE r [<!ENTITY x SYSTEM "file:///etc/passwd">]> and it substitutes the file into &x; — external entities are a feature of XML, not a bug in your code. The same mechanism accepts http://169.254.169.254/latest/meta-data/iam/security-credentials/, which makes XXE a file read and an SSRF delivered in one DOCTYPE.
XXE earned its own slot at A4 in the OWASP Top 10 2017 (folded into Security Misconfiguration in 2021) because it keeps landing in everything that parses XML-ish bytes: SAML Responses, SOAP, RSS, SVG uploads, and .docx/.xlsx — zips of XML, which is how the well-documented 2014 Facebook careers XXE ran through a Word upload. Apache Solr's /update handler took an XXE via <dataConfig> in October 2017 (CVE-2017-12629) and read files off the server.
The defaults that betray you
Every major stack resolves entities differently, and "differently" historically means "on":
- Java:
DocumentBuilderFactoryandSAXParserFactoryresolved external entities for decades.XMLConstants.FEATURE_SECURE_PROCESSINGcaps entity expansion but does not stop external DTD fetches — the flag that does ishttp://apache.org/xml/features/disallow-doctype-decl, orsetAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, ""). - .NET:
XmlResolverfetched externals by default until .NET 4.5.2. The hardened shape isnew XmlReaderSettings { DtdProcessing = DtdProcessing.Prohibit, XmlResolver = null }withXmlReader.Create(stream, settings)— the settings, not the reader class, carry the policy. - PHP:
libxml_disable_entity_loader(true)was the old switch; PHP 8 removed it because libxml ≥2.9 stops loading external entities — exceptLIBXML_NOENT, which re-enables entity expansion. That flag insimplexml_load_stringcalls is the residual bug. - Python: stdlib
xml.etreedoesn't fetch external entities but does expand internal DTDs (the billion-laughs DoS — nested<!ENTITY>declarations that expandlol9into billions of repetitions), andlxml'sXMLParserresolves entities unless built withXMLParser(resolve_entities=False, no_network=True).defusedxmlexists solely to wrap the stdlib and kill DTDs outright — use it.
The Java form, written out:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
dbf.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");Blind XXE is the common case
Most apps don't echo the parsed document back, so nothing shows on screen — that stops nothing. Out-of-band XXE exfiltrates through the fetch itself: point the entity at http://attacker.example/ with the file contents baked into the URL or a parameter entity chain, and the data rides out on the parser's outbound request. no_network kills it dead; an egress filter on the app is the belt to that suspenders.
Why "we don't use XML" is half-wrong
You do: every .docx, .svg, SAML assertion, RSS import, and SOAP endpoint on the way in is XML. The parser usually lives inside a library you didn't pick, running with your process's filesystem and network reach — which is why XXE keeps surfacing in file-upload and SSO plumbing rather than in code anyone remembers writing. The cost asymmetry is why this matters: disallow-doctype-decl or resolve_entities=False costs nothing unless you genuinely parse DTD-bearing documents, which almost nothing does. Keep XInclude off too — <xi:include href="file:///etc/passwd" parse="text"/> is the sibling exfil path when XIncludeAware is enabled.
Practice
Where JSON works, use JSON and delete the XML path entirely. Where XML is mandatory — SAML, docx imports, legacy APIs — reject DOCTYPE at the boundary and set the flags above explicitly; FEATURE_SECURE_PROCESSING alone is not the fix. no_network/ACCESS_EXTERNAL_* matter as much as entity resolution: a parser that can't fetch can't leak. Audit the transitive parsers too — jackson-dataformat-xml, xstream, python-docx, anything rendering SVG — because the entity resolves inside the library, not inside your repo.
Keep reading
Related articles from the SudoSecurity blog.
Building a Production REST API With Node.js and Express
Build a REST API in Node.js and Express the way production systems need: input validation, JWT auth, refresh token rotation, status codes, rate limiting, idempotency keys, and centralized error handling.
RSA in JavaScript Part 2: The JWT Is Where You'll Actually Meet It
Most JavaScript developers never call an RSA function directly. They verify an RS256 token, and two classic attacks turn that into an authentication bypass — both demonstrated here, both fixed by one line.
RSA Signatures: The Version in Most Tutorials Is Forgeable
Signing is encryption with the keys swapped, and that symmetry is exactly what makes the naive implementation breakable. Here are two forgeries executed against textbook RSA signatures, and what PSS does that hashing alone cannot.
Ask Java for AES and You Get ECB. Nobody Warns You.
Cipher.getInstance("AES") compiles, runs, encrypts, decrypts, and hands you the weakest mode in the box. Here is the OpenJDK source that makes that decision, and the line where ECB gets chosen for you.