XXE: when the XML parser fetches for the attacker

An XML external entity (XXE) attack sends an XML document that defines an entity pointing to an outside resource, such as a local file or an internal URL. A parser configured to resolve external entities fetches it and puts the content into the document, which the application may then show, store or send back. The flaw is in the parser's configuration rather than in the application's logic.

Section Web attacks Updated Weakness CWE-611

Quick facts

Weakness
CWE-611: improper restriction of XML external entity reference
What it can do
Read local files, reach internal systems, exhaust memory
Where it hides
XML APIs, SOAP services, file uploads of office documents and SVG images
Main fix
Turn off DTDs and external entity resolution in every XML parser

Definitions follow OWASP and CWE-611.

How an XXE attack works

XML lets a document declare entities, named pieces of content, in a document type definition at the top. An external entity takes its content from a URI. If the parser resolves it, the content of that URI becomes part of the document.

An attacker who can send XML declares an external entity pointing at a file on the server or an internal address, and references it in a field the application returns. The application parses the document, and the response contains the file. The same mechanism makes the server request internal URLs, which is a form of SSRF.

What XXE is used for

  • Reading files. Configuration files and keys on the server, returned in the response.
  • Reaching internal systems. The parser requests internal URLs, as in server-side request forgery.
  • Blind data exfiltration. With no output, the entity sends data to a server the attacker controls.
  • Denial of service. Entities that expand into other entities, many levels deep, exhaust memory.

Many teams do not know they parse XML at all: office documents, SVG images and some single sign-on protocols are XML underneath. The parser can also be exhausted without any external reference; see XML bomb.

WHERE XML ARRIVES XML IS OBVIOUS SYNTAX VISIBLE TO A FILTER FIXED BY PARSER SETTINGS XML API OR SOAP OFFICE DOCUMENT UPLOAD SVG IMAGE UPLOAD SSO ASSERTION // three of four entry points do not look like XML at first
// four entry points, one fix for all of them

XXE vs XML injection

XML injection is the broader term: input that changes the structure of an XML document the application builds, for example by closing a tag early and adding elements of its own. It works like other injection, on the document, and can alter prices, roles or other values the receiving system trusts. Flaws where each request is valid but the outcome is wrong are covered under business logic flaws. Queries over XML have their own variant: XPath injection.

XXE attacks the parser rather than the document. It uses a feature of XML, the external entity, to make the parser fetch files or URLs while reading. The fixes differ accordingly: XML injection needs input encoded before it goes into a document, and XXE needs the parser configured to refuse external entities and document type definitions. A file can also reach the parser through an unrestricted file upload.

An XXE example, step by step

Imagine an endpoint that accepts an order as XML and replies with a confirmation that repeats the customer's name. The parser behind it was left with its defaults, which in older libraries include resolving external entities.

An attacker sends an order whose document type definition declares an entity pointing at a configuration file on the server, and puts a reference to that entity in the name field. The parser reads the file into the name, and the confirmation returns it. Turning off document type definitions in the parser makes the same request fail with an error instead.

The same request aimed at an internal address instead of a file turns the parser into a client for internal services, which is why XXE and SSRF are so often found together.

Finding XML parsers you did not know about

Many applications parse XML without anyone having chosen to. Office documents are compressed folders of XML files, so an upload that previews or converts them parses XML. SVG images are XML, so an image upload that resizes or inspects them may parse it too. Single sign-on based on SAML exchanges XML messages, and some APIs accept XML when the request says so, even if they were built for JSON.

A useful exercise is to list every place that accepts a file or a body from outside and ask which library reads it. Each one needs the same setting: external entities off.

What a WAF catches, and what it misses

A document type declaration with an external entity in a request body is a recognisable structure, and rule sets match it. That covers direct XML APIs.

It misses XML packed inside other formats, such as a zipped office document, and encodings the filter does not decode. Since the fix is a parser setting, the filter is a stopgap while the setting is changed everywhere. For comparison, a hidden-frame trick such as clickjacking is invisible to the server and is handled with headers, not parser settings.

How to prevent XXE

  1. Disable DTDs entirely where you can. This removes external entities and entity expansion at once; the OWASP XXE Prevention Cheat Sheet lists the setting for each common parser.
  2. Otherwise disable external entities and external DTDs. Both general and parameter entities.
  3. Find every parser. Including libraries that read documents, images and SSO messages.
  4. Prefer simpler formats such as JSON where you control both sides.
  5. Keep XML libraries updated. Newer versions often have safer defaults.

Questions

What is an XXE attack?

An XML external entity attack sends XML that defines an entity pointing to an outside resource, such as a local file or internal URL, so a misconfigured parser includes its content in the document.

How do you prevent XXE?

Disable document type definitions in XML parsers, or at least disable external entities and external DTDs, for every parser in the application, including those reading documents and images.

Is XXE still in the OWASP Top 10?

Yes, as a weakness rather than a category: CWE-611 is mapped to A02:2025 Security Misconfiguration.