-
Notifications
You must be signed in to change notification settings - Fork 18k
net/http/httputil: NewSingleHostReverseProxy does not preserve X-Forwarded-Proto
header
#57132
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 @neild |
X-Forwarded-Proto
headerX-Forwarded-Proto
header
I think the intent is to check that it is not explicitly set to nil in which case it would not be updated. Why do you think proxy should pass per-existing value? |
It's not a standard HTTP header, so I don't know if I can provide an authoritative reference here, but MDN says: "The X-Forwarded-Proto (XFP) header is a de-facto standard header for identifying the protocol (HTTP or HTTPS) that a client used to connect to your proxy or load balancer." If |
@neild discussed this bug in the release weekly meeting, any updates? Thanks |
This was added by https://go.dev/cl/407414. The intent is to set Unfortunately, the The new The whole point of adding Let's revert the change to set |
Change https://go.dev/cl/457595 mentions this issue: |
It sounds like the existing semantics will be preserved, and improvements will be limited to
In our use case, a web client (i.e. browser) talks to a cloud provider frontend (e.g. Google Cloud Load Balancer) which sets While it's generally advisable that the cloud provider frontend communicates with its backend over a secure connection, this connection is distinct from the web client <=> cloud frontend connection, which the cloud frontend communicates the protocol used via In our use case, we sometimes will insert yet another reverse proxy between the cloud frontend proxy and our app servers. This reverse proxy uses Go's "The X-Forwarded-Proto (XFP) header is a de-facto standard header for identifying the protocol (HTTP or HTTPS) that a client used to connect to your proxy or load balancer. Your server access logs contain the protocol used between the server and the load balancer, but not the protocol used between the client and the load balancer. To determine the protocol used between the client and the load balancer, the X-Forwarded-Proto request header can be used." |
AWS ALB does the same https://docs.aws.amazon.com/elasticloadbalancing/latest/application/x-forwarded-headers.html#x-forwarded-proto (text looks identical to MDN docs) |
What version of Go are you using (
go version
)?dev branch, which as of time of writing, should be 1.20
Does this issue reproduce with the latest release?
Does not repro in 1.19, which is the latest stable release as of time of writing.
What operating system and processor architecture are you using (
go env
)?https://go.dev/play
What did you do?
https://go.dev/play/p/T80FZx8gCPU?v=gotip
What did you expect to see?
X-Forwarded-Proto: https
should be preserved in the backend, like on 1.19: https://go.dev/play/p/L6Z97pkbuP2.What did you see instead?
X-Forwarded-Proto
got overwritten withhttp
.It looks like this is overwritten here. It looks like the intent of the code is, if
X-Forwarded-Proto
is not present, to infer from http.Request.TLS whetherX-Forwarded-Proto
should be set tohttp
orhttps
. However, it's doing this even whenX-Forwarded-Proto
is present.The text was updated successfully, but these errors were encountered: