From 6074ea8f29c6496e886b457997dbb06e8583d5a9 Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Wed, 8 Nov 2023 19:07:00 -0800 Subject: [PATCH] fix: parse as ipv4 if needed. Closes #3419 --- utils/clientId.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/utils/clientId.go b/utils/clientId.go index 6a8555750..0b9c7f16c 100644 --- a/utils/clientId.go +++ b/utils/clientId.go @@ -26,6 +26,11 @@ func GetIPAddressFromRequest(req *http.Request) string { xForwardedFor := req.Header.Get("X-FORWARDED-FOR") if xForwardedFor != "" { clientIpString := strings.Split(xForwardedFor, ", ")[0] + + // If the IP has a prefix of ::ffff: then it's an IPv4 address. + // Strip the prefix so we can parse it as an IPv4 address. + clientIpString = strings.TrimPrefix(clientIpString, "::ffff:") + if strings.Contains(clientIpString, ":") { ip, _, err := net.SplitHostPort(clientIpString) if err != nil {