XXE Explained: The Bug That Reads Files the Server Should Never Show
Imagine uploading a document to a website and getting back the contents of the server’s password file instead. That is XXE — XML External Entity injection — and despite being an old bug, it still shows up in real applications and real bug bounties.
What Is XML, in 30 Seconds?
XML is a data format applications use to exchange structured information — configuration files, document uploads, API requests. It looks like this:
<user>
<name>Anony</name>
<email>anony@example.com</email>
</user>
XML has a feature called entities: shortcuts defined once and expanded wherever used. A general entity is harmless enough. An external entity is where the trouble starts: it tells the XML parser to fetch content from somewhere else — including a local file.
How the Attack Works
A vulnerable application accepts XML input and parses it with a parser that resolves external entities. An attacker submits:
<?xml version="1.0"?>
<!DOCTYPE user [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<user>
<name>&xxe;</name>
</user>
The parser sees &xxe;, reads /etc/passwd from the server’s own disk, and inserts its contents into the document. If the application then displays the name field, the attacker reads the file. Replace /etc/passwd with application config files, and the damage grows: database credentials, API keys, internal paths.
Worse variants exist. Blind XXE exfiltrates data to an attacker-controlled server when the application never displays the result. And XXE can also trigger server-side requests (SSRF) — asking the server to call internal services that should never be reachable from outside.
Where Hunters Find It
XXE hides wherever XML is parsed:
- File uploads that accept XML, SVG or Office documents (which are XML inside).
- APIs and SOAP web services that take XML bodies.
- SAML-based login flows, which are XML-heavy.
- Anywhere an application says “import” or “upload” and accepts structured data.
In a lab, the test is simple: submit XML with an external entity pointing at a file you control, and see whether its contents come back. PortSwigger’s Web Security Academy has free XXE labs — practice there, not on live sites.
How Developers Fix It
The fix is almost always a configuration change, not a rewrite:
- Disable external entities entirely in the XML parser. In most languages this is one setting — for example, disallow DOCTYPE declarations, or set the parser to never resolve external entities.
- Use a hardened parser configuration (OWASP publishes cheat sheets per language).
- Prefer JSON for new APIs, unless XML is genuinely required.
- Validate uploads — reject unexpected document types rather than parsing everything you receive.
If your application must parse XML from untrusted sources, disabling external entities is non-negotiable.
Why This Bug Still Matters
XXE has been known for over a decade, yet it keeps appearing — because XML parsers historically resolve external entities by default, and developers rarely change defaults. That is the real lesson: a parser’s default settings are a security decision, whether you made it consciously or not.
For bug bounty hunters, XXE is a high-value find precisely because it can escalate from a single upload field to full server file access. For defenders, one parser setting closes the whole class. Check yours today — only on systems you own or have written permission to test.



Comments
Post a Comment