1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-03-17 21:27:52 +02:00

[#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

View File

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