-
Notifications
You must be signed in to change notification settings - Fork 431
fix: Shim for MCP Auth #1872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
fix: Shim for MCP Auth #1872
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -844,10 +844,19 @@ async def get_api_key_user_async( | |||||||||||||||||||||||
| # the user's roles (synced via request.state.jwt_roles -> | ||||||||||||||||||||||||
| # _attach_db_user_id), with a 401 when no recognized role is present. | ||||||||||||||||||||||||
| from auth.jwt_roles import jwt_roles_enabled | ||||||||||||||||||||||||
| from config.settings import IBM_AUTH_ENABLED, get_jwt_auth_header | ||||||||||||||||||||||||
| from config.settings import ( | ||||||||||||||||||||||||
| IBM_AUTH_ENABLED, | ||||||||||||||||||||||||
| get_jwt_auth_header, | ||||||||||||||||||||||||
| get_mcp_forwarded_jwt_header, | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
| from config.utils import resolve_jwt_claims | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| raw_jwt = request.headers.get(get_jwt_auth_header(), "") | ||||||||||||||||||||||||
| # Primary: the gateway-forwarded JWT header (default Authorization). Fallback: | ||||||||||||||||||||||||
| # the header the /mcp shim copies the JWT into, because FastMCP strips | ||||||||||||||||||||||||
| # Authorization before proxying an MCP tool call to this /v1 handler. | ||||||||||||||||||||||||
| raw_jwt = request.headers.get(get_jwt_auth_header(), "") or request.headers.get( | ||||||||||||||||||||||||
| get_mcp_forwarded_jwt_header(), "" | ||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||
|
Comment on lines
+854
to
+859
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Treat blank primary JWT headers as absent before falling back. A whitespace-only primary header is truthy for 🔧 Proposed fix- raw_jwt = request.headers.get(get_jwt_auth_header(), "") or request.headers.get(
- get_mcp_forwarded_jwt_header(), ""
- )
+ primary_jwt = request.headers.get(get_jwt_auth_header(), "").strip()
+ raw_jwt = primary_jwt or request.headers.get(get_mcp_forwarded_jwt_header(), "").strip()📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||
| logger.debug( | ||||||||||||||||||||||||
| "[AUTH] API-key path JWT header lookup", | ||||||||||||||||||||||||
| header_name=get_jwt_auth_header(), | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overwrite client-supplied forwarded JWT headers.
has_targetlets an inboundX-OpenRAG-JWTvalue win over the authenticatedAuthorizationvalue. After FastMCP stripsAuthorization,/v1can consume that client-controlled fallback header as identity/roles. Strip any inbound target header, then append only the value copied fromAuthorization.🛡️ Proposed fix
🤖 Prompt for AI Agents