Validate Origin and Host on --http (DNS rebinding) - #46
Merged
Merged
Conversation
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
The MCP spec requires Streamable HTTP servers to validate
Originto prevent DNS rebinding. Before this change,--httpchecked nothing.Behavior
Originheader gets 403 unless the value ishttp://localhost:<port>,http://127.0.0.1:<port>orhttp://[::1]:<port>on the server's own port, or a value passed with the new repeatable--allowed-origin. Other localhost ports andhttpsare rejected.Hostheader naming anything butlocalhost,127.0.0.1or[::1]gets 403. This is the DNS-rebinding defense.Originheader (non-browser MCP clients) pass through.--allowed-originvalidation: values are checked at startup (absolute http/https, no path, query, userinfo,nullor*), and a trailing/is normalized away. An invalid value exits with code 2 and a message.--allowed-origindoesn't let a browser page call the server directly. The docs say so.Review
An Opus adversarial review approved it with 0 blockers and 0 majors:
Origin: null, trailing slash,http://localhost:03998,127.1,localhost., IPv6 long forms,X-Forwarded-Host, userinfo tricks, every method and path, and h2c.Its 6 minor findings are fixed in the second commit:
initializeand expects 200;--allowed-origin;--allowed-origin.Tests
22 in Integration.Tests (was 0 active), including 3 real-server tests. The solution passes: Build 12, CodeIntelligence 9, Integration 22, Testing 32, Core 67. Verified by the lead session.
🤖 Generated with Claude Code