changed X-Forwarded-For parsing to use the first non-empty leftmost-ish ip as it is more close to the 'real ip'
This commit is contained in:
parent
9fa56b020c
commit
beca0a044e
|
@ -27,6 +27,8 @@
|
||||||
|
|
||||||
- New schema fields UI for "tidier" fields list.
|
- New schema fields UI for "tidier" fields list.
|
||||||
|
|
||||||
|
- Updated the logs "real" user ip to check for `Fly-Client-IP` header and changed the `X-Forward-For` header to use the first non-empty leftmost-ish IP as it the closes to the "real IP".
|
||||||
|
|
||||||
|
|
||||||
## v0.15.2
|
## v0.15.2
|
||||||
|
|
||||||
|
|
|
@ -377,10 +377,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 != "" {
|
||||||
|
// extract the first non-empty leftmost-ish ip
|
||||||
ips := strings.Split(ipsList, ",")
|
ips := strings.Split(ipsList, ",")
|
||||||
// extract the rightmost ip
|
for _, ip := range ips {
|
||||||
for i := len(ips) - 1; i >= 0; i-- {
|
ip = strings.TrimSpace(ip)
|
||||||
ip := strings.TrimSpace(ips[i])
|
|
||||||
if ip != "" {
|
if ip != "" {
|
||||||
return ip
|
return ip
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue