A simple diagram of the XML External Entity (XXE) Injection risk path
Risk path: an input or context crosses a security boundary.
A simple three-step test path for XML External Entity (XXE) Injection
Testing path: establish a baseline, make one controlled change, and verify the effect.

Issue

XML (Extensible Markup Language) is a text format for storing and sharing structured information. It uses tags to label each piece of data. For example, <note><to>Sam</to><message>Hello</message></note> describes a note with a recipient and a message. Programs can read those tags and process the information inside them. W3C XML 1.0

An XML document can include a document type definition (DTD), which describes its structure and can define entities. An entity is a named value that the XML parser replaces while reading the document. Some entities contain text written inside the XML; an external entity points to a resource using a URI, such as a file or network address. If the parser is configured to resolve it, the parser may try to retrieve that resource.

XML External Entity (XXE) injection happens when an application parses XML that a user can influence and the parser follows an external entity declared in that XML. The flow is: the input defines an entity, the parser tries to load the resource, and the application may then use the returned content as part of the parsed document. If the application shows that content in its response, the issue is visible directly. If the content is not shown, the parser may still make a network request or reveal clues through another response or error; this is often called blind XXE. A request to another system is a possible server-side request forgery (SSRF) effect, but it depends on what the parser can reach and does not by itself prove that response data was exposed. OWASP XXE Prevention Cheat Sheet

XML support alone does not mean an application is vulnerable. The important question is whether untrusted XML reaches a parser that can resolve external resources, and whether the application exposes or acts on the result. Common entry points include XML APIs, SOAP services, imports, and file-processing features that parse XML-based formats such as SVG. Related steps such as schema validation or XSLT may also load external resources, so their settings need to be considered separately. Parser behavior depends on the library, version, and configuration. For a visual walkthrough of DTDs and entity resolution, see PwnFunction’s XXE explanation.

Examples

The requests send XML in the HTTP body using Content-Type: application/xml.

Basic XML request

POST /api/notes HTTP/1.1
Host: app.example.test
Content-Type: application/xml
 
<?xml version="1.0"?>
<note>
  <to>Sam</to>
  <message>Hello</message>
</note>

Here, the HTTP request is sent to /api/notes, and the XML document is the body after the blank line. A service must support XML on that endpoint for this example to be accepted.

XML request with an internal entity

POST /api/notes HTTP/1.1
Host: app.example.test
Content-Type: application/xml
 
<?xml version="1.0"?>
<!DOCTYPE note [
  <!ENTITY greeting "Hello">
]>
<note>
  <message>&greeting;</message>
</note>

The document defines greeting inside itself. When a parser processes the entity reference, it substitutes the text Hello into the message. This entity does not point to a file or network location.

XML request with an external entity

Replace probe.example with a controlled callback endpoint.

POST /api/import HTTP/1.1
Host: app.example.test
Content-Type: application/xml
 
<?xml version="1.0"?>
<!DOCTYPE note [
  <!ENTITY marker SYSTEM "https://probe.example/xxe-marker">
]>
<note>&marker;</note>

Here, SYSTEM tells the parser that marker refers to a resource outside the document. If the parser is allowed to resolve it, the server may try to request that URL. A matching request in a controlled callback log would show that a component attempted the fetch; it would not by itself show that the response content reached the user.

Reflected result

HTTP/1.1 200 OKContent-Type: application/json {"note":"CONTROLLED_TEST_MARKER"}

If the controlled endpoint returned CONTROLLED_TEST_MARKER and the application placed it in this response, that is evidence that the external entity’s value was resolved and exposed through the application. It does not demonstrate access to other files or services.

Response from a hardened parser

A hardened parser may reject the document because it contains a DOCTYPE, or may reject external resource resolution. The application should return a controlled error and avoid exposing parser internals. Valid XML that the feature is meant to accept should continue to work.

Impact

The impact depends on what the parser can access and what the application exposes:

  • File disclosure: If the parser can read a file and the application returns or otherwise reveals the resolved content, that content may be exposed.
  • Server-side requests: If the parser can contact a network resource, it may make requests from the server’s network. A tester-controlled callback can show that a request occurred, but does not by itself prove that response data was read or disclosed.
  • Resource exhaustion: XML entity expansion or other parsing behavior can consume excessive memory or processing time. This is a related XML denial-of-service risk; it is not proof that external entities were resolved.

