Skip to content

[v1.x] Bind transport sessions to the authenticated principal#2719

Merged
maxisbey merged 1 commit into
v1.xfrom
v1/session-credential-binding
May 29, 2026
Merged

[v1.x] Bind transport sessions to the authenticated principal#2719
maxisbey merged 1 commit into
v1.xfrom
v1/session-credential-binding

Conversation

@maxisbey
Copy link
Copy Markdown
Contributor

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

@maxisbey maxisbey force-pushed the v1/session-credential-binding branch 2 times, most recently from 739fa13 to 072d8d5 Compare May 29, 2026 16:14
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.
@maxisbey maxisbey force-pushed the v1/session-credential-binding branch from 072d8d5 to 97d5b38 Compare May 29, 2026 16:42
@maxisbey maxisbey enabled auto-merge (squash) May 29, 2026 16:44
@maxisbey maxisbey merged commit ce267b6 into v1.x May 29, 2026
21 checks passed
@maxisbey maxisbey deleted the v1/session-credential-binding branch May 29, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants