Skip to content

streamable HTTP (legacy sessions): a tool's result or progress reaches the response stream after the session's DELETE was acknowledged #1575

Todo

Description

@joulook

Describe the bug

In legacy session mode, a tool call's result or a progress notification can reach its SSE response stream after the
server has acknowledged the session's deletion: an effect after the client's revocation. DELETE /mcp returns 202
before the session worker has stopped, so a tools/call in flight on that session can still hand items to its open
stream after the 202: progress notifications, and the tool's result if the tool returns after the DELETE.

Threat model. The adversary is the legitimate session client itself; its only power is timing. It deletes its
session while a tool call is in flight, the deletion is acknowledged with 202, and yet an effect follows on its own
stream. Whoever relies on the acknowledgement is misled about what the session did after it was
closed. No data or capability is gained. Our
model's adversary process did this within 2 steps (K = 2), and the native test below realises it.

The contract we check is our stated one: the 202 to a session DELETE withdraws the session's authority to send, so
the session worker has stopped and hands no further items to the session's response streams (items already buffered
in a stream may still be read). It is stronger than the pinned text: MCP 2026-07-28 removed protocol-level sessions
and the Mcp-Session-Id header (changelog, item 1), so the session DELETE is the legacy 2025-11-25 path.

A security issue of the effect-after-revocation kind (an effect follows the acknowledged close) under our stated
authority contract; no MUST of the pinned specification is broken.

The path, at 2d77786:

  • handle_delete (tower.rs:2506-2537)
    awaits close_session and then returns accepted_response().
  • LocalSessionManager::close_session (local.rs:96-109)
    removes the session from the map and calls LocalSessionHandle::close
    (local.rs:893-899),
    which only queues SessionEvent::Close on the worker's event channel. The 202 follows.
  • The worker takes its next event in an unbiased tokio::select!
    (local.rs:1143-1180).
    When a handler message is ready together with the queued Close, it can take the handler message first and hand
    it to the request's stream (handle_server_message,
    local.rs:664-683).
  • If that stream's channel is full, the hand-off waits in request_wise.tx.send(message).await (local.rs:672). It
    completes after the 202 as soon as the client reads. The Close is taken only after that
    (local.rs:1251-1253).

The client keeps the request's SSE stream open, so the cancellation signal for Streamable HTTP (closing that
stream) is never given. The session DELETE is the only close.

To reproduce

A self-contained test (attached to the PR as tests/test_session_close_inflight.rs). It uses in-process tower calls,
legacy session mode, and LocalSessionManager with channel_capacity = 2.

  1. Initialize a session, then call a tool with a progress token.
  2. The tool sends three progress notifications and waits. The client reads none, so two fill the request's channel
    and the worker blocks handing over the third.
  3. The client sends DELETE /mcp for the session and gets 202.
  4. Only then is the tool released; it returns a result.
  5. The client reads the request's stream to its end.

The test checks two things: no result after the 202, and at most 2 progress notifications (the client read nothing
before the 202, so at most 2 were in the channel then). Each run is 20 trials,
cargo test -p rmcp --features server,transport-streamable-http-server --test test_session_close_inflight.

On 2d77786:

runs trials with the result after the 202 trials with the third progress after the 202
first machine run 3 5, 1, 2 of 20 20 of 20 in each
independent replay 3 4, 1, 3 of 20 20 of 20 in each

With the fix in the PR (pull request to follow), every run had 0 of 20 in both columns (3 runs each, same two parties).

Expected behavior

When a session DELETE is answered 202, the session's worker has stopped. No message for that session's in-flight
requests reaches a response stream after the 202, and each such stream ends.

Found with. We are a research team at MPI-SWS building Daavar, a conformance checker for distributed protocol
implementations. We found this with a model of rmcp's session close path (the DELETE handler, the session worker and
a request's response stream) under an adversarial client that may delete the session, read its stream, or let the
tool finish, in any order. We checked the model against a specification program that encodes the authority contract
above: it is our contract, not a clause of MCP. We then confirmed the behaviour natively (above). This issue and the
fix were prepared with AI assistance and reviewed by us.

Reproduce with Daavar (conformance test)

The cell k2,c2,p2,s1, the tool of the native test: the client may DELETE, read its stream, or release the tool,
in at most 2 steps, and then reads its stream to the end. The tool sends 2 progress notifications and 1 more from a
spawned task, then waits for its release; the channel capacity is 2. The specification program answers the DELETE
202 and ends the stream in one step, so no new item enters the stream after the 202. port follows rmcp at 2d77786.
The join prints, as uncovered, the client observations of the port that the specification does not produce. The
monitor run counts executions with an item entering the stream that is not causally before the 202 (items
concurrent with it included).

git clone --recurse-submodules https://github.com/joulook/daavar.git && cd daavar
git checkout 9af88e0 && git submodule update --init --recursive
(cd traceforge && cargo build --release -p traceforge --bin conf-join)
cd benchmarks/security-pilot/row2 && (cd port-rust && cargo build --release)
B=port-rust/target/release/security_pilot_row2; J=../../../traceforge/target/release/conf-join; C=k2,c2,p2,s1
$B export spec --out spec.jsonl --program security-pilot-row2 --size $C --model fifo -- spec,$C
$B export impl --out port.jsonl --program security-pilot-row2 --size $C --model fifo -- port,$C
$J --decide spec.jsonl port.jsonl                                # violation: 14 uncovered
$B count impl --model causal --assertions-as-err -- port,mon,$C  # 3011 of 38931 executions fail the monitor

An uncovered observation from the smallest cell k2 (read requests left out): Post, Opened, Delete, Ack, Release, Sse(progress), Sse(result), End. The client reads a progress notification and the tool's result after the 202. The benchmark's
README lists the other cells and their counts.

Activity

  1. github-actions commented on Dec 4, 2026

    @github-actions
    Contributor

    @connor4312 is on triage rotation this week and is the reviewer for this one.

    Automated classification did not run for this one, so it needs a full manual pass.

    Automated triage. Labels are a first pass and the assigned maintainer has the final say.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions