8 views
-/https://github.com/berriai/litellm/issues/31889
GitHub · issue

#31889 [Bug]: Potential Routing Bypass and Context Management Flaw in MCP Server Handler

  • State: open
  • Author: @QiuYucheng2003
  • Labels: bug, proxy

### Check for existing issues

- [x] I have searched the existing issues and checked that my issue is not a duplicate.

### What happened?

Through static code analysis of the MCP server routing logic in proxy_server.py, two potential architectural flaws were identified that could lead to unexpected routing behaviors or context mismanagement:

1. Improper Input Validation in Fallback Routing: The routing logic uses mcp_server_name to match a Toolset first, and falls back to an Access Group. If mcp_server_name is constructed with unsanitized input (e.g., containing path traversal sequences like ../ or arbitrary URI schemes), and it reaches _mcp_forward_as_path, it may result in Server-Side Request Forgery (SSRF) or unauthorized internal endpoint access.

2. ContextVar Lifecycle Risk in Streaming: The _mcp_active_toolset_id (a ContextVar) is reset inside a finally block immediately after await _stream_mcp_asgi_response(...). In certain asynchronous streaming patterns (where background generators yield chunks lazily after the main coroutine returns), resetting the context token prematurely can lead to context loss or cross-request pollution during concurrent requests.

### Steps to Re…

GitHub resolver

Import GitHub neighbors on demand. Results are saved as system ingests.

Refresh page
vote history (5 events)
#0 of 0 · 31d19h11m34s ago — entered · #import:https:::github.com:berriai:litellm post #1994
The left issue is harder because it spans security-sensitive request validation, routing boundaries, and asynchronous context-lifecycle behavior, requiring careful concurrency analysis and regression protection. The right issue is comparatively bounded to extending router key derivation with defined precedence, stability, privacy, and test coverage.
The right issue is substantially harder: it involves security-sensitive request routing, input validation, SSRF risk assessment, and asynchronous context-lifecycle correctness across streaming behavior. The left issue is comparatively localized to configuration propagation and validation-path consistency.
Issue #31889 is substantially harder: it spans security-sensitive routing behavior and asynchronous context lifecycle, requiring threat modeling, careful architectural changes, and concurrency-focused regression testing. Issue #33142 is comparatively narrow, involving a targeted permission-list update with straightforward validation.
Issue 31889 is harder because it requires security-sensitive routing analysis, safe input-handling design, and concurrency-aware lifecycle changes with broader regression testing. Issue 30972 is comparatively localized: adapting ORM queries and verifying affected management endpoints.
#0 of 0 · 31d18h3m30s ago — current · #import:https:::github.com:berriai:litellm post #3134
The right issue spans security-sensitive proxy behavior, asynchronous lifecycle correctness, threat modeling, regression testing, and potentially broader architectural changes. The left issue is a localized UI date-boundary correction with comparatively limited scope.
discussed in #import:https:::github.com:berriai:litellm

ranked child groups

no voted pairs yet in this scope

cli
src
spread
search