Repository navigation
Pin that Modern list calls ignore the session ID - #7276
Conversation
The Modern (2026-07-28) half of "vMCP: session identity binding is not enforced for tools/list (and other list methods)" (#6779) needs no ownership check: classifyingHandler routes Modern requests to dispatchModern, which never reads Mcp-Session-Id and builds every list from the caller's own identity, as the 2026-07-28 spec asks of a stateless server. The Legacy half is already enforced by sessionOwnershipMiddleware and covered for all four list methods. The existing Modern test covered tools/list only and could not tell whose list came back, because the fake core ignored the identity. The fake core now records the subject each list call receives and can return a different list per subject. The test covers tools/list, resources/list, resources/templates/list and prompts/list, asserting the request makes exactly one core call, for the foreign caller, and that the response carries the caller's items, not the session owner's. The response is also the same for a foreign, an unknown and an absent session ID, so it does not reveal whether an ID is live. The owner-side test now decodes each list response, including resources/templates/list, and checks the owner's item is present. Co-authored-by: Mecatl <[email protected]> Fixes #6779
rdimitrov
left a comment
There was a problem hiding this comment.
Approve: test-only change that pins the right behaviour.
Design: Modern (2026-07-28) requests are dispatched by classifyingHandler, which sits outside sessionOwnershipMiddleware, and dispatchModern takes identity from the request context and never reads Mcp-Session-Id. So no production ownership check is needed on that path, and pinning "foreign/unknown/absent session ID gets the caller's own list" is the right guard. The per-subject fake makes the test able to fail if a list handler ever used the session owner's identity or the ownership middleware moved outside the classifier.
Aside (no action needed): telemetry and usage-metrics middleware do read Mcp-Session-Id on Modern requests (span attribute, client-name lookup), so "ignore" in the test comment holds for the response and core calls, not for observability attribution.
🤖 Reviewed with Claude Code
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7276 +/- ##
==========================================
- Coverage 81.89% 81.89% -0.01%
==========================================
Files 915 915
Lines 92853 92853
==========================================
- Hits 76046 76040 -6
- Misses 16802 16808 +6
Partials 5 5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
tools/list(and other list methods) #6779 reported that a foreign caller who sent another user'sMcp-Session-Idgot the session owner'stools/list. The Legacy path is already fixed:sessionOwnershipMiddlewareanswers a foreign session ID with 404 "Session terminated", the same as for an unknown ID. The Modern (2026-07-28) path needs no ownership check.classifyingHandlersends Modern requests todispatchModern, which never readsMcp-Session-Idand builds every list from the caller's own identity. That is what the draft spec recommends for a server that only serves that revision. This PR adds no production code. It makes the existing Modern test strong enough to prove this, because it could not tell whose list came back.fakeCorerecords the subject eachList*call receives and can return a different list per subject (nil by default, so other tests are unchanged).tools/list,resources/list,resources/templates/listandprompts/list. For each it sends the foreign caller's token with the owner's session ID and asserts:Mcp-Session-Idis minted or echoed;Mcp-Session-Idheader, so the response does not reveal whether an ID is live;resources/templates/list, and checks the owner's item is present. Before, it only checked for HTTP 200.Fixes #6779
Type of change
Test plan
Run by CI on this PR, all passing:
Tests / Test Go Code(task test) andLinting / Lint Go Code, plus the E2E jobs. Nothing was run locally.task test)task lint-fix)Changes
pkg/vmcp/server/serve_session_test.gofakeCorerecords the subject per list call and supports per-subject listspkg/vmcp/server/session_ownership_test.goDoes this introduce a user-facing change?
No. No production code changes.
Implementation plan
Approved implementation plan
Plan: session ownership on list methods, Modern vMCP path
Issue: "vMCP: session identity binding is not enforced for
tools/list(andother list methods)" (#6779), Modern half. Branch
modern-list-ownership.Reviewed by a three-reviewer panel (security, MCP protocol, codebase).
Out-of-scope findings are deliberately skipped.
Step 0: premise (done, agreed)
The Modern half is moot. No production change.
adfc5029d.sessionOwnershipMiddleware(pkg/vmcp/server/session_ownership.go:47-103)answers a foreign caller with a plain-text 404 "Session terminated".
TestSessionOwnership_ForeignCallerRejectedOnEveryRoute(
session_ownership_test.go:247-250) covers all four list methods.classifyingHandlerwraps the ownership middleware (server.go:754,762)and sends Modern requests to
dispatchModern.dispatchModerntakes thecaller's identity from the request context (
modern_dispatch.go:80) andcalls
core.List*(ctx, identity), which aggregates backends and filtersfor that identity (
core_vmcp.go:302-376). It never readsMcp-Session-Idand never writes one.classifyingHandlerdoes not send todispatchModernstillgoes through the ownership middleware: other paths, requests the parser did
not parse, Legacy requests, and
server/discoverwhen the gate turns Modernoff.
caller's own filtered list.
subscriptions/listenkeys on the JSON-RPC id.The optimizer turns Modern off for the whole instance.
Streamable HTTP Revisions") says a server that only serves that revision
SHOULD ignore
Mcp-Session-Id. A 404 would push a client that speaks bothrevisions back to
initialize. The streamable proxy ignores the session IDon Modern for the same reason.
Step 1: make the Modern test prove whose list comes back
Gap:
TestSessionOwnership_ModernRequestsIgnoreSessionIDcoverstools/listonly. Its
fakeCore.List*methods ignore the identity they receive(
serve_session_test.go:201,260,266,283), so the test cannot tell thecaller's list from the owner's.
Deliverable (test files only,
pkg/vmcp/server/session_ownership_test.goandserve_session_test.go):fakeCorerecords the identity eachList*call receives.tools/list,resources/list,resources/templates/listandprompts/list. Each row sends Modern headersand
_meta, the foreign caller's token, and the owner's session ID.with other parallel subtests.
TestSessionOwnership_OwnerRequests(:336) also checksresources/templates/list.Acceptance:
Mcp-Session-Id;requireOwnerSessionIntactpasses.Check this once by changing the handler temporarily, then revert.
pkg/vmcp/serverpass.Step 2: final checks and a local commit
Deliverable: one local commit that changes only the test files.
tools/list(and other list methods) #6779 is moot, and the existingtable already covers Legacy.
Co-authored-by: Mecatl <[email protected]>.Acceptance:
task testpasses.Decisions
docs/arch/10-virtual-mcp-architecture.md:1240-1275and the comment atsession_ownership.go:31-33already say Modern skips the check.Mcp-Session-IdinpassthroughHeaders, and the stale wording in thestorage plan.
Special notes for reviewers
tools/list(and other list methods) #6779 and explained why in a comment there. The draft's Streamable HTTP page says a server that only supports this revision should ignoreMcp-Session-Idand not mint or echo session IDs. Refusing would also make a foreign ID distinguishable from a random one, and a bare 4xx can make a client that speaks both revisions fall back toinitialize.Session terminated\nwith the same headers. The foreign path does one extra constant-time compare and aslog.Warn. I did not measure timing, and nothing here claims timing equivalence.fakeCore.listsFor, and the "exactly one core call" assertion in the Modern test. That assertion slices the recorded subjects afterinitialize, so it assumes no asynchronous list call for the owner arrives after the handshake.