fix(server): refuse unparsable allowed-hosts at startup - #125
Merged
Conversation
Host validation could turn on with nothing matchable when MCP_ALLOWED_HOSTS held a typo rmcp cannot parse as a Host authority, and nothing logged the effective on/off list. Split only on commas so a space-containing typo stays one entry, refuse unparsable authorities at HTTP start, and emit one info line with the resolved hosts (I9, I12). Closes #117
The first-cut matcher treated a colon as a port separator, so bare IPv6 (::1) made the whole list a startup error. That spelling is rmcp's default loopback entry and matches inbound Host: [::1]. Parse with http::uri::Authority (wrapping a bare IPv6 literal) and still refuse * / a;b / the #117 typo list. Also name an unparsable --allowed-hosts list in the man page EXIT STATUS, matching the README.
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.
What
Hardens HTTP Host validation so a typo in
--allowed-hosts/MCP_ALLOWED_HOSTScannot silently brick a deployment.Host validation: off/Host validation: on; allowed hosts: …).host:port(*, a scheme-carrying URL,a;b, encoded commas, zero-width unicode, a space-containing typo) is a startup error, named in the message. rmcp 3.1.2 would otherwise keep validation on and store (or skip) a host no inboundHostmatches — deny-all, one 403 at a time.a b.examplestays one unparsable entry instead of becoming a single-labelaplusb.example. Comma-separated lists still work; whitespace around commas is trimmed.MCP_ALLOWED_HOSTS=still reads as unset (validation off).allowed_originsis unchanged. DESIGN.md already records why it has no knob (inherited empty = off); that decision is not reopened.Why
Three operator-hostile gaps from #104's review, all fail-closed: no startup visibility of the effective Host list, unparsable entries as a silent deny-all, and whitespace splitting manufacturing authorities from typos.
Invariants
Verification
Man page and completions regenerated (
bugwarden-gen). Tests are mutation-proof: deleting the info line or the unparsable refusal fails config.rs / server.rs / env_config.rs / http_transport_wiremock.rs.Adversarial review (checklist: silent deny-all, whitespace typo, empty-unset, I12, I9, mutation-proof tests) found no bugs.
Closes #117