---
title: "Turn off external entities in XML · Agent Wranglers"
url: https://agentwranglers.se/playbook/adversarial-testing/injection/xml-entities
updated: 2026-10-20
licence: "All rights reserved"
---

# Turn off external entities in XML

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

- Level: Required
- Chapter: [Injection](https://agentwranglers.se/playbook/adversarial-testing/injection)
- Rule: Parse XML with external entities and document types turned off, or accept JSON instead.
- How: Set the parser options that disable DTDs and external entities. Many parsers still allow them by default. Remember that SVG images, office files and SAML messages are XML too.
- Check: Upload an XML or SVG file that defines an entity pointing at `file:///etc/hostname`. The reply never contains the server's host name.

Example:

```xml
<?xml version="1.0"?>
<!DOCTYPE t [<!ENTITY aw SYSTEM "file:///etc/hostname">]>
<t>&aw;</t>
```

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers security testing playbook: https://agentwranglers.se/playbook/adversarial-testing/injection/xml-entities`.

- Previous: [Strip line breaks from headers and logs](https://agentwranglers.se/playbook/adversarial-testing/injection/header-injection)
- Next: [Never rebuild objects from untrusted data](https://agentwranglers.se/playbook/adversarial-testing/injection/unsafe-deserialisation)
- [Injection](https://agentwranglers.se/playbook/adversarial-testing/injection)
