XML external entities: parsers that fetch and read on behalf of a document
How DTD entity features let an XML document make the parser read local files or fetch URLs, where XML hides (SOAP, SAML, SVG, Office files), and how to disable DTDs in common parsers.
Diagram
A parser following an entity
Step 1 of 4
Upload
A user submits XML: an API body, an SVG, or a document.
# Upload # A user submits XML: an API body, an SVG, or a document.
The example on the open step is one illustration, or the fix you can paste into an application you own.
What this page is made of
3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.
XML is everywhere
- What fails
- SOAP APIs, SAML assertions, SVG images, RSS feeds, and DOCX and XLSX files are all XML.
- Who is affected
- Servers that parse any of those formats.
- What you would notice
- An upload or import feature that accepts those file types.
- What you change
- Inventory every parser and configure each to refuse DTDs.
Defaults vary
- What fails
- Some libraries resolve external entities by default, especially older Java and PHP configurations.
- Who is affected
- Applications that rely on defaults.
- What you would notice
- A parser created with no security features set.
- What you change
- Set the features explicitly and test them.
Blind variants
- What fails
- XXE can fetch URLs without showing content, which works like SSRF.
- Who is affected
- Internal services reachable from the parser host.
- What you would notice
- Outbound requests from a parsing service.
- What you change
- Disable DTDs and restrict egress from parsing services.
Confirming safely in a lab
Submit a small document whose external entity points at a canary URL you control. A request arriving at the canary shows the parser resolves external entities, without reading any local file.
<?xml version="1.0"?> <!DOCTYPE note [ <!ENTITY probe SYSTEM "https://canary.example.net/hb-xxe-7731"> ]> <note>&probe;</note> # canary log: GET /hb-xxe-7731 from 203.0.113.80 -> parser resolves external entities
Review walkthrough
Search for parser construction and check each for DTD settings. Dependencies count: a PDF, Office, or SAML library may parse XML internally with its own configuration.
Related pages
XInclude and Office documents covers formats that hide XML, and parsers in dependencies covers libraries you did not configure yourself.
Check yourself
Recognition and the fix. Nothing here is a procedure.
Which Java feature disables DOCTYPE declarations?
Go deeper
Specific techniques, exercises, and glossary cards for this topic.
- 01XInclude and XML features that fetchTurning off one entity switch is not the whole parser. Includes the diagram and a defensive fix.
- 02XML parsers you did not configureA dependency can parse XML with its own defaults even when your code’s parser is hardened. Includes the diagram and a defensive fix.