IsBlockedLocalHostname returns true if given hostname is resolved to a local network address that is implicitly blocked (i.e. not exempted from the allowlist).
(hostname string, allowlist []string)
| 47 | // network address that is implicitly blocked (i.e. not exempted from the |
| 48 | // allowlist). |
| 49 | func IsBlockedLocalHostname(hostname string, allowlist []string) bool { |
| 50 | for _, allow := range allowlist { |
| 51 | if hostname == allow || allow == "*" { |
| 52 | return false |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | ips, err := net.LookupIP(hostname) |
| 57 | if err != nil { |
| 58 | return true |
| 59 | } |
| 60 | for _, ip := range ips { |
| 61 | for _, cidr := range localCIDRs { |
| 62 | if cidr.Contains(ip) { |
| 63 | return true |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | return false |
| 68 | } |
no outgoing calls