Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
XXE injection abuses an XML parser that resolves external entities, allowing an attacker to read server files, reach internal systems, or exhaust resources.

What Is XXE Injection?
XML has a feature, inherited from SGML, that few developers ever use deliberately: a document can declare entities, and an entity can point at an external resource. A parser configured to resolve them will fetch that resource and substitute its contents. XXE injection, catalogued as CWE-611, is what happens when the document came from a user and the parser was left in its historical default state.
<?xml version="1.0"?>
<!DOCTYPE root [<!ENTITY xxe SYSTEM "file:///etc/passwd">]>
<root>&xxe;</root>
If the parsed value is echoed back in the response, the file contents arrive with it. Swapping the scheme changes the attack: an http:// entity turns the parser into a server-side request forgery primitive that reaches internal services and cloud metadata, and on Java platforms a jar: entity can read inside archives. In PHP, the php://filter wrapper base64-encodes a file so that XML-invalid characters do not break parsing, which is how source code is retrieved.
Most applications do not return the parsed content, and the attack still works. An external DTD hosted by the attacker defines a parameter entity that embeds the stolen file into a URL, and the parser then requests that URL, delivering the data in the query string of an outbound connection. The error-based variation forces the parser to include the file contents in an error message instead. Both require only that the server can make an outbound request, which is why blocking egress from application servers is an effective mitigation in its own right.
Denial of service needs no external access at all. The billion laughs attack defines ten nested entities, each referring ten times to the one below, so a short document expands to around a billion characters and exhausts memory. Entity expansion limits in modern parsers address this, where they are enabled.
Teams often conclude they are unaffected because their API accepts JSON. XML is usually present somewhere less obvious:
The XInclude specification provides an alternative route where a DOCTYPE declaration is rejected but the application places user data inside a server-side XML document, since XInclude does not need a document type declaration at all.
http://apache.org/xml/features/disallow-doctype-decl to true on the factory; in .NET, set DtdProcessing to Prohibit; in Python, use the defusedxml package rather than the standard library parsers.XXE appeared as its own category, A4, in the OWASP Top 10 2017, and was merged into security misconfiguration in 2021, which reflects what it is: a parser left in an unsafe default. The defaults have improved, with libxml2 disabling network access for entities by default from version 2.9 and most modern frameworks shipping safe configurations, but legacy applications and bespoke parser code remain common findings. Testing means submitting an entity that triggers an outbound callback to every XML entry point, including uploaded documents and images, and watching for the interaction rather than the response. That is a standard element of our web application security testing.
Possibly. Check whether your endpoints parse XML when a request declares that content type, which some frameworks do automatically. Then look for XML arriving indirectly: uploaded Office documents and SVG images are XML, as are SAML assertions, and features that import configuration or data files frequently parse it. The absence of an XML API does not mean the absence of an XML parser.
Yes, and blind exploitation is the common case. An external DTD hosted by the attacker embeds the stolen file into a URL that the parser then requests, so the data leaves in an outbound connection rather than in the response. An error-based variant forces the contents into an error message. Both need only outbound network access from the server.
A denial of service using nested entity definitions. Ten entities, each referencing the one below it ten times, expand a small document into roughly a billion characters during parsing, exhausting memory and CPU. It needs no external network access, so it works even where external entities are disabled. Entity expansion limits in modern parsers mitigate it when they are enabled.
In nearly every case, yes. Document type definitions were designed for document validation and have no role in data interchange, so disabling them breaks almost nothing. If a legacy integration genuinely requires one, disable external general and parameter entities and XInclude instead, and keep the restriction as close to the parser factory as possible.
You May Be Interested In These
We use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.