Merge branch 'bug40378' into 'main'

resolve host to IP to check if it's local before connecting

See merge request tpo/anti-censorship/pluggable-transports/snowflake!413
This commit is contained in:
Neel Chauhan 2025-09-20 21:12:54 -04:00
commit b882d9456b
3 changed files with 49 additions and 6 deletions

View file

@ -8,6 +8,7 @@ import (
"net/http"
"slices"
"sort"
"strings"
"github.com/pion/ice/v4"
"github.com/pion/sdp/v3"
@ -171,3 +172,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"
}