Added a check for the port before calling the splitHostPort function (#3372)

Co-authored-by: Aziz Rmadi <azizrmadi@Azizs-MacBook-Air.local>
This commit is contained in:
armadi1809 2023-10-18 19:01:03 -05:00 committed by GitHub
parent 47d5b3c92f
commit 6b27d850d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,6 +26,7 @@ func GetIPAddressFromRequest(req *http.Request) string {
xForwardedFor := req.Header.Get("X-FORWARDED-FOR") xForwardedFor := req.Header.Get("X-FORWARDED-FOR")
if xForwardedFor != "" { if xForwardedFor != "" {
clientIpString := strings.Split(xForwardedFor, ", ")[0] clientIpString := strings.Split(xForwardedFor, ", ")[0]
if strings.Contains(clientIpString, ":") {
ip, _, err := net.SplitHostPort(clientIpString) ip, _, err := net.SplitHostPort(clientIpString)
if err != nil { if err != nil {
log.Errorln(err) log.Errorln(err)
@ -33,7 +34,8 @@ func GetIPAddressFromRequest(req *http.Request) string {
} }
return ip return ip
} }
return clientIpString
}
ip, _, err := net.SplitHostPort(ipAddressString) ip, _, err := net.SplitHostPort(ipAddressString)
if err != nil { if err != nil {
log.Errorln(err) log.Errorln(err)