SECURITY ENGINEERING · PART 8 · WRITING SECURE CODE · AUTH · 116 OF 229

SAML vs OIDC: How Single Sign-On Works

Single sign-on lets one login work across many applications. This episode explains how: the identity provider and service provider model, SAML with its signed XML assertions, how SAML and OpenID Connect compare and when each is used, the security that holds SSO together (signature validation, audience and time checks), the classic SAML vulnerabilities, and why SSO centralises both convenience and risk.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 9
  9. 10
  10. 11
  11. 12
  12. 13
  13. 14
  14. 15
  15. 16
  16. 17
  17. 18
  18. 19
  19. 20
  20. 21
  21. 22
  22. 23
  23. 24
  24. 25
  25. 26
  26. 27
  27. 28
  28. 29
  29. 30
  30. 31
  31. 32
  32. 33
  33. 34
  34. 35
  35. 36
  36. 37
  37. 38
  38. 39
  39. 40
  40. 41
  41. 42
  42. 43
  43. 44
  44. 45
  45. 46
  46. 47
  47. 48
  48. 49
  49. 50
  50. 51
  51. 52
  52. 53
  53. 54
  54. 55
  55. 56
  56. 57
  57. 58
  58. 59
  59. 60
  60. 61
  61. 62
  62. 63
  63. 64
  64. 106
  65. 107
  66. 108
  67. 109
  68. 110
  69. 111
  70. 112
  71. 113
  72. 114
  73. 115
  74. 116
  75. 117
  76. 118
  77. 119
  78. 120
  79. 121
  80. 122
  81. 123
  82. 124
  83. 125
  84. 126
  85. 127
  86. 128
  87. 129
  88. 130
  89. 131
  90. 132
  91. 133
  92. 134
  93. 135
  94. 136
  95. 137
  96. 138
  97. 139
  98. 140
  99. 141
  100. 142
  101. 143
  102. 144
1 / 11

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • IdP vouches to many SPs
  • SAML signed XML, OIDC for new work
  • validate signature, audience, time, replay
  • protect the IdP

Notes

The model

Single sign-on has two main roles. The identity provider, or IdP, is where you actually log in; it holds the accounts and enforces MFA. The service provider, or SP, is the application you want to use. The SP trusts the IdP to vouch for who you are. So you log in once at the identity provider, and every service provider accepts its word. Common identity providers are Okta, Microsoft Entra, Google Workspace, Ping and self-hosted Keycloak. This central trust is the whole idea, and also the whole risk.

IdP and SP
  • identity provider (IdP): where you actually log in, holds the accounts and MFA
  • service provider (SP): the app you want to use
  • the SP trusts the IdP to say who you are log in once at the IdP; every SP accepts its word
  • IdPs: Okta, Entra ID, Google, Ping, Keycloak

SAML

SAML, security assertion markup language, is the older enterprise standard. You visit the service provider, which redirects you to the identity provider. You authenticate there. It sends back a signed XML document, an assertion, stating who you are and your attributes, such as groups. The service provider validates the signature and logs you in. The assertion is the heart of it: an identity plus attributes, signed by the identity provider so the service provider can trust it.

SAML flow
  1. you visit the SP
  2. SP redirects you to the IdP with a request
  3. you authenticate at the IdP
  4. IdP sends back a signed XML "assertion" saying who you are
  5. SP validates the signature and logs you in assertion = identity + attributes + signature

SAML vs OIDC

SAML and OpenID Connect do the same job, and you choose by context. SAML uses XML, is older, and is deeply embedded in enterprise and on-premises applications. OpenID Connect, which we covered last episode, uses JSON and JWTs and was built for mobile apps, single-page apps and APIs. Both provide single sign-on and federation across organisations. For a new integration, prefer OpenID Connect. But many enterprise applications only speak SAML, so you will meet both, and most identity providers support both at once.

Which one
  • SAML: XML, older, deeply embedded in enterprise and on-prem apps
  • OIDC: JSON/JWT, modern, built for mobile, SPAs and APIs
  • both do SSO and federation
  • new integrations: prefer OIDC
  • existing enterprise apps: often SAML only many IdPs support both

What holds it together

The security of SSO lives in how carefully the service provider validates the assertion. Check the signature is valid and from the expected identity provider key. Confirm the assertion itself is signed, not just the surrounding message. Check the audience, that it was issued for this service provider and no other. Check the time window, so expired assertions are rejected. And prevent replay by tracking assertion identifiers. Miss any and the trust breaks.

The SP must check
  • signature: valid, from the expected IdP key
  • what is signed: the assertion itself, not just the wrapper
  • audience: this assertion is for THIS SP
  • time: not expired, not used before its valid window
  • replay: each assertion used once (track the ID)

Classic SAML bugs

SAML has a famous family of vulnerabilities, because validating signed XML correctly is hard. In signature wrapping, an attacker adds a second, unsigned assertion positioned so the signature check validates the real one but the application reads the attacker's. XML external entity flaws leak files. Some bugs let a comment inside a username change which user the application saw. The lesson: use a hardened, current SAML library and never parse or validate the XML yourself.

Known SAML attacks
  • signature wrapping (XSW): an unsigned assertion the app reads but validation ignores
  • XXE in the parser
  • comment-injection in how libraries read NameID
  • accepting unsigned assertions
  • fix: a hardened SAML library; never DIY XML

Concentrated risk

Single sign-on is a trade. It concentrates risk: compromise the identity provider, or one of its admins, and you reach every connected app at once. This is why phishing an identity provider session or its MFA is now the primary attack path in many breaches. So the identity provider is protected hardest of all: phishing-resistant MFA, tight admin restrictions, heavy logging. The flip side is a benefit, deprovisioning: disable someone once and their access disappears everywhere.

The IdP is the crown jewel
  • compromise the IdP or an admin, and you reach every connected app
  • phishing the IdP session or its MFA is the main path
  • protect it hardest: phishing- resistant MFA, admin limits, logging
  • disable once = access gone everywhere

Provisioning and logout

SSO is more than login. Provisioning matters too: the SCIM standard lets the identity provider automatically create, update and disable accounts in connected apps, so a leaver is removed everywhere. Just-in-time provisioning creates the account on first login instead. Single logout aims to end app sessions when the identity provider session ends, though it is hard to make reliable. And the identity provider session lifetime governs real exposure, because a long-lived one is a long-lived key to everything.

Around SSO
  • SCIM: automatically create, update and disable accounts in apps from the IdP
  • JIT provisioning: create the account on first login
  • single logout: ending the IdP session should end app sessions (hard in practice)
  • session length at the IdP governs real exposure

Common mistakes

Mistakes. Hand-rolling SAML XML validation instead of using a hardened library. Accepting unsigned assertions, or checking only the wrapper signature and falling to signature wrapping. Not checking the audience, expiry or replay of an assertion. Leaving XML external entities enabled in the parser. Weak MFA on the identity provider itself, which undermines everything downstream. And no automated deprovisioning, so people who leave keep access to applications long after their accounts should be gone.

Avoid these
  • hand-rolling SAML XML validation
  • accepting unsigned or wrapper-only signatures
  • not checking audience, expiry or replay
  • XXE left enabled in the parser
  • weak MFA on the IdP itself
  • no automated deprovisioning (leavers keep access)

Say it like this

In the interview: the service provider redirects the user to the identity provider, which authenticates them and returns a signed XML assertion. The service provider validates the signature against the identity provider's key, checks the audience, time window and replay, then logs the user in. I stress using a vetted SAML library, not hand-parsed XML, because of signature wrapping. And because SSO concentrates risk, I protect the identity provider with phishing-resistant MFA and automate provisioning with SCIM.

In the interview
  • "The SP redirects the user to the IdP, which authenticates
  • them and returns a signed XML
  • assertion. The SP validates
  • the signature, audience, time
  • and replay, then logs them
  • in. I use a vetted library, never custom XML, protect the IdP with phishing-resistant
  • MFA, and automate deprovisioning."

Interview questions

Q1What is single sign-on?

An arrangement where a user authenticates once with a central identity provider and then accesses many applications without logging in again. Each application trusts the identity provider to assert who the user is.

Q2What is the difference between an identity provider and a service provider?

The identity provider holds user accounts and performs authentication. The service provider is the application the user wants to access, which trusts the identity provider's assertion of the user's identity rather than authenticating the user itself.

Q3What is SAML?

Security Assertion Markup Language: an XML-based standard for exchanging authentication and authorization data between an identity provider and a service provider. The identity provider issues a signed assertion describing the user, which the service provider validates to establish a session.

Q4What is the difference between SAML and OpenID Connect?

Both enable single sign-on and federation. SAML uses signed XML and is common in enterprise and legacy applications. OpenID Connect uses JSON and JWTs and is better suited to mobile apps, single-page applications and APIs. New integrations generally prefer OpenID Connect.

Q5What must a service provider validate in a SAML assertion?

That the signature is valid and from the expected identity provider key, that the assertion itself (not just the wrapper) is signed, the intended audience, the validity time window, and that the assertion has not been replayed. Omitting any check can allow impersonation.

Q6What is a SAML signature wrapping attack?

An attack where a forged, unsigned assertion is inserted into the XML so that the signature validation checks the legitimate assertion while the application processes the attacker's. Robust, up-to-date libraries that validate exactly what was signed prevent it.

Q7Why does single sign-on concentrate risk?

Because compromising the identity provider or one of its administrators grants access to every connected application at once. This makes the identity provider a high-value target and the reason it needs the strongest protection, especially phishing-resistant MFA.

Q8What is SCIM?

System for Cross-domain Identity Management: a standard for automatically provisioning, updating and deprovisioning user accounts in applications from a central identity provider, so that joiners and leavers are reflected across connected systems without manual work.