Fix proxy authentication in RBAC middleware for all protected endpoints#2345
Merged
crivetimihai merged 6 commits intomainfrom Jan 24, 2026
Merged
Fix proxy authentication in RBAC middleware for all protected endpoints#2345crivetimihai merged 6 commits intomainfrom
crivetimihai merged 6 commits intomainfrom
Conversation
Collaborator
Author
|
Passes make autoflake isort black pre-commit
make doctest test lint-web flake8 bandit interrogate pylint verify |
Signed-off-by: Mohan Lakshmaiah <mohalaks@in.ibm.com>
Signed-off-by: Mohan Lakshmaiah <mohalaks@in.ibm.com>
- Add missing blank line between test classes - Remove unused jwt import - Fix excess blank lines Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Add plugin_context_table and plugin_global_context to proxy authentication paths, matching the JWT authentication path. This ensures HTTP_AUTH_CHECK_PERMISSION hooks can access context set by HTTP_PRE_REQUEST hooks when using proxy authentication. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
2ce0b27 to
8b81663
Compare
1. RBAC now checks auth_required when proxy header missing - Returns 401 for API requests, 302 redirect for browsers - Aligns HTTP behavior with WebSocket auth 2. Block anonymous users from token management - Add auth_method=="anonymous" to _require_interactive_session - Prevents token access when proxy header missing 3. Lookup proxy user admin status from database - Check platform_admin_email for admin match - Query EmailUser table for is_admin status - Enables plugin permission hooks to work correctly Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Member
Review Changes AppliedRebased onto main and applied the following fixes: 1. Lint Fixes
2. Plugin Context for Cross-Hook SharingAdded 3. Security Fixes
4. New Tests Added
Files Changed
Test Results
|
crivetimihai
approved these changes
Jan 24, 2026
Update require_auth to check auth_required when proxy header is missing, matching the RBAC/WebSocket behavior. Previously returned "anonymous" even when auth_required=true. - Raise 401 when mcp_client_auth_enabled=false and no proxy header if auth_required=true - Update tests to cover both auth_required=true and false cases Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Member
Additional Fix:
|
| Entry Point | No proxy header + auth_required=true |
|---|---|
| WebSocket | Rejects (1008) |
| Streamable HTTP | 401 (uses mcp_require_auth) |
| RBAC | 401/302 |
| require_auth | 401 ✅ (now fixed) |
kcostell06
pushed a commit
to kcostell06/mcp-context-forge
that referenced
this pull request
Feb 24, 2026
…ts (IBM#2345) * Fix proxy authentication Signed-off-by: Mohan Lakshmaiah <mohalaks@in.ibm.com> * Fix pylint errors Signed-off-by: Mohan Lakshmaiah <mohalaks@in.ibm.com> * fix: Correct lint issues in proxy auth tests - Add missing blank line between test classes - Remove unused jwt import - Fix excess blank lines Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix: Include plugin context in proxy auth for cross-hook sharing Add plugin_context_table and plugin_global_context to proxy authentication paths, matching the JWT authentication path. This ensures HTTP_AUTH_CHECK_PERMISSION hooks can access context set by HTTP_PRE_REQUEST hooks when using proxy authentication. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix: Address security concerns in proxy authentication 1. RBAC now checks auth_required when proxy header missing - Returns 401 for API requests, 302 redirect for browsers - Aligns HTTP behavior with WebSocket auth 2. Block anonymous users from token management - Add auth_method=="anonymous" to _require_interactive_session - Prevents token access when proxy header missing 3. Lookup proxy user admin status from database - Check platform_admin_email for admin match - Query EmailUser table for is_admin status - Enables plugin permission hooks to work correctly Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> * fix: Align require_auth with RBAC proxy enforcement Update require_auth to check auth_required when proxy header is missing, matching the RBAC/WebSocket behavior. Previously returned "anonymous" even when auth_required=true. - Raise 401 when mcp_client_auth_enabled=false and no proxy header if auth_required=true - Update tests to cover both auth_required=true and false cases Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> --------- Signed-off-by: Mohan Lakshmaiah <mohalaks@in.ibm.com> Signed-off-by: Mihai Criveti <crivetimihai@gmail.com> Co-authored-by: Mohan Lakshmaiah <mohalaks@in.ibm.com> Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
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: Fix proxy authentication in RBAC middleware for all protected endpoints
Title
fix: Support proxy authentication in RBAC middleware for all protected endpoints
Description
Problem
When proxy-based authentication was configured (
MCP_CLIENT_AUTH_ENABLED=false,TRUST_PROXY_AUTH=true), all endpoints protected by the@require_permissiondecorator (including/tools/,/resources/,/prompts/, etc.) were still requiring JWT tokens and rejecting requests with only proxy headers.The bug was in
get_current_user_with_permissions()which only checked for proxy authentication after determining no JWT token was present, and only fell back toAUTH_REQUIREDsetting rather than properly handling proxy authentication.Solution
Modified
mcpgateway/middleware/rbac.pyto check for proxy authentication before requiring JWT tokens:MCP_CLIENT_AUTH_ENABLED=false, check proxy headers firstPROXY_USER_HEADERwhenTRUST_PROXY_AUTH=trueMCP_CLIENT_AUTH_ENABLED=trueChanges
mcpgateway/middleware/rbac.py- Updatedget_current_user_with_permissions()functiontests/unit/mcpgateway/utils/test_proxy_auth.pyTesting
/tools/,/resources/,/prompts/,/servers/,/gateways/Impact
This fix enables proxy-based authentication for all 100+ protected endpoints that use the
@require_permissiondecorator, including:Configuration
Works with the following environment variables:
Closes #1528