SP-initiated SAML SSO: correlate each response with its browser login
Create a separate transaction for each AuthnRequest, bind it to the initiating browser, and issue a session only after the selected profile checks pass.
SP-initiated SAML SSO begins when a user opens an application and the Service Provider (SP) sends an AuthnRequest to an Identity Provider (IdP). The SP should store a unique request ID with the browser login transaction and verify that the returned subject confirmation belongs to that request. Create an SP session only after correlation and the selected SAML profile checks succeed.
Request and response
The unauthenticated user opens a protected page; the SP selects an allowed IdP and current browser session.
The SP creates a unique `AuthnRequest` ID with its issuer and needed options. If it specifies an ACS URL or index, it selects only an endpoint registered in metadata.
The SP stores the ID with the browser's pending login transaction and sends the request to the trusted IdP `SingleSignOnService`. Binding and signing follow the integration profile.
The IdP returns a Response to the SP's ACS. The SP verifies that bearer `SubjectConfirmationData.InResponseTo` matches the stored request ID.
Only after the Response and Assertion pass the selected profile validation does the SP link the account and issue its application session.
The ID check alone is insufficient: the response must also belong to the browser transaction that initiated login, or a response from another tab or session could be attached incorrectly.
Keep one transaction per attempt
Store a separate server-side record per request rather than overwriting one session variable. Include the request ID, browser session or secure reference, IdP and allowed ACS, expiry and processing state, and validated internal post-login path. Separate records support concurrent tabs. Mark a transaction complete atomically so duplicate responses cannot create multiple sessions. If the transaction expires or loses its browser binding, ask the user to restart; never reuse an old response for a new transaction.
Restore the original page safely
Bind the destination to the transaction. RelayState can carry a reference, but an unvalidated browser-returned value can create an open redirect. Prefer storing the destination server-side and putting only a random short reference in RelayState. If carrying a path directly, allow only internal relative paths and reject external URLs with a scheme or host. Bind and expire the reference, and use a safe default when it is missing or invalid. RelayState does not replace issuer or signature validation; validate Response and Assertion under the ACS's configured Web Browser SSO profile.
Troubleshoot
| Symptom | Check |
|---|---|
InResponseTo mismatch | Response ID and transaction record; whether tabs overwrite one ID |
| Correct ID, wrong browser logs in | Binding between initiating and responding browser sessions |
| Wrong post-login page | Server-side destination, transaction-bound RelayState reference, fallback path |
| Replay creates another session | Atomic transaction completion and shared replay storage for Response/Assertion IDs |
| Response uses another ACS | Registered and IdP-cached metadata; ACS URL/index policy |
A response without InResponseTo is a separate unsolicited IdP-initiated flow, with its own policy and validation. Do not disable correlation to silence errors.
Verification plan
In a test environment, check single-tab and concurrent two-tab logins, a response received in another browser session, invalid or expired InResponseTo, duplicate responses, expired transactions, and disallowed RelayState destinations. Only a valid response tied to its initiating browser transaction should create a session. This is a proposed plan, not a claim of tests run on a particular product.
References
[OASIS SAML V2.0 Profiles, §4.1 Web Browser SSO](https://docs.oasis-open.org/security/saml/v2.0/saml-profiles-2.0-os.pdf)
[OASIS SAML V2.0 Bindings, HTTP bindings and RelayState](https://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf)
[OASIS SAML V2.0 Core, §3.4 Authentication Request Protocol](https://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf)