Explore our new Cybersecurity Terms Glossary, explained by our experts.

View the Glossary View the Glossary
PRIVIA

Cybersecurity Terms Glossary

What Is XXE Injection?

XXE injection abuses an XML parser that resolves external entities, allowing an attacker to read server files, reach internal systems, or exhaust resources.

Illustration for the cybersecurity term XXE Injection
Home / Blog / Cybersecurity Terms / What Is XXE Injection?
17 November 2026

What Is XXE Injection?

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.

The Payload

<?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.

Blind and Error-Based Variants

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.

Where the XML Hides

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.

Fixing It

  1. Disable DTD processing entirely. This is the complete fix and it costs nothing in almost every application, because DTDs serve no purpose in data interchange. In Java, set 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.
  2. Where a DTD is genuinely required, disable external general and parameter entities and switch off XInclude.
  3. Check every parser in the application, including those inside document and image libraries, since configuration applied to one factory does not reach another.
  4. Block outbound network access from application servers except to an allow-list, which neutralises both the blind exfiltration channel and the request forgery.
  5. Keep parsers patched through software composition analysis, as defaults have tightened over time and older versions behave differently.
  6. Prefer JSON for new interfaces, which has no equivalent feature.

Status and Testing

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.

FAQ – Frequently Asked Questions

We Only Accept JSON. Are We Exposed?

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.

Can XXE Be Exploited Without Seeing the Response?

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.

What Is the Billion Laughs Attack?

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.

Is Disabling DTDs Safe for Our Application?

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.

Related Terms

You May Be Interested In These

What Skills Does a Red Teamer Need?

Cybersecurity Terms

17 November 2026

What Skills Does a Red Teamer Need?

Read More
What Is Telematics Unit Security?

Cybersecurity Terms

17 November 2026

What Is Telematics Unit Security?

Read More
What Is Golden SAML?

Cybersecurity Terms

17 November 2026

What Is Golden SAML?

Read More