Web Security

What Is XXE? XML External Entity Injection Explained

A complete technical guide to XML External Entity (XXE) injection: how XML entities get abused to read files and pivot into SSRF, plus detection, verification, and prevention.

Intermediate13 min·Nyxeara Security Research·2026-09-16·CWE-611
xxeweb-securityxml-securityowasp-top-10
Prerequisites
what-is-httpwhat-is-xml

Short answer

XML External Entity (XXE) injection abuses a legitimate XML feature — entities that get replaced with external content before the document is processed — to make a server read local files or make outbound network requests it never intended to.

The idea in one minute

Imagine handing a form letter to a translator whose job description includes an unusual clause: if the letter contains an instruction like "insert the contents of the file at this location here," the translator will go get that file and paste its contents directly into the translation, no questions asked. Nobody thinks about this clause because ordinary letters never invoke it.

Now someone writes a letter that does. It says: "insert the contents of /etc/passwd here" — and the translator, following their job description exactly as written, fetches it and pastes it in. Nothing was hacked; the translator did precisely what they were always able to do. Nobody had simply given them a letter that asked for it before.

XML entities work the same way. They're a standard, decades-old XML feature for defining reusable substitution text — including text pulled from an external file or URL. XXE is what happens when an application parses attacker-supplied XML with that feature still switched on.

How XXE actually works

XML's Document Type Definition (DTD) syntax lets a document declare custom entities:

<!DOCTYPE foo [
  <!ENTITY myentity "some replacement text">
]>

Anywhere &myentity; appears in the document, the parser substitutes some replacement text. That's an internal entity — harmless. An external entity does the same thing, but the replacement content comes from a URI:

<!ENTITY xxe SYSTEM "file:///etc/passwd">

If a parser resolves external entities by default — which many do unless explicitly configured otherwise — and any part of the parsed document is reflected back to the requester, the attacker gets the contents of whatever file (or, using http:// instead of file://, whatever internal URL) they named.

When the response isn't reflected, XXE becomes blind: the attacker instead points the external entity at a URL they control, and the parser's outbound fetch itself becomes the signal — an SSRF-style out-of-band confirmation rather than a value shown on-page.

The request flow

sequenceDiagram
    participant Attacker
    participant App as Application (XML Parser)
    participant Resource as Local File / Internal Service

    Attacker->>App: XML document with malicious DOCTYPE/ENTITY
    App->>Resource: Parser resolves external entity (file:// or http://)
    Resource-->>App: File contents or internal response
    App-->>Attacker: Content substituted into parsed output (or observed out-of-band)

A minimal example

A malicious XML payload targeting a local file:

<?xml version="1.0"?>
<!DOCTYPE foo [
  <!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<foo>&xxe;</foo>

If an application parses this and echoes the contents of <foo> anywhere in its response, the file's contents appear in that response.

Vulnerable Python parsing (defaults vary by library and version, and older configurations resolve entities):

from lxml import etree
tree = etree.parse(user_supplied_xml_file)   # can resolve external entities

Hardened:

from lxml import etree
parser = etree.XMLParser(resolve_entities=False, no_network=True)
tree = etree.parse(user_supplied_xml_file, parser)

Or, more robustly, use a library built specifically to hold safe defaults (such as Python's defusedxml) rather than relying on remembering to set every flag correctly on every parser call.

Why the vulnerability exists

  • XML parsers have historically shipped with DTD and external entity processing enabled by default; disabling it is opt-in, not opt-out, in many languages and libraries
  • Developers accept raw XML from users without realizing the file format is XML — SVG images, DOCX/XLSX/PPTX documents (zipped XML internally), SAML authentication assertions, and RSS/Atom feeds all qualify
  • Input filtering is a weak defense here: there are many equivalent ways to express the same malicious DTD, making blocklists brittle
  • Fixes are applied to the "obvious" XML endpoint but missed on secondary XML parsing paths — file conversion services, document preview generators, middleware that re-parses uploaded files

What attackers look for

  • Any endpoint that accepts and parses XML directly
  • File uploads that are secretly XML: SVG, DOCX, XLSX, PPTX, ODF formats
  • SOAP-based APIs and SAML single sign-on flows
  • RSS/Atom import or "subscribe to feed" features
  • Legacy integrations where XML is still the primary interchange format

Detection

  • Static/code review: check XML parser initialization across every language and library in use — the specific flag to disable external entities differs by parser, so a single check doesn't cover a mixed-language codebase.
  • Dynamic/DAST: submit a payload with an external entity pointing at a canary domain you control, and watch for an inbound DNS/HTTP callback — this catches blind XXE that never reflects output.
  • File-format aware testing: test every feature that accepts SVG, Office documents, or other XML-based formats, not just endpoints that obviously say "XML" in their name.

Verification: real vulnerability or false positive?

Confirmed when either:

  • The response actually contains the substituted content (real file contents, or a distinguishing internal-service response) — not just an XML parsing error
  • An out-of-band interaction is received at infrastructure you control, uniquely tied to the payload sent

A parser that returns a generic error for malformed XML is not evidence of XXE by itself — many parsers reject external entities safely and simply fail differently. Confirm actual resolution, not just that the input was accepted.

Real-world impact

  • Local file disclosure: reading application source code, configuration files, or credential files from the server's filesystem
  • SSRF pivot: pointing external entities at internal-only HTTP endpoints, cloud metadata services, or internal APIs — XXE is frequently just SSRF delivered through an XML parser instead of a URL-fetch feature
  • Denial of service: the "Billion Laughs" attack nests internal entities recursively so their expansion grows exponentially, exhausting memory or CPU from a tiny input
  • Rare RCE paths: certain parser/language combinations expose gadget chains that escalate XXE into code execution, though this is less common than disclosure or SSRF outcomes

Prevention

  • Disable DTD processing entirely wherever the application doesn't genuinely need it — this is the single most effective control, per OWASP's own guidance, because it removes the entity mechanism altogether rather than trying to filter its use
  • If DTDs are required, disable external general and parameter entities specifically, and disable XInclude
  • Keep parsers and language runtimes current — several ecosystems (PHP 8+, Go's standard XML decoder) now ship safe-by-default behavior, but only in recent versions
  • Use a hardened wrapper library rather than manually setting flags on every raw parser instantiation across a codebase
  • Apply this to every XML-shaped file format, not just literal .xml uploads — SVG and Office document parsing paths need the same scrutiny

Related vulnerabilities

  • SSRF — the mechanism XXE most commonly escalates into once it reaches beyond simple file reads
  • Path traversal — a related "reach outside the intended boundary" primitive, often relevant to the same file-based attack surface
  • Denial of service — via entity expansion, a distinct impact from disclosure
  • File upload vulnerabilities — the delivery mechanism for XXE payloads disguised as SVG or Office documents

Testing methodology (do this safely)

  • Only test targets you're authorized to test.
  • Prefer out-of-band canary domains for detection over reading real local files, especially outside a dedicated lab environment.
  • Be cautious with entity-expansion (Billion Laughs) payloads — they can cause a genuine denial-of-service condition, so use them only where explicitly authorized and never against production systems without prior agreement.
  • Test every format that's secretly XML (SVG, DOCX, XLSX), not only endpoints labeled as XML.
  • Document the exact payload, the parser/library involved if known, and the evidence of resolution.

Further reading

Nyxeara perspective

Safe XML parser defaults vary wildly across languages, library versions, and even between two parsers in the same language — a config review alone can miss a genuinely exploitable path. Confirming actual entity resolution behavior, via file content or an out-of-band callback, is what separates "this library is probably safe" from a verified finding.

Published 2026-09-16 · Updated 2026-09-16