[#282] reversed the X-Forwarded-For ips iteration

This commit is contained in:
Gani Georgiev 2022-08-20 08:01:54 +03:00
parent d4f160d959
commit 3f4f4cf031
1 changed files with 4 additions and 3 deletions

View File

@ -317,9 +317,10 @@ func realUserIp(r *http.Request, fallbackIp string) string {
if ipsList := r.Header.Get("X-Forwarded-For"); ipsList != "" { if ipsList := r.Header.Get("X-Forwarded-For"); ipsList != "" {
ips := strings.Split(ipsList, ",") ips := strings.Split(ipsList, ",")
// extract the rightmost ip // extract the rightmost ip
for _, ip := range ips { for i := len(ips) - 1; i >= 0; i-- {
if trimmedIp := strings.TrimSpace(ip); trimmedIp != "" { ip := strings.TrimSpace(ips[i])
return trimmedIp if ip != "" {
return ip
} }
} }
} }