Skip to content

Commit 820b65c

Browse files
committed
Allow the end-to-end test's host under DNS rebinding protection
## Motivation and Context `MCP::Server::OAuth::EndToEndTest` drives the SDK's HTTP client against a Rack stack through WebMock's `to_rack`, which until WebMock 3.32 passed the app no `Host` header. WebMock 3.34.0 fills `HTTP_HOST` in from the request URL, so the transport's DNS rebinding protection, on by default, now refuses `mcp.example.com` with `403 Forbidden: Invalid Host header`, and the test errors with "You are forbidden to make initialize requests" on every CI run since that release. The test now builds the transport with `allowed_hosts: ["mcp.example.com"]`, as a deployment serving that host would, so it passes with either WebMock. The library is unchanged. ## How Has This Been Tested? `test/mcp/server/oauth/end_to_end_test.rb` with WebMock 3.34.0, where it errored before, and with WebMock 3.26.4, where it passed before and still does. ## Breaking Changes None.
1 parent 9d12f51 commit 820b65c

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎test/mcp/server/oauth/end_to_end_test.rb‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,14 @@ def setup
4646
WhoamiTool.observations.clear
4747

4848
@server = MCP::Server.new(name: "e2e_server", tools: [WhoamiTool])
49-
@transport = Transports::StreamableHTTPTransport.new(@server, enable_json_response: true)
49+
# The transport serves `mcp.example.com`, so the host is allow-listed as a deployment there would:
50+
# DNS rebinding protection rejects any other `Host`, and WebMock 3.34 and later hand the Rack app
51+
# the host of the request URL.
52+
@transport = Transports::StreamableHTTPTransport.new(
53+
@server,
54+
enable_json_response: true,
55+
allowed_hosts: [URI(MCP_URL).host],
56+
)
5057

5158
@metadata = ProtectedResourceMetadata.new(
5259
resource: MCP_URL,

0 commit comments

Comments
 (0)