The vulnerability lies in the handle method of the org.forgerock.oauth2.core.AuthorizationCodeGrantTypeHandler class. In vulnerable versions, this method was responsible for exchanging an authorization code for an access token. When a client uses PKCE, it provides a code_challenge in the authorization request, and OpenAM stores this challenge with the authorization code. When the client later redeems the code at the token endpoint, it must provide a code_verifier.
The vulnerability existed because the handle method only enforced the code_verifier check under two conditions:
- A global setting,
codeVerifierEnforced, was enabled for the realm. This was false by default.
- The client voluntarily included the
code_verifier parameter in the token request.
If the global setting was disabled and an attacker intercepted a PKCE-protected authorization code, they could simply make a request to the token endpoint without the code_verifier parameter. The vulnerable code (if (codeVerifier != null)) would see the missing parameter and skip the PKCE validation entirely, issuing an access token.
The patch corrects this logic. It introduces a check, codeWasIssuedWithChallenge, which is true if the authorization code was originally issued with a code_challenge. The validation logic is changed to if (providerSettings.isCodeVerifierRequired() || codeWasIssuedWithChallenge), ensuring that if a code_challenge was ever associated with the code, the code_verifier is now mandatory. Furthermore, the check that calls the verifier function was changed from if (codeVerifier != null) to if (codeWasIssuedWithChallenge), ensuring the check is always performed for PKCE codes, and will fail if the verifier is missing. This correctly enforces the PKCE flow as described in RFC 7636, preventing the authorization bypass. The fix also changes the default for the provider-wide enforcement to true as a defense-in-depth measure.