XXE: when the XML parser fetches for the attacker
An XML external entity (XXE) attack sends an XML document that defines an entity pointing to an outside resource, such as a local file or an internal URL. A parser configured to resolve external entities fetches it and puts the content into the document, which the application may then show, store or send back. The flaw is in the parser's configuration rather than in the application's logic.
Quick facts
- Weakness
- CWE-611: improper restriction of XML external entity reference
- OWASP category
- A02:2025 Security Misconfiguration
- What it can do
- Read local files, reach internal systems, exhaust memory
- Where it hides
- XML APIs, SOAP services, file uploads of office documents and SVG images
- Main fix
- Turn off DTDs and external entity resolution in every XML parser
How an XXE attack works
XML lets a document declare entities, named pieces of content, in a document type definition at the top. An external entity takes its content from a URI. If the parser resolves it, the content of that URI becomes part of the document.
An attacker who can send XML declares an external entity pointing at a file on the server or an internal address, and references it in a field the application returns. The application parses the document, and the response contains the file. The same mechanism makes the server request internal URLs, which is a form of SSRF.
What XXE is used for
- Reading files. Configuration files and keys on the server, returned in the response.
- Reaching internal systems. The parser requests internal URLs, as in server-side request forgery.
- Blind data exfiltration. With no output, the entity sends data to a server the attacker controls.
- Denial of service. Entities that expand into other entities, many levels deep, exhaust memory.
Many teams do not know they parse XML at all: office documents, SVG images and some single sign-on protocols are XML underneath.
An XXE example, step by step
Imagine an endpoint that accepts an order as XML and replies with a confirmation that repeats the customer's name. The parser behind it was left with its defaults, which in older libraries include resolving external entities.
An attacker sends an order whose document type definition declares an entity pointing at a configuration file on the server, and puts a reference to that entity in the name field. The parser reads the file into the name, and the confirmation returns it. Turning off document type definitions in the parser makes the same request fail with an error instead.
The same request aimed at an internal address instead of a file turns the parser into a client for internal services, which is why XXE and SSRF are so often found together.
What a WAF catches, and what it misses
A document type declaration with an external entity in a request body is a recognisable structure, and rule sets match it. That covers direct XML APIs.
It misses XML packed inside other formats, such as a zipped office document, and encodings the filter does not decode. Since the fix is a parser setting, the filter is a stopgap while the setting is changed everywhere.
How to prevent XXE
- Disable DTDs entirely where you can. This removes external entities and entity expansion at once; the OWASP XXE Prevention Cheat Sheet lists the setting for each common parser.
- Otherwise disable external entities and external DTDs. Both general and parameter entities.
- Find every parser. Including libraries that read documents, images and SSO messages.
- Prefer simpler formats such as JSON where you control both sides.
- Keep XML libraries updated. Newer versions often have safer defaults.
Questions
What is an XXE attack?
An XML external entity attack sends XML that defines an entity pointing to an outside resource, such as a local file or internal URL, so a misconfigured parser includes its content in the document.
How do you prevent XXE?
Disable document type definitions in XML parsers, or at least disable external entities and external DTDs, for every parser in the application, including those reading documents and images.
Is XXE still in the OWASP Top 10?
Yes, as a weakness rather than a category: CWE-611 is mapped to A02:2025 Security Misconfiguration.