Skip to content

Ensure Base64URL decoding is used #938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2025
Merged

Ensure Base64URL decoding is used #938

merged 1 commit into from
Apr 14, 2025

Conversation

Avery-Dunn
Copy link
Collaborator

In #894, some of the nimbus dependency was removed to simplify how the tokens were handled by the library.

Unfortunately, as discovered by #922 and #937, the replacement code introduced a regression: despite the name, nimbus's Base64Codec.decode() was decoding them as Base64URL, not Base64. This was not caught during testing because none of the library's tests happened to produce an encoded token with characters that a Base64 decoder would not accept.

This PR fixes that bug by using Base64.getUrlDecoder() instead of Base64.getDecoder() in TokenRequestExecutor.createAuthenticationResultFromOauthHttpResponse(). In addition, it adds a unit tests showing the behavior is now correct:

  • It uses TestHelper.createIdToken() to get an encoded token, and shows that token would throw an IllegalArgumentException if passed into Base64.getDecoder() like was used in the old code
  • It then sends encoded token through a typical flow, and shows the token was successfully decoded by checking the username which would've caused an IllegalArgumentException in the old code

@Avery-Dunn Avery-Dunn requested a review from a team as a code owner April 14, 2025 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants