Skip to content

Use NSURLComponents to properly encode tokens - #618

Merged
w-goog merged 6 commits into
mainfrom
refactor/revoke-url-components
Aug 18, 2026
Merged

w-goog merged 6 commits into
mainfrom
refactor/revoke-url-components

Conversation

@w-goog

@w-goog w-goog commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

The two URLs here interpolated tokens into the query strings, and then called urlWithString:. An &, #, =, or plausibly + in a token would break the URL. RFC 6750 & RFC 6749 define the bearer & access tokens such that "=" and "+" are allowed (and the access token allows even more characters).

I've also added an explicit test for the "+" character's behaviour in various forms.

Base automatically changed from refactor/consolidate-logging-parameters to main August 7, 2026 23:09
w-goog added 3 commits August 7, 2026 16:09
Assemble the token revocation URL from components and query items rather
than by string formatting, so the token and the logging parameters are
percent-encoded rather than interpolated raw into a URL string.
Assemble the user info URL from components and query items so the access
token is percent-encoded rather than interpolated raw into a URL string,
matching the revoke URL construction.
Revoke a token containing "&", "=" and "#" and assert it round-trips
through the revoke URL intact, along with the logging parameters. Against
the previous string-formatted URL this fails: the token is truncated at
the "&" and both logging parameters are lost to the fragment.
@w-goog
w-goog force-pushed the refactor/revoke-url-components branch from 389ce68 to a6c6902 Compare August 7, 2026 23:09
w-goog added 3 commits August 13, 2026 17:52
Revoke a token containing "+" and assert it round-trips through the
revoke URL intact.
OAuth parameters are application/x-www-form-urlencoded per RFC 6749
Appendix B, where "+" means a space and a literal plus is sent as "%2B".
NSURLComponents encodes per RFC 3986, which permits "+" literally in a
query, so encode it explicitly for the revoke and user info URLs.
One test pins NSURLComponents encoding a space as "%20" rather than "+",
which the "+" to "%2B" rewrite depends on. The other checks that a "+"
token survives a form-urlencoded read of the revoke URL, the way a server
would parse it.
@w-goog
w-goog marked this pull request as ready for review August 14, 2026 01:20
@w-goog
w-goog requested a review from AkshatG6 August 14, 2026 01:21
@w-goog
w-goog merged commit 1793586 into main Aug 18, 2026
22 checks passed
@w-goog
w-goog deleted the refactor/revoke-url-components branch August 18, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants