fix(honeypot/naive): implement better IP parsing logic
Signed-off-by: Xe Iaso <me@xeiaso.net>
This commit is contained in:
parent
122e4bc072
commit
40afc13d7f
2 changed files with 7 additions and 3 deletions
|
|
@ -100,6 +100,9 @@ func XForwardedForToXRealIP(next http.Handler) http.Handler {
|
|||
ip := xff.Parse(xffHeader)
|
||||
slog.Debug("setting X-Real-Ip from X-Forwarded-For", "to", ip, "x-forwarded-for", xffHeader)
|
||||
r.Header.Set("X-Real-Ip", ip)
|
||||
if addr, err := netip.ParseAddr(ip); err == nil {
|
||||
r = r.WithContext(context.WithValue(r.Context(), realIPKey{}, addr))
|
||||
}
|
||||
}
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue