The idea: log in at one place, trusted by many apps

A company has dozens of web apps. With SAML 2.0 (Security Assertion Markup Language) none of them keeps passwords. Each app is a service provider (SP). One server, the identity provider (IdP), logs people in and then writes a signed statement, an assertion: "this is alice@example.org, she logged in at 09:00, this is for app X, valid for 5 minutes". The app checks the signature and believes it.

Time runs down. Three columns: SP, alice's browser, IdP. 1 the browser asks the SP for /reports. 2 the SP answers 302 to the IdP with SAMLRequest, AuthnRequest _req1. 3 the browser follows it to the IdP's /sso. 4 alice logs in at the IdP, skipped with an IdP session. 5 the IdP returns an auto-submit form with the signed SAMLResponse. 6 the browser POSTs it to /saml/acs. 7 the SP checks signature, audience, time and InResponseTo. 8 the SP answers 302 to /reports with Set-Cookie sp_session. No arrow joins the SP and the IdP.
SP-initiated SSO: the SP and the IdP never call each other; redirects and a form post make the browser carry both messages.

The canvas follows one login. On the left is the SP sp.example.com, in the middle alice's browser with its address bar and cookies, on the right the IdP idp.example.org. The panel below shows the SAML message of the moment as XML. Blue boxes carry the AuthnRequest, orange boxes the signed Response, grey boxes plain HTTP.

Metadata: what the two sides know in advance

Before any login, the SP and the IdP swap metadata, small XML files that an admin uploads once. Nothing else connects them.

SideentityID (its name)EndpointKey
SPhttps://sp.example.com/samlACS URL /saml/acs (HTTP-POST)trusts the IdP certificate
IdPhttps://idp.example.orgSSO URL /sso (HTTP-Redirect)signs with its private key

The ACS URL (Assertion Consumer Service) is the one address where the SP accepts assertions. The IdP sends an answer only to an ACS URL it has in that SP's metadata.

Step 1: the AuthnRequest rides a redirect

alice opens /reports without a session. The SP makes an <samlp:AuthnRequest> with a fresh ID (_req1), its own entityID as Issuer and its ACS URL, and remembers _req1 as pending for this browser. It does not call the IdP. It answers 302 Found: the request is deflated, base64-encoded and put in the Location URL as SAMLRequest, next to RelayState=/reports (where to go afterwards). This is the HTTP-Redirect binding. The browser follows it to the IdP (Demo: SP-initiated login, end to end).

Step 2: the IdP answers with a signed Response

The IdP logs alice in on its own page, so only the IdP ever sees her password. Then it builds a <samlp:Response> holding an <saml:Assertion> and signs the assertion with its private key (an XML signature, RSA-SHA256). A Response is too big for a URL, so the IdP returns an HTML page with a hidden form field SAMLResponse and a script that submits it at once to the ACS URL: the HTTP-POST binding.

FieldSaysExample
Issuerwho wrote ithttps://idp.example.org
ds:Signatureproof that the IdP wrote it, unchangedRSA-SHA256 over _as1
NameIDwho the user isalice@example.org
Audience, Recipient, Destinationwhich SP it is forhttps://sp.example.com/saml, its ACS URL
NotOnOrAfteruntil when it may be usedIssueInstant + 5 min
InResponseTowhich request it answers_req1
AuthnStatementhow and when she logged inSessionIndex="_s1"

Step 3: what the SP checks at the ACS URL

The Response came through the browser, so the browser (or whoever controls it) could have changed it, delayed it or swapped it. HTTPS does not help here: it only protects the hop, not the content. The SP therefore trusts nothing until four checks pass, and each failure case on this page fails exactly one of them.

The Response box with ID _resp1, InResponseTo _req1 marked 4, Destination marked 2 and Issuer, and inside it the orange Assertion box with Signature marked 1, NameID alice@example.org, Recipient marked 2, NotOnOrAfter 09:05:09 marked 3, InResponseTo marked 4, Audience marked 2 and AuthnStatement. On the right: 1 signature valid, checked with the IdP certificate, stops an edited assertion; 2 made for this SP, stops one made for another SP; 3 not expired, stops an old or delayed copy; 4 asked for, stops an unsolicited one.
Each check reads different fields of the assertion and stops a different trick.
CheckFails whenDemo
1. Signature verifies with the IdP certificate from metadataany byte of the assertion changed (NameID edited to admin@example.org)assertion edited in the browser
2. Destination, Recipient and Audience name this SPthe IdP made it for another SP (Mallory's wiki)Mallory forwards a wiki assertion
3. The SP clock is before NotOnOrAfterit arrives after 5 minutesform posted 10 min late
4. InResponseTo is a request this browser startednobody here asked for it (login CSRF)Mallory posts her own Response

Check 2 matters because every SP of the same IdP receives assertions about alice. Without it, a dishonest SP could log in to all the others as alice with what it received. Check 4 stops the reverse: Mallory logs alice in to Mallory's account, and alice then uploads her files to it. The SP also crosses _req1 off its pending list, so the same Response cannot be posted twice. Real SPs add a few more checks: the Issuer, NotBefore, a small clock-skew allowance, and a cache of assertion IDs already used. See How a Digital Signature Works for how the signature check itself works, and CSRF and SameSite Cookies for the general form of check 4's attack.

Two sessions: SSO and the app

After a login there are two cookies on two domains. idp_session on the IdP is what makes it single sign-on: the next app that sends alice to the IdP gets an assertion without a password prompt (Demo: SSO, already signed in at the IdP). sp_session on the SP is the app's own login; every later request uses only that cookie, with no SAML at all. Ending one does not end the other: the SP session ends button clears only the SP cookie, so the next login skips the password. See JWT vs Session Cookies for how such an app session is kept.

SAML vs OpenID Connect

OpenID Connect solves the same problem on top of OAuth 2.0. Its IdP is called an OpenID Provider and its assertion is an ID token, a signed JSON Web Token.

SAML 2.0OpenID Connect
FormatXML, XML signatureJSON, JWT signed with JWS
RequestAuthnRequest in a redirect/authorize?response_type=code&scope=openid
How the token reaches the appthrough the browser, in a form POST to the ACS URLusually a short code through the browser, then the ID token on a direct back-channel call
"For this app" fieldAudienceaud = client_id
"Answers my request" fieldInResponseTononce (and state)
Expiry fieldNotOnOrAfterexp
Typical useenterprise apps, the corporate loginconsumer logins, mobile apps, APIs

The checks are the same idea with different names. The big practical difference is the channel: in SAML the signed assertion always passes through the browser, so the signature carries all the trust; in the OpenID Connect code flow the app fetches the token from the provider directly. Kerberos is the older single sign-on of a company network: it hands out tickets instead of signed statements.

What the page leaves out

  • IdP-initiated login (the user starts at an IdP portal; there is no AuthnRequest and no InResponseTo to check), and the Artifact binding, where the SP fetches the assertion over a back channel.
  • Encrypted assertions (EncryptedAssertion), signed AuthnRequests and signing the whole Response instead of the assertion.
  • Attributes (AttributeStatement: groups, roles, email), NameID formats such as persistent and transient IDs.
  • Single Logout (LogoutRequest to every SP of a session), ForceAuthn and IsPassive.
  • XML details: canonicalization, enveloped signatures and the XML signature wrapping attacks that careless parsers fall for.
  • Real IDs are random 128-bit or longer values, and real clocks allow a little skew.

On the mind map

Open the Web & Security mind mapWeb & SecurityCrypto building blocks: keys, hashes, signaturesCrypto building blocksStoring passwords: slow salted hash, never plaintextStoring passwordsBrowser rules: which request carries whatBrowser rulesRequest attacks: trick a browser or a serverRequest attacksLogin & identity: prove who you areLogin & identityOWASP Top 10 2025: common flaws, then the fixOWASP Top 10 2025OWASP: supply chain & ops: dependencies, logs and error pathsOWASP: supply chain & opsOAuth 2.0 with PKCEOAuth 2.0 with PKCEapp gets a scoped token, not the passwordOpenID ConnectOpenID ConnectID token says who; check iss, aud, nonceSAML Single Sign-OnSP checks the IdP's signed assertionJWT vs session cookieJWT vs session cookieJWT: signed, stateless, hard to revokeKerberosKerberosTGT from the KDC, then a ticket per serviceLDAP directoryLDAP directorySearch for the DN, then bind as the userMutual TLSMutual TLSboth sides show and prove a certificateEmail SPF, DKIM, DMARCEmail SPF, DKIM, DMARCDMARC: SPF or DKIM must align with From:TOTP two-factor codesTOTP two-factor codesHMAC(secret, time/30s) → 6 digitsRBAC vs ABACRBAC vs ABACRoles grant rights; attributes decide liveBell-LaPadula and BibaBell-LaPadula and BibaNo read up, no write down; Biba flips itGRANT and REVOKEGRANT and REVOKEMariaDB REVOKE never cascadesOpen the Web & Security mind mapWeb & Securityprove who you areLogin & identityOAuth 2.0 with PKCEOAuth 2.0 with PKCEapp gets a scoped token, not the passwordOpenID ConnectOpenID ConnectID token says who; check iss, aud, nonceSAML Single Sign-OnSP checks the IdP's signed assertionJWT vs session cookieJWT vs session cookieJWT: signed, stateless, hard to revokeKerberosKerberosTGT from the KDC, then a ticket per serviceLDAP directoryLDAP directorySearch for the DN, then bind as the userMutual TLSMutual TLSboth sides show and prove a certificateEmail SPF, DKIM, DMARCEmail SPF, DKIM, DMARCDMARC: SPF or DKIM must align with From:TOTP two-factor codesTOTP two-factor codesHMAC(secret, time/30s) → 6 digitsRBAC vs ABACRBAC vs ABACRoles grant rights; attributes decide liveBell-LaPadula and BibaBell-LaPadula and BibaNo read up, no write down; Biba flips itGRANT and REVOKEGRANT and REVOKEMariaDB REVOKE never cascades
This page on the Web & Security mind map · 45 pages in 7 branches · open it to see the whole map and test yourself in recall mode.