XML External Entity (XXE) Injection

The application's XML parser resolves external entities declared in user-supplied XML, letting an attacker read local files or make the server send requests.

SeverityHigh
CVSS 3.17.5 CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N Open in the calculator
CVSS 4.08.7 CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:N/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-611: Improper Restriction of XML External Entity Reference
OWASP Top 10A02:2025 Security Misconfiguration
MITRE ATT&CKT1190 Exploit Public-Facing Application
CategoryInjection

Description

The application parses XML received from users, such as SOAP or REST request bodies, uploaded files (SVG images, Office documents, which are zipped XML, and XML imports) or SAML messages, with a parser that processes document type definitions (DTDs) and resolves external entities. Several common parsers, particularly in Java, resolve external entities unless configured otherwise. An attacker can declare an entity whose value is loaded from a URI, such as file:///etc/passwd or an internal web address, and reference it in the document, so that the parser reads the resource and places its content in the parsed data.

This lets an attacker read files that the application's account can access, such as configuration files containing credentials, source code and private keys, and make the server send requests to internal systems, which turns the weakness into server-side request forgery against services that are not reachable from the internet. No authentication is needed where the affected endpoint is public. Depending on the platform, the same techniques can cause denial of service and, in rare configurations, code execution, and a related weakness, entity expansion (the billion laughs attack), uses nested internal entities to exhaust the server's memory.

XML external entity injection typically shows itself on a test when the content of a local file appears in the response or, in blind cases, when the parser makes a DNS or HTTP request to a server under the tester's control, which can also carry file content out through parameter entities and an external DTD. Error messages that include the resolved value are another channel. Burp Suite and other scanners test for XXE with out-of-band interactions, and endpoints that normally accept JSON sometimes also accept XML when the content type is changed.

Remediation

Configure every XML parser that handles untrusted input to refuse DTDs, or at least external entities:

  • Disable DTD processing entirely where it is not needed, which prevents external entities and entity expansion together. In Java, set the disallow-doctype-decl feature on DocumentBuilderFactory and SAXParserFactory; in .NET, set DtdProcessing to Prohibit and XmlResolver to null; in Python, use the defusedxml package; in PHP, do not enable LIBXML_NOENT or LIBXML_DTDLOAD for untrusted input.
  • Where DTDs are required, disable external general entities, external parameter entities and external DTD loading, and leave XInclude disabled.
  • Keep XML libraries up to date, and apply the same settings to components that parse XML indirectly, such as those that process SVG images, Office documents and SAML messages.
  • Prefer simpler formats such as JSON where the interface allows, and reject XML on endpoints that are not meant to accept it.
// Java DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); dbf.setXIncludeAware(false); // .NET var settings = new XmlReaderSettings(); settings.DtdProcessing = DtdProcessing.Prohibit; settings.XmlResolver = null;

Confirm the fix by repeating the original tests, including out-of-band payloads, and checking that the document is rejected or the entities are not resolved.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Web Applications Findings

Every Web Applications finding