Harden HTTP transport: enable DNS-rebinding protection and default to loopback bind - #314
Open
winstoncrooker wants to merge 1 commit into
Open
Conversation
… loopback bind The --transport http /mcp endpoint is unauthenticated and proxies every tool call with the configured Brave API key. Without Host/Origin validation a website (via DNS rebinding to 127.0.0.1) or a cross-host party can reach it and run searches under the operator's key. Enable the SDK's enableDnsRebindingProtection + allowedHosts on all transports and default the bind to loopback.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Harden the HTTP transport: enable DNS-rebinding protection and default to a loopback bind
Background
When the server runs with
--transport http, the/mcpendpoint is unauthenticated and every tool call is proxied toapi.search.brave.comwith the configuredX-Subscription-Token(src/BraveAPI/index.ts). So any party that can reach the listener can invoke search tools under the operator's Brave Search API key.Two things make that reachable in the current defaults:
Host/Originvalidation. The threeStreamableHTTPServerTransportconstructions insrc/protocols/http.tsdon't setenableDnsRebindingProtection/allowedHosts. Without it, a website the operator visits can use DNS rebinding to point its hostname at127.0.0.1andPOSTtohttp://localhost:<port>/mcp— the browser request is accepted. This is the exact attackenableDnsRebindingProtectionexists to stop.0.0.0.0bind by default (src/config.ts). With the listener on all interfaces, any other host on the network (or a co-located process/container) can reach/mcpdirectly.The pinned
@modelcontextprotocol/sdk@1.29.0already exposesenableDnsRebindingProtection/allowedHosts/allowedOrigins; they just weren't wired up. This aligns with the MCP transport-security guidance (validateOrigin, bind to localhost, and authenticate local HTTP servers).Change
src/protocols/http.ts: setenableDnsRebindingProtection: trueandallowedHosts: config.allowedHostson all three transports.src/config.ts: default the bind host to127.0.0.1, and build aHostallowlist that defaults to the bind host plus loopback. A new--allowed-hostsflag /BRAVE_MCP_ALLOWED_HOSTSenv lets proxied/remote deployments (a gateway, or the stateless AgentCore path) add their public host.Default/local usage is unaffected — loopback hosts are allowed. Deployments that intentionally expose the server keep doing so by setting
--host/BRAVE_MCP_HOSTand--allowed-hosts/BRAVE_MCP_ALLOWED_HOSTS.Verification (before / after)
tools/listPOST to/mcpwith a spoofedHostheader vs. the legitimate loopback host:Hostheadermain)attacker.example(DNS-rebind / cross-host)HTTP 200(accepted)HTTP 403(rejected)127.0.0.1:<port>(legitimate)HTTP 200HTTP 200Repro:
References
@modelcontextprotocol/sdkStreamable HTTP options:enableDnsRebindingProtection,allowedHosts,allowedOrigins.