Beta

Create a tenant

A new tenant starts with its own users, OAuth settings, audit history and logs. You are its first Tenant Admin.

Validating a response

A SAML response reaches the service provider through the browser, so nothing in it can be taken at its word. This lesson follows the training service as it decides whether one response may open Avery's account: what it compares the message with, which element the signature has to cover, the restrictions that decide whether a genuine statement applies here, and why the session comes last.

A familiar name is not acceptance

A form arrives at https://training.example/saml/acs. Decoded, it names Cedar Inc. as issuer and cedar-training-742 as the subject, and it is full of the right-looking XML. The training service now has to decide whether this exact message may open Avery's account. Everything about the message came through a browser, so none of it can be taken at its word, however familiar it looks.

The decision starts from what the training service already knows, not from the message. From its agreement with Cedar Inc., recorded in the metadata the two exchanged, it knows the identity provider's entity ID and signing keys, its own entity ID and ACS, the algorithms it accepts, and whether it accepts unsolicited responses. From its own records it knows which requests it has sent and to which browsers. The message is compared with those facts, and nothing in the message can change them. A response that says "trust this other key" or "deliver to this other address" gets no say.

The checks below are what a maintained SAML library performs. Knowing them lets you configure the library correctly, read its errors, and recognize when an application has bypassed part of it.

Reading the signed thing

Before any value is trusted, the document must be parsed safely: document type declarations refused, size and depth limited, and the structure checked against the SAML schema, the published description of which elements may appear where. Then comes the signature. XML signatures and wrapping attacks showed that a successful check means "this element is signed", so the first question is which element.

Cedar Inc. can sign the response, the assertion or both, and the choice changes what is protected:

What each signing choice protects
What is signedProtectedNot protected
Assertion onlyIssuer, subject, confirmation data, conditions, statementsThe response's Destination, InResponseTo and Status
Response onlyThe whole response, including the assertion inside itThe assertion, if it is ever taken out of this response and used alone
BothEverything, and the assertion stays protected on its ownNothing within the message

The training service's metadata says WantAssertionsSigned="true", so it requires a valid signature on the assertion it will use. When only the assertion is signed, it takes the request and recipient facts from the signed SubjectConfirmationData inside the assertion, never from the unsigned attributes of the response around it. The signature must verify with a key from Cedar Inc.'s metadata, using an allowed algorithm, and the element the library verified must be the one the application reads.

Matching the restrictions

A valid signature says Cedar Inc. made the statement. The remaining checks decide whether the statement applies here and now. In order:

The restrictions the training service checks after the signature
CheckWhere to read itMust equal
The sign-in succeededsamlp:StatusCode/@Valueurn:oasis:names:tc:SAML:2.0:status:Success, otherwise no assertion is used
Who is speakingsaml:Issuer of the assertion (and response)Cedar Inc.'s entity ID, the one whose key verified the signature
How it may be presentedSubjectConfirmation/@Methodurn:oasis:names:tc:SAML:2.0:cm:bearer
Where it may be presentedSubjectConfirmationData/@Recipient, and the response's Destination if presentThis ACS, https://training.example/saml/acs
Until when it may be presentedSubjectConfirmationData/@NotOnOrAfterLater than now
Which request it answersSubjectConfirmationData/@InResponseToA pending request sent to this browser, not yet used and not expired; absent only if unsolicited responses are allowed
When it is validConditions/@NotBefore and @NotOnOrAfterNow falls inside, with a small clock allowance
Who may rely on itAudienceRestriction/AudienceThe training service's entity ID, https://training.example/saml
Not seen beforeThe assertion's IDNot in the replay cache; add it until the assertion expires

Each row closes a specific door. Status stops a failed sign-in from being read as a success. Issuer and key stop another identity provider from speaking for Cedar Inc. Recipient and audience stop a statement made for another service from being used here. The two time windows stop old statements. InResponseTo and the browser link stop a response from being carried to a browser that never asked, the login CSRF of SP-initiated and IdP-initiated sign-in. The replay cache stops the same assertion from being used twice. Two requests can arrive with the same assertion at once, so the check and the insert happen as one atomic step, a single change that either happens completely or not at all.

