Skip to content

Failed signature verification on SAML2 LogoutRequest #11235

Closed
@markiewiczart

Description

@markiewiczart

When IDP uses other URL-encoding than Spring, signature verification for a LogoutRequest coming from the IDP fails, because the content used for the signature computation on the RP-side is different than on the IDP-side.

We experience the following error scenario when trying to integrate with MS Azure:

  1. Azure calls our logout endpoint with the query params SAMLRequest={samlRequest}&Signature={signature}&SigAlg=http%3a%2f%2fwww.w3.org%2f2001%2f04%2fxmldsig-more%23rsa-sha256. Note that slashes are escaped with the sequence %2f and this fact is incorporated into the signature.
  2. Saml2LogoutRequestFilter intercepts the request and creates an instance of Saml2LogoutRequest. At this point all information about URL-encoding is lost, because Saml2LogoutRequest is filled with decoded URL params.
  3. The Saml2LogoutRequest is later validated in the OpenSamlLogoutRequestValidator which under the hood reconstructs the content to be signed by concatenating the necessary query parameters and applying URL-encoding from Spring's UriUtils (see OpenSamlVerificationUtils.RedirectSignature). However, this results in a different content than the original one as Spring uses upper-case escape characters: SAMLRequest={samlRequest}&SigAlg=http%3A%2F%2Fwww.w3.org%2F2001%2F04%2Fxmldsig-more%23rsa-sha256
  4. As a result the signature computed from the reconstructed query string doesn't match the signature computed by the IDP and world starts burning.

The SAML spec (page 17) states pretty clearly, that the unmodified values received in the query string should be used for the signature verification:

Further, note that URL-encoding is not canonical; that is, there are multiple legal encodings for a given
value. The relying party MUST therefore perform the verification step using the original URL-encoded
values it received on the query string. It is not sufficient to re-encode the parameters after they have been
processed by software because the resulting encoding may not match the signer's encoding.

This behavior was observed in Spring Security 5.6.3.

Metadata

Metadata

Assignees

Labels

in: saml2An issue in SAML2 modulestype: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions