feat(botfilter): add util.go

This commit is contained in:
hoelee committed 2026-01-08 14:16:00 +08:00
1 parent e12d44de05
commit 681866529d
1 file changed
+11
+11
View File
@@ -15,3 +15,14 @@ func clientIP(r *http.Request, cfg *compiledConfig) netip.Addr {
return remote
}
// A trusted reverse proxy must overwrite (not append to an untrusted
// client-provided value) this header. The left-most valid value is the
// original client in the conventional X-Forwarded-For representation.
for _, value := range strings.Split(r.Header.Get(cfg.clientIPHeader), ",") {
if addr, err := netip.ParseAddr(strings.TrimSpace(value)); err == nil {
return addr.Unmap()
}
}
return remote
}