Description
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:
- 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. Saml2LogoutRequestFilter
intercepts the request and creates an instance ofSaml2LogoutRequest
. At this point all information about URL-encoding is lost, becauseSaml2LogoutRequest
is filled with decoded URL params.- The
Saml2LogoutRequest
is later validated in theOpenSamlLogoutRequestValidator
which under the hood reconstructs the content to be signed by concatenating the necessary query parameters and applying URL-encoding from Spring'sUriUtils
(seeOpenSamlVerificationUtils.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
- 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.