Skip to content

Commit 579e1cb

Browse files
authored
Fix x-forwarded-for header calculation
Setting the x-forwarded-for header is actually broken as it omit the separator between IPs passed by clients and other reverse proxies and the actual client request. Like in the current httputil.reverseproxy library (https://golang.org/src/net/http/httputil/reverseproxy.go?s=575:1776#L188) I suggest to add the following patch. Thank's for the work, Salim
1 parent 81f50fb commit 579e1cb

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

reverse.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ func addXForwardedForHeader(req *http.Request) {
215215
// X-Forwarded-For information as a comma+space
216216
// separated list and fold multiple headers into one.
217217
if prior, ok := req.Header["X-Forwarded-For"]; ok {
218-
clientIP = strings.Join(prior, ", ") + clientIP
218+
clientIP = strings.Join(prior, ", ") + ", " + clientIP
219219
}
220220
req.Header.Set("X-Forwarded-For", clientIP)
221221
}

0 commit comments

Comments
 (0)