fix(mcp): configurable session owner fingerprint and cap for shared keys - #35498
fix(mcp): configurable session owner fingerprint and cap for shared keys#35498sidmhatre17 wants to merge 4 commits into
Conversation
Allow LITELLM_MCP_MAX_STATEFUL_SESSIONS_PER_OWNER and prefer an explicit session-owner header or client IP over a shared API key so IDE users behind one service-account key get independent stateful session buckets. Co-authored-by: Cursor <cursoragent@cursor.com>
|
siddhesh mhatre seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Greptile SummaryThis PR makes stateful MCP session limits configurable and adds optional request-header or client-IP owner fingerprints for shared API keys.
Confidence Score: 4/5This PR should not merge until session ownership remains bound to authenticated identity and invalid non-positive session caps are rejected or handled safely. A client-controlled header can satisfy another session's ownership check independently of the authenticated key, while non-positive configured caps make every stateful initialization fail. Files Needing Attention: litellm/proxy/_experimental/mcp_server/server.py, litellm/constants.py
|
| Filename | Overview |
|---|---|
| litellm/constants.py | Adds MCP owner configuration, but the new session cap is not constrained to the positive values required by enforcement. |
| litellm/proxy/_experimental/mcp_server/server.py | Adds header/IP fingerprint precedence at all ownership call sites, but the header can replace authenticated identity without being bound to it. |
| tests/test_litellm/proxy/_experimental/mcp_server/test_mcp_session_owner.py | Covers fingerprint precedence and defaults but omits cross-key owner isolation and invalid configured-cap cases. |
Reviews (1): Last reviewed commit: "fix(mcp): configurable session owner fin..." | Re-trigger Greptile
PR overviewAll previously flagged issues have been addressed. No open security concerns remain on this pull request. Security reviewNo open security issues remain on this pull request. Fixed/addressed: 2 · PR risk: 0/10 |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Address Greptile/Veria P1 findings: combine owner header/IP with the authenticated credential instead of replacing it, add a per-auth-identity hard ceiling against header rotation, and reject non-positive session caps. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Addressed the Greptile / Veria P1 findings in 5253514:
Regression coverage updated in |
Route session-owner settings through env helpers (matching the cap parsers), annotate the auth-identity registry as intentionally mutable, and avoid new mutable list/dict annotations so lint/docs checks pass. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Pushed CI fixes in c0e49df:
Companion docs PR for the public env reference: BerriAI/litellm-docs#737 |
Unauthenticated clients could rotate x-litellm-mcp-session-owner to bypass both session caps; fall back to IP/anonymous instead. Co-authored-by: Cursor <cursoragent@cursor.com>
TLDR
Problem this solves:
How it solves it:
LITELLM_MCP_MAX_STATEFUL_SESSIONS_PER_OWNERmakes the per-owner cap configurablex-litellm-mcp-session-owner(or client IP) is bound to the authenticated identity (key+hdr/key+ip), not a replacement — shared-key users get independent buckets without cross-key hijackingLITELLM_MCP_MAX_STATEFUL_SESSIONS_PER_AUTH_IDENTITYhard-caps total sessions under one credential so rotating the owner header cannot bypass the per-owner limitanonymous(same as pre-fix keyless behavior)Relevant issues
Fixes #35383
Linear ticket
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Unit regression coverage for the session-owner fingerprint paths (no live LLM calls required — this is proxy MCP session accounting):
Type
🐛 Bug Fix
Changes
LITELLM_MCP_MAX_STATEFUL_SESSIONS_PER_OWNER,LITELLM_MCP_MAX_STATEFUL_SESSIONS_PER_AUTH_IDENTITY); clamp non-positive valueskey+hdr:…/key+ip:…when the owner header or prefer-IP is set; default remainskey:…anonymoustests/test_litellm/proxy/_experimental/mcp_server/test_mcp_session_owner.pyFinal Attestation