Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(mcp): accept the app host behind a same-host reverse proxy - #308

Open
ngunyimacharia wants to merge 1 commit into
razorpay:masterfrom
ngunyimacharia:ngunyimacharia/mcp-allowed-hosts
Open

ngunyimacharia wants to merge 1 commit into
razorpay:masterfrom
ngunyimacharia:ngunyimacharia/mcp-allowed-hosts

Conversation

@ngunyimacharia

Copy link
Copy Markdown

What and why

Behind a reverse proxy on the same host (Laravel Cloud, or any sidecar nginx/Caddy forwarding to 127.0.0.1), every /mcp request fails with 403 invalid Host header. mcp-go's DNS rebinding guard sees a loopback connection carrying a public Host and treats it as an attack. OAuth succeeds, so clients get a token they can never use.

This upgrades mcp-go to v1.6.0 and passes the host of SLASHDOCS_APP_ORIGIN to WithAllowedHosts. Loopback hosts stay allowed and any other Host is still rejected, so the guard stays on.

Closes #303

How it was tested

  • New cases in server_mcp_test.go send MCP requests over a loopback connection, the way a same-host proxy does: the app's public Host gets 200, and any other Host still gets 403.
  • go test ./api/... ./cli/... ./internal/... and make lint pass.
  • Running in production behind Laravel Cloud's proxy, with MCP clients connecting over OAuth.

Checklist

  • make lint and make test pass locally
  • Tests added or updated for the change
  • No breaking change, or the migration path is described below

Breaking changes

With an allowlist set, mcp-go checks Host on every request, not only loopback ones. An agent that calls /mcp through a name other than the app origin (for example an in-cluster service name) now gets 403 and should use the public origin. Browser and OAuth clients are unaffected, since OAuth tokens are already bound to <app origin>/mcp.

Laravel Cloud's web proxy runs in the app container and forwards to the
server over 127.0.0.1 while keeping the public Host header. mcp-go's DNS
rebinding guard reads that as an attack and answers every /mcp request with
403 "invalid Host header", so OAuth succeeds but no client can connect.

Upgrade mcp-go to v1.6.0 and allow the app origin's host with
WithAllowedHosts. Loopback hosts stay allowed and every other Host header
is still rejected, so the guard stays on.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP endpoint returns 403 "invalid Host header" behind a same-host reverse proxy

1 participant