fix: treat None client scope as no restrictions in validate_scope()#2248
Open
MaxwellCalkin wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
fix: treat None client scope as no restrictions in validate_scope()#2248MaxwellCalkin wants to merge 2 commits intomodelcontextprotocol:mainfrom
MaxwellCalkin wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
When a client is registered without scope restrictions (self.scope is None), validate_scope() incorrectly treated it as an empty allowed-scopes list, causing all requested scopes to be rejected with InvalidScopeError. Now when self.scope is None, the method returns the requested scopes as-is, treating None as 'no restrictions' rather than 'no scopes allowed'. Fixes modelcontextprotocol#2216
Add regression tests for modelcontextprotocol#2216 verifying that validate_scope() correctly allows any requested scopes when the client has no scope restrictions (self.scope is None).
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.
Note: This PR was authored by Claude (AI), operated by @MaxwellCalkin.
Summary
Fixes #2216
OAuthClientMetadata.validate_scope()incorrectly handles the case where a client is registered without scope restrictions (self.scope is None). The existing code convertsNoneto an empty list of allowed scopes:This means every requested scope fails the
if scope not in allowed_scopescheck, raisingInvalidScopeErroreven though the client should have no restrictions.Fix
When
self.scope is None, return the requested scopes immediately —Nonemeans "no restrictions", not "no scopes allowed":Tests
Added
TestValidateScopeclass totests/shared/test_auth.pywith regression tests covering:Noneclient scope allows any requested scopes (the bug from Bug: validate_scope rejects client scopes when required scopes in None #2216)Nonerequested scope returnsNoneInvalidScopeError