XML External Entity (XXE)

Improper Restriction of XML External Entity Reference (XXE)

CWE-611 · High severity · Updated November 6, 2026

What it is

CWE-611 exists when an XML parser processes documents with external entity references enabled, allowing an attacker who controls the XML input to read local files, issue HTTP requests from the server (SSRF), enumerate ports on the internal network, or cause denial of service via entity expansion attacks.

Why it matters

XXE persisted long after XML peaked because so much enterprise infrastructure (SAML, SOAP, DOCX, SVG, XMP metadata, configuration files) still uses XML internally. SAML parsers in particular have been a recurring source of XXE in identity-provider integrations: a malicious SAML response can disclose /etc/passwd from the relying party. SVG processors used in image upload pipelines can be XXE vectors too. The vulnerability class predates the CWE Top 25 but is still flagged in OWASP Top 10 (A02:2025 Security Misconfiguration).

Common patterns

  • Python lxml with resolve_entities=True, or an old lxml version that expands entities by default.
  • Java DocumentBuilderFactory, SAXParserFactory, or XMLInputFactory created without disabling external entities and DTDs.
  • .NET XmlDocument or XmlReader instantiated with default DtdProcessing (Parse rather than Prohibit on older versions).
  • Node libxmljs with noent: true.
  • SAML response parsers, SOAP request handlers, DOCX content extractors that pass user-controlled XML to a default parser.
  • SVG sanitizers that fail to strip external entity declarations.

Languages affected

Java, Python, C#, JavaScript, TypeScript, Ruby, Go

What Deva detects

Deva flags XML parsers that allow external entities, with rules for Python lxml (explicit resolve_entities=True), Java and Kotlin parser factories, PHP, Ruby Nokogiri, and C#. JavaScript XML libraries are not yet covered.

Example

Vulnerable

from lxml import etree

def parse_saml(xml_bytes):
    parser = etree.XMLParser(resolve_entities=True)
    return etree.fromstring(xml_bytes, parser)

Fixed

from lxml import etree

def parse_saml(xml_bytes):
    parser = etree.XMLParser(resolve_entities=False, no_network=True, load_dtd=False)
    root = etree.fromstring(xml_bytes, parser)
    # SAML has no use for a DOCTYPE, so refuse any document that carries one.
    if root.getroottree().docinfo.doctype:
        raise ValueError('DOCTYPE not allowed')
    return root

The vulnerable version turns on entity resolution, as older code and older lxml defaults did. An attacker submitting <!DOCTYPE foo [<!ENTITY xxe SYSTEM 'file:///etc/passwd'>]><root>&xxe;</root> reads the system password file via the server's response or via an HTTP exfiltration callback. The fix disables entity resolution, DTD loading, and network access on the parser, and rejects any document with a DOCTYPE. For the Python standard library's XML modules, defusedxml is the usual choice, though its lxml wrapper is deprecated. For Java, the equivalent is setting the relevant XML features (http://apache.org/xml/features/disallow-doctype-decl=true and external-general-entities=false) on the DocumentBuilderFactory.

Where this fits in OWASP Top 10

Compliance framework references

These references explain how the weakness relates to control topics. They do not mean Deva offers evaluation for every framework listed. CMMC evaluation and SPRS scoring are currently unavailable. See the FAQ for offered frameworks and preview status. Deva provides code-level evidence for your assessment, without certifying compliance.

FrameworkControls
OWASP Top 10:2025A02:2025 Security Misconfiguration
NIST 800-53 Rev 5SI-10 Information Input Validation, CM-6 Configuration Settings
PCI-DSS v4.0.16.2.4 Software engineering techniques
CMMC L2CM.L2-3.4.6 Least functionality

Related CWEs

  • CWE-918 · SSRF: XXE often pivots to SSRF via SYSTEM URL entities.
  • CWE-776 · Improper restriction of recursive entity references (Billion Laughs).
  • CWE-827 · Improper control of document type definition.
  • CWE-610 · Externally controlled reference to a resource in another sphere: the parent weakness.

Related glossary terms