The vulnerability is an HTTP Parameter Pollution issue in Keycloak's handling of the redirect_uri parameter. The core of the issue lies in the org.keycloak.protocol.oidc.utils.RedirectUtils.verifyRedirectUri function. This function is tasked with ensuring that the redirect_uri provided in an authentication request is valid and matches the client's configuration. However, before the patch, this function failed to check if the redirect_uri itself already contained query parameters that are reserved for the OIDC/OAuth2 response, such as code, state, session_state, iss, etc.
An attacker could exploit this by crafting an authentication link containing a redirect_uri with a malicious code or state parameter (e.g., &redirect_uri=https://client.app/callback?code=attacker_code). When a victim clicks this link and authenticates, Keycloak would process the login and then redirect back to the client application, adding its own code and state parameters. The final URL would look something like: https://client.app/callback?code=attacker_code&code=real_code&state=real_state. Depending on how the client application's web server and application framework parse the query string, it might prioritize the first code parameter (attacker_code), leading to a security bypass.
The patch addresses this by introducing a check within verifyRedirectUri. It now maintains a blocklist of forbidden OIDC parameters and rejects any redirect_uri that contains them in its query string. The analysis of the commit patches clearly shows the addition of the containsForbiddenOidcParameters check within the verifyRedirectUri function, confirming it as the location of the vulnerability.