A refusal that protects the right boundary

One afternoon the training service's logs show a refused sign-in. The assertion in the captured response contains:

xml
<saml:Subject>
  <saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">cedar-expenses-193</saml:NameID>
  <saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
    <saml:SubjectConfirmationData Recipient="https://expenses.example/saml/acs"
        NotOnOrAfter="2026-10-12T14:35:10Z"/>
  </saml:SubjectConfirmation>
</saml:Subject>
<saml:Conditions NotBefore="2026-10-12T14:29:40Z" NotOnOrAfter="2026-10-12T14:35:10Z">
  <saml:AudienceRestriction>
    <saml:Audience>https://expenses.example/saml</saml:Audience>
  </saml:AudienceRestriction>
</saml:Conditions>

The signature is valid, made with Cedar Inc.'s current key. The times are fine. But the audience is the expense service and the recipient is the expense service's ACS, so the training service refused it, correctly. Cedar Inc. really did say this, to someone else. Trusting Cedar Inc. does not make its statements interchangeable between the services that trust it; otherwise anyone able to sign in to the expense service could carry their assertion to the training service and be accepted.

Signed for the expense service

Issuer
Cedar Inc.
Signature
Valid, current key
Times
Within the window
Recipient
https://expenses.example/saml/acs
Audience
https://expenses.example/saml

What it expects

Issuer
Cedar Inc.
Signature
Key from Cedar Inc.'s metadata
Times
Now falls inside
Recipient
https://training.example/saml/acs
Audience
https://training.example/saml

Refused, no session

Trusting Cedar Inc. does not make its statements interchangeable between the services that trust it.

The captured response beside what the training service expects. Issuer, signature and times fit, but the recipient and audience name the expense service, so the response is refused and no session is created.

The repair is not to add https://expenses.example/saml to the training service's accepted audiences. It is to find out why an expense assertion arrived at the training ACS. Perhaps a launcher tile is pointed at the wrong application, perhaps someone is testing what the training service accepts. The refusal showed exactly where to look, and it gave no session to anyone.

Creating the account session last

Only after every check passes does the training service look at who the assertion is about. It finds the account linked to Cedar Inc.'s entity ID and the persistent NameID cedar-training-742. If there is no link, it follows its policy for new people, perhaps creating an account, but it never falls back to matching a display name or an email address against existing accounts, because that would let anyone whose identity provider sends a matching email take over the account. Then it checks its own permissions, and creates its session.

Every failure ends the same way for Avery: a short message saying the sign-in could not be completed, with no session created. For whoever runs the service, the failure is recorded with its stage and a safe reason, such as wrong audience or expired, plus the request ID, so a support engineer can tell a clock problem from a configuration mistake from an attack. The record never holds the assertion itself or the session cookie, since either could be replayed by someone reading the logs.

Check your understanding

Try these questions before moving on. If an answer isn't right, use the feedback and try again.

A response signed with Cedar Inc.'s current key arrives at the training ACS. Its Audience is https://expenses.example/saml. What should the training service do? 1 of 3

Choose one answer.

Two copies of the same valid response reach the ACS within a second of each other. Which check stops both from creating sessions? 2 of 3

Choose one answer.

Every check passes for a response whose persistent NameID is not linked to any training account. Its email attribute matches an existing account. What should the training service do? 3 of 3

Choose one answer.

Try it in the Lab

Try a Capture the Flag challenge

Apply this lesson against an isolated, intentionally vulnerable application. Capture a flag, explain the mistake, then repair and retest it.

  1. The Partner SAML Role Difficulty 4 of 5 · About 45 minutes · API target

We value your privacy

We use cookies and similar technologies to enhance your browsing experience, and analytics to understand our traffic. By clicking "Allow all", you consent to optional analytics. Cookie Policy

Learn identity