-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Description
Describe the bug
When SAML SP generate a SAML request to redirect user to IDP, the base64 encoded message has \r\n
inserted every 76 character. When redirect binding is chosen, this will result in %0A
appear in the url. The below issue may occur:
- Some IDP implementation cannot parse line feeds in the encoded message, and it will result in failure on validation;
- For security reasons, some web server or firewall implementation will have CRLF filter to also filter out
%0A
in URL. When this happen, the message sent out is modified and signature validation will fail; - It violates SAML spec "http://docs.oasis-open.org/security/saml/v2.0/saml-bindings-2.0-os.pdf" chapter 3.4.4.1 about redirect binding:
- The compressed data is subsequently base64-encoded according to the rules specified in IETF
RFC 2045 [RFC2045]. Linefeeds or other whitespace MUST be removed from the result.
- The compressed data is subsequently base64-encoded according to the rules specified in IETF
To Reproduce
- Config your SAML IDP to support redirect binding and let SAML SP (using Spring Security SAML SP) to send using redirect binding;
- Trigger authentication request from SAML SP in a browser with developer mode on;
- Check the request that redirect from SP to IDP, url params contains SAML message, which has
%0A
.
Expected behavior
The BASE64 encoded message should not have line feeds for redirect binding.
Sample
https://www.example.org/app/logout?SAMLResponse=jVLBaoNAEP0V2buuq6vZDFEwsYFAemlCDr2Ejdk2lnVXnBXy%2BVVDaQol7WVgmPdm3nvMAmWjW9ja%0Ad9u7F4WtNai8a6MNwjTKSN8ZsBJrBCMbheAq2BXPW4iCENrOOltZTW6Ux2CJqDpXW0O8UqGrjRyb%0AjFycaxEo%2FTgrY2r03TAM1FU2rVZBZRvaKK2toXoSSbxNmZFNeYyEFGnIKp%2FP50ORs9gX8sR9Nj%2Bf%0A3lgaztK5GMDmy9XeZuTIZyVLlglbx0tWPBWcRatiWYikTNcFL8ORgNirjUEnjctIFDLhs9BnyT4K%0AIUkgTgMu0lfiHVSHk%2FzBGskXY1gwcbu7%2BP4bSP5XBiA4j6ns3YV2SuoG6YhY0LuzNw0t7Jx0Pf7s%0AVvasvIPUvXqsCCc07PqqUoiE5rcL30vpb%2F%2BSfwI%3D&RelayState=https%3A%2F%2Fjdennis-test.example.com%2Flogged-out.html&SigAlg=http%3A%2F%2Fwww.w3.org%2F2001%2F04%2Fxmldsig-more%23rsa-sha256&Signature=fhk%2BaH4gkG0qeTxHga42mtCMrA12ShVLLhmth%2Bk7d5vVkqsA0L2mAJ9wc8j8STqedrhQgGxzIfa1CpIjVK3vf27%2B06HvZWsuM9RLY3Q%2BhqtBKC3eTbvFD88uhYkKfnp1ws79psdzwo5%2FVY50MIoaersS5ac%2FX9AJm9cCRawuPpfpOXul13kwPEv0IQFrKkK7%2FOYWYcWMuMrY4aGwgmRmTIYubmUiZxkTmfw4Nc0hqe76%2BrJmLjPKIACJZZsvd4i2757yGNrREdE%2BfkEM5EeUcshRYOhTQn4uQY1EeA4Xn%2F2F%2BVjdqsPewNHAfA5QUC9mBkTQwIKUmiYs928sYkJUjA%3D%3D
Message encoding code was changed in this commit: 0b59e77
It fixed the base64 decoding issue. At the same time, however, it also change to use RFC2045 MIME encoder to encode outward messages.
// Saml2Utils.java
static String samlEncode(byte[] b) {
return Base64.getMimeEncoder().encodeToString(b);
}