Join our Newsletter — 33% off our NHI Course
Home› FAQ› Cyber Security› What mitigations reduce the risk of XML entity…
Cyber Security

What mitigations reduce the risk of XML entity expansion?

← Back to all FAQ
By NHI Mgmt Group Editorial Team Updated October 19, 2026 Domain: Cyber Security

Disable external entities and entity expansion unless there is a clear business need, and use XML parsers configured to reject document types that can trigger expansion attacks. Limit input size, depth, and parsing time, and prefer safer data formats where possible. Entity expansion can exhaust memory or CPU and can also expose local or remote resources through parser behaviour.

How to reduce XML entity expansion risk at the parser boundary

The most effective mitigation is to make the parser non-expanding by default. Disable DTD processing, external entity resolution, and general entity expansion unless the application has a documented need for them. Use parser settings that fail closed on document type declarations, because the attack depends on the parser turning markup into repeated in-memory expansion.

Safer configuration matters more than string filtering. xml entity expansion is not just a malformed-input problem, it is a parser-behaviour problem, so controls need to be applied in the XML library or framework you actually use. Where possible, prefer data formats that do not support general entity expansion semantics.

When XML must be accepted, treat size and complexity limits as part of the control, not as a backup. Cap input size, nesting depth, entity expansion depth, and parse time so a single request cannot drive runaway CPU or memory consumption. If the parser or framework offers secure processing or hardened defaults, enable them and verify they are active in production.

What to do when XML is still required by the business

If a workflow genuinely needs XML, narrow the allowed feature set to the smallest workable subset. Keep external entity access disabled, reject document types unless they are explicitly required, and avoid exposing the parser to network or file-system resources it does not need. In practice, the safest configuration is one that cannot resolve references beyond the document itself.

For APIs, integrations, and file ingestion pipelines, validate at the edge before parsing and isolate the parser from sensitive local resources. If the application must transform or re-emit XML, apply the same restrictions to every parsing step, not just the first one. Multiple parser invocations are a common place for a secure initial parse to be undone later in the flow.

Operationally, it is worth using the XML library’s secure defaults or a well-reviewed wrapper rather than relying on custom defensive code. Parser hardening is easier to audit when the configuration is centralized, and it reduces the chance that one service quietly re-enables expansion for convenience.

How to detect and contain a failed mitigation

Even well-configured parsers can be bypassed by inconsistent library versions, unsafe wrapper code, or alternate code paths that parse XML outside the expected hardening settings. Watch for unusual parse latency, repeated memory pressure, and requests that contain doctypes or deeply nested entity definitions. Those are the operational signs that the control is either missing or being exercised.

Containment should assume that a parser can become a resource-exhaustion point. Rate limit XML-heavy endpoints, set request timeouts, and run parsing in a constrained service context so a failed parse does not threaten the whole application or host. If the parser can reach local files, internal services, or remote fetches, the same weakness can become a data exposure path as well as a denial-of-service issue.

Risk and Threat Considerations

XML entity expansion is dangerous because the input is usually small while the expansion cost can become very large. That makes it useful for denial-of-service attempts and, when external entities are permitted, for unintended file or network access through parser behaviour.

Failure mechanism: The parser expands entity references recursively or resolves external resources, multiplying work until CPU, memory, or outbound access becomes the limiting factor.

Impact: A successful payload can slow or crash the service, exhaust shared infrastructure, and expose local or remote resources that the application never intended to read.

Standards & Framework Alignment

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

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

FrameworkControl / ReferenceRelevance
NIST SP 800-53 Rev 5SI-10 — Information Input ValidationXML entity expansion is driven by hostile input that must be constrained before parsing.
SC-18 — Mobile CodeParser-resolved external references can fetch and execute remote content-like behaviour.
CP-10 — System Recovery and ReconstitutionExpansion attacks can exhaust resources and require service recovery after disruption.
Recommendation — Validate XML inputs and reject parser-triggering constructs before processing. Restrict parser features that fetch or process external XML references. Build recovery steps for parser-induced resource exhaustion events.
OWASP ASVSV1 — Encoding and SanitizationXML input handling requires rejecting dangerous markup and parsing constructs safely.
Recommendation — Harden XML input handling so dangerous entity constructs are rejected.
CIS Controls v8CIS-16 — Application Software SecuritySafe XML parsing is an application security configuration and validation concern.
Recommendation — Configure XML libraries to disable risky parser features by default.

Practitioner Guidance

What to verify: Confirm that the exact parser instance used in production rejects document types, blocks external entity resolution, and preserves those settings across all code paths, including helper libraries and transformation steps.

What to prioritise: Put the strongest controls at the parsing boundary first, then add input limits and service-level timeouts so the application fails quickly rather than consuming resources indefinitely.

Practitioner takeaway: The real control is not “sanitising XML”, it is ensuring the parser cannot be persuaded to expand attacker-controlled structure into uncontrolled work or unintended resource access.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 19, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org