only check Contains if IP address (#14487)
* only check Contains if IP address * fix typo * add bug fix changelog
This commit is contained in:
parent
dd4a3b339e
commit
6ae9c76970
|
@ -0,0 +1,3 @@
|
|||
```release-note:bug
|
||||
sdk/cidrutil: Only check if cidr contains remote address for IP addresses
|
||||
```
|
|
@ -10,6 +10,10 @@ import (
|
|||
sockaddr "github.com/hashicorp/go-sockaddr"
|
||||
)
|
||||
|
||||
func isIPAddr(cidr sockaddr.SockAddr) bool {
|
||||
return (cidr.Type() & sockaddr.TypeIP) != 0
|
||||
}
|
||||
|
||||
// RemoteAddrIsOk checks if the given remote address is either:
|
||||
// - OK because there's no CIDR whitelist
|
||||
// - OK because it's in the CIDR whitelist
|
||||
|
@ -24,7 +28,7 @@ func RemoteAddrIsOk(remoteAddr string, boundCIDRs []*sockaddr.SockAddrMarshaler)
|
|||
return false
|
||||
}
|
||||
for _, cidr := range boundCIDRs {
|
||||
if cidr.Contains(remoteSockAddr) {
|
||||
if isIPAddr(cidr) && cidr.Contains(remoteSockAddr) {
|
||||
// Whitelisted.
|
||||
return true
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue