From 6b27d850d8f1e820074f2891370f2e03adc495fa Mon Sep 17 00:00:00 2001 From: armadi1809 <46684200+armadi1809@users.noreply.github.com> Date: Wed, 18 Oct 2023 19:01:03 -0500 Subject: [PATCH] Added a check for the port before calling the splitHostPort function (#3372) Co-authored-by: Aziz Rmadi --- utils/clientId.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/utils/clientId.go b/utils/clientId.go index 38188bcdc..6a8555750 100644 --- a/utils/clientId.go +++ b/utils/clientId.go @@ -26,14 +26,16 @@ func GetIPAddressFromRequest(req *http.Request) string { xForwardedFor := req.Header.Get("X-FORWARDED-FOR") if xForwardedFor != "" { clientIpString := strings.Split(xForwardedFor, ", ")[0] - ip, _, err := net.SplitHostPort(clientIpString) - if err != nil { - log.Errorln(err) - return "" + if strings.Contains(clientIpString, ":") { + ip, _, err := net.SplitHostPort(clientIpString) + if err != nil { + log.Errorln(err) + return "" + } + return ip } - return ip + return clientIpString } - ip, _, err := net.SplitHostPort(ipAddressString) if err != nil { log.Errorln(err)