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.
v1.x backport of #2718.
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.
Differences from #2718
main has a strict-coverage gate that the in-process SSE tests bring into play, so #2718 also adds an SSE round-trip test, edge-case tests, tests/server/test_transport_security.py, and removes no cover pragmas. v1.x has no such gate, so this PR carries only the credential-binding tests.
Behaviour
Same as #2718.
Breaking changes
None for default deployments. A hand-rolled SSE setup that applies BearerAuthBackend only to the POST route and not the GET route would now reject every message; FastMCP applies auth at the app level and is unaffected.
AI Disclaimer