fix: use valid ip mask in api keys when remote address is ipv6 (#2695)

This commit is contained in:
Colin Adler
2022-06-27 20:31:18 +00:00
committed by GitHub
parent 69f27efead
commit a494489ffa
2 changed files with 4 additions and 2 deletions
+2 -1
View File
@@ -815,6 +815,7 @@ func (api *API) createAPIKey(rw http.ResponseWriter, r *http.Request, params dat
if ip == nil {
ip = net.IPv4(0, 0, 0, 0)
}
bitlen := len(ip) * 8
key, err := api.Database.InsertAPIKey(r.Context(), database.InsertAPIKeyParams{
ID: keyID,
UserID: params.UserID,
@@ -822,7 +823,7 @@ func (api *API) createAPIKey(rw http.ResponseWriter, r *http.Request, params dat
IPAddress: pqtype.Inet{
IPNet: net.IPNet{
IP: ip,
Mask: ip.DefaultMask(),
Mask: net.CIDRMask(bitlen, bitlen),
},
Valid: true,
},