mirror of
https://github.com/owncast/owncast.git
synced 2024-11-24 13:50:06 +03:00
fix: parse as ipv4 if needed. Closes #3419
This commit is contained in:
parent
86472d711c
commit
6074ea8f29
1 changed files with 5 additions and 0 deletions
|
@ -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…
Reference in a new issue