Fix production 421 "Invalid Host header" on /mcp - #160
Open
brianglass wants to merge 1 commit into
Open
Conversation
orthocal/asgi.py called mcp.streamable_http_app() with no arguments, so the SDK defaulted host='127.0.0.1' and auto-enabled DNS-rebinding protection restricted to localhost -- fine in dev, but it rejected every real request in production, since Cloud Run's own hostname (forwarded as the Host header by the Firebase Hosting proxy in front of it) isn't on that allowlist. Confirmed via Cloud Run logs showing "Invalid Host header: orthocal-6czswbhara-uc.a.run.app" on every /mcp request since the merge. DNS-rebinding protection defends a server bound to localhost against a malicious webpage's JS reaching it through the browser; it doesn't apply to a public HTTPS API with no localhost-only trust boundary, so disabling it explicitly is the correct fix. Verified locally by replaying the exact Host header from the production error logs. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Hf6j2xXQXywHVh3HAVRxB3
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.
Summary
/mcpreturned 421 "Invalid Host header" for every real request in production, confirmed via Cloud Run logs (Invalid Host header: orthocal-6czswbhara-uc.a.run.appon every request since PR Add an MCP server exposing calendar and saint-search tools #158 merged).orthocal/asgi.pycalledmcp.streamable_http_app()with no arguments. The SDK defaultshost='127.0.0.1'in that case, which auto-enables DNS-rebinding protection restricted tolocalhost/127.0.0.1/::1— fine in local dev (where the Host header naturally islocalhost), but it rejects every real production request, since Cloud Run's own hostname (forwarded as the Host header by the Firebase Hosting proxy in front of it) isn't on that allowlist.transport_security=TransportSecuritySettings(enable_dns_rebinding_protection=False). DNS-rebinding protection defends a server bound to localhost against a malicious webpage's JS reaching it through the browser — it doesn't apply to a public HTTPS API with no localhost-only trust boundary, so disabling it here is the correct fix, not a workaround.Test plan
docker compose run --rm tests— 135/135 passingHost: orthocal-6czswbhara-uc.a.run.app) against the dev server — confirmed 200 OK after the fix, reproduced the 421 before it🤖 Generated with Claude Code
https://claude.ai/code/session_01Hf6j2xXQXywHVh3HAVRxB3