server/utils: verify trusted ip headers are valid ip addresses (#23140)

Co-authored-by: Ibrahim Serdar Acikgoz <ibrahim@ibrahims-mac.local>
Этот коммит содержится в:
Ibrahim Serdar Acikgoz
2023-05-04 09:29:21 +03:00
коммит произвёл GitHub
родитель 96b537167c
Коммит b2e0aa7088
2 изменённых файлов: 127 добавлений и 97 удалений

Просмотреть файл

@@ -107,16 +107,15 @@ func GetIPAddress(r *http.Request, trustedProxyIPHeader []string) string {
}
}
if address != "" {
if address != "" && net.ParseIP(address) != nil {
return address
}
}
if address == "" {
address, _, _ = net.SplitHostPort(r.RemoteAddr)
}
host, _, _ := net.SplitHostPort(r.RemoteAddr)
return address
return host
}
func GetHostnameFromSiteURL(siteURL string) string {