← All tracks
IdentitySAML6 labsAdvanced5h practice

SAML

One signed assertion, many trusted copies.

“The identity provider signed an analyst assertion, but the service provider read the role from an unsigned copy and granted administrator.”

OASIS SAML 2.0 CoreOASIS SAML 2.0 ProfilesW3C XML Signature Syntax and ProcessingNIST SP 800-63B: Digital Identity GuidelinesOWASP SAML Security Cheat Sheet
The mental model
SAML is XML with a signature, and XML has many equivalent representations. Security depends on verifying the signature over the exact element that is later used for authorization, then enforcing audience, recipient, time and replay rules.

Service providers often parse XML into a document, verify one assertion, then read identity or attributes from another node, another namespace or an unsigned extension. Signature wrapping, comment truncation, stripped signatures and missing audience or recipient checks let an attacker reuse a valid signature while changing what the application trusts. A response can also be replayed to a different SP or ACS when those constraints are not enforced.

The victim sees a normal single sign-on redirect. The service provider sees a cryptographically signed response and trusts the surrounding XML more than the signature boundary.

Threat model

What is actually at stake?

Before touching a payload, map the assets, the actors and the boundary that is supposed to protect them. A finding only becomes a vulnerability when you can connect the failed boundary to a real asset.

Assets

  • User identity and role attributes
  • Administrator console access
  • Tenant and organization membership claims
  • Session lifetime and single sign-on state

Actors

  • Unauthenticated attacker with a valid analyst account
  • Attacker who can capture a signed assertion from another service
  • Malicious identity provider or compromised signing key
  • Insider who can alter XML in transit or in a logging pipeline

Trust boundaries

  • Browser to service provider ACS
  • Service provider XML parser to signature verifier
  • Signature verifier to attribute consumer
  • Identity provider trust configuration
  • Assertion replay cache and session store

Abuse cases

  • Submit an unsigned response when the SP fails open on a missing signature
  • Remove the signature element and change the role attribute
  • Append a second admin assertion while keeping the original signed assertion valid
  • Replay a valid assertion issued for a different audience or ACS
  • Modify an unsigned role attribute that sits outside the signed assertion
PrerequisitesSAML roles: identity provider, service provider and principalAuthnRequest, Response, Assertion, Subject and AttributeStatement structureEnveloped XML signatures, canonicalization and reference resolutionAudience, Recipient, InResponseTo, NotBefore and NotOnOrAfter constraintsSingle logout and replay cache concepts
Request anatomy

Follow the decision, not the payload

Every family has a moment where trusted data becomes an authorization, parsing or state decision. Learn to point at that moment in the request path.

  1. 01

    Receive

    The browser posts a base64 SAMLResponse to the service provider's assertion consumer service.

  2. 02

    Parse

    The XML parser builds a document tree with assertions, signatures, namespaces and attributes.

  3. 03

    Verify

    The SP checks the signature over a specific element and resolves the reference and canonicalization.

  4. 04

    Select

    The application chooses the assertion, NameID and attributes that will define the session.

  5. 05

    Authorize

    The role attribute is mapped to permissions; any mismatch between the verified and selected node becomes privilege escalation.

Case study

XML signature wrapping in SAML

Somorovsky et al., On Breaking SAML: Be Whoever You Want to Be, USENIX Security 2012
Context

Researchers analyzed SAML service providers and found that many verified one assertion but consumed identity or attributes from another. The XML Signature specification permits multiple equivalent document structures, which makes naive node selection dangerous.

Discovery

By moving the signed assertion, duplicating IDs, adding a second assertion or exploiting parser differences, they produced responses that passed signature validation while the application read attacker-controlled values.

Impact

Authentication bypass and privilege escalation, including administrator access to service providers that trusted role attributes from the wrong node.

Root cause

The signature verifier and the business logic resolved different nodes. Audience, recipient and replay checks were also frequently missing.

Fix

Verify the signature over the exact assertion used for identity, reject unsigned or multiply signed structures, enforce audience and recipient, reject duplicate IDs, and use a maintained SAML library with a strict profile.

Read it as a chain: discovery → failed decision → impact → fix. Then ask which link would have broken earliest.

Attacker lens

A repeatable testing sequence

  1. Decode the SAMLResponse and map every Assertion, Signature, NameID and Attribute node.
  2. Determine which node the signature covers and which node the application uses for identity and role.
  3. Test unsigned responses, removed signatures, duplicated assertions, wrapped assertions and altered namespace or ID references.
  4. Replay a valid assertion to a different audience or ACS and observe whether either check is enforced.
  5. Prove administrator access or another privilege change, and record the exact node the SP trusted.

Where smart people get fooled

  • A signature that exists is not a signature that covers the data you changed; verify the reference and the canonicalization.
  • Removing the signature must fail closed; a parser that treats absence as valid is the vulnerability.
  • Audience and recipient are authorization constraints, not decoration; a valid signature for another SP is still a valid attack.
  • XML comments, namespace prefixes and duplicate IDs can change which node a parser selects without changing the visible text.
Detection engineering

What would the logs show?

A control is stronger when someone can see it fail. These signals are starting points for a detection rule, not a complete SIEM use case.

  • SAMLResponses with no Signature, multiple Assertions or duplicate ID values
  • Audience or Recipient values that do not match the service provider
  • A signature reference that resolves to a different assertion than the one consumed
  • The same assertion ID replayed within its validity window
  • Role or group attributes that change between the signed and consumed nodes
Starter query
index=idp sourcetype=saml | eval anomalies=if(match(raw, "<Signature>")=0 OR match(raw, "<Assertion")>1 OR match(raw, "ID=\"([^\"]+)\".*ID=\"\\1\""),1,0) | stats count values(issuer) values(audience) by user, src_ip | where anomalies=1 OR count > 3
The defender's move

Fix the decision, then prove it stays fixed

  • Use a maintained SAML library and verify the signature over the exact assertion that supplies identity and attributes.
  • Reject unsigned assertions, enforce audience, recipient, issuer, NotBefore and NotOnOrAfter, and bind responses to the request ID.
  • Reject duplicate IDs, unexpected namespace declarations and multiple assertions unless the profile explicitly allows them.
  • Use short assertion lifetimes, one-time replay caches, signed request/response exchange and strict XML parsing.
Vulnerable patterntypescript
const assertion = parseXml(body.SAMLResponse).querySelector('Assertion');
const signature = body.SAMLResponse.includes('<Signature>');
if (signature) createSession(assertion.getAttribute('NameID'), assertion.getAttribute('role'));
Safer patterntypescript
const response = await saml.validateResponse(body.SAMLResponse, {
  audience: 'https://app.example/saml/metadata',
  recipient: 'https://app.example/saml/acs',
  clockSkewMs: 60000
});
if (!response.assertion) return reject('invalid_assertion');
if (!(await replayCache.claim(response.assertion.id))) return reject('replay');
createSession(response.nameId, response.attributes.role);

Use a maintained SAML library that returns the verified assertion and its attributes from the same validated object. Never parse twice, never trust a boolean that says a signature exists, and enforce audience, recipient, issuer, time and replay.

Regression tests a reviewer would ask for

Unsigned response is rejected

GivenA SAMLResponse with no Signature element

WhenThe service provider validates it

ThenAuthentication fails with an explicit signature error

Signature wrapping is rejected

GivenA response containing a valid signed assertion plus a second admin assertion

WhenThe service provider validates the response

ThenThe request is rejected or only the verified assertion is used

Audience and recipient enforced

GivenA valid assertion issued for another service provider

WhenIt is posted to this ACS

ThenThe service provider rejects it for audience or recipient mismatch

Replay rejected

GivenThe same assertion ID submitted twice within its validity window

WhenThe second response arrives

ThenThe replay cache rejects it and no new session is created

False positives

What this finding is not

Strong testers kill their own findings before someone else does. These are the shortcuts that turn a real bug into a weak report — or a false alarm into a wasted escalation.

  • The SP rejects the response before reading any attribute; a signature error is not a bypass.
  • The changed attribute is inside the signed assertion and the signature check fails.
  • The response is accepted only for the same audience and recipient and the attacker gains no new privilege.
  • A reflected SAML error page contains attacker input but no session is established.
Working vocabulary

Terms you should be able to use precisely

Assertion
A signed XML statement from an identity provider about a subject, authentication event and attributes.
ACS
Assertion Consumer Service: the service provider endpoint that receives and validates SAML responses.
Signature wrapping
Moving or duplicating signed XML so the verifier checks one node while the application reads another.
Audience
The service provider for which an assertion is intended; it must be checked to prevent replay elsewhere.
Recipient
The ACS URL that should receive the assertion; it is a separate constraint from audience.
Canonicalization
The process of producing a deterministic byte representation of XML before signing or verifying it.
Interview drill

Answer these without reciting a payload

Why is checking that a Signature element exists insufficient?

The signature must cover the exact assertion that supplies identity and attributes. An attacker can keep a valid signature over one node and change or add another node that the application trusts.

What is the difference between audience and recipient?

Audience identifies the service provider the assertion is for; recipient identifies the ACS endpoint that should receive it. Both must be enforced to prevent replay to another service or endpoint.

How should a service provider handle XML with duplicate IDs?

Reject it. Duplicate IDs create ambiguity about which node a signature reference covers and are a common signature-wrapping primitive.

Knowledge check

Can you separate the mechanism from the payload?

Four questions, graded on the server. Answers and explanations are released only after you submit, and signed-in learners keep a best score.

4 questions
01Which check must cover the assertion that actually defines the session?
02A valid assertion issued for another service provider is replayed. Which check should stop it?
03What does a missing signature on a SAMLResponse indicate in a vulnerable SP?
04Why are duplicate assertion IDs dangerous?
الخلاصة الموسّعة
لماذا هذا مهم؟

SAML تعتمد على XML وتوقيعه، لكن XML يسمح بتمثيلات كثيرة لنفس المحتوى. الثغرة الكلاسيكية هي XML Signature Wrapping: يتحقق الخادم من توقيع Assertion معيّن ثم يقرأ الهوية أو الدور من Assertion آخر. الحل: استخدم مكتبة SAML مُصانة تُرجع العقدة الموقعة والخصائص من نفس الكائن، وارفض الاستجابات غير الموقعة أو ذات المعرفات المكررة، واشترط audience وrecipient وissuer والوقت، وأضف ذاكرة منع تكرار. لا تكتفِ بوجود عنصر Signature، ولا تسمح لاختلاف الـparser بين المتحقق ومنطق الأعمال.

If the XML parser and the signature verifier disagree about which Assertion is the real one, which component should be considered authoritative?