Repository navigation
Fix MCP Host validation with --unsafe-http - #40
Merged
Merged
Conversation
dmaivel
added a commit
that referenced
this pull request
Oct 23, 2026
…t policy Follow-up to #40, which answers requests addressed to any host under `--unsafe-http`: - CHANGELOG: a Fixed line. The loopback Host check shipped in v0.49.1, so the server has been out of the network's reach since. - `--unsafe-http`'s help and docs/integrations/mcp.md say it also lifts the Host check, besides the bind address and browser origins. - The test sent a bare GET and expected rmcp's 406 for its missing Accept header, which pins an rmcp detail rather than the Host policy. It now sends a valid initialize and expects the session to open (200) for a permitted host, 403 otherwise. With the middleware applied unconditionally again, it fails on the first --unsafe-http host. Checked live: with --unsafe-http on 0.0.0.0, an initialize to the LAN address and to a DNS name gets 200 (403 before #40); on the default loopback bind, those Host headers still get 403.
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.
Requests to MCP using a network IP or hostname receive HTTP 403 even with
--unsafe-http, because the router always installs the loopback Host middleware.Apply that middleware only when
unsafe_httpis false, consistent with the existing bind and CORS policies. Extract router construction so a regression test exercises the actual MCP route for localhost, a remote IP, and a DNS hostname under both policies. The test checks that permitted requests reach rmcp's Accept-header validation, while disallowed hosts still receive 403.Closes #39.
Validation:
cargo fmt --all --checkgit diff --checkcargo test --locked --no-default-features --features cli,mcp --lib hosts::mcp::tests— 14 passed.An initial MCP-only build (
--features mcp) encountered an existing missingthread_labelimport insrc/hosts/repl/mod.rs; validation used CLI + MCP instead.