Repository navigation
Fix: enforce AuthnContextClassRef validation in SAML broker (comparison=exact) - #50044
stav-berkovitch wants to merge 1 commit into
Conversation
…on=exact) Keycloak configured authnContextClassRefs in the outbound AuthnRequest but never validated the ClassRef returned in the SAML Response. An attacker controlling an IdP (or performing a MitM on the SAML flow) could return any AuthnContextClassRef — including the weakest (urn:oasis:names:tc:SAML:2.0:ac:classes:unspecified) — and Keycloak would accept it unconditionally, effectively bypassing authentication-level requirements such as MFA or PasswordProtectedTransport. Fix: after extracting the AuthnStatement, validate that the returned AuthnContextClassRef is present in the configured list when comparison=exact (the SAML 2.0 default). If validation fails, the response is rejected with INVALID_SAML_RESPONSE and the user sees IDENTITY_PROVIDER_AUTHENTICATION_FAILED. Backwards-compatible: realms that do not configure authnContextClassRefs are unaffected. comparison=minimum/maximum/better are not enforced here as they require an authentication-class hierarchy not defined in the codebase. Ref: SAML 2.0 Core §3.3.2.2.1
|
@NadavWizman @danSayag — thanks for the collaboration on this fix. |
|
Thank you for contributing this PR. Please link this PR to an issue, and also sign-off your commit as outlined in CONTRIBUTING.md |
|
Hi @stav-berkovitch and @ahus1, I was reviewing the SAML broker flow and saw that the response-side If @stav-berkovitch is no longer planning to pick it up, I’d be happy to help with current-main regression tests and any needed implementation updates, while keeping credit for the existing work. Should I open the requested issue first, contribute here, or leave this with you? |
Hi, Just to clarify, I was part of the team working with @stav-berkovitch when we investigated and identified this issue. I’d be happy to help move this forward. How would you recommend we proceed from here? Should I open the requested issue and work on the regression tests and any necessary implementation updates, or would you prefer a different approach? Thanks! |
|
The original author didn't respond, and didn't add a sign-off which we as an open source project need. This PR is stale and can't move further without that. I've opened an issue, but it would need more input from SAML experts: #55261 As this PR is stale, I close it to open the path for a new PR that has a sign-off. |
Problem
Keycloak sends
authnContextClassRefsin the outbound AuthnRequest but nevervalidates the ClassRef returned in the SAML Response. An attacker controlling
an IdP can return any ClassRef (e.g.
unspecified) and Keycloak accepts it,bypassing authentication-level requirements such as MFA.
Vulnerable code:
SAMLEndpoint.java— after extracting theAuthnStatement,callback.authenticated()is called immediately without comparing the returnedClassRef against the configured list.
Fix
After extracting the
AuthnStatement, validate that the returnedAuthnContextClassRefis present inconfig.getAuthnContextClassRefs()whencomparison=exact(SAML 2.0 Core §3.3.2.2.1). If it doesn't match, rejectwith
INVALID_SAML_RESPONSE.Testing
Backwards compatibility
Realms that do not configure
authnContextClassRefsare unaffected.