Repository navigation
security(server): validate Host header to block DNS rebinding - #1360
Merged
Merged
Conversation
On a loopback bind, accept only localhost / *.localhost / loopback-IP Host values (plus [server] allowed_hosts / --allowed-host); anything else is 403. A non-loopback bind (Docker service names) keeps accepting every Host unless allowed_hosts is set. A missing Host header is allowed. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
Keep both test modules appended to handlers.rs.
Keep both test modules appended to handlers.rs; give the new mcp test ReqCtx the host_guard field.
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
uteke-servenow validates theHostheader (newHostGuardincontext.rs, enforced first thing inroute(), before preflight and health):127.0.0.1,::1,localhost): onlylocalhost,*.localhost, and loopback IPs are accepted, plus any[server] allowed_hosts/--allowed-hostentries. Everything else gets403 Host not allowed.0.0.0.0in Docker, where the service name is theHost): everyHostis accepted unlessallowed_hostsis set, in which case the list is enforced.Hostheader (HTTP/1.0) is accepted; rebinding browsers always send one.docs/tls.md(new section + checklist row) anddocs/configuration.md.Why
With auth disabled (the default) a DNS-rebinding page can reach the local server even with CORS off (#1321), because the browser sends the request to 127.0.0.1 with
Host: <attacker name>. CheckingHostcloses that.Behavior change to be aware of: a loopback-bound server behind a reverse proxy that forwards the public hostname (
Host: uteke.example.com) will now return 403 until that name is added toallowed_hosts. Deployments bound to0.0.0.0are unaffected unless they setallowed_hosts.Closes #1326
Testing
cargo test -p uteke-server: 59 passed, includinghost_guard_tests(loopback accept/reject matrix incl.127.0.0.1.evil.example,localhost.evil.example, IPv6, missing header, allowlist, Docker-style) andhost_guard_route_tests(end-to-end throughroute(): loopback bind rejectsHost: evil.example; Docker-style bind with and withoutallowed_hosts).cargo clippy -p uteke-server --all-targets -- -D warnings,cargo fmt --all -- --checkclean;cargo run -p docgenno diff.🤖 Generated with Claude Code