auth: add Scopes allowlist to AuthorizationCodeHandlerConfig#1044
Open
toabctl wants to merge 1 commit into
Open
auth: add Scopes allowlist to AuthorizationCodeHandlerConfig#1044toabctl wants to merge 1 commit into
toabctl wants to merge 1 commit into
Conversation
59e58c3 to
06621c6
Compare
The authorization-code handler requests every scope advertised in the protected resource's metadata (or named in the WWW-Authenticate challenge), with no way for a client to narrow that set. Some servers advertise a scope a client should not request: Gmail's MCP server lists gmail.metadata, and the Gmail API refuses the search "q" parameter on any token carrying gmail.metadata even when gmail.readonly is also granted. Add an optional Scopes field that, when non-empty, intersects the discovered scopes with the allowlist (order preserved). An empty intersection is ignored so a misconfigured allowlist never leaves the client requesting no scopes; offline_access is applied after filtering and so is unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
06621c6 to
5d1b260
Compare
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.
Summary
The authorization-code handler requests every scope advertised in the protected resource's metadata
scopes_supported(or named in theWWW-Authenticatechallenge), and offers the caller no way to narrow that set. Some servers advertise a scope a client should not request:gmail.metadatainscopes_supported.qparameter on any token that carriesgmail.metadata— even whengmail.readonlyis also granted (a long-standing documented Gmail restriction, see BUG when using both metadata and gmail.readonly scopes together googleapis/google-api-python-client#582).Because the handler requests the full advertised set,
gmail.metadataends up in the grant and breaks search, with no client-side remedy.Change
Add an optional
Scopes []stringfield toAuthorizationCodeHandlerConfig. When non-empty, the discovered scopes are intersected with it (order preserved). Semantics chosen to be safe:offline_access(SEP-2207) and step-up union (SEP-2350) logic, so refresh-token support and scope accumulation are unaffected.Test
TestAuthorize_ScopesAllowlistdrives a full authorize flow and asserts the requestedscopeparameter: filtered-to-allowlist, empty-intersection-fail-open, and no-allowlist-unchanged.go test ./auth/...,go vet, andgofmtare clean.🤖 Generated with Claude Code