Skip to content

net/http/httputil: ReverseProxy req.Header copying is unclear #18327

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

Closed
FiloSottile opened this issue Dec 15, 2016 · 3 comments
Closed

net/http/httputil: ReverseProxy req.Header copying is unclear #18327

FiloSottile opened this issue Dec 15, 2016 · 3 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@FiloSottile
Copy link
Contributor

ReverseProxy makes an attempt at not modifying the original req.Header

	// We are modifying the same underlying map from req (shallow
	// copied above) so we only copy it if necessary.
	copiedHeaders := false

However it skips the check for X-Forwarded-For

outreq.Header.Set("X-Forwarded-For", clientIP)

But more importantly, Director is called on the shallow copied req, and the NewSingleHostReverseProxy one modifies req.Header without making a new map

		if _, ok := req.Header["User-Agent"]; !ok {
			// explicitly disable User-Agent so it's not set to default value
			req.Header.Set("User-Agent", "")
		}

It looks to me like this is useless unless it's consistent. It should either make a new Header map before calling Director, or make no attempt at copying them at all.

See also #18326

@bradfitz bradfitz added this to the Go1.9 milestone Dec 15, 2016
@bradfitz bradfitz added the NeedsFix The path to resolution is known, but the work has not been done. label Dec 15, 2016
@bradfitz
Copy link
Contributor

I suppose it should just always copy.

This isn't a regression from Go 1.7 to master, is it? How is this related to #18326?

@FiloSottile
Copy link
Contributor Author

Not a regression, even if 24d8f3f is a partial fix.

I linked #18326 because I expect it to end up into a discussion of whether you are supposed to modify req.Header, which is relevant to this issue. (And also because it's how I found #18326.)

@gopherbot
Copy link
Contributor

CL https://golang.org/cl/46716 mentions this issue.

@golang golang locked and limited conversation to collaborators Jun 26, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants