Repository navigation
Limit the OAuth2 access token on avatar fetches to the user info origin - #349
Merged
Merged
Conversation
The OAuth2 callback handed the avatar saver the oauth2 client, which adds the user's access token to every request, so the picture was fetched with the token from whatever host the picture URL named. The saver now gets a client that adds the token only to requests for the scheme, host and port of the provider's user info URL, checked on every redirect hop; a host with non-ASCII characters never matches. Requests go through the oauth2 client's base transport and redirect policy, with the 5 second timeout the other providers' avatar clients already use. The Microsoft Graph photo, which needs the token and is served by the info host, keeps loading; pictures on CDNs and other hosts are fetched without the token.
Coverage Report for CI Build 46088161991Coverage increased (+0.004%) to 88.456%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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.
Previously, the OAuth2 callback passed the avatar saver the client returned by
oauth2.Config.Client, which adds the user's access token to every request it makes. The avatar proxy fetched the user's picture with it, so the access token went to whichever host the picture URL named, and to any host a redirect led to.After this change, the saver gets a client that adds the token only to requests for the scheme, host and port of the provider's user info URL. The check runs on every request, so a redirect from the info host to another host drops the token on that hop. A host with non-ASCII characters never matches. Pictures on other hosts are fetched without the token. All picture requests go through the oauth2 client's base transport and redirect policy, with the 5 second timeout the other providers' avatar clients already use.
Built-in providers:
https://graph.microsoft.com/beta/me/photo/$value, needs the bearer token and is served by the same host as its user info URL.go-oauth2/oauth2server) and the dev provider serve the picture from the same host as the user info, so they keep the token.A custom provider whose picture needs the token outside the origin of its
InfoURLnow gets an identicon from the default avatar proxy. A customAvatarSaverreceives the restricted client too. TheAvatarSaverdoc comment and the README describe the new behaviour.Verified:
TestOauth2AvatarFetchSendsTokenOnlyToInfoHost, in both modules, runs the OAuth2 login against servers that record theAuthorizationheader: the picture on the info host gets the token, a picture on another host and the target of a redirect from the info host do not. It fails with either the original client or a plain one in place of the new client.TestOauth2AvatarClientTransportchecks which picture URLs get the token through the oauth2 client's base transport, including a host that differs only by a non-ASCII letter, and that the client keeps the oauth2 client's redirect policy.TestURLOrigincovers default ports, host case, a scheme change, a different port and a subdomain.go test -racefor both modules, the_examplebuild, and golangci-lint v2.15.0 with the CI flags for both modules.