Skip to content
high

XXE in SAML responses

SAML XXE targets single sign-on: a SAMLResponse is an XML document the service provider parses to authenticate users, so injecting a DOCTYPE with an external entity into that XML can make the SP's parser read local files or issue server-side requests while it processes the login.

Target formats
SAMLXML (SSO)
Affected parsers
Java SAML stacks.NET SAML librarieslibxml-based SP toolkits
Impact
Local file disclosureSSRFAuth-flow compromise

How it works

SAML is built on XML and XML Signatures. A service provider receives a SAMLResponse (often base64-encoded, sometimes deflated) and parses it to extract the assertion. If that parsing happens before (or regardless of) signature validation and the parser resolves external entities, a crafted DOCTYPE in the response triggers XXE.

Because SAML endpoints are unauthenticated by design (they are how you log in), they are an attractive and reachable target.

Which parser configuration makes it work

Requires an SP that parses the incoming SAML XML with a parser that allows DOCTYPE/external entities. Pre-signature-check parsing and outdated SAML toolkits are the common culprits.

Representative payloads

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

DOCTYPE injected into a SAMLResponse
<?xml version="1.0"?>
<!DOCTYPE samlp:Response [
  <!ENTITY xxe SYSTEM "file:///etc/passwd">
]>
<samlp:Response ...>
  <saml:Assertion>...&xxe;...</saml:Assertion>
</samlp:Response>

Base64-encode (and deflate for redirect binding) the modified XML before sending.

Detection

As a tester, decode the SAMLResponse, insert a DOCTYPE, re-encode and submit. As a defender, decode inbound SAML messages and reject any that contain a DOCTYPE at all — well-formed SAML never needs one — and ensure your SAML library parses with a hardened, entity-disabling parser and validates signatures on the exact bytes it trusts.

  • DOCTYPE present in a decoded SAMLResponse/AuthnRequest
  • SP host making file:// or outbound requests during SSO
  • SAML parsing occurring before signature validation

Remediation

Use a maintained SAML library and configure (or confirm) that it parses with DOCTYPE/DTD processing disabled — most modern SAML stacks reject DOCTYPE outright, which is the correct behaviour. Reject any SAML message containing a DOCTYPE before processing. Validate the XML signature over the canonical bytes you actually parse, and keep the SP toolkit patched, since several historical SAML XXE and signature-wrapping bugs stem from unsafe parsing.

Fix checklist

  • Reject SAML messages that contain a DOCTYPE (primary fix)
  • Use a maintained SAML library with entity resolution disabled
  • Validate signatures over the exact bytes parsed; beware signature wrapping
  • Keep the SP/IdP toolkit patched

Parser-specific configuration: Java, .NET.

Related techniques

References