Repository navigation
fix(mcp): bind sessions to their principal and reclaim idle ones - #115
Merged
Merged
Conversation
MCP session ids came from a sequential counter, sessions were never expired, and POST/GET/DELETE on /platform/mcp only checked that an id existed. Any caller that could reach the endpoint could guess an id and read another session's stream and replay buffer or end it, including the stdio session through the shared HTTP listener. Follow Protean's McpSessionRegistry and McpHttpController: - issue random UUID v4 session ids - bind each session to the principal that initialized it; another principal's POST/GET answers 404 as for an unknown session and its DELETE is a 204 no-op - reclaim sessions idle for 30 minutes (only owner lookups count as activity), closing their streams; embedders can change the timeout with McpSessionStore::set_session_idle_timeout - validate the session before registering the request for cancellation, as Java does before dispatch - end the stdio session as the stdio-local principal at EOF Design doc 17 records the timeout config key non-parity. Closes #113 Tags: #mcp #security #session Co-Authored-By: htjulia <htjulia1@gmail.com>
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
MCP sessions on
/platform/mcpused sequential ids, never expired, and were not bound to the principal that created them. This bringsMcpSessionStoreto parity with Protean'sMcpSessionRegistry/McpHttpController.uuid::Uuid::new_v4, CSPRNG-backed), as Java'sUUID.randomUUID().initializerequest's principal (or none) owns the session. POST/GET/DELETE from any other principal behave exactly as for an unknown session: POST404UNKNOWN_SESSIONproblem, GET bare404, DELETE204with the session kept. An unauthenticated session is usable only by unauthenticated requests (JavaObjects.equals(owner, principal)).protean.mcp.session.timeoutdefault) are removed and their GET stream closed. Reclaim runs on every store access and every 15 s on an open stream (Java's heartbeat cadence). Only an owner's successful lookup counts as activity. Embedders can change it withMcpSessionStore::set_session_idle_timeout(Duration::ZEROdisables, as<= 0does in Java).notifications/cancelled, as Java validates before dispatch. A blankMcp-Session-Idis treated as no session, as in Java.stdio-local, so the HTTP listener sharing the store cannot reach it. The host now sends its EOFDELETEasstdio-localso it still ends the session.Java evidence
McpSessionRegistry.java:88-92—create(owner)withUUID.randomUUID()McpSessionRegistry.java:98-105—get(id, principalName): another owner is indistinguishable from unknown, only a successful lookup touchesMcpSessionRegistry.java:296-304— idle sweep terminates sessions (closes the stream)McpHttpController.java:107-113(POST 404 problem),:165-168(GET bare 404),:174-182(DELETE only by owner, always 204)McpConfiguration.java:112—protean.mcp.session.timeout:30mMcpSessionOwnershipHttpTest.java— cross-principal POST/GET 404, DELETE 204 keeps the session, unauthenticated cannot use an owned sessionNon-parity (recorded in
docs/design/17-mcp-session-and-extension-contract.md§2.1)The idle timeout is a Spring property in Java, not a
ConfigRegistrykey, so it is not added to the Protrus config registry; the standalone host uses the 30-minute default and embedders set it through the library API.Tests
New:
mcp_session_ids_are_random_uuids,mcp_another_principal_cannot_use_stream_or_end_the_session,mcp_sessions_are_reclaimed_after_the_idle_timeout. Existing MCP tests updated for the newopensignature only.cargo test --workspace --locked: 407 passed, 0 failed, 6 ignored (38 test binaries, includingprotrus-hostmcp_scenarios).Closes #113