-
Notifications
You must be signed in to change notification settings - Fork 4k
RequireAuthMiddleware omits RFC 6750 scope in WWW-Authenticate on 401/403 #3103
Copy link
Copy link
Labels
P2Moderate issues affecting some users, edge cases, potentially valuable featureModerate issues affecting some users, edge cases, potentially valuable featureauthIssues and PRs related to Authentication / OAuthIssues and PRs related to Authentication / OAuthbugSomething isn't workingSomething isn't workingneeds confirmationNeeds confirmation that the PR is actually required or needed.Needs confirmation that the PR is actually required or needed.v1Affects the v1.x maintenance lineAffects the v1.x maintenance linev2Affects the v2 line (2.x on main)Affects the v2 line (2.x on main)
Description
Activity
Metadata
Metadata
Assignees
Labels
P2Moderate issues affecting some users, edge cases, potentially valuable featureModerate issues affecting some users, edge cases, potentially valuable featureauthIssues and PRs related to Authentication / OAuthIssues and PRs related to Authentication / OAuthbugSomething isn't workingSomething isn't workingneeds confirmationNeeds confirmation that the PR is actually required or needed.Needs confirmation that the PR is actually required or needed.v1Affects the v1.x maintenance lineAffects the v1.x maintenance linev2Affects the v2 line (2.x on main)Affects the v2 line (2.x on main)
Initial Checks
Description
Summary
RequireAuthMiddleware._send_auth_errorbuildsWWW-Authenticatewitherroranderror_description(and optionalresource_metadata), but never includes thescopeparameter, even whenrequired_scopesis configured.This breaks RFC 6750 Section 3.1 and the MCP Authorization scope-selection / step-up flow. The SDK client already expects
scopeviaextract_scope_from_www_auth()and uses it inget_client_metadata_scopes()as the highest-priority source when handling403 insufficient_scope.Actual behavior
For a server configured with
required_scopes=["api.read"]:401 (no/invalid token):
403 (token missing required scope):
Neither response includes
scope="api.read".Expected behavior
When
required_scopesis non-empty, the challenge should include the RFC 6750scopeparameter, e.g.:(and similarly for 401 when scopes are configured, so the client can request the correct scopes on initial authorization).
Impact
scopes_supported(or omits scope), which is lower priority per the MCP scope selection strategy and can fail when PRM does not advertise scopes.Root cause
In
src/mcp/server/auth/middleware/bearer_auth.py,_send_auth_errorbuilds:It never appends
scope=fromself.required_scopes, which is already available on the middleware instance.Present on both
v1.xandmain(verified in current source).Suggested fix
When
self.required_scopesis non-empty, append:Happy to open a PR against
v1.xonce a maintainer assigns this issue to me. Please also advise whether a follow-up formain(v2) is desired.Example Code
Python & MCP Python SDK