These outcomes require specific conditions, including attacker-controlled XML reaching the relevant parser, the parser’s ability to access the resource, and an observable result or side effect. XXE evidence alone does not establish authentication bypass, account takeover, or broad data theft. OWASP XXE Prevention Cheat Sheet

Testing

1. Check external entity resolution

Send XML containing an external entity that refers to a controlled test resource. Compare the response and the resource’s access logs to see whether the parser resolved it.

Example: The application may return the entity value or fetch it without returning it. A parser error alone does not prove external access.

POST /api/import HTTP/1.1
Host: app.example.test
Content-Type: application/xml
 
<!DOCTYPE item [<!ENTITY xxe SYSTEM "https://marker.example.test/value.txt">]><item>&xxe;</item>

2. Check whether an entity can read a test file

In a controlled environment, point an external entity at a known marker file available to the test parser. Compare the response with the file’s known content and any parser logs.

Example: The marker appears only if that file is actually resolved and its value reaches the output. A parser error alone is not evidence that the file was read.

POST /api/import HTTP/1.1
Host: app.example.test
Content-Type: application/xml
 
<!DOCTYPE item [<!ENTITY xxe SYSTEM "file:///tmp/xxe-marker.txt">]><item>&xxe;</item>

3. Check alternate XML processing paths

Test each XML input and any feature that unpacks or transforms XML-based documents. Compare behavior when a document type declaration or external reference is present.

Example: An API and a document importer may use different XML parsers. A fix in one does not prove the other is protected.

POST /api/import HTTP/1.1
Host: app.example.test
Content-Type: application/xml
 
<!DOCTYPE item [<!ENTITY demo "hello">]><item>&demo;</item>

4. Review parser configuration and limits

Where code or configuration is available, check whether external entities, external DTDs, and unnecessary network access are disabled. Review entity expansion limits as a separate availability concern.

Example: A harmless internal entity can show parsing behavior. It does not prove external entities are enabled.

Interpret evidence carefully:

  • A correlated callback is evidence that a component made a network request. It does not prove file disclosure or that the application returned the callback response.
  • A marker appearing in parsed output is stronger evidence that the entity was resolved and its value propagated to that output.
  • A parser error, a changed status code, or a slower response is only an indicator. These can result from malformed XML, timeouts, or unrelated application behavior.
  • No callback does not prove safety: outbound traffic may be blocked, the parser may use a different resolver, or the request may not be observable.
  • Browser developer tools can show what XML the client sent and what response it received. They do not establish whether a server-side parser resolved an entity. Use server logs or controlled callback logs for that evidence.

Mitigation

Primary fixes

  • Disable DTD processing and external entity resolution for untrusted XML when the feature does not need them. Reject DOCTYPE declarations where the parser supports that control.
  • Apply the policy to every XML-processing component. Configure the parser, wrappers, validators, and transformation libraries actually used by the application. XSLT and schema processing can load external resources through mechanisms separate from XML external entities.
  • Fail closed. If a required security setting is unsupported or cannot be applied, stop processing untrusted XML rather than continuing with partial protections.
  • Use a narrow allowlist if external resources are required. Resolve only explicitly approved identifiers to known resources; do not allow arbitrary file or network locations.
  • Limit parser resources. Configure appropriate size, entity-expansion, and processing limits. Disabling XXE alone does not prevent every XML denial-of-service condition.

OWASP recommends disabling DTDs where possible and restricting external access in parsers and related processors. These controls vary by parser and version. OWASP XXE Prevention Cheat Sheet

Illustrative Java DOM configuration for the built-in JAXP provider on Java 9 or later:

DocumentBuilderFactory factory =    DocumentBuilderFactory.newDefaultInstance(); factory.setFeature(    "http://apache.org/xml/features/disallow-doctype-decl",    true);factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); DocumentBuilder builder = factory.newDocumentBuilder();Document document = builder.parse(untrustedXmlStream);

Treat failure to set a required feature as a configuration error. This snippet applies to this DOM parsing path; it does not automatically secure other providers, StAX readers, schema validators, XSLT processors, or wrapper libraries. Use the parser-specific guidance for the implementation in use. OWASP Java parser guidance

Additional defenses

Run XML-processing services with limited filesystem permissions and restrict unnecessary outbound network access. These measures can reduce the consequences of a parser flaw, but they do not replace secure parser configuration.

Retest

Repeat the same authorized tests after the change. Confirm that external references are not fetched or returned, that the application handles disallowed XML safely, and that valid required XML still works. Check every relevant processing path, including background jobs and document conversion.