SP-initiated and IdP-initiated sign-in
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. sign-in can start at the training service, which then knows what it asked for, or at Cedar Inc.'s portal, which sends a response nobody requested. The difference decides what the training service can check, and what an unsolicited response lets an attacker try.
Starting at the application
Avery's manager sends her a link to a fire safety course, https://training.example/courses/fire-safety. She clicks it, signs in at Cedar Inc. and lands on the course. That flow, the one in How SAML sign-in works, is SP-initiated sign-in: the service provider noticed that Avery had no 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. and started the exchange with an AuthnRequest.
Starting at the application gives the training service two things it will use when the response arrives. It knows what it asked for, because it sent the request, and it knows which browser asked, because it saved a note in that browser's context. Both let it treat the response as the answer to a question it actually put, rather than as a message that simply turned up.
Cedar Inc. checks the request before anyone signs in. The Issuer must be a service provider it has an agreement with, 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. on the query string must verify with that provider's certificateA signed statement that a public key belongs to a name, such as a website's hostname, for stated purposes and a limited period. A certificate authority signs it, so software that trusts the authority can connect the key to the name. if signed requests are required, and the 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. named in the request must be one the provider registered. A signature authenticates the requester; it does not make every value in the request acceptable.
Keeping the round trip together
When the training service sent the request _a7f3c2e91b0d, it saved a record of it: the request ID, the time, the course Avery wanted, and a reference stored in a 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. on Avery's browser. Cedar Inc. answers with InResponseTo="_a7f3c2e91b0d", and so does the signed SubjectConfirmationData inside the assertion. At the ACS, the training service checks three things together: the ID names a request it sent, that request is still pending and within its deadline, and it belongs to the browser presenting the response.
The last check matters because a valid response is valuable to anyone who can carry it. Suppose two browsers have each started a sign-in:
| Browser | Pending request | Wanted |
|---|---|---|
| Avery's laptop | _a7f3c2e91b0d | The fire safety course |
| Another browser | _d40b7e26c1f9 | The finance course |
If a response with InResponseTo="_a7f3c2e91b0d" arrives from the other browser, the ID is genuine, but it belongs to a different browser's attempt, and the training service refuses it. Each pending request is also used once and expires after a few minutes, so a response cannot be accepted twice or long after Avery walked away.
The cookie that ties the request to the browser meets a browser rule on the way back. The response arrives as a form post from login.cedar.example, a cross-site request, so the browser leaves out cookies marked SameSite=Lax or Strict. A training service that keeps its pending-request cookie that way will find it missing at the ACS. The usual fix is to give that one short-lived cookie SameSite=None; Secure, while the training service's own session cookie keeps its stricter setting.
RelayState travels alongside the messages and comes back unchanged. The training service can use it to remember that Avery wanted the fire safety course. The safest value is an opaque reference to the saved record, such as c7f2a9, rather than a URLA web address, such as https://photos.example/api/albums/42?limit=10. It names how to connect (https), the domain, the path to a particular page or resource, and any extra parameters after the question mark.. A service that redirects to whatever URL arrives in RelayState has built an open redirector, which an attacker can use to send people from a trusted address to a malicious one.
Starting at the provider
Many companies also give staff a launcher, a page at the identity provider with a tile for each application. When Avery clicks the training tile, Cedar Inc. already knows who she is, so it builds a response for the training service straight away and posts it to the ACS. No AuthnRequest was ever sent. This is IdP-initiated sign-in, and the response is called unsolicited.
The response looks almost the same as before. It is signed, it has the right Audience, Recipient and validity window, and the training service can check all of that. What is missing is InResponseTo, both on the response and in the SubjectConfirmationData, because there is nothing to respond to. The SAML profile allows this, and the training service must decide in advance whether it accepts unsolicited responses at all.
What an unsolicited response risks
Without a request, the training service loses its link between the response and the browser presenting it. That gap enables an attack called login cross-site request forgery, or login CSRF. An attacker signs in to the training service through Cedar Inc. with their own account, if they have one, and captures the genuine response before it reaches the ACS. They then put that response in a form on a page they control. When Avery visits the page, her browser posts the attacker's response to the training service, which sees a valid, unsolicited assertion and signs Avery's browser in, as the attacker.
Avery may not notice. She keeps working, uploads a document or types notes into what she thinks is her own account, and the attacker later reads them by signing in normally. With a request, this fails: the attacker's response would name a request that Avery's browser never made.
The second risk is replay. A captured unsolicited response stays acceptable at the ACS until its NotOnOrAfter, and with no pending request to consume, the only protection is the training service's memory of assertion IDs it has accepted. That replay cache becomes essential, not optional.
A service that accepts unsolicited responses can reduce both risks: very short assertion lifetimes, a strict replay cache, and a confirmation page after an unsolicited sign-in that shows which account was signed in before anything is done in it. The strongest option removes the gap entirely, as the next section describes.
Choosing the experience deliberately
A launcher tile does not have to send an unsolicited response. Cedar Inc. can point the tile at the training service's own sign-in address, for example https://training.example/saml/login?target=courses. The training service then starts an ordinary SP-initiated exchange, Cedar Inc. sees that Avery already has a session and answers at once, and Avery notices no difference. She still starts from the tile, while the protocolAn agreed set of rules for the messages two systems exchange and what each message means. HTTP, OAuth 2.0, OpenID Connect and SAML are all protocols. starts at the application, with a pending request, an InResponseTo and full protection against login CSRF.
Some service providers go further and, when an unsolicited response arrives, do not use it at all: they redirect the browser to start an SP-initiated sign-in, which Cedar Inc. completes silently. Either way, which initiation modes are allowed is part of the agreement, and each is tested on its own.
When a sign-in fails, the mode is a good first question. A refused unsolicited response may be the policy working, not a broken certificate. A response with an unknown InResponseTo may mean the pending record expired, or the cookie was dropped on the way back. Turning off request matching to make the error go away would reopen exactly the gap this lesson describes.
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
- Identify whether the service provider started the sign-inComplete a SAML sign-in the application started, then see a signed response nobody asked for, and one meant for another browser, refused by the same receiver.