Repository navigation
fix(middleware): harden redirect URL construction - #3220
Merged
Merged
Conversation
vishr
added a commit
that referenced
this pull request
Nov 12, 2026
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.
Summary
Fixes #3217.
Removing a bare
www.Host can producehttps:///attacker.com/login. Reject empty, leading colon/dot, or percent-bearing redirect hosts with HTTP 400. Rely onnet/httpfor Host syntax validation, and do the additional checks only when a redirect is needed.WWW matching is case-insensitive. Empty or absolute-form request targets fall back to
URL.RequestURI();ws/wssbecome HTTP schemes.OPTIONS *passes through without constructing a Location.Related: #3218. Leading double slashes remain part of the path when the validated host already anchors an absolute URL.
Evidence
OPTIONS *emittedhttps://example.com*.After: tests assert 400 and no application-handler call when an invalid host requires a redirect, including over TCP HTTP. Asterisk targets and requests that need no redirect reach the next handler.
GOTOOLCHAIN=go1.27.4 go test -race ./...,go vet ./...,golint -set_exit_status ./..., and current staticcheck pass.Merge Danger
Door: two-way
Blast Radius: redirects
Requests requiring a redirect now return 400 for the additional invalid-host cases, including percent-bearing zoned IPv6 authorities. Canonical requests and asterisk targets pass through without redirect validation.