Repository navigation
fix(web): trade only codes sent back to locallibrary on this computer - #290
Merged
Merged
Conversation
The token exchange took any redirect_uri. Mixcloud checks a code's redirect only against the authorize request's, and has no PKCE, so a sign-in link with Local Network's client and someone else's redirect handed them a code the exchange would trade for the signed-in person's token. A grant's redirect_uri now has to be http://127.0.0.1:<port>/callback or http://[::1]:<port>/callback, the only ones locallibrary sends, and anything else is refused before it reaches the service.
Coverage Report for apps/web
File Coverage
SizeCompared with main. KiB are 1,024 bytes.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bnb
approved these changes
Oct 29, 2026
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.
What and why
The token exchange accepted any
redirect_uri. Mixcloud compares a code's redirect only with the authorize request's, not with one registered for the client, and has no PKCE. So someone could send a Mixcloud sign-in link with Local Network's client and their own redirect. The person signing in sees "Local Network" and approves, and the code goes to that redirect. The exchange would then trade it for that person's Mixcloud token.Changed: a grant's
redirect_urimust be exactlyhttp://127.0.0.1:<port>/callbackorhttp://[::1]:<port>/callback, the only ones locallibrary sends (callback.rs). Anything else is a 400invalid_requestbefore the service is contacted, and the redirect isn't logged. That applies to code grants, and to refresh grants that carry one. The file's header comment andapps/web/README.mdsay so.How it was tested
exchange.test.ts: both loopback forms are traded; 12 bad redirects (https,localhost, no port, another path, a query, userinfo,127.0.0.1.attacker.example, other spellings of the address) are refused for Mixcloud and SoundCloud, with nothing sent upstream and the redirect absent from logs; a refresh with a foreign redirect is refused, and one without a redirect still works. The check was broken four ways and each failed the tests.format:check,lint,check,knip,test(736) andtest:coverage(924 passed, thresholds met;exchange.ts100% lines and functions, 97.82% branches).Checklist
docs/and--helpstill say what the code does