fix: include resource_metadata in all 401 WWW-Authenticate responses#3993
Open
ecthelion77 wants to merge 1 commit intoIBM:mainfrom
Open
fix: include resource_metadata in all 401 WWW-Authenticate responses#3993ecthelion77 wants to merge 1 commit intoIBM:mainfrom
ecthelion77 wants to merge 1 commit intoIBM:mainfrom
Conversation
b2ca5b6 to
3dbb6b2
Compare
Contributor
Author
|
Suggested labels: |
3dbb6b2 to
27772c3
Compare
74fd9d3 to
f74e717
Compare
…auth Signed-off-by: Olivier Gintrand <olivier.gintrand@forterro.com>
f74e717 to
68b5341
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.
🐛 Bug-fix PR
📌 Summary
When a client sends an empty
Authorization: Bearerheader to an OAuth-enabled server, the 401 response'sWWW-Authenticateheader is missing theresource_metadataattribute (RFC 9728). This prevents MCP clients (Open WebUI, VS Code) from discovering the OAuth authorization server to initiate the flow.The root cause is that the empty-bearer check in
_auth_no_token()fires before the per-server OAuth enforcement, returning a genericBearerwithout theresource_metadataURL.Fixes #3990
🔁 Reproduction Steps
oauth_enabled=trueAuthorization: Bearerheader (orAuthorization: Bearerwith trailing space)WWW-Authenticate: Bearer— missingresource_metadata🐞 Root Cause
In
_auth_no_token(), the empty-bearer check (bearer_header_supplied) runs before_check_server_oauth_enforcement(). When the client sends an empty Bearer header to an OAuth-enabled server, the function returns early with a genericWWW-Authenticate: Bearerthat lacks theresource_metadataattribute.The strict-mode check (
mcp_require_auth) also uses a hardcoded"Bearer"string withoutresource_metadata.💡 Fix Description
www_auth = "Bearer"at the top of_auth_no_token()OAuthRequiredErroris raised and handled with fullresource_metadata(unchanged behavior)www_authvariable instead of hardcoded"Bearer"This ensures that:
resource_metadatain their 401 responses (viaOAuthRequiredErrorhandler)Bearer(unchanged)www_authpropagationThe change is a pure reordering — no new logic, no new code paths. Line count: +11/−11.
🧪 Verification
make lintmake testmake coverage📐 MCP Compliance (if relevant)
✅ Checklist