Security operations

What Is XXE? XML External Entity Attacks Explained and Fixed

XXE turns a normal XML parser into a file reader for attackers. Here is how it works, where it hides, and the fix that stops it.

Cysoro Security TeamPublished · 6 min read
<!DOCTYPEENTITY xxeSYSTEM "file://"Disable DTDs Block entities SECURITY OPERATIONS What is XXE? A parser flaw that reads your files.
Quick answer

XXE, or XML External Entity injection, is an attack where a weakly configured XML parser resolves an external entity in untrusted XML input and reads a local file or makes a network request chosen by the attacker. It can disclose confidential data, cause denial of service, or lead to server-side request forgery. The fix is to disable DTDs entirely, or disable external entities and XInclude if DTDs are required.

Key takeaways

  • XXE happens when a parser resolves external entities in untrusted XML, reading files or making internal requests.
  • It can disclose files, cause denial of service through Billion Laughs, or lead to SSRF and port scanning.
  • The safest fix is to disable DTDs completely; if that is not possible, disable external entities and XInclude.

Your app accepts XML, a user uploads a file, and your parser quietly reads a file from your own server and hands it back. That is XXE, and it is not a new trick. It comes from a parser feature that was designed before security was a priority, and it still shows up in APIs, file uploads and single sign-on today.

What is XXE?

XXE, or XML External Entity injection, is an attack against an application that parses XML input. It occurs when XML input containing a reference to an external entity is processed by a weakly configured XML parser, which then reads a local file or makes a network request chosen by the attacker.

XML lets a document define shortcuts called entities in a DOCTYPE declaration. An external entity points to a file path or URL, and the parser fetches that resource when it reads the document. If the application returns the result, the attacker reads it; if it does not, the attacker can still steal data through other channels.

How does an XXE attack work?

An XXE attack follows four steps. First, the attacker finds an endpoint that accepts XML, such as an API body, a SOAP request or an uploaded file. Second, the attacker adds a DOCTYPE declaration that defines an external entity pointing to a sensitive resource.

Third, the attacker references that entity inside a field the application displays or processes. Fourth, the parser resolves the entity and fetches the resource. The classic example defines an entity that points to file:///etc/passwd and then uses it in a name field, so the parsed output contains the file contents.

How XXE works1Attacker sends XMLWith a DOCTYPEand external entity2Parser resolves itFetches a local fileor internal URL3App returns dataFile contents appearin the response4Attacker reads itOr exfiltrates itvia DNS or SSRFThe parser does the attacker's work: it fetches the resource the attacker named.
The parser does the attacker's work: it fetches the resource the attacker named. Illustration by Cysoro.

What are the main types of XXE attacks?

XXE attacks differ in how the attacker gets data out and where the malicious XML enters the application. The most common types are in-band, blind, SSRF-based and denial-of-service attacks, and the same vulnerable parser can often be used for several of them.

TypeAttacker sees the result?Main goal
In-band XXEYes, in the responseRead local files directly
Blind XXENo, via out-of-band channelsExfiltrate data through DNS or HTTP
SSRF via XXEIndirectlyReach internal systems and scan ports
Billion LaughsNoExhaust memory and CPU with nested entities
XInclude attackYes, if includedLoad resources without a DOCTYPE

In-band XXE is the simplest: the file contents appear in the application's response. Blind XXE is harder to spot, because the application does not return the result, so the attacker uses DNS requests or outbound HTTP calls to carry data out. SSRF via XXE forces the parser to make network requests inside your network, which can reach internal services and scan ports.

Billion Laughs: a denial-of-service variant

Billion Laughs needs no external access at all. It defines ten nested entities, each referring ten times to the one below, so a short document expands to around a billion characters during parsing and exhausts memory and CPU. Entity expansion limits in modern parsers mitigate it when they are enabled.

XInclude: the route without a DOCTYPE

XInclude is an alternative route where a DOCTYPE declaration is rejected but the application places user data inside a server-side XML document. XInclude does not need a document type declaration, so disabling DTDs alone does not stop it. Keep XInclude disabled unless you explicitly need it.

What does an XXE payload look like?

A typical in-band payload is short and easy to recognize once you have seen it. It starts with an XML declaration, then a DOCTYPE that defines an external entity, then a normal-looking document that uses that entity in a field.

Here is a simplified, illustrative example that reads a Unix password file. Do not use it against a system you do not own or have permission to test.

<?xml version="1.0"?><!DOCTYPE user [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]><user><name>&xxe;</name></user>1. DOCTYPE defines an external entity named xxe2. The entity points to a local file on the server3. The parser replaces &xxe; with the file contents
An illustrative XXE payload. The parser fetches the file the attacker named. Illustration by Cysoro.

The key line is the DOCTYPE. If your parser rejects DOCTYPE declarations, this payload fails before it can do anything. If it accepts them and resolves external entities, the file contents replace the entity reference in the parsed document.

Where does XXE hide in real applications?

XXE affects any software that parses XML. That includes SOAP and REST APIs that accept XML, SAML single sign-on, RSS feeds and file uploads in XML-based formats such as SVG, DOCX, XLSX and PDF forms.

It also hides in libraries. A secure setting on one parser does not reach another parser inside a document or image library, so you must check every parser in the application, including those inside third-party code. The same applies to XSLT style sheets and XML schemas, which can load external resources independently of external entities.

For a wider view of web risks, read our guide to spear phishing, which shows how attackers combine technical flaws with social engineering.

You can also check your site with our security headers checker.

What damage can XXE cause?

XXE can lead to disclosure of confidential data, denial of service, server-side request forgery, port scanning from the perspective of the machine where the parser is located, and other system impacts. The exact damage depends on what the parser can reach and whether the attacker can see the result.

File disclosure is the most common impact: configuration files, passwords, private keys and user data that the application server can read. SSRF is often more serious, because it lets the attacker reach internal services that are not exposed to the internet, such as cloud metadata endpoints, internal admin panels and databases.

XXE is tracked as CWE-611, improper restriction of XML external entity reference. It had 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. You can read the official guidance in the OWASP XXE Prevention Cheat Sheet.

How do you test for XXE?

The easiest way to test is to upload an XML document that tries to read an innocent local file, and see whether it succeeds. Use a harmless file you control, in a test environment, with written permission, and never test a production system you do not own.

Test every place XML enters the application: API bodies, SOAP requests, file uploads, SAML responses and RSS feeds. Test blind XXE too, by pointing an entity at a server you control and watching for DNS or HTTP requests. If the parser makes an outbound request, it is resolving external entities, even if it does not return the result.

Also test XInclude and parameter entities, which can bypass a simple DOCTYPE block. A parser that rejects DOCTYPE declarations but still processes XInclude is still vulnerable through a different route.

How do you prevent XXE?

The safest way to prevent XXE is always to disable DTDs completely. Depending on the parser, the method is similar to setting disallow-doctype-decl to true in Java. Disabling DTDs also makes the parser secure against denial-of-service attacks such as Billion Laughs.

If it is not possible to disable DTDs completely, then external entities and external document type declarations must be disabled in the way that is specific to each parser. In Java, set the external general and parameter entity features to false. In .NET, set DtdProcessing to prohibit. In Python, use the defusedxml package rather than the standard library parsers.

Prevent XXE in four steps1. Disable DTDsReject DOCTYPE declarations entirely2. Block external entitiesDisable general and parameter entities3. Disable XIncludeIt can load resources without a DOCTYPE4. Limit outbound accessAllow-list only the hosts the server needs
Apply the policy to every parser, including those inside libraries. Illustration by Cysoro.

Check every parser, keep parsers patched, and block outbound network access from application servers except to an allow-list. That last step neutralizes both the blind exfiltration channel and the request forgery, even if a parser setting is missed. Prefer JSON or another format for new APIs where you do not need XML at all, and validate input before parsing.

For developers, the OWASP cheat sheet gives parser-specific settings for Java, .NET, Python, PHP and other languages. The Wikipedia overview of XXE also explains the history and the main attack types in plain terms.

The bottom line

XXE is a parser configuration flaw, not a clever new attack. A weakly configured XML parser will fetch whatever file or URL an attacker names in a DOCTYPE, and that can expose files, reach internal systems or crash the server.

Disable DTDs entirely, block external entities and XInclude, check every parser in your application, and limit outbound access from your servers. You can check your public website security in seconds with the free security headers checker.

Frequently asked questions

What is XXE in simple terms?

XXE is an attack where a hacker sends XML that tells your server's parser to read a local file or visit an internal web address. The parser follows the instruction and returns the result, or sends it out through another channel.

What does XXE stand for?

XXE stands for XML External Entity. An external entity is a shortcut in an XML document that points to a file or URL, and the parser fetches that resource when it reads the document.

Is XXE still a problem in 2026?

Yes. XXE affects any software that parses XML, including APIs, SAML single sign-on and file uploads in XML-based formats such as SVG, DOCX and XLSX. It is now part of the OWASP Top 10 security misconfiguration category.

What is the Billion Laughs attack?

Billion Laughs is a denial-of-service attack using nested entity definitions. Ten entities, each referring ten times to the one below, expand a short document into roughly a billion characters during parsing, exhausting memory and CPU.

How do you prevent XXE?

Disable DTDs completely, which is the safest fix. If DTDs are required, disable external general and parameter entities, disable XInclude, and limit outbound network access from application servers to an allow-list.

Can XXE happen without a DOCTYPE?

Yes, through XInclude. XInclude does not need a document type declaration, so it can load resources even when DOCTYPE declarations are rejected. Keep XInclude disabled unless you explicitly need it.

What is CWE-611?

CWE-611 is the Common Weakness Enumeration entry for improper restriction of XML external entity reference. It is the standard identifier for the XXE weakness, used by vulnerability databases and scanners.

Should I still use XML in new applications?

Prefer JSON or another format for new APIs where you do not need XML. If you must use XML, use a hardened parser with DTDs disabled, and validate input before parsing.

Sources

  1. OWASP — XML External Entity Prevention Cheat Sheet
  2. Wikipedia — XML external entity attack
  3. Indusface — XML External Entity (XXE): How to Identify and Fix
  4. Detectify — OWASP Top 10: XXE
  5. Intigriti — XXE Vulnerabilities: XML External Entity Attacks and Fixes
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against the OWASP XXE Prevention Cheat Sheet, CWE-611 and the OWASP Top 10.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free