Guide · By Sam Ortega (pen name) ·

MCP session hijacking: how to bind sessions to users

Title card: MCP session hijacking: how to bind sessions to users

MCP session hijacking happens when a server treats possession of a session ID or state handle as proof of who is calling. The MCP Python, Ruby and C# SDKs and SurrealDB each shipped that flaw, letting an authenticated caller who obtained someone else's session ID act inside that session. The fix: bind state to the verified user and check every request.

This guide covers only binding sessions and state to users. For how agents get identities in the first place, see our AI agent identity comparison. Identity only helps if each session stays bound to the right principal. All sources were checked on 11 November 2026.

Session IDs and state handles: two eras, one rule

MCP has two session models in the field. The 2026-07-28 transports page says "Earlier protocol revisions established a connection-scoped session with an initialize handshake". In those revisions, and in SDK stateful modes, the server may issue a session ID; the 2025-11-25 transports page says a Streamable HTTP server "MAY assign a session ID at initialization time", which it returns in the MCP-Session-Id header. Our MCP explainer covers the protocol basics.

The current Security Best Practices page says "MCP is stateless and has no protocol-level sessions." Servers that need state across requests "mint an explicit handle, such as a shopping cart ID or a workflow ID", and receive it back "as an ordinary tool argument on each request." The attack is the same in both eras. In the newer page's words, the server "does not check whether the handle belongs to the caller and operates on the original user's state". So moving to the stateless core does not remove the duty; it moves it from the transport into your application.

MCP session hijacking in practice: four implementations, one class of bug

ImplementationRecordWhat went wrongAffectedFixed in
MCP Python SDK (mcp)CVE-2026-52869, GHSA-jpw9-pfvf-9f58Session lookup by ID alone, no principal checkBefore 1.27.21.27.2
MCP C# SDK (ModelContextProtocol.AspNetCore)GHSA-x863-g495-4cjcPrincipals without a user ID claim all compared as null0.1.0-preview.9 before 1.4.2; 2.0.0-preview.1 before 2.3.11.4.2, 2.3.1
MCP Ruby SDK (mcp gem)CVE-2026-67431, GHSA-5p9g-j988-pcwvSession ID not bound to a session ownerBefore 0.23.00.23.0
SurrealDBCVE-2026-121419, GHSA-pgh9-49q4-hqcxSession fingerprint used the access method name, not the user3.1.0 before 3.3.03.3.0

Python SDK. The advisory (published 5 June 2026) says the SSE and Streamable HTTP transports "routed incoming requests to an existing session based only on the session identifier, without verifying that the request was authenticated as the same principal that created the session." On Streamable HTTP the response "is returned on the injecting request, so the injecting client can also read the result." Servers on stdio, stateless Streamable HTTP, or with no authentication configured "are not affected." Version 1.27.2 "records the authenticated principal that created each session" and answers a different principal "with the same 404 response as for an unknown session." The advisory adds that where many end users share one OAuth client, such as hosted clients and gateways, the token verifier should populate AccessToken.subject "so sessions are isolated per user rather than per client."

C# SDK. The advisory (3 November 2026) says the binding reads only the NameIdentifier, sub or UPN claim, and a principal lacking all three is treated as null, the same value as an unauthenticated principal. Two such users then match, so an attacker "who obtains another user's high-entropy Mcp-Session-Id" can act inside the victim's session. Legacy SSE has the same root cause. The structured fields give 1.4.2 and 2.3.1 as patched, and both were released on 3 November with session-hardening fixes, although the description text still says "Patched versions: none known".

Ruby SDK. The CVE record (GHSA-5p9g-j988-pcwv, July 2026) says that before 0.23.0 the Streamable HTTP transport "does not bind a session ID to a session owner, allowing an attacker with a stolen session ID to send tools/call requests that execute in the victim's session." It is fixed in 0.23.0 and rated CVSS 4.0 8.3 (High).

SurrealDB. According to the CVE record, the MCP BoundSubject fingerprint used the access method name rather than each user's identity for JWT and Bearer access, so any user holding a low-privilege token for the same access method, plus a victim's mcp-session-id, could take over the victim's session. SurrealDB's own advisory (19 October) gives a narrower range in its prose; its structured field and the CVE say 3.1.0 before 3.3.0, which we use.

Related isolation bugs. In the TypeScript SDK, CVE-2026-111767 says the experimental taskStore "did not check which session created a task", fixed in 1.32.0. GHSA-jm63-cq47-j5jp says shared transport or server instances could deliver one client's responses to another because "Messages were matched to a connection by JSON-RPC id alone"; the fix in @modelcontextprotocol/server 2.3.0 also requires code changes. Separately, Python's CVE-2026-59951 (session entries kept with no idle expiry or count limit, a resource exhaustion issue fixed in 1.30.0 and 2.2.0) is hygiene rather than principal binding.

Go and Java. As of 11 November 2026, we found no published advisory describing this failure in the official Go SDK or Java SDK advisory lists. That is a statement about published records, not about the code.

Our assessment: these map to identity and privilege abuse (ASI03) in our OWASP agentic analysis. They are a different surface from MCP tool poisoning: here the tools are honest and the session lookup fails.

What the MCP spec requires

Both security pages state their rules in MUST and SHOULD form, but the levels differ: the 2025-11-25 page makes non-deterministic session IDs a MUST, while the 2026-07-28 page makes non-deterministic handles a SHOULD. Binding to the user is a SHOULD in both. From the 2025-11-25 page (session IDs):

