Skip to content

Bind delegated sessions to client and actor - #7315

Merged
jhrozek merged 5 commits into
mainfrom
delegated-session-binding
Nov 26, 2026
Merged

jhrozek merged 5 commits into
mainfrom
delegated-session-binding

Conversation

@jhrozek

@jhrozek jhrozek commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Summary

An MCP session is bound to whoever created it, and today that binding is only the issuer and subject (iss\x00sub). With delegated access, one user can have several agents and clients acting for them, each holding its own delegated access token. Under the current binding, any of those agents, another client of the same user, or the user's own interactive login can pick up a delegated session by presenting its session ID. A delegated session should belong to the client and the agent that opened it.

  • Delegated sessions now bind to issuer, user, route, client_id, and, when present, the immediate actor (act.iss, act.sub). jti, exp and authorization_details are not part of the binding, so a renewed token keeps its session. Interactive and unspecified sessions keep the two-field binding byte for byte, so existing sessions and stored records are unaffected.
  • The new forms are route-tagged and NUL-separated: iss\0sub\0delegated\0client_id without an actor, and …\0act_iss\0act_sub with one. Every component must be non-empty and free of NUL. A token on a route the code does not recognise cannot open or use a session.
  • A delegated token that cannot be bound fails closed: a missing or invalid client_id, a malformed or incomplete act, or an explicit act: null. It never falls back to the user-only binding.
  • vMCP resolves the binding before it connects to any backend, uses the same rule for creation, restore and every tool, resource and prompt call, and no longer puts the stored binding in error messages. A tokenless identity gets an anonymous session only on the unspecified or interactive route.
  • A validator bound to the embedded authorization server now rejects a token that carries the delegated-access marker but cannot be admitted as delegated, for example one verified through the HTTP JWKS fallback or with no audience configured. Before, such a token got the user-only binding and could reuse the user's interactive session.
  • The ordinary MCP server proxies (streamable, transparent, HTTP+SSE) pick up the new binding through the shared sessionbinding package; the storage layer already compares bindings as opaque strings.

Fixes #6888

Type of change

  • Bug fix
  • New feature
  • Refactoring (no behavior change)
  • Dependency update
  • Documentation
  • Other (describe):

Test plan

  • Unit tests (task test)
  • E2E tests (task test-e2e)
  • Linting (task lint-fix)
  • Manual testing (describe below)

The tests cover the binding format and its fuzz targets, compatibility with the v0.69.0 parser (frozen in a test), a real token validator bound and unbound, vMCP session creation, restore and per-call checks, the vMCP HTTP ownership check, the streamable and transparent proxies, and Redis and in-memory session storage with multi-NUL bindings.

Changes

