Skip to content

fix: treat None client scope as no restrictions in validate_scope()#2248

Open
MaxwellCalkin wants to merge 2 commits intomodelcontextprotocol:mainfrom
MaxwellCalkin:fix-validate-scope-none-handling
Open

fix: treat None client scope as no restrictions in validate_scope()#2248
MaxwellCalkin wants to merge 2 commits intomodelcontextprotocol:mainfrom
MaxwellCalkin:fix-validate-scope-none-handling

Conversation

@MaxwellCalkin
Copy link

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 converts None to an empty list of allowed scopes:

allowed_scopes = [] if self.scope is None else self.scope.split(" ")

This means every requested scope fails the if scope not in allowed_scopes check, raising InvalidScopeError even though the client should have no restrictions.

Fix

When self.scope is None, return the requested scopes immediately — None means "no restrictions", not "no scopes allowed":

requested_scopes = requested_scope.split(" ")
if self.scope is None:
    # No scope restrictions registered for this client; allow any scopes
    return requested_scopes
allowed_scopes = self.scope.split(" ")

Tests

Added TestValidateScope class to tests/shared/test_auth.py with regression tests covering:

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: validate_scope rejects client scopes when required scopes in None

1 participant