Home / patterns

XML parsers that resolve external entities (XXE)

A developer at a sunny desk marking up a printed page of blurred angle-bracket markup with a red pen, an unbranded laptop, a stack of papers and a USB drive beside him, no brand logos
Quick answer: If your app parses XML you did not write—an uploaded SVG, a DOCX or XLSX import, a SAML response, an RSS feed, a SOAP or XML API—an AI-written parser setup may still honor DOCTYPE declarations and external entities. MITRE calls this CWE-611. OWASP’s XXE Prevention Cheat Sheet says it can expose local files, cause server-side request forgery (SSRF) or exhaust resources. The fix is to reject DTDs where possible and turn off external entity and external DTD loading in every parser that sees untrusted XML.

Last updated November 9, 2026

Steps

  1. List every place the server parses XML from outside: file uploads (SVG, DOCX, XLSX, ODT and other zip-of-XML formats), SAML or SSO responses, RSS or sitemap imports, payment or shipping XML APIs, and any ‘import from XML’ feature an AI tool added.
  2. For each one, find the parser and its options. Look for settings that expand entities, load external DTDs or enable XInclude (for example libxml2’s NOENT and DTDLOAD options or similar flags in other libraries) and turn them off.
  3. Follow OWASP’s general rule: disable DTDs entirely when you can and reject any document with a DOCTYPE. If you truly need DTDs, disable external entity resolution and external DTD loading and limit entity expansion.
  4. In Python, follow the standard library’s XML security guidance and use the defusedxml parsing functions for untrusted XML, with forbid_dtd=True where available. In PHP, OWASP’s current guidance is to install an external-entity loader callback that returns null and not to enable LIBXML_NOENT or LIBXML_DTDLOAD for untrusted input. For Java, use the parser-specific settings in the cheat sheet.
  5. Treat a missing or unsupported security setting as a failure, not a warning: if the library cannot be hardened, do not feed it untrusted XML.
  6. If you only need to display uploaded SVGs, consider not parsing them server-side at all, or convert them to a raster image in an isolated worker. Keep file-size limits in place, since XXE fixes do not stop every XML denial-of-service problem.
  7. Retest by uploading a small XML or SVG file of your own that contains a DOCTYPE and confirm your app rejects it or ignores the entity.

Why it matters

CWE-611 (Improper Restriction of XML External Entity Reference) describes processing XML that can contain entities whose URIs resolve to documents outside the intended sphere of control, so the product embeds the wrong documents into its output. OWASP’s XML External Entity Prevention Cheat Sheet lists the consequences—local file exposure, SSRF and resource exhaustion—and gives parser-by-parser settings. XXE is also part of the misconfiguration family in the OWASP Top 10. Many modern libraries are safer by default, but an AI suggestion that copies an old example or flips an “expand entities” option can switch the risk back on. This page is about finding and turning off that behavior in your own app.

Sources

MITRE CWE-611: Improper Restriction of XML External Entity Reference — https://cwe.mitre.org/data/definitions/611.html

OWASP Cheat Sheet: XML External Entity Prevention — https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html

OWASP Top 10 2025: A02 Security Misconfiguration — https://owasp.org/Top10/2025/A02_2025-Security_Misconfiguration/

Python documentation: XML processing modules (XML security) — https://docs.python.org/3/library/xml.html

defusedxml on PyPI — https://pypi.org/project/defusedxml/

Checked at the source on November 9, 2026.

Related patterns

Found a problem you'd rather not fix yourself?

Tell us what's wrong. A StorenTech engineer reviews your app and replies with a fixed quote, so you know the cost before any work starts.

Get it fixed by StorenTech

Vibe Security Weekly

One email a week with new failure patterns and how to fix them.

By joining you agree we may email you this newsletter. See our privacy policy. Free. Unsubscribe anytime. We'll never sell your email.