MCPcopy Create free account
hub / github.com/authorizerdev/authorizer / isPrivateIP

Function isPrivateIP

internal/validators/endpoint.go:44–71  ·  view source on GitHub ↗

isPrivateIP returns true if the IP is in a private, loopback, link-local, or otherwise non-routable range.

(ip net.IP)

Source from the content-addressed store, hash-verified

42// isPrivateIP returns true if the IP is in a private, loopback, link-local,
43// or otherwise non-routable range.
44func isPrivateIP(ip net.IP) bool {
45 privateRanges := []struct {
46 network *net.IPNet
47 }{
48 {parseCIDR("10.0.0.0/8")},
49 {parseCIDR("172.16.0.0/12")},
50 {parseCIDR("192.168.0.0/16")},
51 {parseCIDR("127.0.0.0/8")},
52 {parseCIDR("169.254.0.0/16")}, // link-local
53 {parseCIDR("100.64.0.0/10")}, // CGN
54 {parseCIDR("::1/128")}, // IPv6 loopback
55 {parseCIDR("fc00::/7")}, // IPv6 ULA
56 {parseCIDR("fe80::/10")}, // IPv6 link-local
57 {parseCIDR("0.0.0.0/8")}, // "this" network
58 {parseCIDR("192.0.0.0/24")}, // IETF protocol assignments
59 {parseCIDR("192.0.2.0/24")}, // TEST-NET-1
60 {parseCIDR("198.51.100.0/24")}, // TEST-NET-2
61 {parseCIDR("203.0.113.0/24")}, // TEST-NET-3
62 {parseCIDR("224.0.0.0/4")}, // multicast
63 {parseCIDR("240.0.0.0/4")}, // reserved
64 }
65 for _, r := range privateRanges {
66 if r.network.Contains(ip) {
67 return true
68 }
69 }
70 return false
71}
72
73func parseCIDR(cidr string) *net.IPNet {
74 _, network, _ := net.ParseCIDR(cidr)

Callers 2

SafeHTTPClientFunction · 0.85
ValidateEndpointURLFunction · 0.85

Calls 1

parseCIDRFunction · 0.85

Tested by

no test coverage detected