aboutsummaryrefslogtreecommitdiff
path: root/internal/netutil/netutil.go
diff options
context:
space:
mode:
authorJoe Chen <jc@unknwon.io>2022-03-14 22:06:08 +0800
committerGitHub <noreply@github.com>2022-03-14 22:06:08 +0800
commit714383a063f64fcc7c6a458182c4f9cf5a46df66 (patch)
treeebed76f917e9817cd78c4dda07813f93f3bb16bd /internal/netutil/netutil.go
parenta2c632526111b3333de482c69709a7ca70a173f8 (diff)
conf: add allowlist for accessing local network (#6842)
Diffstat (limited to 'internal/netutil/netutil.go')
-rw-r--r--internal/netutil/netutil.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/internal/netutil/netutil.go b/internal/netutil/netutil.go
index e3b3b8cc..5059d463 100644
--- a/internal/netutil/netutil.go
+++ b/internal/netutil/netutil.go
@@ -47,8 +47,15 @@ func init() {
}
}
-// IsLocalHostname returns true if given hostname is a known local address.
-func IsLocalHostname(hostname string) bool {
+// IsLocalHostname returns true if given hostname is resolved to local network
+// address, except exempted from the allowlist.
+func IsLocalHostname(hostname string, allowlist []string) bool {
+ for _, allow := range allowlist {
+ if hostname == allow {
+ return false
+ }
+ }
+
ips, err := net.LookupIP(hostname)
if err != nil {
return true