Skip to content

Transparent proxy: batch containing initialize skips the unknown-session guard #5883

Closed as not planned

Description

@jhrozek

Summary

In the transparent proxy's tracingTransport.RoundTrip, the unknown-session guard is:

if sid := req.Header.Get("Mcp-Session-Id"); sid != "" && !sawInitialize {
    // reject stale/forged/unknown session IDs
}

parseRPCRequest sets sawInitialize = true for a batch if any member is initialize. So a batch such as [{"method":"initialize"},{"method":"tools/call"}] carrying a stale/forged Mcp-Session-Id skips the guard entirely — the one place a bad session ID is rejected at the proxy layer (relevant for multi-replica, Redis-backed deployments where the guard's doc comment treats it as authoritative).

Scope / status

Recommendation

Decide whether the guard exemption should be narrowed to a single genuine initialize request rather than "any batch member named initialize." If narrowed:

  • Tighten parseRPCRequest so a batch never reports sawInitialize for guard-exemption purposes.
  • Update/invert TestRoundTripAllowsBatchInitializeWithUnknownSession to reflect the intended semantics.
  • Add a regression test: a batch with a non-initialize member on an unknown session is rejected at the guard.

Surfaced by external review of #5831.

Activity

  1. added
    needs-triage
    on Jul 20, 2026
  2. removed
    needs-triage
    on Jul 27, 2026
  3. jhrozek commented on Jul 27, 2026

    @jhrozek
    ContributorAuthor

    Closing as already fixed.

    #5931 (a18f17e2d) added an unconditional mcp.IsBatchRequest rejection at the top of tracingTransport.RoundTrip (transparent_proxy.go:591), which returns HTTP 400 / -32600 before the unknown-session guard at :624 is ever reached. So no batch — with or without an initialize member — can reach the guard to be exempted from it. The rejection inspects the first non-whitespace byte rather than the Content-Type, so it can't be smuggled past under a non-JSON content type either.

    That commit also deleted TestRoundTripAllowsBatchInitializeWithUnknownSession (the test this issue asked to invert) and replaced it with TestRoundTripRejectsBatch in backend_routing_test.go, whose first case is the exact payload from this report — [{"method":"initialize"},{"method":"tools/list"}] carrying an unknown Mcp-Session-Id — asserting HTTP 400 and failing the test if the backend is contacted.

    One leftover worth noting: the batch-scanning branch in parseRPCRequest still computes sawInitialize by scanning batch members, but it is now dead code in the production path (only the parseRPCRequest unit table still exercises it). Harmless today, but it's the piece that would resurrect this bug if anyone ever relaxes or moves the batch rejection. Leaving it as-is rather than churning the code, just flagging it here for whoever touches that guard next.

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

Metadata

Metadata

Assignees

No one assigned

    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