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

Fix x-forwarded-for header processing for ws connections #860

Merged
merged 2 commits into from
May 6, 2022

Conversation

bn0ir
Copy link
Contributor

@bn0ir bn0ir commented Jan 25, 2022

Fix x-forwarded-for header processing logic for ws connections.
Instead of simply use remoteIP as x-forwarded-for header for backend, server add remoteIP to the end of x-forwarded-for header from client and send result to backend.

This PR possibly connected with issue #828

@CLAassistant
Copy link

CLAassistant commented Jan 25, 2022

CLA assistant check
All committers have signed the CLA.

@nathanejohnson
Copy link
Member

@leprechau could you take a look at this one? This rings of this old thread:

#449

r.Header.Set("X-Forwarded-For", remoteIP)
targetHeader := []string{remoteIP}
sourceHeader := r.Header.Get("X-Forwarded-For")
if sourceHeader != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some subtle things going on here. It would be good to mirror the functionality in the standard library:

https://github.com/golang/go/blob/master/src/net/http/httputil/reverseproxy.go#L296

The Get() call on the header only grabs the first element if there is more than one.

if sourceHeader != "" {
targetHeader = append([]string{sourceHeader}, targetHeader...)
}
r.Header.Set("X-Forwarded-For", strings.Join(targetHeader, ","))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Down here, these should be joined by

", "

as it is done in the standdard library here:

https://github.com/golang/go/blob/master/src/net/http/httputil/reverseproxy.go#L303

@aaronhurt
Copy link
Member

Agreed, we should be trying to mirror the functionality in the standard library where possible. This also shouldn't have an impact on the ACL functionality.

@nathanejohnson nathanejohnson merged commit 22e41e4 into fabiolb:master May 6, 2022
@ketzacoatl
Copy link

@nathanejohnson / @leprechau can this be released in a v1.6.1?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants