Browse Source

fix: parse as ipv4 if needed. Closes #3419

pull/3414/head
Gabe Kangas 2 years ago
parent
commit
6074ea8f29
No known key found for this signature in database
GPG Key ID: 4345B2060657F330
  1. 5
      utils/clientId.go

5
utils/clientId.go

@ -26,6 +26,11 @@ func GetIPAddressFromRequest(req *http.Request) string { @@ -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 {

Loading…
Cancel
Save