From grimoire
Disables external entity processing and DTD loading in XML parsers to prevent file disclosure, SSRF, and DoS attacks from XXE. Provides code examples for Python, Java, and other languages.
How this skill is triggered — by the user, by Claude, or both
Slash command
/grimoire:prevent-xxeThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Disable external entity processing and DTD loading in all XML parsers — eliminating file disclosure, SSRF, and denial-of-service attacks through XML document processing.
Disable external entity processing and DTD loading in all XML parsers — eliminating file disclosure, SSRF, and denial-of-service attacks through XML document processing.
Adopted by: OWASP Top 10 included XXE (A04:2017, merged into A05:2021). CVE-2019-0251 (Apache Solr XXE), CVE-2018-1000632 (dom4j XXE), CVE-2017-5638 (Equifax Struts2) all resulted from default XML parser configurations. SANS Top 25 Most Dangerous Software Errors lists XXE. SAP, Oracle, and Microsoft have all issued XXE patches for their XML-parsing products.
Impact: XXE enables reading arbitrary server files (/etc/passwd, /etc/shadow, AWS credentials), internal SSRF to reach metadata endpoints, and billion-laughs XML bomb DoS that crashes parsers with 1KB of input. The Equifax breach (2017, 147M records) exploited an Apache Struts vulnerability where XXE was part of the attack chain. Facebook, Ubisoft, and Groupon have paid XXE bug bounties.
Why best: Input sanitization attempting to strip DOCTYPE declarations is the alternative — it fails on encoded variants and CDATA tricks. Disabling external entity processing and DTDs at the parser level eliminates the vulnerability structurally, regardless of input content.
Sources: OWASP XXE Prevention Cheat Sheet; Equifax breach post-mortem; CWE-611; NVD XXE CVE database
Python (lxml, ElementTree, xml.etree):
# ElementTree (safe by default since Python 3.8 — defusedxml for older)
from defusedxml import ElementTree
tree = ElementTree.parse(xml_file)
# lxml — disable external entities explicitly
from lxml import etree
parser = etree.XMLParser(
resolve_entities=False,
no_network=True,
load_dtd=False
)
tree = etree.parse(xml_file, parser)
Java:
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
// Disable DTDs entirely
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
// Disable external entities
dbf.setFeature("http://xml.org/sax/features/external-general-entities", false);
dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
// Disable external DTD loading
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
dbf.setXIncludeAware(false);
dbf.setExpandEntityReferences(false);
DocumentBuilder db = dbf.newDocumentBuilder();
Same flags apply to SAX, StAX, and JAXB parsers — configure each parser instance, not globally.
PHP:
// Disable entity loading (PHP < 8.0)
libxml_disable_entity_loader(true);
// PHP 8.0+ — entity loading disabled by default
$doc = new DOMDocument();
$doc->loadXML($xml, LIBXML_NOENT | LIBXML_DTDLOAD); // Do NOT use these flags
$doc->loadXML($xml); // Correct: no entity loading flags
.NET (C#):
XmlReaderSettings settings = new XmlReaderSettings();
settings.DtdProcessing = DtdProcessing.Prohibit; // disables DTD
settings.XmlResolver = null; // disables external resolution
XmlReader reader = XmlReader.Create(xmlStream, settings);
Node.js — avoid XML parsers that enable entities. Use fast-xml-parser with entity disabled or xml2js (safe by default):
const { XMLParser } = require('fast-xml-parser');
const parser = new XMLParser({
processEntities: false, // disable entity processing
});
const result = parser.parse(xmlString);
Validate that DTD processing is disabled before accepting XML in production — send a test payload and verify it's rejected or entities are unexpanded:
<?xml version="1.0"?>
<!DOCTYPE test [<!ENTITY xxe SYSTEM "file:///etc/passwd">]>
<root>&xxe;</root>
If the response contains passwd file contents, DTD processing is enabled.
For SOAP and REST services that accept XML — validate Content-Type and reject requests declaring text/xml or application/xml from untrusted sources unless your service explicitly needs to process them.
disallow-doctype-decl) is stronger than disabling only external entities — internal entity expansion can still cause DoS (billion laughs attack).LIBXML_NOENT in PHP — this flag ENABLES entity substitution, the opposite of what's needed.npx claudepluginhub jeffreytse/grimoire --plugin grimoireDetects XXE vulnerabilities in XML parsers processing untrusted input across JavaScript, TypeScript, Python, Go, Ruby, PHP, Java. Guides auditing configurations, defaults, and input flows for file read/SSRF risks.
Guides XML External Entity injection testing: classic XXE, blind XXE (OOB), XXE via file upload (SVG/docx), SOAP/REST XXE, error-based XXE, XInclude, and filter bypass. For authorized web app security assessments or bug bounty.
Analyzes PHP code for XXE vulnerabilities. Detects unsafe SimpleXML/DOMDocument/XMLReader, missing libxml_disable_entity_loader, LIBXML flags, XSLT/SOAP/XML-RPC attacks.