Move Scope ID handling into CIDR check

This commit is contained in:
Niklas Roth 2025-04-08 15:06:20 +02:00 committed by GitHub
parent e961e52dea
commit 23eeeee701
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -57,12 +57,7 @@ func GetRequesterIP(r *http.Request) string {
//e.g. [15c4:cbb4:cc98:4291:ffc1:3a46:06a1:51a7]
requesterRawIp = requesterRawIp[1 : len(requesterRawIp)-1]
}
// Trim away scope ID if present (e.g. %eth0 in IPv6)
if i := strings.Index(requesterRawIp, "%"); i != -1 {
requesterRawIp = requesterRawIp[:i]
}
return requesterRawIp
}
@ -92,6 +87,11 @@ func MatchIpWildcard(ipAddress, wildcard string) bool {
// Match ip address with CIDR
func MatchIpCIDR(ip string, cidr string) bool {
// Trim away scope ID if present in IP (e.g. fe80::1%eth0)
if i := strings.Index(ip, "%"); i != -1 {
ip = ip[:i]
}
// parse the CIDR string
_, cidrnet, err := net.ParseCIDR(cidr)
if err != nil {