internal/util: match "localhost" case-insensitively in IsLoopback - #1316
Merged
guglielmo-san merged 1 commit intoSep 29, 2026
Merged
guglielmo-san merged 1 commit into
guglielmo-san merged 1 commit into
Conversation
akshita317
force-pushed
the
util/loopback-case-insensitive
branch
from
September 29, 2026 14:02
14115ca to
35e9799
Compare
Host names are case-insensitive (RFC 4343), but IsLoopback compared the host to "localhost" exactly. net/http keeps the Host header as the client sent it, so a client configured with http://LocalHost:8080/mcp got 403 "invalid Host header" from a streamable or SSE server listening on 127.0.0.1: the DNS rebinding check took the capitalized name for a foreign host. The same comparison made oauthex reject an HTTP discovery URL on LOCALHOST as non-loopback, and made the authorization code handler classify such a redirect URI as a web one. Accepting any capitalization does not weaken the rebinding protection. It rejects requests whose Host names an attacker's domain, and every spelling of localhost names the local machine. The new TestIsLoopback cases and the TestStreamableLocalhostProtection case fail without the change. Fixes modelcontextprotocol#1319 Signed-off-by: Akshita <110122283+akshita317@users.noreply.github.com>
akshita317
force-pushed
the
util/loopback-case-insensitive
branch
from
September 29, 2026 14:05
35e9799 to
08d53dd
Compare
guglielmo-san
approved these changes
Sep 29, 2026
Contributor
|
@akshita317 thank you for the contribution! |
guglielmo-san
enabled auto-merge (squash)
September 29, 2026 15:48
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.
Host names are case-insensitive (RFC 4343), but IsLoopback compared the
host to "localhost" exactly. net/http keeps the Host header as the client
sent it, so a client configured with http://LocalHost:8080/mcp got 403
"invalid Host header" from a streamable or SSE server listening on
127.0.0.1: the DNS rebinding check took the capitalized name for a
foreign host. The same comparison made oauthex reject an HTTP discovery
URL on LOCALHOST as non-loopback, and made the authorization code
handler classify such a redirect URI as a web one.
Accepting any capitalization does not weaken the rebinding protection.
It rejects requests whose Host names an attacker's domain, and every
spelling of localhost names the local machine.
The new TestIsLoopback cases and the TestStreamableLocalhostProtection
case fail without the change.
Fixes #1319