Skip to main content

Overview

XML External Entity (XXE) is a vulnerability that allows an attacker to interfere with an application’s processing of XML data. If a poorly configured XML parser processes user-supplied XML that contains a reference to an external entity, the attacker can exploit it to read sensitive files from the server, perform network scans of the internal network (SSRF), or cause a denial of service (DoS).

Business Impact

XXE can be a critical vulnerability, leading to the complete disclosure of server-side files, including source code, configuration files with credentials, and sensitive OS files. It effectively gives an attacker read-access to the server’s file system, which can be a stepping stone for full system compromise.

Reference Details

CWE ID: CWE-611 OWASP Top 10 (2021): A05:2021 - Security Misconfiguration Severity: High

Framework-Specific Analysis and Remediation

Most modern XML parsers have been made secure by default against XXE. Vulnerabilities typically exist in older applications or when a developer explicitly enables risky features like DTD (Document Type Definition) processing to support legacy formats. The universal fix is to ensure all XML parsers are configured to disable DTDs and disallow the resolution of external entities.

Framework Context

Python’s standard library xml.etree.ElementTree is not vulnerable to XXE. However, the more powerful and commonly used third-party library lxml is vulnerable by default. Django applications that parse XML must ensure lxml is configured securely.

Vulnerable Scenario 1: Processing a SOAP Request

A Django API view uses lxml to parse an incoming SOAP request from a legacy system.

Vulnerable Scenario 2: A Document Upload Feature

A feature allows users to upload an XML-based document (e.g., for data import), which is then parsed on the server.

Mitigation and Best Practices

When using lxml, always instantiate a parser with entity resolution explicitly disabled. This is the only guaranteed way to make parsing safe.

Secure Code Example

Testing Strategy

Write an integration test that uploads an XML file containing a malicious XXE payload. The test should assert that the application returns a controlled error (e.g., a 400 Bad Request due to invalid XML) and does not attempt to resolve the external entity. Mocking filesystem access can confirm that no unauthorized file reads occurred.