Area Change
pkg/auth/sessionbinding Delegated binding format, parser, validator; FromIdentity switches on the admission route
pkg/vmcp/session One ResolveBinding step before backends are dialled; anonymous sessions limited to unspecified and interactive routes; no stored binding in errors
pkg/auth/token.go Bound validator rejects marked tokens that are not admitted as delegated
pkg/vmcp/server, pkg/transport/** Tests only, plus comment updates
docs/arch/03, 10, 13, 16, 17, docs/authz.md, docs/middleware.md Binding format, refusal cases, trust boundaries, rolling upgrades

Does this introduce a user-facing change?

Yes, for deployments that issue delegated access tokens (ID-JAG redemption with subject resolution, a Go-only setting).

  • Before: a delegated session could be reused by another client of the same user, by another agent, or by the user's interactive token. After: those requests get the existing refusal (vMCP Legacy: 404 Session terminated; MCP server proxies: 404 not found), and the owner's session is untouched.
  • Before: a delegated token without client_id, or with a malformed act, got a user-only session. After: it cannot open or use a session. On the proxies this shows up through refusals that already existed: HTTP+SSE 401, transparent SSE 502, streamable and transparent initialize 404. On Legacy vMCP the initialize reply carries a session ID for a session that is already terminated, so the next request gets 404.
  • Before: a validator bound to the embedded authorization server served a marked token it could not classify as delegated. After: it answers 401 invalid_token.
  • Rolling upgrades: ordinary proxies check session owners only from v0.51.0, and vMCP answers 404 to every request on a foreign session only from v0.57.0. Upgrade every replica that shares the session store before turning on subject resolution. If it was already on while older replicas ran, sessions they created for delegated tokens carry the two-field binding; let them expire or invalidate them before relying on the isolation.
  • Go API: sessionbinding.Parse and binding.Parse keep their signatures and accept the delegated forms, but return only the issuer and subject prefix. Compare full bindings with Validate, never with Format(Parse(s)). Format errors now wrap ErrInvalidBinding, so use errors.Is.

Implementation plan

Approved implementation plan
  1. pkg/auth/sessionbinding: route-tagged, arity-discriminated binding. Two fields for interactive and unspecified routes, four for delegated without an actor, six with one. An unknown route fails closed. A present act needs a non-empty act.iss and act.sub; only the immediate actor is bound. Parse with chained strings.Cut. Test against a frozen copy of the v0.69.0 parser.
  2. vMCP sessions: resolve the binding once, before backends are dialled. Use sessionbinding throughout. Keep the existing rejection log reasons. Leave the Modern (stateless) path alone, since it ignores Mcp-Session-Id.
  3. Tests across vMCP HTTP, enforceSessionBinding, the streamable and transparent proxies, and Redis and local storage.
  4. Architecture docs: binding fields, cross-route isolation, rolling upgrades, trust boundaries.
  5. Follow-up from review: reject marked tokens a bound validator cannot admit as delegated, rather than serving them with the user-only binding.

Special notes for reviewers

  • The Modern (stateless, 2026-07-28) path is deliberately unchanged. It ignores Mcp-Session-Id, so there is no session binding to enforce there.
  • Only the immediate actor is bound; nested act.act is informational per RFC 8693 §4.1. Without an actor, agents are isolated only if each uses its own client_id.
  • Self-issued RFC 8693 token exchanges and unmarked JWT-bearer grants are not marked delegated. They keep the two-field binding and can still reuse the user's interactive session. Binding those is planned as separate work.
  • The last commit changes token admission in pkg/auth, not session code. It is separate so it can be reviewed on its own. Nothing mints the marker in a released configuration yet, because subject resolution is still Go-only and off.
  • Behaviour that already existed but is now reachable by more callers:
    • When an embedder mounts vMCP without the ownership middleware, a foreign tools/call terminates the owner's session through enforceSessionBinding. Serve refuses first, so the default setup is unaffected.
    • On the transparent proxy, an initialize refused after forwarding leaves the backend session to time out on its own.

@jhrozek
jhrozek requested a review from ChrisJBurns as a code owner November 25, 2026 21:57
rdimitrov
rdimitrov previously approved these changes Nov 25, 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: the binding change is made at the right owner and fails closed.

Design: sessionbinding.FromIdentity/Validate are the single place every proxy and vMCP path (streamable, transparent, SSE, vMCP ownership middleware, create/restore/per-call checks) derives and compares the session owner, so extending the owner string there covers all entry points; the Modern stateless vMCP path ignores Mcp-Session-Id and has nothing to bind. Delegated tokens now get an arity-tagged owner (client and actor included) while interactive and unspecified bindings stay byte-identical, and a marked token the validator cannot classify gets a 401 instead of silently falling back to a user-only binding. The act/client_id edge cases and the audience requirement for bound validators trace through cleanly.

Upgrade effect to put in the release notes: sessions a delegated-route caller created before the upgrade carry the old 2-field owner, so they return 404 until the client re-initializes, and old replicas reject the new 4/6-field values during a rolling upgrade. Accepting the legacy form would defeat the fix, so this is the right trade-off. It only affects deployments that mint the delegated marker, which is off by default today.

🤖 Reviewed with Claude Code

jhrozek and others added 5 commits November 26, 2026 09:19
Extend pkg/auth/sessionbinding so delegated identities bind sessions to
issuer, user subject, the delegated route tag, client_id, and the
outermost actor (act.iss and act.sub) when present, while keeping
interactive and unspecified bindings byte-identical to the two-field
form and failing closed on unknown routes or malformed actor claims.

Parse preserves its exported signature and validates both standard and
delegated bindings while Validate compares the full binding string in
constant time. Frozen v0.69.0 tests confirm older replicas reject the
extended format during rolling upgrades.

Co-authored-by: Mecatl <[email protected]>
Route vMCP session binding extraction through pkg/auth/sessionbinding so
delegated sessions carry client_id, actor, and route metadata on creation
and restore, matching the shared ownership middleware.

Harden ShouldAllowAnonymous and anonymous-session upgrade checks against
synthetic tokenless delegated identities, extract security.ResolveBinding
so makeSession fails fast before dialing backends on unbindable
identities, and omit raw binding values from RestoreSession errors.

Co-authored-by: Mecatl <[email protected]>
Add end-to-end ownership tests verifying delegated session binding across
Legacy vMCP HTTP routes, direct enforceSessionBinding calls, streamable
and transparent MCPServer proxies, and local/Redis session storage.

Cover wrong client_id, wrong actor issuer or subject, cross-route
interactive and delegated mismatches, renewed delegated tokens with
different jti/exp/authorization_details, rejection log reasons without
PII, and multi-NUL exact matching versus prefix rejection in storage.

Co-authored-by: Mecatl <[email protected]>
Document the four- and six-field delegated session binding format,
fail-closed rules, two-way rolling-upgrade behavior, and admission-route
trust boundaries across the architecture docs and user-facing
authorization guide.

Co-authored-by: Mecatl <[email protected]>
A validator bound to the embedded authorization server admitted a token
carrying the delegated-access marker on the unspecified route when it
could not classify it as delegated: when the key came from the HTTP JWKS
fallback or the claims from introspection, when no audience was set, or
when the token also carried a token session ID. Such a token got the
two-field session binding and could reuse the user's interactive MCP
session, silently undoing the cross-route isolation of delegated
sessions.

Return 401 invalid_token for these tokens instead, before upstream
credentials are loaded, and log the cause at WARN. Unmarked tokens and
validators not bound to the embedded issuer behave as before. Only the
ID-JAG redeemer mints the marker, under subject resolution, which is not
yet enabled.

Co-authored-by: Mecatl <[email protected]>
@jhrozek
jhrozek force-pushed the delegated-session-binding branch from dff98ab to d199ee7 Compare November 26, 2026 08:26
@github-actions github-actions Bot added the size/XL Extra large PR: 1000+ lines changed label Nov 26, 2026
@jhrozek

jhrozek commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@rdimitrov the force-push dismissed your approval, sorry about that. Main picked up "Enforce call-bound access tokens at the vMCP" (#7302), which edits the same paragraph of docs/authz.md that I rewrote for the session binding, so the PR conflicted there. That was the only conflict.

I kept main's call-binding text exactly as it is and put my paragraph on delegated session binding after it. The ownership sentence says "Legacy vMCP", as it did in my version, since the Modern path ignores session IDs.

I rebased onto current main and pushed. There are no other functional changes: git range-diff shows four of the five commits identical, and the fifth (the docs commit) differs only in docs/authz.md. Build, vet, lint and the tests for the touched packages pass after the rebase.

Could you take another look when you get a chance?

@codecov

codecov Bot commented Nov 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.02913% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 82.13%. Comparing base (05cb704) to head (d199ee7).

Files with missing lines Patch % Lines
pkg/auth/token.go 91.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7315      +/-   ##
==========================================
+ Coverage   82.11%   82.13%   +0.02%     
==========================================
  Files         931      931              
  Lines       94390    94451      +61     
==========================================
+ Hits        77507    77578      +71     
+ Misses      16878    16868      -10     
  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.

@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.

Re-review of d199ee7: still approve. The push rebased the branch onto the current main, and the one commit that changed is the docs commit.

The PR's own change is byte-identical to the previously approved one, except for the docs/authz.md paragraph. That paragraph was merged with the newer call-binding and loopback Host guard text on main, and now says "Legacy vMCP", which matches docs/arch/10. The rebased code composes with the call-bound token middleware on main: it only reads the session ID and runs before the ownership check. The doc links and version claims resolve, and CI is green.

Design: unchanged. Delegated sessions are bound to the issuer and user, the delegated route, the OAuth client and the actor, and the check lives in the shared sessionbinding package that the proxies and vMCP all use.

🤖 Reviewed with Claude Code

@jhrozek
jhrozek merged commit 619c160 into main Nov 26, 2026
47 checks passed
@jhrozek
jhrozek deleted the delegated-session-binding branch November 26, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Extra large PR: 1000+ lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vMCP: bind sessions to the client, acting agent, and delegated-access marker, not just the user

2 participants