MCPcopy Create free account
hub / github.com/gogs/gogs / IsBlockedLocalHostname

Function IsBlockedLocalHostname

internal/netutil/netutil.go:49–68  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

47// network address that is implicitly blocked (i.e. not exempted from the
48// allowlist).
49func 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}

Callers 5

runSyncMethod · 0.92
deliverMethod · 0.92
ParseRemoteAddrFunction · 0.92
validateWebhookFunction · 0.92
TestIsLocalHostnameFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestIsLocalHostnameFunction · 0.68