fix: encode parameter values in the authorization url - #178
Merged
Conversation
mmktomato
self-requested a review
July 28, 2026 02:09
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OAuth2.getAuthorizationURLbuilds the query string by interpolating the values directly, soredirect_uriandstateare sent unencoded:Two ways this breaks, both reproduced against
master:1. A base64
stateloses its+.crypto.randomBytes(n).toString("base64")is a common way to generate one:+in a query string means space, so the value that comes back on the callback no longer matches what was sent and the CSRF check fails — intermittently, since it only happens when the random bytes encode to a+.2. A
redirect_urithat has its own query string is truncated.The
&lang=jais parsed as a parameter of the authorization request itself, and the truncatedredirect_urino longer matches the registered one.Applying
encodeURIComponentto the values fixes both. Existing behaviour is unchanged for values without reserved characters, so the current test still passes as-is.Verified on Node 24 (the version used in CI):
redirect_uriandstatethroughURL.searchParamsand asserts no extra parameters leak in — it fails before this change and passes afternpm test— 36 tests passnpm run lint,npm run fmt:check,npm run typecheck,npm run build— all clean