XXE

Also known as: XML external entity · XML external entity injection

On this page 7

XXE, short for XML external entity injection, is a vulnerability in which an application parses untrusted XML with a parser that resolves attacker-controlled entity declarations, allowing the attacker to read local files, reach internal network services or exhaust server resources. Application security teams treat it as a parser configuration flaw rather than a coding bug in the business logic, because the dangerous behavior comes from features that many XML libraries enabled by default for years.

Within cybersecurity, XXE sits close to SSRF and path traversal, since its most common impacts are server-side requests and unauthorized file disclosure. It appeared as its own category in the 2017 edition of the OWASP Top 10 and was later folded into the broader security misconfiguration category, which reflects its root cause: an unsafe default that developers did not switch off.

How XML external entities are resolved

An XXE attack works because the XML specification allows a document to declare a Document Type Definition (DTD), and a DTD may define entities that the parser substitutes into the document. An external entity points to a URI, such as file:///etc/passwd or an internal HTTP address, and a compliant parser fetches that resource and inserts its contents wherever the entity is referenced.

The attacker therefore needs only two things: an endpoint that accepts XML and a parser that processes DTDs and resolves external references. A typical payload declares <!DOCTYPE with a SYSTEM entity and then references it inside a field that the application echoes back in its response. The server, not the attacker, performs the file read or network request, which is why XXE bypasses perimeter firewalls.

The following table summarizes the entity types involved and the role each plays in an attack.

Entity typeDeclared asRole in an attack
General internal entityLiteral text valueBuilding blocks for expansion attacks
General external entitySYSTEM or PUBLIC URIReads files or triggers server-side requests
Parameter entityPercent sign prefix in the DTDBuilds dynamic DTDs for blind exfiltration
External DTD subsetURI in the DOCTYPE lineLoads attacker-hosted declarations
Entity types relevant to XXE

Variants and impact of XXE attacks

XXE comes in several variants that differ in how the attacker receives the data and what the payload is meant to achieve. The simplest is in-band XXE, where the resolved content appears directly in the application response. When the response does not reflect the entity, attackers turn to blind XXE and rely on side channels.

Blind techniques use out-of-band exfiltration: a parameter entity loads an external DTD from an attacker server, and that DTD constructs a second request whose URL contains the stolen file content. Another blind method triggers error-based disclosure, in which the parser reports a failed lookup whose error message includes the file contents.

VariantData channelTypical impact
In-band XXEApplication responseDirect reading of local files
Blind out-of-band XXEDNS or HTTP to attacker hostExfiltration without visible output
Error-based XXEParser error messagesFile content leaked in errors
XXE to SSRFInternal HTTP requestsAccess to cloud metadata and admin services
Billion laughsNone neededDenial of service through entity expansion
Common XXE variants compared

The billion laughs attack is technically an entity expansion attack rather than an external entity attack, yet it is usually discussed alongside XXE because the same DTD processing enables it. Nested internal entities expand exponentially, so a document of about one kilobyte can demand gigabytes of memory. In some environments, such as PHP with the expect wrapper, XXE can even escalate to remote command execution, although this is rare.

Where XXE hides in modern applications

XXE is not limited to legacy SOAP services; it appears wherever XML is parsed implicitly, often in places developers do not associate with XML. Office documents, vector images and federated identity messages are all XML underneath, so an upload or login flow can expose the same parser weakness.

  • SOAP and XML-RPC endpoints that accept request bodies directly.
  • File uploads of DOCX, XLSX, PPTX and SVG files, which are ZIP containers or XML documents.
  • SAML assertions in single sign-on flows, which are parsed before the signature is verified.
  • REST endpoints that silently accept application/xml when the content type is changed.
  • RSS and Atom feed importers, sitemap parsers and configuration import features.

The content-type switch deserves particular attention. Many frameworks bind request bodies to objects regardless of format, so an endpoint designed for JSON may parse XML if the client sends that header. Testers routinely try this substitution because it exposes forgotten parser paths that never received hardening.

Preventing XXE through parser hardening

The most reliable defense against XXE is to disable DTD processing entirely in every XML parser that handles untrusted input. If DTDs are genuinely required, the fallback is to disable external entity resolution and external DTD loading while limiting entity expansion. Input validation and filtering of the word DOCTYPE are weak substitutes because encodings and parameter entities can evade naive checks.

Default behavior varies by language and library version, which is why security reviews must confirm settings explicitly rather than trust assumptions. The table below lists representative hardening settings.

PlatformParser or libraryRecommended setting
JavaDocumentBuilderFactoryEnable the disallow-doctype-decl feature
.NETXmlReaderSet DtdProcessing to Prohibit
PHPlibxmlAvoid the LIBXML_NOENT flag; versions 2.9 and later block external entities by default
PythonStandard library parsersUse the defusedxml package for untrusted input
RubyNokogiriKeep the NONET option and avoid NOENT
Representative parser hardening settings

Beyond parser flags, defense in depth reduces the impact of a missed configuration. Useful layers include egress filtering that blocks unexpected outbound connections, running services with least-privilege file access, preferring simpler formats such as JSON where possible, and keeping XML libraries patched through software composition analysis.

Detecting XXE and avoiding common mistakes

XXE detection combines static analysis of parser instantiation code with dynamic testing that submits crafted payloads and watches for file contents, errors or out-of-band callbacks. Dynamic scanners use a collaborator server to catch DNS and HTTP interactions, which is the standard way to confirm blind cases.

MistakeWhy it failsBetter approach
Filtering the DOCTYPE keywordEncodings such as UTF-16 bypass simple filtersDisable DTDs in the parser
Hardening only the main parserLibraries create their own parser instancesAudit every XML entry point
Ignoring file uploadsDOCX and SVG contain XMLHarden document and image processors
Relying on response checksBlind XXE leaves no visible outputTest with out-of-band callbacks
Frequent mistakes and their fixes

A related misconception holds that signature validation protects SAML. In practice, the parser reads the assertion before any cryptographic check, so an unsafe parser can be exploited by an unauthenticated user. Hardening must therefore happen before any XML is parsed, not after trust has been established.

Explained without jargon

XML is a common format that programs use to exchange data. It has an old feature that lets a document say: fetch this other file and paste it here. If a server reads XML from strangers without switching that feature off, a stranger can ask the server to fetch its own private files and hand them back.

Imagine a mailroom clerk who follows every note inside a parcel, including one that says to photocopy the contents of the locked filing cabinet and mail them to the sender. The fix is simple: tell the clerk to ignore such notes. For software, that means turning off the feature in the program that reads the XML.

A typical use case

A logistics company runs an invoice import feature that accepts supplier uploads in XLSX format. During a scheduled penetration test, a tester unzips a spreadsheet, adds a DOCTYPE declaration with an external entity pointing to an internal address, and repackages the file. The tester then uploads it and watches a collaborator server.

Within seconds, the collaborator records a request from the application server, proving blind XXE. A second payload shows that the server can reach the cloud metadata endpoint, which would expose temporary credentials. The development team sets the Java parser to reject DOCTYPE declarations, adds egress rules that block metadata access from the import service, and reruns the test. The retest confirms that no outbound request occurs, and the finding is closed within the same sprint.