
SAML 2.0 Explained: The Complete Guide to Enterprise SSO
A walkthrough of SAML 2.0, covering how identity providers and service providers enable enterprise single sign-on using SAML assertions.
Most engineers confuse Single Sign-On (SSO) with a magic cookie that follows you everywhere. In reality, SAML 2.0 is a protocol for transferring trust. It does not store your password in a shared database; instead, it allows a trusted Identity Provider (IdP) to tell a Service Provider (SP) who you are, and the SP verifies that claim using a cryptographic signature. This mechanism solves the "password fatigue" problem without requiring the application to ever see your credentials.
The Actors and Artifacts
To understand the flow, we must first define the actors and the artifacts they exchange. The Identity Provider (IdP) is the entity that knows your credentials (e.g., Okta, Azure AD). The Service Provider (SP) is the application you want to access (e.g., Salesforce, Slack). The artifact that carries the proof of identity is the SAML Assertion. This is a specific XML document containing three parts: the Subject (who you are), the Conditions (when the assertion is valid), and the Statements. Crucially, while Assertions can contain Authorization Decision Statements, most enterprise assertions primarily contain Attribute Statements detailing identity and group membership. Unlike a session cookie which the browser sends automatically, a SAML Assertion is a large XML block that the browser must physically transport from the IdP to the SP via an HTTP POST or Redirect.
The mechanism of trust relies entirely on XML signature. When the IdP generates an assertion, it signs it using a private key. The SP holds the corresponding public key (usually distributed as an X.509 certificate during metadata exchange). When the SP receives the response, it does not trust the IdP because of a pre-existing network tunnel; it trusts the response because the cryptographic signature matches the public key. If a man-in-the-middle alters even a single byte of the XML assertion, the signature verification fails, and the SP rejects the login. This ensures that the authentication event cannot be forged by a third party intercepting the traffic.
The Assertion Flow
Let's walk through a concrete scenario to visualize the data flow. Imagine Alice wants to access her company's CRM. She types the CRM URL, which triggers the SP. The SP checks its local session cache, finds no valid session, and generates a SAMLAuthnRequest. This request is a small XML document asking, "Is Alice authenticated?" The SP encodes this request and redirects Alice's browser to the IdP's Single Sign On Service (SSO) URL. The browser now acts as a proxy, carrying the request to the IdP.
At the IdP, Alice enters her username and password. The IdP authenticates her against its directory. Once verified, the IdP constructs a SAMLResponse. This response contains the SAMLAssertion stating "Alice is authenticated at 10:00 AM." The IdP then digitally signs this entire XML document. Finally, the IdP sends this massive XML payload back to the SP's Assertion Consumer Service (ACS) endpoint, usually via an HTTP POST with the assertion encoded in a SAMLResponse parameter. The browser submits this form, and the SP receives the data.
The SP now performs the critical validation step. It parses the incoming XML, extracts the signature, and verifies it against the IdP's public certificate. If the signature is valid, the SP checks the Conditions within the assertion to ensure it hasn't expired and that the Audience URI matches its own identifier. Only after these checks pass does the SP create a local session for Alice and redirect her to the CRM. The entire process happens without the CRM ever seeing Alice's password; it only sees the signed assertion proving she logged in elsewhere.
Binding Mechanisms and Security Boundaries
A common point of confusion is the binding mechanism. While the protocol defines many bindings, the most common for enterprise SSO is the HTTP POST Binding. In this method, the browser submits the XML assertion as a form post. This is distinct from the HTTP Redirect Binding, where the assertion is base64-encoded and placed in the URL query string. The POST binding is generally preferred for assertions containing sensitive data because it keeps the XML out of server logs and browser history, which might otherwise record the query string.
However, the security model has specific boundaries. The assertion itself is signed, but it is often not encrypted. This means anyone intercepting the network traffic can see the username (the Subject) and the groups associated with it, even if they cannot forge the login. For scenarios requiring privacy, the IdP can encrypt the assertion using the SP's public key, ensuring only the SP can read the contents. But in standard enterprise setups, the signature is the primary control. If the signature is compromised, the attacker can replay a valid assertion. To mitigate this, assertions include a NotOnOrAfter timestamp and a unique ID attribute. The SP must track these IDs to ensure a valid assertion is never accepted twice, preventing replay attacks.
Common Pitfalls
Implementing a federated identity system often reveals subtle configuration errors.
- Assertion Replay: If the SP fails to track the unique
IDof assertions, an attacker can capture a valid login response and replay it to gain unauthorized access. - Unencrypted Sensitive Data: Relying solely on signatures leaves the Subject and Attributes visible in network traffic. In high-security environments, failing to enable assertion encryption exposes user attributes to network sniffers.
- Metadata Misconfiguration: Incorrectly mapping the Entity ID or failing to update certificates during rotation can break the trust relationship immediately, causing a cascade of login failures across the organization.
Practical Takeaways
To master SAML 2.0 as part of your enterprise-security strategy, remember these rules of thumb:
- Trust the Signature, Not the Source: The SP must never assume the IdP is trustworthy based on network location; it must always verify the cryptographic signature.
- The Browser is a Transport, Not a Participant: The browser carries the payload but has no business logic; it simply forwards the XML from the IdP to the SP.
- Time is Critical: Always enforce strict
NotBeforeandNotOnOrAfterconditions to limit the window of opportunity for replay attacks.
FAQ
Q: Is SAML 2.0 the same as OAuth 2.0? A: No. SAML is an authentication flow protocol focused on verifying identity via XML assertions, while OAuth 2.0 is an authorization framework focused on granting delegated access to resources.
Q: Why do we need an Identity Provider if the application manages users? A: Centralizing identity management via an IdP allows organizations to enforce consistent security policies, such as Multi-Factor Authentication (MFA), across all applications without managing credentials in each system.
Q: Can SAML work without HTTPS? A: While technically possible, using SAML over non-HTTPS connections is a severe security risk. The SSO protocol relies on the transport layer to protect the XML payload from tampering; without HTTPS, the signed assertion can be intercepted and modified.
Conclusion
In summary, SAML 2.0 works by decoupling the identity verification from the resource access. The IdP becomes the source of truth, and the SP becomes a verifier of claims. The mechanism relies on the browser as a transport vessel for signed XML documents, ensuring that the trust relationship is established cryptographically rather than through shared secrets. This architecture allows organizations to manage access centrally while maintaining strict security boundaries between the identity layer and the application layer.
Related posts
SAML Artifact Binding: Low-Latency SSO Architecture
An examination of SAML artifact binding for achieving low-latency SSO performance and reducing network overhead.
CAS Protocol vs SAML vs OIDC: Legacy SSO Protocol Comparison
A technical comparison of CAS protocol, SAML, and OIDC for legacy authentication systems in university environments.
SAML Single Logout: Implementation Patterns and Pitfalls
An examination of SAML single logout implementation patterns, covering session management and pitfalls in SP-initiated and IdP-initiated logout flows.