-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http: HTTP requests sent via HTTP proxy are forwarded to the wrong host #30775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
cc: @bradfitz |
I asked myself why this was not discovered before, because it seems to be a quite common use-case. Two reason I can come up with:
|
Hi all! This is a year old by now. I think the fix should be quite straight forward... Any opinions? |
I still cannot set a proxy in between to validate my HTTP client, because of this bug :/ What do you suggest? Do you need a merge request? I mean it's just one variable to be switched, as suggested in the screenshots above... |
Proxies use absolute URIs and RFC 7230 Section 5.4 says
See also #16265 (comment) Closing as working as intended |
It's still not working as intended. The connection information ("server" and "port") should not be taken from the host header, because the "port" might not be defined there. The host header is just a flag for the web server to pick the desired application, in a multi application (vhost) environment. When you issue a request, you first connect to a server, e.g.:
then, you send it an HTTP request, including a host header to define the desired application, e.g.:
That host header value (domain.tld) does not necessarily need to contain the port 345 and (to my knowledge) usually doesn't. Now, in A URL defines http://server:port. Not http://vhost:port. In production environments (and with working DNS) they are equal, so modern browsers are just setting "server" as "vhost", but in testing environments, or if you don't have a nameserver the situation may be different. |
By spec (RFC 7230), HTTP requests should either be: relative URI
or absolute URI with Host the same as in the URI
There is no room for controlling which server you connect to. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I tried to send an HTTP request with a custom host header via an HTTP proxy. Sample code:
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:

With my suggested fix, it is correct, like this:

The text was updated successfully, but these errors were encountered: