Validate Host header against TLS domains in HTTP→HTTPS redirect#120
Validate Host header against TLS domains in HTTP→HTTPS redirect#120kevinmcconnell merged 3 commits intomainfrom
Conversation
The httpRedirectHandler built the redirect Location header directly from the client-supplied Host header without checking it against the configured TLS_DOMAIN allowlist. A request with a spoofed Host header would get a 301 redirect to https://<spoofed-host>/..., which is an open redirect (though not exploitable from a browser without MITM). The handler now validates the request Host against the configured TLS domains before redirecting, returning 421 Misdirected Request for unrecognized hosts. Both configured domains and incoming hosts are normalized via idna.Lookup.ToASCII to match the normalization that autocert.HostWhitelist applies for certificate issuance. Hosts or configured domains that fail IDNA normalization are rejected/skipped, again matching autocert behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1f3d3a1 to
b090a2e
Compare
There was a problem hiding this comment.
Pull request overview
This PR mitigates an open-redirect vector in the HTTP→HTTPS redirect path by validating the incoming Host header against the configured TLS_DOMAIN allowlist (including IDNA normalization), returning 421 Misdirected Request for unrecognized/invalid hosts.
Changes:
- Refactors
httpRedirectHandlerto accept configured TLS domains, normalize them viaidna.Lookup.ToASCII, and enforce allowlisted redirects. - Returns
421 Misdirected Request(instead of301) for spoofed or IDNA-invalidHostheaders. - Adds test coverage for allowlist behavior (spoofed host, ports, multiple domains, case-insensitivity, IDN handling).
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| internal/server.go | Implements allowlist + IDNA normalization for HTTP→HTTPS redirects; rejects unrecognized hosts with 421. |
| internal/server_test.go | Adds unit tests covering spoofed host rejection and allowed host redirect behavior (including ports, multiple domains, and IDNs). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Document behavior when all TLS domains fail IDNA normalization - Downgrade per-request IDNA failure log from Warn to Debug to avoid log noise from client-controlled input - Assert Location header in IDN subtests for both unicode and punycode hosts Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Hi — I reported a Host header injection / open redirect issue via HackerOne on March 22, which appears to align with the fix in this PR (HTTP→HTTPS redirect using unvalidated Host). Appreciate the remediation here. If this change was informed by that report, I’d be grateful for attribution in the PR or changelog. Thanks. |
Use the already-configured `HostPolicy` to determine whether the requested host is in our allowed list of domains.
69d594a to
186b8f5
Compare
|
@flavorjones thanks for the fix! The logic looks good. I think we can lean on the existing |
Summary
httpRedirectHandlerbuilt the redirectLocationheader directly from the client-suppliedHostheader without checking it against the configuredTLS_DOMAINallowlist. A spoofedHostheader would produce a301redirect tohttps://<spoofed-host>/....Hostagainst configured TLS domains before redirecting, returning421 Misdirected Requestfor unrecognized hosts.idna.Lookup.ToASCIIto match the normalization thatautocert.HostWhitelistapplies for certificate issuance. Hosts or configured domains that fail IDNA normalization are rejected/skipped.Test plan
ref: https://3.basecamp.com/2914079/buckets/1666/card_tables/cards/9714031628
Reported by @Pa345-ai
🤖 Generated with Claude Code