From the 2026-07-28 page (state handles):

The 2025-11-25 page also describes a variant it calls Session Hijack Prompt Injection: with a stolen session ID, an attacker sends a malicious event to one server, which queues it, and another server then delivers it to the client. See prompt injection.

Fix checklist: MCP session binding

Our assessment, built from the rules and advisories above:

  1. Inventory state. List every server using stateful Streamable HTTP, SSE or application state handles. Stdio and stateless servers without handles fall outside this checklist.
  2. Patch. Upgrade to the fixed versions or later: Python SDK 1.27.2, Ruby SDK 0.23.0, C# SDK 1.4.2 or 2.3.1, SurrealDB 3.3.0, TypeScript SDK 1.32.0 and @modelcontextprotocol/server 2.3.0, including the code changes that advisory requires.
  3. Re-check the principal on every request. Derive the user ID from the verified token and compare it with the session or handle owner. Answer a mismatch like an unknown ID, as the Python fix does, so the response does not confirm the ID exists.
  4. Key state by user. Store state as <user_id>:<session_id> or <user_id>:<handle>. Never accept a user ID supplied by the client.
  5. Make sure there is a user ID to bind to. Populate a stable user claim: sub, NameIdentifier or UPN for the C# SDK, AccessToken.subject for the Python SDK behind shared clients. Treat a missing claim as a failure, never as a match.
  6. Bind per user, not per access method or client. The SurrealDB and Python cases show that binding to a shared access method or a shared client is not per-user isolation.
  7. Do not share server or transport instances across clients. The TypeScript advisory says the fixed SDK refuses to be shared and lists three alternatives: a factory that builds a new server on every call, a new server and transport per request, or one server and transport per session.
  8. Use random IDs, then expire and reclaim them. Random IDs are required for session IDs and recommended for handles, but they are not sufficient on their own. Expire idle sessions and handles; Python's CVE-2026-59951 shows what happens when they are not reclaimed.
  9. Prefer stateless mode where you do not need server state. If you mint handles, apply items 3 to 6 to them.
  10. Test with two users. User B presenting user A's session ID or handle must fail. Add the test to CI so a refactor cannot silently drop the check, and keep access scoped by least privilege so a missed case exposes less.

See also the MCP and agent identity glossary entries.

Frequently asked questions

What is MCP session hijacking?

The 2025-11-25 MCP security page defines session hijacking as an attack where a client is given a session ID by the server and an unauthorized party obtains and uses that same ID "to impersonate the original client and perform unauthorized actions on their behalf."

Did the 2026-07-28 MCP revision remove sessions?

It removed protocol-level sessions: the current security page says "MCP is stateless and has no protocol-level sessions." Servers that need state now mint explicit handles, and those handles carry the same binding duty.

Which MCP SDKs have had this bug?

The Python SDK (CVE-2026-52869, fixed in 1.27.2), the Ruby SDK (CVE-2026-67431, fixed in 0.23.0) and the C# SDK (GHSA-x863-g495-4cjc, fixed in 1.4.2 and 2.3.1). SurrealDB's MCP server had the same class of bug (CVE-2026-121419). As of 11 November 2026 we found no published advisory of this kind for the official Go or Java SDKs.

Is a random session ID enough?

No. The Python and C# advisories both describe randomly generated or high-entropy IDs that were still exploitable once obtained. The 2025-11-25 security page says servers "MUST NOT use sessions for authentication", and the 2026-07-28 page says they "MUST NOT treat possession of a state handle as authentication."

How do I test that sessions are bound to users?

Sign in as two different users. Have user B send user A's session ID or state handle. The request must fail, ideally with the same response as an unknown ID.

Sources

  1. MCP documentation: Security Best Practices (2026-07-28), State Handle Hijacking
  2. MCP documentation 2025-11-25: Security Best Practices, Session Hijacking
  3. MCP specification 2026-07-28: Transports
  4. MCP specification 2025-11-25: Transports
  5. GitHub Security Advisory GHSA-jpw9-pfvf-9f58 (MCP Python SDK, 5 Jun 2026)
  6. CVE.org: CVE-2026-52869 (MCP Python SDK)
  7. MCP Python SDK release v1.27.2
  8. GitHub Security Advisory GHSA-x863-g495-4cjc (MCP C# SDK, 3 Nov 2026)
  9. MCP C# SDK release v1.4.2
  10. MCP C# SDK release v2.3.1
  11. GitHub Security Advisory GHSA-5p9g-j988-pcwv (MCP Ruby SDK, Jul 2026)
  12. CVE.org: CVE-2026-67431 (MCP Ruby SDK)
  13. MCP Ruby SDK release v0.23.0
  14. CVE.org: CVE-2026-121419 (SurrealDB)
  15. GitHub Security Advisory GHSA-pgh9-49q4-hqcx (SurrealDB, 19 Oct 2026)
  16. CVE.org: CVE-2026-111767 (MCP TypeScript SDK taskStore)
  17. GitHub Security Advisory GHSA-jm63-cq47-j5jp (MCP TypeScript server, 15 Oct 2026)
  18. CVE.org: CVE-2026-59951 (MCP Python SDK session accumulation)
  19. MCP Go SDK: security advisories
  20. MCP Java SDK: security advisories

This article is analysis. Bylines on AIAgentThreats are disclosed pen names of our editorial team. Spotted an error? Email info@aiagentthreats.com. See our Editorial Standards.