Skip to content

Only accept assertion-only signatures on a SAML Response - #55344

Open
naruto-lgtm wants to merge 1 commit into
keycloak:mainfrom
naruto-lgtm:saml-assertion-only-signature-response
Open

naruto-lgtm wants to merge 1 commit into
keycloak:mainfrom
naruto-lgtm:saml-assertion-only-signature-response

Conversation

@naruto-lgtm

Copy link
Copy Markdown
Contributor

Repro: with "Validate Signature" on for a SAML identity provider, POST to /realms/{realm}/broker/{alias}/endpoint an unsigned samlp:LogoutRequest with the broker Destination, a victim's NameID, and any genuine assertion signed by that IdP (for example the attacker's own login assertion, expired or not) copied unchanged into samlp:Extensions. Every brokered session of the victim is logged out.
Cause: XMLSignatureUtil.validate falls back to "the root is unsigned but every saml:Assertion in the document is signed" for any root element, so the signed assertion stands in for the LogoutRequest it does not cover. The same fallback is reached by SamlService for POST/SOAP AuthnRequest, LogoutRequest, LogoutResponse and ArtifactResolve, and by the SAML adapter.
Fix: keep that fallback only for a samlp:Response root or the single samlp:Response payload of an ArtifactResponse, which are the only messages where a signed assertion is what gets consumed and where both the POST and artifact bindings rely on it today. Every other message has to be signed at the root, matching what the Redirect binding already enforces through the query signature. SAML2SignatureTest gains a regression test for the wrapped LogoutRequest (fails before, passes after) and two guards for the assertion-only Response and ArtifactResponse cases; the SAML broker tests in tests/base stay green.

XMLSignatureUtil.validate accepted a document with an unsigned root whenever every saml:Assertion in it was signed, whatever the root element was. An unsigned LogoutRequest carrying a genuine IdP-signed Assertion in its Extensions therefore passed signature validation. Restrict that fallback to a samlp:Response root or the single samlp:Response payload of an ArtifactResponse; other messages have to be signed at the root.

Signed-off-by: Nayyar <nayyar@bugqore.com>
@naruto-lgtm
naruto-lgtm requested a review from a team as a code owner November 19, 2026 08:04
Copilot AI balanced review requested due to automatic review settings November 19, 2026 08:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The shared SAML signature-acceptance changes require security-sensitive binding interoperability validation across broker, server, and adapter flows that could not be performed in this review environment.

No open issues 🎉

What changed in this PR

This PR tightens shared SAML signature validation so a signed assertion cannot authenticate an unsigned non-Response message, such as a LogoutRequest.

Changes:

  • Restricts assertion-only validation to a SAML Response or the single Response payload of an ArtifactResponse.
  • Adds a regression test for unsigned LogoutRequests containing signed assertions and compatibility tests for supported Response cases.
File Description
saml-core/​src/​test/​java/​org/​keycloak/​saml/​processing/​api/​saml/​v2/​sig/​SAML2SignatureTest.java Adds rejection and compatibility tests using signed assertions.
saml-core/​src/​main/​java/​org/​keycloak/​saml/​processing/​core/​util/​XMLSignatureUtil.java Gates assertion-only validation on the root or artifact payload message type.

Review effort: Balanced

@keycloak-github-bot keycloak-github-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unreported flaky test detected, please review

@keycloak-github-bot

Copy link
Copy Markdown

Unreported flaky test detected

If the flaky tests below are affected by the changes, please review and update the changes accordingly. Otherwise, a maintainer should report the flaky tests prior to merging the PR.

org.keycloak.testsuite.broker.KcSamlFirstBrokerLoginTest#testVerifyEmailRequiredActionWhenChangingEmailDuringFirstLogin

Keycloak CI - FIPS IT (strict)

jakarta.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:250)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.DefaultEntityExtractorFactory$3.extractEntity(DefaultEntityExtractorFactory.java:41)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:146)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:104)
...

Report flaky test

org.keycloak.testsuite.broker.KcSamlFirstBrokerLoginTest#testFixDuplicationsByReviewProfile

Keycloak CI - FIPS IT (strict)

jakarta.ws.rs.InternalServerErrorException: HTTP 500 Internal Server Error
	at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:250)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.DefaultEntityExtractorFactory$3.extractEntity(DefaultEntityExtractorFactory.java:41)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:146)
	at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:104)
...

Report flaky test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants