Why is protecting against XML external entity attacks, commonly abbreviated as XXE, an important security consideration when parsing XML documents that come from an untrusted or external source?
Short answer
An XML external entity attack exploits a feature of the XML specification that allows a document to define a custom entity referencing an external resource, such as a local file on the server or an internal network address, and if an XML parser is not properly configured to…
Advertisement
AModel answer
An XML external entity attack exploits a feature of the XML specification that allows a document to define a custom entity referencing an external resource, such as a local file on the server or an internal network address, and if an XML parser is not properly configured to disable this feature, a malicious XML document submitted by an attacker could potentially be used to read sensitive local files from the server or make unintended requests to internal network resources, making it essential to explicitly disable external entity loading whenever your application parses XML documents originating from an untrusted external source.
libxml_disable_entity_loader(true);
$xml = simplexml_load_string($untrustedXmlInput, 'SimpleXMLElement', LIBXML_NOENT | LIBXML_DTDLOAD);Real-world example
An API that accepts XML formatted data submitted by external third party partners explicitly disables external entity loading before parsing any incoming XML, preventing a malicious partner from crafting a document designed to read sensitive files directly from the server.
Likely follow-ups
- What specific sensitive information could realistically be exposed through a successful XXE attack?
- Has this specific vulnerability's default behavior changed across different PHP or libxml versions over time?
Related topics