Validating a response
A SAMLThe Security Assertion Markup Language, a federation standard widely used for workplace single sign-on, in which the identity provider sends the application a signed assertion about the user. response reaches the service providerSAML's name for the application that relies on an identity provider's sign-in, which OpenID Connect calls a relying party. In SCIM, the same term means the application that stores the accounts. 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 signatureA value made with a private key that lets anyone holding the matching public key check that a message came from the key's holder and has not been changed. It proves origin and integrity; it does not hide the message. has to cover, the restrictions that decide whether a genuine statement applies here, and why the sessionThe ongoing connection between later requests and an earlier sign-in, so you are not asked for your password on every click. It is often tracked with a cookie holding an unpredictable session identifier. comes last.
A familiar name is not acceptance
A form arrives at https://training.example/saml/acs. Decoded, it names Cedar Inc. as issuerThe party that creates and signs a token, assertion, or certificate, named in a token's iss claim. A recipient must check that the issuer is exactly the one it expected and trusts. 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 providerA service that authenticates users and tells other applications about the sign-in, so those applications never handle the users' passwords. In OpenID Connect it is called an OpenID Provider.'s entity ID and signing keys, its own entity ID and ACSThe endpoint at a SAML service provider that receives the identity provider's response, usually as a form the browser posts. The service provider publishes its ACS URL in metadata, and the identity provider sends responses only there., 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 is signed | Protected | Not protected |
|---|---|---|
| Assertion only | Issuer, subject, confirmation data, conditions, statements | The response's Destination, InResponseTo and Status |
| Response only | The whole response, including the assertion inside it | The assertion, if it is ever taken out of this response and used alone |
| Both | Everything, and the assertion stays protected on its own | Nothing 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:
| Check | Where to read it | Must equal |
|---|---|---|
| The sign-in succeeded | samlp:StatusCode/@Value | urn:oasis:names:tc:SAML:2.0:status:Success, otherwise no assertion is used |
| Who is speaking | saml:Issuer of the assertion (and response) | Cedar Inc.'s entity ID, the one whose key verified the signature |
| How it may be presented | SubjectConfirmation/@Method | urn:oasis:names:tc:SAML:2.0:cm:bearer |
| Where it may be presented | SubjectConfirmationData/@Recipient, and the response's Destination if present | This ACS, https://training.example/saml/acs |
| Until when it may be presented | SubjectConfirmationData/@NotOnOrAfter | Later than now |
| Which request it answers | SubjectConfirmationData/@InResponseTo | A pending request sent to this browser, not yet used and not expired; absent only if unsolicited responses are allowed |
| When it is valid | Conditions/@NotBefore and @NotOnOrAfter | Now falls inside, with a small clock allowance |
| Who may rely on it | AudienceRestriction/Audience | The training service's entity ID, https://training.example/saml |
| Not seen before | The assertion's ID | Not 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 CSRFAn attack in which another site makes your browser send a request you did not intend, and the receiving application treats it as yours because your session cookie came with it. Cookie settings such as SameSite reduce it by keeping the cookie off requests other sites start. 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:
<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 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 NameIDThe value in a SAML assertion's subject that identifies the user to the service provider, in a declared format such as a persistent opaque identifier or an email address. 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 cookieA small value that a website asks the browser to store and send back with later matching requests. Cookies commonly carry a session identifier, so the site can recognize an ongoing sign-in without your password., 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.
Try it in the Lab
- Refuse a response without trusting the wrong signing keyMake Lab Mail trust the wrong certificate and watch a correctly signed response fail, repair the trust, then see a wrong audience and a replayed response refused without a session.
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.