Disabling unsafe XML external entity processing
Disabling unsafe XML external entity processing connects a security requirement to the behaviour of a real feature. The relevant controls need to remain effective across custom code, integrations and the production configuration. Understanding disabling unsafe XML external entity processing helps establish which security property the feature needs and where that property is actually enforced.
What does this involve?
Input validation defines the structures, sizes and meanings an application expects to receive. It must happen before information influences a sensitive operation. Validation does not replace safe interpreter APIs, output encoding or permission checks, because those controls address different boundaries.
Disable document type definitions (DTDs) whenever possible. Reject DOCTYPE declarations if the parser supports it. If your application needs DTDs, disable external entity resolution and external DTD loading, and limit entity expansion.
For SAX2XMLReader, configure the reader that will parse the document. The Xerces-C++ feature documentation describes fgXercesDisableDefaultEntityResolution: it prevents fallback resolution when resolveEntity returns NULL. A custom resolver must also reject unapproved resources.
Why it matters
Consider a realistic failure: an XML parser resolves an external reference from an untrusted document.
Untrusted input can change application behaviour, consume excessive resources or reach data and execution paths outside the intended feature. The practical result depends on where the value is used and which privileges are available there.
Implementation guidance should be applied to a real feature and its deployment. Framework defaults, custom handlers and integrated services all influence whether the intended protection remains effective.
How penetration testers check for it
Trace the relevant feature from its entry point to the data or operation it protects, including custom code and alternate paths.
- Trace input from every relevant entry point to its use.
- Check types, lengths, ranges and ambiguous representations.
- Compare parsing across components and alternate request formats.
- Use controlled invalid inputs to establish effects rather than assumptions.
How to fix it
Use the appropriate maintained mechanisms and verify the result in the actual production configuration.
- Keep XInclude disabled unless explicitly required; it can load resources independently of DTDs.
- Restrict external access during schema validation and style sheet processing as well as XML parsing.
- Guidance from Microsoft on how to prevent XXE and XML Denial of Service in .NET.
- iOS4 and earlier: All external entities are loaded by default.
- Reject unexpected structures before sensitive processing.
- Apply resource bounds and predictable failure handling.
Blocking a few known attack strings is not a complete validation strategy. The intended data model and downstream interpretation determine which protections are needed.
Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.
Related issues
- Implementing safe XML parsing, validation and transformation
- Implementing signed, replay-resistant webhook processing
- Verifying evidence of actions performed by external AI agents
Read about our methodology or contact pentested.com to discuss secure development and code review.