fix: treat IPv6 and shared-space addresses as internal (#357)

IsInternalIP returned false for unique-local and link-local IPv6, for
100.64.0.0/10, and for NAT64, 6to4, and Teredo addresses that carry an
internal IPv4 address.

Fixes #356
This commit is contained in:
Sash authored and GitHub committed 2026-10-13 11:00:26 +08:00
1 parent 747dddee8b
commit 835111c832
2 files changed
+54 -5

No files matched your search

+30
View File
@@ -95,6 +95,36 @@ func TestIsInternalIP(t *testing.T) {
}
}
func TestIsInternalIPCoversIPv6AndSharedSpace(t *testing.T) {
t.Parallel()
assert := internal.NewAssert(t, "TestIsInternalIPCoversIPv6AndSharedSpace")
ips := []net.IP{
net.ParseIP("fd12:3456:789a::1"),
net.ParseIP("fe80::1"),
net.ParseIP("100.64.0.1"),
net.ParseIP("100.127.255.255"),
net.ParseIP("100.63.255.255"),
net.ParseIP("100.128.0.1"),
net.ParseIP("::ffff:192.168.0.1"),
net.ParseIP("64:ff9b::a9fe:a9fe"),
net.ParseIP("64:ff9b::808:808"),
net.ParseIP("2002:7f00:1::1"),
net.ParseIP("2002:808:808::1"),
net.ParseIP("2001::80ff:fffe"),
net.ParseIP("2001:db8::1"),
}
expected := []bool{
true, true, true, true, false, false, true,
true, false, true, false, true, false,
}
for i := 0; i < len(ips); i++ {
assert.Equal(expected[i], IsInternalIP(ips[i]))
}
}
func TestGetIps(t *testing.T) {
ips := GetIps()
t.Log(ips)