Skip to content

[Vulnerability] modelcontextprotocol/rust-sdk: Header Validation Bypass #40

Open

Description

@github-actions

Potential Security Vulnerability Detected

Repository: modelcontextprotocol/rust-sdk
Commit: 6677eee
Author: SIDDARTHA REDDY
Date: 2026-09-24T19:36:16Z

Commit Message

style: cargo fmt fixes on validate_standard_headers changes (#1275)

Signed-off-by: SIDDARTHA REDDY <75976672+SIDDARTHAREDDY8@users.noreply.github.com>

Pull Request

PR: #1275 - Fix: streamable-http server: a supplied Mcp-Method contradicting an initialize body is silently accepted
Labels: T-test, T-core, T-transport

Description:
Fixes #1271.

Implemented the fix for modelcontextprotocol/rust-sdk issue #1271 in crates/rmcp/src/transport/streamable_http_server/tower.rs. In validate_standard_headers, the InitializeRequest arm no longer returns Ok(()) blindly: a supplied Mcp-Method header is now checked against the body method (initialize), tolerating absence but rejecting contradiction with a header_mismatch JSON-RPC error (HTTP 400), mirroring the existing validate_header_matches_init_body pattern used for MCP-Protocol-Ve...

Analysis

Vulnerability Type: Header Validation Bypass
Severity: High

Description

The initialize handshake was accepting contradictory Mcp-Method headers without validation, allowing middleboxes that route on headers to be exploited. The patch adds validation to reject supplied Mcp-Method headers that contradict the body method, preventing routing confusion between the header and actual request body that could lead to request smuggling or authentication bypass.

Affected Code

if matches!(&req.request, ClientRequest::InitializeRequest(_)) {
    return Ok(());
}

Proof of Concept

POST /mcp HTTP/1.1
Content-Type: application/json
Mcp-Method: tools/list
Mcp-Protocol-Version: 2026-07-28

{"jsonrpc": "2.0", "id": 1, "method": "initialize", "params": {"protocolVersion": "2026-07-28", "capabilities": {}, "clientInfo": {"name": "test", "version": "1.0"}}}

Before patch: Returns HTTP 200 and creates session despite contradictory header
After patch: Returns HTTP 400 with error code -32020 (header_mismatch)

This issue was automatically created by Vulnerability Spoiler Alert.
Detected at: 2026-10-06T07:48:26.865Z

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions