fix(streamable_http): stop sending a spec-incorrect Origin header - #154
Open
guizaols wants to merge 1 commit into
Open
fix(streamable_http): stop sending a spec-incorrect Origin header#154guizaols wants to merge 1 commit into
guizaols wants to merge 1 commit into
Conversation
build_common_headers set `Origin` to the MCP endpoint's own URL, path included. RFC 6454 §7 defines Origin as scheme + host [+ port] only, so that value can never match a server allowlist. The MCP Streamable HTTP spec asks servers to validate Origin against DNS rebinding, and servers that do (GitHub's remote MCP, Metabase, Grafana...) reject every request with 403. A server-to-server client has no browser origin to report, and the reference TypeScript and Python SDKs send none. Drop the automatic header. An Origin passed explicitly through the `headers` option is still forwarded untouched. Fixes patvice#140
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.
Problem
StreamableHTTP#build_common_headerssetsOriginto the MCP endpoint's own URL, path included — e.g.Origin: https://api.githubcopilot.com/mcp/.Originvalue asscheme "://" host [ ":" port ]. A path is never part of it, so no server allowlist can match what the gem sends.Originto prevent DNS rebinding. Servers that do so (GitHub's remote MCP server, Metabase's MCP endpoint, Grafana, …) reject every request with403/"Origin not allowed", regardless of how the server-side allowlist is configured.Originheader at all.Reproduction and sources are in #140. The
prependworkaround posted there (removingOriginfrombuild_common_headers) is what affected users are running in production today; this PR makes it unnecessary.Fix
Remove the one line that sets the header. Nothing else changes:
Originpassed explicitly via theheadersoption is still forwarded untouched, for anyone who genuinely needs one.Origin, so it is unaffected.Tests
Two specs added to
streamable_http_spec.rb:OriginOriginis preservedThe first spec fails on
mainand passes with this change.bundle exec rspec spec/ruby_llm/mcp/native/transports/streamable_http_spec.rbis green (142 examples),rubocopclean.Fixes #140