Skip to content

Commit

Permalink
Rewrite fabio X-Forwarded-For header set for WS connections based on …
Browse files Browse the repository at this point in the history
…golang standard library code
  • Loading branch information
bn0ir committed Apr 16, 2022
1 parent 96c2aa2 commit e483a1b
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions proxy/http_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,18 @@ func addHeaders(r *http.Request, cfg config.Proxy, stripPath string) error {
// http proxy which sets it.
ws := r.Header.Get("Upgrade") == "websocket"
if ws {
targetHeader := []string{remoteIP}
sourceHeader := r.Header.Get("X-Forwarded-For")
if sourceHeader != "" {
targetHeader = append([]string{sourceHeader}, targetHeader...)
clientIP := remoteIP
// If we aren't the first proxy retain prior
// X-Forwarded-For information as a comma+space
// separated list and fold multiple headers into one.
prior, ok := r.Header["X-Forwarded-For"]
omit := ok && prior == nil // Issue 38079: nil now means don't populate the header
if len(prior) > 0 {
clientIP = strings.Join(prior, ", ") + ", " + clientIP
}
if !omit {
r.Header.Set("X-Forwarded-For", clientIP)
}
r.Header.Set("X-Forwarded-For", strings.Join(targetHeader, ","))
}

// Issue #133: Setting the X-Forwarded-Proto header to
Expand Down

0 comments on commit e483a1b

Please sign in to comment.