fix: Split host and port before storing IP (#2594)

The IP was always nil prior, and this fixes the test to
check for that as well!
This commit is contained in:
Kyle Carberry
2022-06-26 16:22:03 -05:00
committed by GitHub
parent 545a9f3435
commit 4851d932c4
3 changed files with 8 additions and 5 deletions

View File

@ -167,7 +167,8 @@ func ExtractAPIKey(db database.Store, oauth *OAuth2Configs) func(http.Handler) h
// Only update LastUsed once an hour to prevent database spam.
if now.Sub(key.LastUsed) > time.Hour {
key.LastUsed = now
remoteIP := net.ParseIP(r.RemoteAddr)
host, _, _ := net.SplitHostPort(r.RemoteAddr)
remoteIP := net.ParseIP(host)
if remoteIP == nil {
remoteIP = net.IPv4(0, 0, 0, 0)
}