Skip to content
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

net/http/request: distinguish request target and host header when using proxy #43588

Closed
kidkidkid opened this issue Jan 8, 2021 · 2 comments
Closed
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@kidkidkid
Copy link

kidkidkid commented Jan 8, 2021

What version of Go are you using (go version)?

$ go version

go version go1.14.6 darwin/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

What did you do?

What did you expect to see?

According to RFC 7230, absoluteURI should be passed when using proxy. When i set Host header, the host in absoluteURI is rewrote by the header, which is not acceptable. For example, using curl as follows:

curl -H '{Host:A}' http://B/some/page -x {proxy}

When capturing the traffic, we could get packet like this:

GET http://B/some/page HTTP 1.1\r\n
HOST A\r\n

While using http.Proxy in Go, i can set host by setting request.Host, but it cannot preserve original Host in absoluteURI.

u, _ := url.Parse(""proxy)
transport := &http.Transport{}
transport.Proxy = http.ProxyURL(u)
cli := &http.Client{Transport: transport}
req,  _ := http.NewRequest("GET", "http://B/some/page", nil)
req.Host="A"
cli.Do(req)

Packet captured is like this:

GET http://A/some/page.com 1.1\r\n
HOST A\r\n

Sometimes Host header can be used to verify the request, and Host is not equal with host domain in such case. I know proxy should rewrite Host according to RFC, but i think it's acceptable to distinguish host header and host in absoluteURI.

What did you see instead?

Maybe the user defined host won't rewrite the host in absoluteURI.
https://github.com/golang/go/blob/master/src/net/http/request.go#L585

@kidkidkid kidkidkid changed the title net/http/request: Support Host header set when using proxy net/http/request: Distinguish request target and host header when using proxy Jan 12, 2021
@cagedmantis cagedmantis added this to the Backlog milestone Jan 13, 2021
@cagedmantis cagedmantis changed the title net/http/request: Distinguish request target and host header when using proxy net/http/request: distinguish request target and host header when using proxy Jan 13, 2021
@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 13, 2021
@cagedmantis
Copy link
Contributor

/cc @bradfitz @neild

@seankhliao
Copy link
Member

Duplicate of #16265

@seankhliao seankhliao marked this as a duplicate of #16265 Sep 13, 2021
@golang golang locked and limited conversation to collaborators Sep 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants