Security & Identity
SAML 2.0 and Single Sign-On: Assertions, Bindings and Federation
Intermediate7 min readUpdated
SAML 2.0 still carries enterprise single sign-on in universities, government and large corporations, and integrating with it means reading XML rather than JSON. This guide explains the federation model, the anatomy of an assertion, both initiation flows and their bindings, metadata and certificate rotation, the signature pitfalls that made SAML notorious, and when to choose it over OpenID Connect.
What you will learn
- Explain the federation model and the roles of identity provider and service provider
- Read a SAML assertion and identify the subject, conditions, statements and signature
- Distinguish SP-initiated from IdP-initiated flows and the Redirect and POST bindings
- Exchange metadata and rotate signing certificates without an outage
- Avoid the signature-validation errors that lead to authentication bypass
- Decide between SAML and OpenID Connect for a new integration
Long before browsers spoke JSON to identity providers, enterprises needed one login to open a dozen applications, some of them running in another organisation entirely. SAML 2.0, standardised by OASIS in 2005, solved that with an XML vocabulary for making and transporting statements about an authenticated user, and it has been quietly holding up university federations, government portals and corporate application estates ever since. If you sell software to large organisations, sooner or later a customer will send you a metadata file rather than a client secret.
Working with SAML is different from working with OpenID Connect in ways that go beyond the serialisation format. Trust is established out of band by exchanging certificates rather than by fetching a discovery document; the security of the whole exchange rests on XML digital signatures, a specification with famously sharp edges; and there is no notion of an access token for calling APIs. This guide covers what you need to integrate correctly and what has historically gone wrong.
Federation and the two roles
Single sign-on means a user authenticates once and subsequent applications accept that authentication instead of asking again. Federation extends this across organisational boundaries: the application trusts an assertion made by an identity provider it does not control, on the strength of a certificate exchanged in advance.
- The identity provider (IdP) authenticates the user and issues assertions. There is typically one per organisation.
- The service provider (SP) is the application consuming the assertion. It never sees the user's credentials.
- The assertion is the signed XML document carrying the statements.
- The circle of trust is the set of parties that have exchanged metadata and agreed to accept each other's statements.
The practical consequence is that credentials stay with the employer's directory. A person leaving the organisation is disabled once, centrally, and every federated application stops admitting them — the identity lifecycle argument developed further in identity and access management.
Anatomy of an assertion
An assertion is a <saml:Assertion> element with an issuer, a signature, a subject, validity conditions and one or more statements. Stripped of namespace noise, a realistic one looks like this.
<saml:Assertion ID="_a1b2c3d4e5" IssueInstant="2026-09-07T09:14:22Z" Version="2.0"
xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">
<saml:Issuer>https://idp.university.example/idp/shibboleth</saml:Issuer>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"> ... </ds:Signature>
<saml:Subject>
<saml:NameID Format="urn:oasis:names:tc:SAML:2.0:nameid-format:persistent">
c7f1e0a9-2b44-4d7e-9f30-8a0e1c2b3d45
</saml:NameID>
<saml:SubjectConfirmation Method="urn:oasis:names:tc:SAML:2.0:cm:bearer">
<saml:SubjectConfirmationData NotOnOrAfter="2026-09-07T09:19:22Z"
Recipient="https://app.example.com/saml/acs"
InResponseTo="_req-88f21a"/>
</saml:SubjectConfirmation>
</saml:Subject>
<saml:Conditions NotBefore="2026-09-07T09:14:12Z" NotOnOrAfter="2026-09-07T09:24:22Z">
<saml:AudienceRestriction>
<saml:Audience>https://app.example.com/saml/metadata</saml:Audience>
</saml:AudienceRestriction>
</saml:Conditions>
<saml:AuthnStatement AuthnInstant="2026-09-07T09:14:20Z" SessionIndex="_sess-4471">
<saml:AuthnContext>
<saml:AuthnContextClassRef>
urn:oasis:names:tc:SAML:2.0:ac:classes:MobileTwoFactorContract
</saml:AuthnContextClassRef>
</saml:AuthnContext>
</saml:AuthnStatement>
<saml:AttributeStatement>
<saml:Attribute Name="urn:oid:0.9.2342.19200300.100.1.3">
<saml:AttributeValue>[email protected]</saml:AttributeValue>
</saml:Attribute>
<saml:Attribute Name="urn:oid:1.3.6.1.4.1.5923.1.1.1.1">
<saml:AttributeValue>staff</saml:AttributeValue>
<saml:AttributeValue>member</saml:AttributeValue>
</saml:Attribute>
</saml:AttributeStatement>
</saml:Assertion>
Each part carries obligations for the consumer. The NameID format determines whether you receive a reusable identifier: persistent gives a stable pseudonym unique to this SP pairing, transient gives a value valid for one session only, and emailAddress gives something readable but changeable. Conditions must be enforced — the audience restriction is what stops an assertion minted for one application being replayed at another, and the time window must be checked against a clock synchronised by NTP. The AuthnContextClassRef is SAML's equivalent of an authentication strength claim and is how an SP demands multi-factor authentication. Attributes are commonly named by LDAP object identifiers, which is why integration guides are full of strings like urn:oid:1.3.6.1.4.1.5923.1.1.1.1.
Flows and bindings
A binding describes how a SAML message travels over HTTP. Two matter.
HTTP-Redirect puts a deflated, base64-encoded, URL-encoded message in a query parameter, with the signature as a separate parameter. It suits small messages such as an authentication request, and it is limited by URL length.
HTTP-POST puts the base64-encoded message in a hidden form field that a small auto-submitting page posts to the peer. Responses carrying assertions always use this binding, because they are far too large for a URL.
SP-initiated SSO is the flow to prefer. The user asks for a protected page, the SP builds an AuthnRequest with a unique ID and redirects the browser to the IdP; the IdP authenticates, then POSTs a Response containing the assertion to the SP's Assertion Consumer Service.
GET /idp/profile/SAML2/Redirect/SSO?SAMLRequest=fVLLTsMwEPwVy3fHTkI...
&RelayState=%2Freports%2Fq3
&SigAlg=http%3A%2F%2Fwww.w3.org%2F2001%2F04%2Fxmldsig-more%23rsa-sha256
&Signature=Xk9c2Fq... HTTP/1.1
Host: idp.university.example
POST /saml/acs HTTP/1.1
Host: app.example.com
Content-Type: application/x-www-form-urlencoded
SAMLResponse=PHNhbWxwOlJlc3BvbnNlIHhtbG5zOnNhbWxwPSJ1cm46b2FzaXM6...&RelayState=%2Freports%2Fq3
RelayState carries the SP's own state — usually the page the user originally wanted — and must be treated as untrusted input: validate it as a relative path, or you have built an open redirect. Because the payloads are base64, a base64 decoder is the quickest way to read a captured message while debugging an integration, though production code must always work from the parsed and verified document.
IdP-initiated SSO starts from a portal link: the IdP posts an unsolicited assertion with no InResponseTo. It is convenient and weaker, since the SP has no request of its own to correlate the response with. Support it only when a customer insists, and compensate with short lifetimes and strict single-use tracking of assertion identifiers.
Metadata and certificates
Metadata is the machine-readable description of a party: its entity identifier, its endpoints, the NameID formats it supports and, crucially, its certificates.
<md:EntityDescriptor entityID="https://app.example.com/saml/metadata"
xmlns:md="urn:oasis:names:tc:SAML:2.0:metadata">
<md:SPSSODescriptor protocolSupportEnumeration="urn:oasis:names:tc:SAML:2.0:protocol"
AuthnRequestsSigned="true" WantAssertionsSigned="true">
<md:KeyDescriptor use="signing">
<ds:KeyInfo xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:X509Data><ds:X509Certificate>MIIDdzCCAl+gAwIBAgIE...</ds:X509Certificate></ds:X509Data>
</ds:KeyInfo>
</md:KeyDescriptor>
<md:AssertionConsumerService index="0"
Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
Location="https://app.example.com/saml/acs"/>
<md:SingleLogoutService
Binding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
Location="https://app.example.com/saml/slo"/>
</md:SPSSODescriptor>
</md:EntityDescriptor>
Two operational habits prevent most SAML outages. Serve metadata at a stable HTTPS URL and consume the partner's the same way on a schedule, rather than trading files by email. And rotate certificates with an overlap: publish the new one alongside the old, wait until every partner has refreshed, switch the signing key, then remove the old certificate. A certificate expiring at midnight with no overlap is the classic Monday-morning federation incident.
Signature validation, done carefully
SAML's security rests entirely on XML digital signatures, and XML signatures are harder than they look because the signature references a portion of the document by identifier rather than covering the bytes wholesale. That indirection produced the family of signature wrapping attacks: an attacker takes a legitimately signed assertion, wraps or relocates it in the document, and inserts a forged assertion that the application's parser happens to read. The signature still verifies — over the original, now-hidden element — while the application acts on the attacker's version.
The defences are specific:
- Verify first, then read. Validate the signature and then extract the subject and attributes from the exact element that was signed, never from a fresh XPath query over the whole document.
- Use a maintained SAML library, not a general-purpose XML toolkit. Correct handling of references, canonicalisation and the signed-element identity is not something to reimplement.
- Decide in advance what must be signed — the response, the assertion, or both — and reject anything that does not meet that policy. An unsigned assertion inside a signed response is not automatically safe.
- Pin the certificate from metadata. Never trust a certificate embedded in the incoming message itself, and check the issuer entity identifier against the key you expect.
- Disable external entity resolution and DTDs in the parser. XML external entity processing turns a login endpoint into a file-read primitive; the XML processing guide covers the parser settings involved.
- Enforce the full condition set: audience,
NotBefore,NotOnOrAfter,Recipient,InResponseTo, and one-time use of the assertion identifier. - Require SHA-256 or stronger. Reject SHA-1 signature algorithms and RSA keys shorter than 2048 bits.
Single logout, and mapping attributes
Single logout propagates a logout from one application to the whole circle of trust: the initiating party sends a LogoutRequest naming the SessionIndex, and the IdP relays it to every other SP. In practice it is fragile — one unreachable SP, one browser blocking a redirect chain, and the sequence stalls halfway. Many deployments therefore log out locally, redirect to the IdP to end the central session, and accept that other applications will expire naturally. If reliable global logout is a requirement, treat it as a design constraint from the start rather than a checkbox.
Attribute mapping is the unglamorous part of every integration. The IdP releases whatever the organisation's policy permits, under names you do not choose, and your application must translate them into its own roles. Two rules save a great deal of pain: never make a group name from the customer's directory a hard-coded authority in your code — map it through configuration — and treat attribute values as untrusted strings that need the same validation and output encoding as any other input.
SAML or OpenID Connect?
| Aspect | SAML 2.0 | OpenID Connect |
|---|---|---|
| Format | XML with XML digital signatures | JSON with JWS |
| Trust setup | Metadata and certificate exchange | Discovery document plus JWKS |
| API authorization | Not covered | Built on OAuth 2.0 access tokens |
| Mobile and SPA support | Awkward, browser-centric | Designed for it |
| Enterprise and academic reach | Very wide, entrenched | Growing, universal in new products |
| Implementation risk | Signature handling is unforgiving | Simpler, but token validation still matters |
For a new integration with a choice, pick OpenID Connect: the cryptography is easier to get right, the same infrastructure secures your APIs through OAuth 2.0, and mobile clients are first-class. Choose SAML when the counterpart only speaks SAML, which in enterprise and academic contexts is often the whole story. Many products support both, and a modern identity provider will happily act as a SAML IdP for one application and an OpenID Provider for the next.
Key takeaways
- SAML federates authentication by having a service provider trust a signed XML assertion from an identity provider, with trust anchored in exchanged metadata.
- An assertion's conditions — audience, time window, recipient and
InResponseTo— are security controls that the consumer must enforce, not documentation. - SP-initiated flows with the HTTP-POST binding for responses are the safe default; unsolicited IdP-initiated assertions lose replay protection.
- Metadata served over HTTPS and refreshed on a schedule, with overlapping certificates, turns key rotation into a routine change.
- Validate the signature with a real SAML library, read only the signed element, pin certificates from metadata, and disable external entities.
- Prefer OpenID Connect for new work; support SAML when the counterpart requires it, and expect single logout to need deliberate design.
Sources and further reading
Frequently asked questions
- Is SAML obsolete?
- It is mature rather than obsolete. New consumer and mobile integrations use OpenID Connect, but SAML remains the default in higher education federations, government services and large enterprise software estates, and those deployments are not being rewritten. If you build software sold to enterprises, supporting SAML is frequently a procurement requirement rather than a technical preference.
- Why is IdP-initiated SSO discouraged?
- Because the service provider receives an unsolicited assertion with no request of its own to correlate it against, which removes the natural replay and CSRF protection that InResponseTo provides. An attacker who captures an assertion, or who can make a victim's browser post one, can trigger a login the victim never started. Where the flow is unavoidable, enforce short assertion lifetimes and strict one-time-use tracking.
- Do I have to encrypt assertions as well as sign them?
- Signing is mandatory for trust; encryption protects confidentiality of the attributes. Since assertions travel through the browser, anything sensitive in them is visible to the user and to anything running in that browser. If the assertion carries only an opaque identifier over TLS, signing alone is usually acceptable; if it carries personal data, roles or entitlements you would not show the user, encrypt the assertion.
- How should certificate rotation be handled?
- Publish metadata containing both the outgoing and incoming signing certificates for an overlap period, so verifiers accept either. Roll the signing key only after every partner has refreshed its copy of the metadata, then republish with the old certificate removed. Consuming metadata from a URL on a schedule rather than by emailing files is what makes this a routine change instead of an outage.