An XML entity is a placeholder that the parser resolves. If it can resolve a SYSTEM entity, it can read a file or make a request.
The parser accepts a DTD and resolves external entities. The attacker declares an entity pointing to `file:///flag` and references it in a parsed field. The parser replaces the entity with the file contents.
We treat XML as data. The parser treats entities as instructions.
What is actually at stake?
Before touching a payload, map the assets, the actors and the boundary that is supposed to protect them. A finding only becomes a vulnerability when you can connect the failed boundary to a real asset.
Assets
- Local files and configuration
- Internal HTTP services
- Cloud metadata credentials
- Parser availability and application memory
Actors
- Attacker who controls an XML body or uploaded file
- Integration partner sending SAML or SOAP
- Malicious document imported by a back office
Trust boundaries
- XML document to parser entity resolver
- Parser to filesystem
- Parser to internal network
- Uploaded file to server-side preview
Abuse cases
- Define an external entity pointing to file:///etc/passwd
- Use an HTTP entity to reach an internal service
- Query cloud metadata for credentials
- Use nested entities to exhaust memory
- Exploit an XInclude or SVG parser path
Follow the decision, not the payload
Every family has a moment where trusted data becomes an authorization, parsing or state decision. Learn to point at that moment in the request path.
- 01
Receive XML
The application accepts XML for an API, import, SAML assertion, SVG or document preview.
- 02
Parse DTD
The parser reads a DOCTYPE and entity declarations, often with external resolution enabled by default.
- 03
Resolve entity
A SYSTEM identifier is fetched from the filesystem, an internal URL or an attacker-controlled server.
- 04
Substitute
The resolved content is inserted where the entity is referenced, and may appear in a response or error.
- 05
Expand
Nested or recursive entities can consume memory or CPU even when no data is returned.
WordPress media parsing XXE, 2021
WordPress 5.7.1 security release, 2021WordPress 5.7.1 addressed an XML external entity issue in a media-related parsing path. The vulnerable feature processed files that an authenticated author could upload.
A crafted file caused the XML parser to resolve an external entity. The issue required a privileged upload but demonstrated that media pipelines are part of the XML attack surface.
An attacker with upload rights could reach files or internal resources available to the web server, depending on parser configuration.
The parser accepted a DTD and resolved external entities for content that should have been treated as untrusted data.
Disable DTDs and external entity resolution, prefer JSON where possible, validate file types, and run parsers with least privilege.
Read it as a chain: discovery → failed decision → impact → fix. Then ask which link would have broken earliest.
A repeatable testing sequence
- Find XML, SOAP, SAML, SVG, RSS and import features.
- Declare a `SYSTEM` entity and reference it in a text field.
- Try `file:///flag`, HTTP callbacks and parameter entities.
- Look for the resolved value in the response or an error.
Where smart people get fooled
- JSON-only APIs can still have an XML import.
- A parser may resolve entities even when the response is quiet.
- Blocking `<!DOCTYPE` is not always enough.
What would the logs show?
A control is stronger when someone can see it fail. These signals are starting points for a detection rule, not a complete SIEM use case.
- XML bodies containing DOCTYPE, ENTITY or SYSTEM
- Outbound HTTP requests from the parser to unexpected hosts
- File access errors or paths in XML processing logs
- Large memory spikes during a small XML upload
- SVG or document uploads that trigger server-side parsing
index=web sourcetype=app_logs | eval xxe=if(match(request_body,"(?i)(<!DOCTYPE|<!ENTITY|SYSTEM|PUBLIC)"),1,0) | where xxe=1 | stats count values(path) by clientip, user_id | where count > 0Fix the decision, then prove it stays fixed
- Disable DTDs and external entity resolution.
- Use a safe parser configuration and least privilege.
- Reject XML where a simpler format would work.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(inputStream);DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
factory.setXIncludeAware(false);
factory.setExpandEntityReferences(false);Disable DTDs and external entities explicitly for every parser. Library defaults differ, and a safe default in one version can change in another.
Regression tests a reviewer would ask for
File entity
GivenAn endpoint accepts XML
WhenThe body declares an external entity pointing to a local file
ThenThe parser rejects the DTD and returns no file content
Internal HTTP entity
GivenThe parser can make network calls
WhenAn entity points to an internal service
ThenNo outbound request is made and the request is logged
XInclude
GivenThe parser supports XInclude
WhenThe document uses an XInclude directive
ThenXInclude is disabled or rejected
Expansion bomb
GivenA small XML document contains nested entities
WhenThe parser processes it
ThenExpansion is bounded and the request is rejected without exhausting memory
What this finding is not
Strong testers kill their own findings before someone else does. These are the shortcuts that turn a real bug into a weak report — or a false alarm into a wasted escalation.
- The parser rejects the DOCTYPE: external entities may already be disabled; test XInclude and alternate XML entry points.
- The entity is resolved but the response is empty: use an out-of-band callback to confirm the fetch.
- The endpoint accepts JSON only: check file imports, SAML, SOAP, SVG and document preview features.
- A billion-laughs payload times out: this is a denial-of-service finding even without file disclosure.
Terms you should be able to use precisely
- XML external entity
- A DTD entity that references content outside the document, such as a file or URL.
- DTD
- Document Type Definition: a schema and entity declaration block at the start of an XML document.
- XInclude
- An XML inclusion mechanism that can pull external content into a document.
- Billion laughs
- A denial-of-service attack using recursively expanded entities.
- Out-of-band
- Confirming a blind vulnerability through a callback to an attacker-controlled server.
- Parser hardening
- Explicitly disabling dangerous features such as DTDs, external entities and XInclude.
Answer these without reciting a payload
Why is XXE still common in modern applications?
XML appears in integrations, SAML, SOAP, SVG, office documents and preview pipelines. Parser defaults vary and developers often assume the endpoint is JSON-only.
How do you confirm blind XXE?
Use an external entity that points to a controlled HTTP or DNS endpoint, then observe the callback. Response content is not required.
What is the difference between XXE and SSRF?
XXE is an XML parser feature that can cause file reads or network requests. SSRF is a broader class where a server-side request is influenced by the client; XXE is one possible path to it.
Can you separate the mechanism from the payload?
Four questions, graded on the server. Answers and explanations are released only after you submit, and signed-in learners keep a best score.
XXE ليست ثغرة في XML نفسه، بل في قرار المحلل أن يقرأ تعريفات خارجية وينفذها نيابة عن المستخدم.
المدخل قد يكون API، أو ملف SAML، أو SVG، أو مستندًا يُعاين على الخادم. عطّل DTD والكيانات الخارجية وXInclude صراحةً في كل محلل، وافضل JSON حين لا تحتاج XML. اختبر أيضًا الحالة العمياء عبر خادم تستمع عليه، ولا تنسَ هجوم تضخيم الكيانات الذي يستهلك الذاكرة دون تسريب أي ملف.
What can an entity reference that a normal text node cannot?