Skip to content

Pin that Modern list calls ignore the session ID - #7276

Merged
jhrozek merged 1 commit into
mainfrom
modern-list-ownership
Nov 24, 2026
Merged

jhrozek merged 1 commit into
mainfrom
modern-list-ownership

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Issue vMCP: session identity binding is not enforced for tools/list (and other list methods) #6779 reported that a foreign caller who sent another user's Mcp-Session-Id got the session owner's tools/list. The Legacy path is already fixed: sessionOwnershipMiddleware answers 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. classifyingHandler sends Modern requests to dispatchModern, which never reads Mcp-Session-Id and 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.
  • fakeCore records the subject each List* call receives and can return a different list per subject (nil by default, so other tests are unchanged).
  • The Modern test now covers tools/list, resources/list, resources/templates/list and prompts/list. For each it sends the foreign caller's token with the owner's session ID and asserts:
    • the response carries the caller's items and not the owner's;
    • the core was called exactly once, with the caller's subject;
    • no Mcp-Session-Id is minted or echoed;
    • a foreign, an unknown and an absent session ID give the same status, body and Mcp-Session-Id header, so the response does not reveal whether an ID is live;
    • the owner's session is undisturbed.
  • The owner-side Legacy test now decodes each list response, including resources/templates/list, and checks the owner's item is present. Before, it only checked for HTTP 200.

Fixes #6779

Type of change

  • Other (describe): test-only hardening, no production change

Test plan

Run by CI on this PR, all passing: Tests / Test Go Code (task test) and Linting / Lint Go Code, plus the E2E jobs. Nothing was run locally.

  • Unit tests (task test)
  • Linting (task lint-fix)

Changes

File Change
pkg/vmcp/server/serve_session_test.go fakeCore records the subject per list call and supports per-subject lists
pkg/vmcp/server/session_ownership_test.go Table-driven Modern test over all four list methods; owner-side test decodes responses

Does 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 (and
other 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.

  • The Legacy half is fixed by the advisory merge 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.
  • classifyingHandler wraps the ownership middleware (server.go:754,762)
    and sends Modern requests to dispatchModern. dispatchModern takes the
    caller's identity from the request context (modern_dispatch.go:80) and
    calls core.List*(ctx, identity), which aggregates backends and filters
    for that identity (core_vmcp.go:302-376). It never reads
    Mcp-Session-Id and never writes one.
  • Every request classifyingHandler does not send to dispatchModern still
    goes through the ownership middleware: other paths, requests the parser did
    not parse, Legacy requests, and server/discover when the gate turns Modern
    off.
  • Nothing on Modern belongs to a session. Pagination cursors are applied to the
    caller's own filtered list. subscriptions/listen keys on the JSON-RPC id.
    The optimizer turns Modern off for the whole instance.
  • The 2026-07-28 spec (Streamable HTTP, "Backward Compatibility › Earlier
    Streamable HTTP Revisions") says a server that only serves that revision
    SHOULD ignore Mcp-Session-Id. A 404 would push a client that speaks both
    revisions back to initialize. The streamable proxy ignores the session ID
    on Modern for the same reason.

Step 1: make the Modern test prove whose list comes back

Gap: TestSessionOwnership_ModernRequestsIgnoreSessionID covers tools/list
only. Its fakeCore.List* methods ignore the identity they receive
(serve_session_test.go:201,260,266,283), so the test cannot tell the
caller's list from the owner's.

Deliverable (test files only, pkg/vmcp/server/session_ownership_test.go and
serve_session_test.go):

  • fakeCore records the identity each List* call receives.
  • The Modern test is table-driven over tools/list, resources/list,
    resources/templates/list and prompts/list. Each row sends Modern headers
    and _meta, the foreign caller's token, and the owner's session ID.
  • Each subtest has its own server, so the identity it records does not race
    with other parallel subtests.
  • TestSessionOwnership_OwnerRequests (:336) also checks
    resources/templates/list.

Acceptance:

  • Each of the four subtests asserts all of these:
    • the status is 200;
    • the body contains the expected item;
    • the response has no Mcp-Session-Id;
    • the core received the foreign caller's subject, not the owner's;
    • requireOwnerSessionIntact passes.
  • The test fails when a Modern list handler uses the session owner's identity.
    Check this once by changing the handler temporarily, then revert.
  • The scoped tests for pkg/vmcp/server pass.

Step 2: final checks and a local commit

Deliverable: one local commit that changes only the test files.

Acceptance:

  • task test passes.
  • The commit exists only locally: no push, no PR, no GitHub comment.

Decisions

  • No docs change. Clients see no difference, and
    docs/arch/10-virtual-mcp-architecture.md:1240-1275 and the comment at
    session_ownership.go:31-33 already say Modern skips the check.
  • Out of scope, skipped: the issuer in the capability cache key,
    Mcp-Session-Id in passthroughHeaders, and the stale wording in the
    storage plan.

Special notes for reviewers

  • Deliberate deviation from Legacy. Legacy refuses a foreign session ID with a 404. Modern ignores the ID and lists for the caller. The issue's earlier acceptance ("a foreign user is refused on all four methods on both paths") would have had Modern refuse too. I rewrote the acceptance on vMCP: session identity binding is not enforced for 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 ignore Mcp-Session-Id and 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 to initialize.
  • Legacy equivalence. A foreign, an unknown and a terminated session ID all get 404 Session terminated\n with the same headers. The foreign path does one extra constant-time compare and a slog.Warn. I did not measure timing, and nothing here claims timing equivalence.
  • Where to look. The per-subject override in fakeCore.listsFor, and the "exactly one core call" assertion in the Modern test. That assertion slices the recorded subjects after initialize, so it assumes no asynchronous list call for the owner arrives after the handshake.

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
@jhrozek
jhrozek requested a review from ChrisJBurns as a code owner November 24, 2026 16:41
@github-actions github-actions Bot added the size/S Small PR: 100-299 lines changed label Nov 24, 2026

@rdimitrov rdimitrov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 81.89%. Comparing base (c6c1b40) to head (2f069bd).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions github-actions Bot added size/S Small PR: 100-299 lines changed and removed size/S Small PR: 100-299 lines changed labels Nov 24, 2026
@jhrozek
jhrozek merged commit 65cc86f into main Nov 24, 2026
77 of 79 checks passed
@jhrozek
jhrozek deleted the modern-list-ownership branch November 24, 2026 17:33
@github-actions github-actions Bot mentioned this pull request Nov 24, 2026
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Small PR: 100-299 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vMCP: session identity binding is not enforced for tools/list (and other list methods)

2 participants