Enterprise SSO and SCIM
Let each customer's own identity provider log people in and remove them, and check every answer it sends you.
Updated since you finished it. We changed this lesson after you marked it done. Your progress is kept.
What broke
On 12 March 2025, GitHub's security lab published a write-up called "Sign in as anyone". It described critical bugs in ruby-saml, a Ruby library that apps use to accept SAML logins. 1
The library used two different XML parsers while it checked a signature. An attacker could build a document that the two parsers read differently. One parser found one signature. The other parser found a different one. So the check passed on content that was never really signed. 1
The attacker needed one valid signature from the target company's identity provider. That could come from an ordinary user's login response. In some cases, it could come from the provider's public metadata. With it, they could forge an assertion for any user and log in as that user. 1
The researchers found a working instance in GitLab. GitLab released a critical patch on 12 March 2025. That was the same day as the write-up. On a GitLab instance with SAML login, "an attacker with access to a valid signed SAML document from the IdP could authenticate as another valid user". 2
GitLab's stopgaps show where the flaw was. Turn on two-factor login inside GitLab. Require admin approval for new users created on the fly. Multi-factor login at the identity provider "does not mitigate this vulnerability". 2 The flaw was in the SAML library inside the app. The forged login never passed through the provider, so nothing the provider did could stop it.
The lesson: when a customer's identity provider logs users in to your app, your app must check every answer it receives. One weak check, and anyone can be anyone.
It happens for real
ruby-saml (open source), GitLab · 12 Mar 2025ruby-saml: two XML parsers disagreed, so anyone could sign in as anyoneCritical bugs in ruby-saml up to 1.17.0 let an attacker with one valid signed SAML document forge an assertion for any user and log in as them. GitHub's researchers found an exploitable instance in GitLab, which shipped a critical patch. All incidents tagged “security”The idea in simple words
A large customer has thousands of staff. It keeps them all in one directory, such as Okta or Microsoft Entra ID. It wants three things from every SaaS app it buys:
- Single sign-on. Staff log in with their company account and company MFA. No separate password for your app.
- Provisioning. New staff get an account on day one, with the right role.
- Deprovisioning. When someone leaves, their access to your app ends the same day.
Two kinds of standards do this. SAML 2.0 and OpenID Connect (OIDC) handle the login. SCIM 2.0 handles creating, changing and removing users. Microsoft says SCIM "is becoming the de facto standard for provisioning". 8
The customer's system is the identity provider (IdP). Your app is the service provider (SP) in SAML, or the relying party (RP) in OIDC. Each customer is a tenant with its own IdP. See Multi-tenancy and noisy neighbours.
The key idea. In enterprise SSO, someone else's system tells you who the user is. Find the right IdP for the tenant, check every signed answer strictly, and let the IdP remove users, not only add them.
How it works
Step through one SAML login. Use Next and Back, or the ← and → keys.
- Asha types her work email. Your app finds acme.com in its list of verified domains. That domain belongs to tenant 42, which uses its own identity provider (IdP).
- Your app is the service provider (SP). It sends the browser to tenant 42's IdP with a SAML AuthnRequest. The request has an ID, here r7. The app remembers it.
- Asha logs in at her company's IdP, with MFA. The IdP signs a SAML Response that holds an assertion about her. The browser posts it to your app's assertion consumer service URL.
- Now the checks. Verify the signature with the certificate stored for tenant 42. Read data only from the signed element. Check the audience, InResponseTo r7 and the time window, with a small skew allowance.
- Only now find the user. Key the account on the tenant and a persistent ID from the IdP that is never reassigned, not on the email. Then create a normal session, as in the login lesson.
SAML and OIDC in one table
The authentication lesson covered OIDC ID tokens. SAML does the same job with older tools.
| SAML 2.0 | OIDC | |
|---|---|---|
| The proof of login | An XML assertion, inside a Response | An ID token, which is a JWT |
| How it is signed | XML Signature | JSON Web Signature |
| How it reaches you | The browser posts it to your assertion consumer service (ACS) URL | Usually, your server swaps a code for it |
| Who it is for | Audience must be your entity ID 3 | aud must hold your client ID 4 |
Our advice: support both if you sell to enterprises. For new work, prefer OIDC. It is simpler to check, because there is no XML.
SP-initiated and IdP-initiated login
In SP-initiated login, the user starts at your app. You send an AuthnRequest with an ID. The response must return that ID in InResponseTo. 3
In IdP-initiated login, the user clicks your app's tile in the IdP's portal. A response arrives that you never asked for. OWASP says this is "inherently less secure by design", because it has no login CSRF protection. 3 If customers need it, add replay detection, and check RelayState against an allowlist. 3
The checks on every SAML response
OWASP lists them. 3 In short:
- Schema first. Validate the XML against trusted local schema copies.
- The right key. Trust the X.509 certificate stored for this tenant. Ignore any
KeyInfoin the message, so an attacker cannot send their own key. - Signed means used. The signature's reference must cover the assertion you read. Never use
getElementsByTagNameto find security elements. Breaking this rule allows XML signature wrapping: the attacker keeps the signed part and adds an unsigned part that your code reads. These attacks on SAML were described in 2012. 3 - Destination and recipient.
DestinationandRecipientmust match your ACS URL exactly. - Audience.
Audiencemust be your entity ID. Otherwise a response meant for another app works on yours. - Time. Check
NotBeforeandNotOnOrAfter.
Clocks on two systems never agree exactly. This is clock skew. The OIDC spec allows "some small leeway, usually no more than a few minutes". 4 Use the same small window for SAML. Never turn off the time check to fix a skew error.
Do not write these checks yourself. Use a well-known library, keep it patched, and test it with bad responses.
Routing users to the right IdP
Your login page has one email box. Many SaaS apps route by email domain:
const domain = email.split("@")[1].toLowerCase();
const conn = await ssoConnections.findVerified(domain);
if (conn) return redirectToIdp(conn); // tenant's SAML or OIDC
return showPasswordLogin();The word that matters is "verified". A tenant proves it owns acme.com by adding a DNS TXT record with a value you give it. 11 Without this, a tenant could claim gmail.com or a rival's domain.
Store one connection per tenant: IdP entity ID, SSO URL, signing certificates and your ACS URL. Allow two certificates at once, so the customer can rotate keys without downtime. Once SSO works, let the tenant admin enforce it. Docker, for example, then requires SSO for every login. 11
JIT provisioning versus SCIM
Just-in-time (JIT) provisioning creates the user at their first login, from the assertion's attributes. It is easy. But Docker's docs say it plainly: "It doesn't deprovision users." 10
SCIM is a REST API that you host and the IdP calls. RFC 7643 defines two core resources, User and Group. 6 RFC 7644 defines the calls: 7
POST /Userscreates a user. Return 201. A duplicateuserNamegets 409.GET /Users?filter=userName eq "asha@acme.com"finds one.PATCHchanges some attributes. The body listsadd,removeandreplaceoperations.DELETEreturns 204. Later GETs must return 404.
Store externalId. It is the IdP's own ID for the user. 6
Offboarding
When someone leaves, Microsoft Entra can soft-delete the user with a PATCH like this: 9
{
"schemas": ["urn:ietf:params:scim:api:messages:2.0:PatchOp"],
"Operations": [{ "op": "Replace", "path": "active", "value": false }]
}Note Replace with a capital R. Entra sends op values that way, so match them without regard to case. 9
Entra expects GET to keep returning an inactive user. Only a hard delete removes it. 9 The spec leaves the meaning of active to you. 6 So make active: false end everything: sessions, API tokens and pending invites. If old sessions survive, the IdP believes the person is gone while they are still inside.
Groups to roles
A user's groups attribute is read-only. Membership changes arrive on the Group resource. 6 Entra sends a PATCH that adds or removes members. 9 Let each tenant admin map their groups to your roles, such as "Acme-Finance" to "billing-admin". Then your normal authorization model takes over. See Authorization models.
Never link accounts by unverified email
Any IdP can put any email in an assertion. OIDC says only iss and sub together are stable. Email "MUST NOT be used" as a unique ID. 4 In 2023, Microsoft warned that apps using the email claim for authorization risk privilege escalation, because some emails were not verified. 5
Key each SSO identity on the tenant, the IdP and its subject ID. In SAML, ask for a persistent NameID or a fixed, never-reassigned user ID attribute. An email-format or transient NameID is not stable. Link an SSO identity to an existing password account only after that user proves they own the account.
Trade-offs
| Option | Removes users when they leave? | Setup cost | Main risk | Use it when |
|---|---|---|---|---|
| Passwords plus invites | No An admin must remember. | Low | Former staff keep access. | Small customers with no IdP. |
| SSO plus JIT | No It only creates and updates at login. 10 | Medium | Accounts and sessions outlive the job. | A first enterprise tier. |
| SSO plus SCIM | Yes The IdP sends active: false or DELETE. 9 | High. You host a SCIM API. | Partial PATCH support breaks syncs. | Customers with security reviews and audits. |
| IdP-initiated login | Not related. | Low | No InResponseTo, so replay and login CSRF. 3 | Only when customers need portal tiles. |
Simple rule: offer SSO with JIT first. Add SCIM before your first large customer's security review. Make deactivation end every session.
At work: how a senior uses this
- Ask: "Which element did we verify, and which element did we read the user from?" They must be the same.
- Keep a test suite of bad SAML responses: unsigned, wrong audience, wrong recipient, expired and wrapped. Run it on every library upgrade.
- Pin each tenant's certificate. Alert two weeks before it expires.
- Ask: "When SCIM sets active to false, what still works?" Test sessions, API tokens and mobile refresh tokens.
- Log every SCIM call with tenant, operation and result. Customers will ask why a user still had access.
- Never let a tenant claim a domain without DNS proof.
- Subscribe to security advisories for your SAML and OIDC libraries.
With AI
What to ask the agent
"List every check our SAML handler runs, in order. For each, show the line. Compare with the OWASP SAML Security Cheat Sheet and mark what is missing."
"Write tests that post these SAML responses to our ACS endpoint: unsigned, signed for another audience, expired, and with a second unsigned assertion added. Each must fail."
"Implement PATCH /scim/v2/Users/{id} per RFC 7644. When active becomes false, revoke all sessions and API tokens for that user in that tenant."
What to check yourself
- The code does not parse SAML with a hand-written XML lookup. It calls a maintained library.
- Users are found by tenant plus IdP subject ID, never by email alone.
- Domain routing reads only verified domains.
- Every SCIM query and write is scoped to the tenant that owns the bearer token.
- Deactivation revokes tokens, not only the login.
- The AI did not invent SCIM fields. Compare them with RFC 7643.
Check yourself
Your progress is saved only in this browser. Export it to keep it safe.
You have finished 5 lessons. Your progress lives only in this browser. Export a copy so you don’t lose it.
Go deeper
Show 11 sources and related lessons
- Peter Stöckli, Sign in as anyone: Bypassing SAML SSO authentication with parser differentials, The GitHub Blog (12 March 2025) (opens in a new tab)
How two XML parsers in one library disagreed about which signature to check, and how that let an attacker log in as any user. - GitLab Critical Patch Release: 17.9.2, 17.8.5, 17.7.7 (opens in a new tab)
The vendor's advisory for the same flaw, who was affected, and the stopgaps for customers who could not upgrade at once. - OWASP Cheat Sheet Series, SAML Security Cheat Sheet (opens in a new tab)
The checks a service provider must run on every SAML response, and why IdP-initiated login is weaker. - OpenID Foundation, OpenID Connect Core 1.0 (opens in a new tab)
Clock skew leeway, the email_verified claim, and why only iss plus sub identifies a user. - Microsoft Security Response Center, Potential Risk of Privilege Escalation in Azure AD Applications (20 June 2023) (opens in a new tab)
A real case of apps trusting an email claim that nobody had verified. - Hunt, Grizzle, Wahlstroem and Mortimore, RFC 7643: System for Cross-domain Identity Management: Core Schema (IETF, 2015) (opens in a new tab)
The User and Group resources, and the userName, externalId, active and members attributes. - Hunt, Grizzle, Ansari, Wahlstroem and Mortimore, RFC 7644: System for Cross-domain Identity Management: Protocol (IETF, 2015) (opens in a new tab)
The SCIM HTTP API, with create, filter, PATCH and DELETE, and their status codes. - Microsoft Learn, What is automated app user provisioning in Microsoft Entra ID (opens in a new tab)
Why companies automate provisioning and deprovisioning, and where SCIM, SAML and OIDC fit. - Microsoft Learn, Tutorial - Develop a SCIM endpoint for user provisioning to apps from Microsoft Entra ID (opens in a new tab)
What one big identity provider actually sends to your SCIM endpoint, with request and response examples. - Docker Docs, User provisioning overview (opens in a new tab)
A short, real comparison of JIT provisioning and SCIM in one SaaS product. - Docker Docs, Set up single sign-on (opens in a new tab)
Domain verification with a DNS TXT record, and what changes when SSO is enforced.
Real incident: ruby-saml (open source), GitLab, 12 Mar 2025: ruby-saml: two XML parsers disagreed, so anyone could sign in as anyone
Related: Authentication and authorization · Multi-tenancy and noisy neighbours · Authorization models: RBAC, ABAC and ReBAC · OWASP Top 10 and secure coding
- Authentication and authorization: sessions, OAuth and ID token checks.
- Authorization models: where SCIM groups end up.
- Multi-tenancy and noisy neighbours: keeping each tenant's IdP config and users apart.