Skip to content

security(server): validate Host header to block DNS rebinding - #1360

Merged
ajianaz merged 3 commits into
developfrom
security/host-header-validation
Oct 7, 2026
Merged

ajianaz merged 3 commits into
developfrom
security/host-header-validation

Conversation

@ajianaz

@ajianaz ajianaz commented Oct 7, 2026

Copy link
Copy Markdown
Collaborator

What

uteke-serve now validates the Host header (new HostGuard in context.rs, enforced first thing in route(), before preflight and health):

  • Loopback bind (127.0.0.1, ::1, localhost): only localhost, *.localhost, and loopback IPs are accepted, plus any [server] allowed_hosts / --allowed-host entries. Everything else gets 403 Host not allowed.
  • Non-loopback bind (e.g. 0.0.0.0 in Docker, where the service name is the Host): every Host is accepted unless allowed_hosts is set, in which case the list is enforced.
  • Entries match with or without port, case-insensitively. A request with no Host header (HTTP/1.0) is accepted; rebinding browsers always send one.
  • Docs: docs/tls.md (new section + checklist row) and docs/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>. Checking Host closes 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 to allowed_hosts. Deployments bound to 0.0.0.0 are unaffected unless they set allowed_hosts.

Closes #1326

Testing

  • cargo test -p uteke-server: 59 passed, including host_guard_tests (loopback accept/reject matrix incl. 127.0.0.1.evil.example, localhost.evil.example, IPv6, missing header, allowlist, Docker-style) and host_guard_route_tests (end-to-end through route(): loopback bind rejects Host: evil.example; Docker-style bind with and without allowed_hosts).
  • cargo clippy -p uteke-server --all-targets -- -D warnings, cargo fmt --all -- --check clean; cargo run -p docgen no diff.

🤖 Generated with Claude Code

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]>
@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

🔍 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.
@ajianaz
ajianaz merged commit 8c25563 into develop Oct 7, 2026
15 checks passed
@ajianaz
ajianaz deleted the security/host-header-validation branch October 7, 2026 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security: validate Host header to block DNS rebinding

1 participant