Skip to content

Compare Host and Origin case-insensitively (#3437) - #3456

Closed
chrono-glitch wants to merge 1 commit into
modelcontextprotocol:mainfrom
chrono-glitch:fix/3437-case-insensitive-host
Closed

Compare Host and Origin case-insensitively (#3437)#3456
chrono-glitch wants to merge 1 commit into
modelcontextprotocol:mainfrom
chrono-glitch:fix/3437-case-insensitive-host

Conversation

@chrono-glitch

Copy link
Copy Markdown

Fixes #3437

Problem

TransportSecurityMiddleware._validate_host() and _validate_origin() compare
the incoming Host / Origin header against allowed_hosts / allowed_origins
case-sensitively — both the exact-match check and the :* wildcard-port loop.

Host names are case-insensitive (RFC 9110 §4.2.3), and every WHATWG-URL based
client (fetch, undici, browsers, and therefore mcp-remote) lowercases the URL
host before sending. On Windows this is the default path into the bug:
%COMPUTERNAME% is uppercase, so deriving allowed_hosts from the machine name
yields MYHOST:*, the client sends host: myhost:8000, and the server returns
421 to every request while configured exactly as intended.

Fix

Normalize both sides to lowercase in _validate_host and _validate_origin
(exact match and the wildcard-port loop). The original header value is kept in
the logger.warning line for observability. Origin scheme + host are likewise
case-insensitive (RFC 6454 §4); an origin has no path component so lowercasing
the whole string is safe.

Tests

tests/server/test_transport_security.py:

  • 4 new parametrized cases in test_validate_request_checks_host_then_origin
    (uppercase request vs lowercase allowlist, host + origin, exact + wildcard).
  • new test_validate_host_case_insensitive_with_uppercase_allowlist — the
    Windows scenario: allowed_hosts=["MYHOST:*"] accepts myhost:8000 and
    MYHOST:8000, still rejects other:8000.

Local: uv run pytest tests/server/test_transport_security.py tests/server/test_sse_security.py tests/server/test_streamable_http_security.py
→ 71 passed. ruff check, ruff format --check, pyright clean.

Notes

  • Targets main (v2). Happy to open the equivalent against the v1 branch.
  • Assisted by an AI coding tool; the change and tests were reviewed, run, and
    are owned by me.

Host names are case-insensitive (RFC 9110 Section 4.2.3) and WHATWG-URL
clients (fetch, undici, browsers, mcp-remote) lowercase the URL host before
sending. TransportSecurityMiddleware compared the Host and Origin headers
against allowed_hosts / allowed_origins case-sensitively, so an uppercase
allowlist entry -- the default when deriving it from %COMPUTERNAME% on
Windows -- rejected every fetch-based client with 421.

Normalize both sides to lowercase in _validate_host and _validate_origin
(exact match and the :* wildcard-port loop); keep the original value in the
log line. Origin scheme+host are likewise case-insensitive (RFC 6454 Section 4).

Assisted by an AI coding tool; reviewed and tested by me.
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #3437.

If a maintainer assigns you to #3437, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take.

You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way.

CONTRIBUTING.md has the full reasoning, but in short:

  • We're a small team with very little capacity to review community PRs right now.
  • Many recent PRs are AI-generated with little human review, and reviewing one carefully still costs a maintainer as much time as it ever did. A well-described issue is usually more useful to us than the code.

Maintainers: reopen, remove missing-issue-link, or add bypass-issue-check to override.

@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Sep 5, 2026
@github-actions github-actions Bot closed this Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

1 participant