Skip to content

Commit

Permalink
only check Contains if IP address (#14487)
Browse files Browse the repository at this point in the history
* only check Contains if IP address

* fix typo

* add bug fix changelog
  • Loading branch information
swayne275 authored Mar 15, 2022
1 parent b064da3 commit f4292d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog/14487.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
sdk/cidrutil: Only check if cidr contains remote address for IP addresses
```
6 changes: 5 additions & 1 deletion sdk/helper/cidrutil/cidr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit f4292d8

Please sign in to comment.