Bind transport sessions to the authenticated principal#2718
Merged
Conversation
3708dba to
6421a41
Compare
Both HTTP transports now record the principal that created each session — the OAuth client together with the issuer and subject when the token verifier supplies them — and serve subsequent requests for that session only when they present the same principal. Requests presenting a different principal receive the same 404 response as for an unknown session ID, and SSE session entries are removed when the connection ends. Servers without authentication, and authentication backends other than the built-in BearerAuthBackend, are unaffected: no principal is recorded and the comparison always passes. The new in-process SSE tests bring connect_sse, handle_post_message, and TransportSecurityMiddleware under tracked coverage, so the corresponding no-cover pragmas are removed.
6421a41 to
41ab75d
Compare
felixweinberger
approved these changes
May 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Streamable HTTP and SSE transports now record the principal that created each session — the OAuth client together with the issuer and subject when the token verifier supplies them — and serve subsequent requests for that session only when they present the same principal. Requests presenting a different principal receive the same 404 response as for an unknown session ID. SSE session entries are also removed when the connection ends rather than retained for the lifetime of the transport.
The new in-process SSE tests bring
connect_sse,handle_post_message, andTransportSecurityMiddlewareunder tracked coverage, so the correspondingno coverpragmas are removed.Motivation
Brings the Python transports in line with the Go SDK (
TokenInfo.UserID-keyed) and C# SDK (UserIdClaim-keyed). Relevant for hosted MCP hosts and gateways where many end-users go through one OAuth client.Behaviour
BearerAuthBackendauthBearerAuthBackend, verifier populatessubject/claims["iss"]{client_id, issuer, subject}BearerAuthBackend, verifier does notNoneand the comparison degrades to the remaining ones — see the simple-auth example verifier for populating themTest plan
TransportSecurityMiddleware.validate_requesthost/origin/content-type tests./scripts/testcleanBreaking changes
None for default deployments. A hand-rolled SSE setup that applies
BearerAuthBackendonly to the POST route and not the GET route would now reject every message;MCPServerapplies auth at the app level and is unaffected.AI Disclaimer