diff --git a/common/util/util.go b/common/util/util.go index 844ef2f..aba2df5 100644 --- a/common/util/util.go +++ b/common/util/util.go @@ -8,6 +8,7 @@ import ( "net/http" "slices" "sort" + "strings" "github.com/pion/ice/v2" "github.com/pion/sdp/v3" @@ -165,3 +166,22 @@ func GetCandidateAddrs(sdpStr string) []net.IP { } return sortedIpAddr } + +// Checks whether the hostname is local +func IsHostnameLocal(hostname string) bool { + // Per https://en.wikipedia.org/wiki/Special-use_domain_name + tlds := []string{ + ".internal", + ".invalid", + ".local", + ".localhost", + ".onion", + ".test", + } + for _, tld := range tlds { + if strings.HasSuffix(hostname, tld) { + return true + } + } + return hostname == "localhost" +} diff --git a/proxy/lib/snowflake.go b/proxy/lib/snowflake.go index ceefab9..483a5e0 100644 --- a/proxy/lib/snowflake.go +++ b/proxy/lib/snowflake.go @@ -172,25 +172,6 @@ func isRemoteAddress(ip net.IP) bool { return !(util.IsLocal(ip) || ip.IsUnspecified() || ip.IsLoopback()) } -// Checks whether the hostname is local -func isHostnameLocal(hostname string) bool { - // Per https://en.wikipedia.org/wiki/Special-use_domain_name - tlds := []string{ - ".internal", - ".invalid", - ".local", - ".localhost", - ".onion", - ".test", - } - for _, tld := range tlds { - if strings.HasSuffix(hostname, tld) { - return true - } - } - return hostname == "localhost" -} - func genSessionID() string { buf := make([]byte, sessionIDLength) _, err := rand.Read(buf) @@ -690,7 +671,7 @@ func checkIsRelayURLAcceptable( } if !allowPrivateIPs { hostname := parsedRelayURL.Hostname() - if isHostnameLocal(hostname) { + if util.IsHostnameLocal(hostname) { return fmt.Errorf("rejected Relay URL: private hostnames are not allowed") } ipArray, err := net.LookupIP(hostname)