From fcfe9ee9765f906ad40da699c8dc35261b6ce58a Mon Sep 17 00:00:00 2001 From: hoelee Date: Tue, 13 Jan 2026 14:16:00 +0800 Subject: [PATCH] feat(botfilter): add util.go --- util.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/util.go b/util.go index bc871156..81477174 100644 --- a/util.go +++ b/util.go @@ -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 +} +