This article is a comprehensive guide to XXE (XML External Entity) injection vulnerabilities covering detection, exploitation techniques, and reporting. It explains how attackers exploit XML parsers' trust in document declarations to read local files, pivot to SSRF attacks, and exfiltrate data through various methods. The material matters because XXE remains prevalent in production systems due to insecure parser defaults, and file uploads—especially SVG and Office documents—represent a hidden attack surface that security professionals frequently overlook.
- How XXE exploits parser behaviorXXE works by declaring external entities in XML's DOCTYPE that instruct the parser to load resources from attacker-specified locations. When an entity like is resolved and the application echoes it back, the file contents appear in the response. The vulnerability exists because many XML parsers historically resolved external entities by default, and even patched modern systems often run legacy code or explicitly re-enable DTD processing for legitimate reasons without considering security implications.
- File uploads as hidden XML entry pointsSVG images, DOCX/XLSX/PPTX Office documents (which are ZIP archives containing XML), and PDFs with XMP metadata all contain XML internally and are frequently parsed server-side for rendering, thumbnail generation, or text extraction. An attacker embedding an XXE payload inside the XML within these uploaded files can exploit the parser despite the file format appearing innocuous. The article states this is 'one of the most common real-world XXE entry points because upload features rarely expect XML attacks.'
- In-band exploitation via reflected contentThe simplest XXE exploitation occurs when a declared external entity is referenced in a field the application echoes back in its response or error message. For example, injecting into a productId field and referencing it as &xxe; will display file contents in an 'Invalid product ID' error. The article emphasizes proving impact with harmless files like /etc/hostname rather than dumping sensitive data, requiring only a single request to confirm file-read capability.
- XXE pivots to internal SSRF attacksBy replacing file:// paths with http:// URLs in external entity declarations, the XML parser becomes an SSRF engine. An entity pointing at http://169.254.169.254/latest/meta-data/ or internal service URLs causes the server to make requests from the parser context, reaching cloud metadata endpoints and internal-only services. The article notes this is 'often the highest-impact XXE outcome' and that confirming reachability to metadata endpoints without extracting or using captured credentials is the appropriate reporting practice.
- Blind XXE exploitation via out-of-band exfiltrationWhen the parser processes entities but reflects no data, attackers host a malicious external DTD containing parameter entities (using % syntax) that read local files via php://filter/convert.base64-encode/resource= and embed the base64-encoded contents into a URL callback. The parser resolves these nested parameter entities during DTD processing and makes a request to the attacker's Collaborator listener with the exfiltrated data in the query string, proving file read despite zero reflected output.
- Error-based exfiltration when outbound networking blocksIf the server cannot make outbound HTTP requests but reflects XML parse errors, attackers can read files into a parameter entity then reference a non-existent file path that includes the data. When the parser tries to open file:///nonexistent/, it fails and echoes the full path in the 'file not found' error message, leaking the file contents through the error itself. This technique works when egress is firewalled but parse errors are reflected to the client.
- Parameter entities enable DTD-level exploitationParameter entities (declared and referenced with % syntax like %entity;) are resolved during DTD processing rather than document body parsing, making them essential for blind and out-of-band exploitation. The article explains that general entities (&entity;) won't work for blind XXE because they're only expanded in the document body which isn't reflected; parameter entities expand inside the DTD itself, allowing attackers to build nested entity chains that exfiltrate data even when the parsed document produces no output.
- Effective XXE reporting requires proof-of-concept specificityHigh-quality XXE reports include the exact endpoint, the exact injected payload, and evidence appropriate to the exploitation variant—reflected file contents for in-band, metadata responses for SSRF pivots, or decoded Collaborator callbacks for blind XXE. The article emphasizes naming the specific parser setting and flag for the target's technology stack (e.g., FEATURE_SECURE_PROCESSING for Java, disallow-doctype-decl for PHP libxml) rather than generic 'sanitize input' advice, as this demonstrates root-cause understanding and influences severity rating and triager response.
Bottom line: XXE severity scales with what an attacker can reach, from High for file read to Critical when SSRF pivots to cloud metadata or internal services; the most practical defense is disabling DTD processing and external entity resolution entirely in XML parsers, and the most commonly missed attack surface is file uploads containing XML (especially SVG and Office documents) that are parsed server-side for rendering or processing.
FREE
Part of the Bug Bounty 60-Day Course
/etc/hostname or the first line of a config file is sufficient proof. Never dump private keys, customer data, or credentials in bulk. For SSRF pivots, confirm reachability without extracting secrets. Stay within the programme’s scope and rules of engagement.<!ENTITY xxe SYSTEM "file:///etc/passwd"> — and referenced it where the response echoes a value. The parser dutifully opens the file and drops its contents into the response. From there it only gets worse: swap file:// for http://169.254.169.254 and the parser becomes an SSRF primitive reaching cloud metadata and internal services. And when nothing is reflected, a malicious external DTD exfiltrates the data to your server out-of-band. One parser setting left on by default turns a file upload into local file read, SSRF, and sometimes credential theft.🎯 What you’ll master in Day 38
⏱ ~30 min read · 3 hands-on exercises · Burp Suite + Collaborator + PortSwigger Academy
📋 XXE injection – Bug Bounty Day 38 of 60
What XXE is — external entities explained
XML documents can define entities — reusable placeholders, like variables. A normal internal entity is just a string: <!ENTITY name "SecurityElites">, and &name; expands to that string wherever it appears. An external entity, declared with the SYSTEM keyword, tells the parser to load its value from a URL or file path: <!ENTITY xxe SYSTEM "file:///etc/passwd">. When the parser resolves &xxe;, it opens that file and substitutes the contents. If the attacker controls the XML and the parser resolves external entities, the attacker controls which files and URLs the server opens.
The entity declarations live in the document’s DTD — the Document Type Definition — which can be inline in a <!DOCTYPE> block or loaded from an external URL. There are two flavors of entity: general entities (referenced as &entity; in the document body) and parameter entities (referenced as %entity; inside the DTD itself). Parameter entities are the key to blind and out-of-band exploitation, because they’re resolved during DTD processing even when the document body isn’t reflected.
The vulnerability exists because many XML parsers historically resolved external entities by default. Modern, patched defaults disable them — but countless applications still run parsers with the old behavior, or explicitly re-enable DTD processing for legitimate reasons and forget the security implications. The fix is simple (disable DTDs); the prevalence is high because the insecure behavior was the default for so long.
🧠 EXERCISE 1 — THINK LIKE A HACKER (10 MIN · NO TOOLS)
Reason about entry points and entity mechanics before testing:
- An app has a “bulk import” feature that accepts an XML file of products and echoes back which products it imported, including each product’s name. Where in this flow would you place an external entity reference, and what would you expect to see in the response if XXE works?
- A profile page lets you upload an avatar. You upload a PNG and it works. You upload an SVG and it also renders. Why does the SVG upload matter for XXE when the PNG doesn’t, and what is an SVG actually made of?
- The target parses your XML but the response is a fixed
{"status":"ok"}with none of your input reflected. Internal entities referencing files won’t show up anywhere. What category of XXE are you now in, and what two capabilities (one network, one not) could still let you prove and exploit it?
Finding XML entry points
XXE lives anywhere XML is parsed. The obvious entry points are request bodies with a Content-Type of application/xml or text/xml, SOAP endpoints, and SAML assertions. The non-obvious and often more fruitful entry points are file uploads, because so many formats are XML internally and upload handlers rarely anticipate XML attacks.
In-band file read
The simplest and most convincing XXE is in-band file read: you declare an external entity pointing at a local file and reference it in a value the response echoes back. If the file contents appear in the response, you have confirmed file read with a single request.
<?xml version="1.0"?>
<!DOCTYPE foo [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]>
<stockCheck><productId>&xxe;</productId></stockCheck>
RESPONSE 400 Invalid product ID:
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
…file contents reflected in the error message…
< or &), in-band read will fail to parse. Wrap the read in a CDATA section using nested parameter entities, or switch to out-of-band exfiltration which base64-encodes the data with the php://filter wrapper (on PHP targets: php://filter/convert.base64-encode/resource=/path). Base64 avoids the character problem entirely.Pivoting XXE to SSRF
Point the external entity at an internal URL instead of a file, and the XML parser becomes an SSRF engine. Every lesson from Day 33 applies — internal service discovery, cloud metadata, IAM credential disclosure — except the entry point is the XML parser rather than a URL parameter. This is often the highest-impact XXE outcome.
Blind XXE via a malicious DTD
When the application parses your XML but reflects nothing, you’re in blind XXE. The technique is out-of-band exfiltration using a malicious external DTD hosted on your server. The in-document DTD declares a parameter entity that loads your external DTD; your external DTD reads a local file into one parameter entity, then builds a second entity that embeds the file contents into a URL pointed at your Collaborator. When the parser resolves everything, it makes a request to your server with the file contents in the URL.
Error-based exfiltration
Sometimes the parser resolves external entities but cannot make outbound network requests (egress is firewalled), yet it reflects XML parse errors. You can smuggle the file contents into an error message by referencing a non-existent file path that includes the exfiltrated data — the parser’s “file not found” error echoes the path, and the path contains your data.
⚡ EXERCISE 2 — BURP LAB (25 MIN)
Work through PortSwigger Web Security Academy’s XXE labs:
- Start with Exploiting XXE to retrieve files. Intercept the stock-check request, inject a DOCTYPE with an external entity for
/etc/passwd, and confirm the contents reflect. - Do Exploiting XXE to perform SSRF. Point the entity at the EC2 metadata endpoint and retrieve the metadata — this is the XXE-to-SSRF pivot in practice.
- Do the Blind XXE labs: first out-of-band exfiltration with a malicious external DTD and Burp Collaborator, then error-based exfiltration. Host the DTD on the Collaborator or the lab’s exploit server.
- Finally, try an XXE via SVG image upload lab to see the file-upload entry point first-hand.
% entities, the nested % escape, the external DTD) are the part people trip on; doing the blind labs by hand once fixes that permanently.Writing the report that pays
An XXE report should let the triager reproduce with one request and immediately see the impact. Give the exact entry point, the exact payload, and the evidence appropriate to the variant — reflected file contents for in-band, the metadata response for SSRF, or the decoded Collaborator callback for blind. Then rate severity by what was actually reachable.
Severity: High (CVSS 8.6) — local file read confirmed; Critical if SSRF reaches cloud metadata/credentials (see impact)
Affected Endpoint: POST https://www.target.com/api/stock-check (Content-Type: application/xml)
Summary: The /api/stock-check endpoint parses the request body as XML with external entity resolution enabled. An attacker can declare an external entity pointing at a local file or internal URL; the parser resolves it, enabling local file disclosure and server-side request forgery from the XML parser.
Steps to Reproduce (file read):
1. POST to /api/stock-check with Content-Type: application/xml and body:
<?xml version=”1.0″?><!DOCTYPE foo [<!ENTITY xxe SYSTEM “file:///etc/hostname”>]><stockCheck><productId>&xxe;</productId></stockCheck>
2. Response reflects the contents of /etc/hostname in the “invalid product” error [screenshot attached]
Steps to Reproduce (SSRF pivot):
3. Replace the entity with SYSTEM “http://169.254.169.254/latest/meta-data/” → the response reflects the EC2 metadata index, confirming SSRF from the parser [screenshot attached]. I did not retrieve or use any credentials.
Impact: An unauthenticated attacker can read local server files and make server-side requests to internal-only services and the cloud metadata endpoint. Depending on IAM configuration this can escalate to credential disclosure and internal network compromise. Local file read alone exposes application source, configuration, and secrets.
Remediation: Disable DTD processing and external entity resolution in the XML parser. For this stack, set the parser to disallow DOCTYPE declarations entirely (e.g. FEATURE_SECURE_PROCESSING plus disallow-doctype-decl). If DTDs are genuinely required, disable external general and parameter entity resolution. Do not rely on input filtering — disable the feature at the parser.
⚡ EXERCISE 3 — WRITE THE REPORT (15 MIN)
Convert one of your PortSwigger XXE lab solves into a full report:
- Write the report using the template above for whichever variant you solved. Use the exact payload and the exact evidence (reflected contents or decoded callback). Keep the PoC to one request plus, for blind, the hosted DTD.
- Write the impact section for three scenarios and rate each: (a) read of a non-secret file only, (b) SSRF reaching internal services, (c) SSRF reaching the metadata endpoint that returns IAM credentials. Explain why the rating changes.
- Write the remediation specifically — name the parser setting for the target’s stack (pick one: Java DocumentBuilderFactory, .NET XmlReader, PHP libxml, Python lxml) and the exact flag that disables external entities. Generic “sanitize input” advice gets reports downgraded.
💰 Quick check: the target parses your XML but reflects nothing in the response, and your in-document external entity referencing a local file produces no output. Outbound HTTP from the server to your Collaborator also never fires. The response does, however, show XML parse errors. What is your best next move?
📋 Day 38 reference card
✅ Mark Day 38 complete
You can find XML entry points including hidden ones in file uploads, read local files in-band, pivot to SSRF, exfiltrate blind XXE out-of-band with a malicious DTD, fall back to error-based leakage, and write a report whose severity reflects exactly what you reached.
❓ Frequently asked questions
What is XXE injection?
What is blind XXE and how do you exploit it?
Can XXE be exploited through file uploads?
How does XXE become SSRF?
What severity does XXE usually get?
How is XXE fixed?
📚 Further reading
- SSRF — Day 33 — XXE frequently pivots into SSRF; everything in the SSRF guide (metadata, internal discovery, filter bypasses) applies once the entity points at an http:// URL.
- Burp Suite Deep Dive — Day 5 — Burp Repeater for editing XML bodies and Collaborator for catching blind XXE callbacks are the two core tools for this class.
- External: PortSwigger — XXE Injection — the complete free lab series covering file read, SSRF, blind out-of-band, and error-based exfiltration.
- External: OWASP XXE Prevention Cheat Sheet — the exact parser hardening settings per language, ideal to cite in the remediation section of a report.

