Join our Newsletter — 33% off our NHI Course

What causes XML Entity Expansion?

XML entity expansion is caused by parsing XML that allows entity references to resolve recursively or in large numbers. Attackers abuse it by supplying crafted documents that force excessive memory or CPU use, or by reaching external entities if those are enabled. Defenders disable unneeded entity resolution and limit parser resources.

Why XML Entity Expansion Happens

xml entity expansion happens when an XML parser resolves entity references repeatedly, or in large volume, while processing a document. That behaviour is part of normal XML support, but it becomes dangerous when untrusted input can define or trigger nested entities, causing the parser to spend excessive memory and CPU on expansion.

The core issue is not XML itself, but parser behaviour. If entity resolution is enabled and limits are weak, a small input can expand into a much larger in-memory structure during parsing. That makes the parser the bottleneck, and in a hostile case, the attacker controls how much work the parser must do before the application ever sees the data.

External entities can make the problem worse when the parser is allowed to fetch content outside the document. In that case, expansion is no longer only a local resource problem, because the parser may also follow external references, which can introduce file access, outbound requests, or other unexpected data retrieval depending on configuration.

How Crafted XML Turns Parsing Into a Resource Exhaustion Problem

A malicious XML document usually exploits the parser’s trust in document structure. The attacker supplies entities that reference other entities, or repeats them enough times that the expanded result grows far beyond the original payload. This can create the classic denial-of-service pattern where a tiny request consumes disproportionate server resources.

The practical failure mode is parser amplification. A parser that accepts recursive entity expansion can spend time expanding content instead of validating or handling the request, while memory usage rises quickly as expanded text is materialised. In application stacks that process XML automatically, that can degrade a single service or cascade into broader availability issues.

Where the parser also permits external entities, the risk is no longer limited to exhaustion. External resolution can expose the application to data disclosure or unexpected dependency on network and file access, which is why XML parser hardening matters even when the original concern looks like simple input validation.

What Defenders Should Control in the Parser and Application Stack

The safest position is to disable entity resolution unless the application truly needs it. If XML features are required, limit expansion depth, entity size, and overall parser resource consumption so the parser cannot be turned into a work multiplier by crafted input. That matters as much as schema validation, because validation does not stop expansion by itself.

Application teams should also treat XML handling as a boundary decision, not just a library choice. A secure default in one component can be undermined by a wrapper, framework, or legacy setting that re-enables entities. That is why parser configuration review and integration testing are just as important as code review for this issue.

For deeper attack-pattern context across XML-based injection and expansion issues, see the Web Application Attacks Guide. It places XML entity expansion alongside adjacent web input abuses such as XXE, XPath injection, and other parser-driven attack paths.

Risk and Threat Considerations

XML entity expansion is a denial-of-service risk first, but it can also become a broader exposure problem if external entity handling is enabled. Attackers do not need a complex exploit chain here, they only need a parser that expands attacker-controlled structure before the request is bounded or rejected.

Failure mechanism: The parser recursively resolves entities or expands them at a scale that exceeds available CPU or memory, and if external entities are permitted it may also dereference attacker-influenced external content.

Impact: The application can slow down, hang, or crash, and in misconfigured environments the same parser behaviour may also create unintended file access or outbound retrieval exposure.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP ASVS, NIST SP 800-53 Rev 5 and CIS Controls v8 set the governance and control requirements practitioners need to meet.

Framework Control / Reference Relevance
OWASP ASVS V4 — API and Web Service Security XML parsing and entity handling are web service input risks.
Recommendation — Validate XML inputs and disable dangerous parser features in service endpoints.
NIST SP 800-53 Rev 5 SI-10 — Information Input Validation XML entity expansion is triggered by untrusted input processing.
Recommendation — Validate and constrain XML input before parser expansion occurs.
CIS Controls v8 16 — Application Software Security Parser hardening and safe input handling are application security controls.
Recommendation — Harden XML handling and remove unsafe parser defaults in application code.

Practitioner Guidance

What to verify: Confirm whether the XML parser used in each code path has entity resolution enabled by default, and whether expansion limits are enforced at the library or framework layer rather than assumed in application logic.

Decision rule: If the application processes untrusted XML and does not explicitly require entities, disable them; if entities are required for a narrow use case, constrain expansion and isolate that parser path from general-purpose ingestion.

Practitioner takeaway: Treat entity expansion as a parser governance problem, not just an input filter problem, because the real control is whether untrusted XML can force the parser to do unbounded work.