From e10f8da66be0c5ce0df115a158c73fd92876d299 Mon Sep 17 00:00:00 2001 From: ari melody Date: Fri, 1 May 2026 17:14:13 +0100 Subject: [PATCH] IP resolver: add v6 support --- controller/ip.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/controller/ip.go b/controller/ip.go index cbc3054..355b0c3 100644 --- a/controller/ip.go +++ b/controller/ip.go @@ -10,14 +10,18 @@ import ( // Returns the request's original IP address, resolving the `x-forwarded-for` // header if the request originates from a trusted proxy. func ResolveIP(app *model.AppState, r *http.Request) string { - addr := strings.Split(r.RemoteAddr, ":")[0] + iSplit := strings.LastIndex(r.RemoteAddr, ":") + addr := r.RemoteAddr[0:iSplit] if slices.Contains(app.Config.TrustedProxies, addr) { forwardedFor := r.Header.Get("x-forwarded-for") if len(forwardedFor) > 0 { // discard extra IPs; cloudflare tends to append their nodes forwardedFor = strings.Split(forwardedFor, ", ")[0] - return forwardedFor + addr = forwardedFor } } + if addr[0] == '[' && addr[len(addr) - 1] == ']' { + addr = addr[1:len(addr) - 1] + } return addr }