fix: implement RFC 6750 Section 3.1 compliance for missing authentication#785
Closed
runeb wants to merge 5 commits intomodelcontextprotocol:mainfrom
Closed
fix: implement RFC 6750 Section 3.1 compliance for missing authentication#785runeb wants to merge 5 commits intomodelcontextprotocol:mainfrom
runeb wants to merge 5 commits intomodelcontextprotocol:mainfrom
Conversation
…tion The requireBearerAuth middleware was incorrectly treating missing Authorization headers as invalid tokens, violating RFC 6750 Section 3.1 which states: "If the request lacks any authentication information, the resource server SHOULD NOT include an error code or other error information." Changes: - Add MissingAuthenticationError class for missing authentication cases - Update bearerAuth middleware to throw MissingAuthenticationError when no Authorization header is present - Handle MissingAuthenticationError by returning WWW-Authenticate header with only realm parameter (no error codes) - Update tests to expect RFC 6750 compliant behavior for missing authentication - Preserve existing behavior for invalid/malformed tokens Before (non-compliant): WWW-Authenticate: Bearer error="invalid_token", error_description="Missing Authorization header" After (RFC 6750 compliant): WWW-Authenticate: Bearer realm="protected" Fixes RFC 6750 compliance issue while maintaining backward compatibility for all other authentication error scenarios.
pcarleton
requested changes
Jul 24, 2025
Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>
Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>
Co-authored-by: Paul Carleton <paulcarletonjr@gmail.com>
More precise naming - what's missing is the Authorization header specifically.
Author
|
Thank you for the thoughtful review @pcarleton. I agree with you that adding the So a plain but it does not feel right to mention a realm here and not elsewhere. I have therefore concluded that the least problematic solution is to keep the current implementation as that only violates a SHOULD versus a MUST. It seems my PR only makes sense if users can configure a realm. |
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.
The MCP SDK's
requireBearerAuthmiddleware was incorrectly treating missing Authorization headers as invalid tokens, violating RFC 6750 Section 3.1 compliance.Motivation and Context
The current implementation violates RFC 6750 Section 3.1, which states:
Current behavior (non-compliant):
RFC 6750 compliant behavior:
This fix improves interoperability with OAuth 2.0 clients that expect standards-compliant bearer token authentication.
How Has This Been Tested?
Test scenarios covered:
Bearer realm="protected"Bearer error="invalid_token"Bearer error="insufficient_scope"Breaking Changes
None. This is a compliance fix that only changes the WWW-Authenticate header format for missing authentication. All other authentication error scenarios remain unchanged.
Types of changes
Checklist
Additional context
Implementation approach:
MissingAuthenticationErrorclass following existing error patternsrequireBearerAuthmiddleware to throwMissingAuthenticationErrorfor missing headersStandards reference:
Files changed:
src/server/auth/errors.ts- Added MissingAuthenticationError classsrc/server/auth/middleware/bearerAuth.ts- Updated middleware logicsrc/server/auth/middleware/bearerAuth.test.ts- Updated test expectations