Description
What version of Go are you using (go version
)?
go version go1.11.2 windows/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env set GOARCH=amd64 set GOHOSTARCH=amd64 set GOHOSTOS=windows
What did you do?
I tried to send an HTTP request with a custom host header via an HTTP proxy. Sample code:
func Test(t *testing.T) {
proxy, errParse := url.Parse("http://127.0.0.1:8080")
if errParse != nil {
t.Errorf("could not parse proxy URL '%s'", errParse)
}
// Define custom client allowing insecure SSL connections and any SSL ciphers (in case of HTTPS)
client := &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyURL(proxy),
},
// CheckRedirect: -> default is nil, which tells it to stop after 10 consecutive requests
}
// Build request
req, errNew := http.NewRequest("GET", "http://192.168.0.01", nil)
if errNew != nil {
t.Errorf("could not parse proxy URL '%s'", errParse)
}
// Set virtual host
req.Host = "mynotexistinghostheader1589.com"
// Set request headers
req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0")
// Send request
resp, errDo := client.Do(req)
if errDo != nil {
t.Errorf(errDo.Error())
}
fmt.Println(resp)
return
}
What did you expect to see?
The sent request should be sent (by the proxy on behalf of me) to "http://192.168.0.01" along with the host header "mynotexistinghostheader1589.com".
When I define the web server host as "xxx" with a vhost "yyy", the proxy should do the same.
What did you see instead?
The proxy did NOT connect to 192.168.0.01 in order to send the HTTP request, but it directly tried to connect to "mynotexistinghostheader1589.com" taken from the request's host header. This is wrong, "mynotexistinghostheader1589.com" is not the server, it is just the vhost, so the request obviously could not be delivered.
Where is the bug?
I have already traced the issue. net/http/request.go:545 (line number from current master) takes data from the host header:
It should take it from the original URL, like this:
Proof
Here is a screenshot form BurpSutite, showing, that it receives the request but forwards it to mynotexistinghostheader1589.com instead of 192.168.0.01: