Browse Source

fix(urllib): treat special-purpose IPv6 ranges as non-public

IsNonPublicIP blocked the IPv4 benchmarking range 198.18.0.0/15 but
classified several IPv6 blocks that are not globally reachable as
public:

- 100::/64, discard-only (RFC 6666)
- 2001:2::/48, benchmarking (RFC 5180)
- 2001:db8::/32 and 3fff::/20, documentation (RFC 3849, RFC 9637)
- 5f00::/16, SRv6 SIDs (RFC 9602)

Add them to the list of non-public prefixes used by the fetcher and
integration client private-network guards.
Frédéric Guillot 1 ngày trước cách đây
mục cha
commit
b2058ff868

+ 5 - 0
internal/urllib/url.go

@@ -25,6 +25,11 @@ var (
 		netip.MustParsePrefix("240.0.0.0/4"),     // Reserved and limited broadcast (RFC 6890).
 		netip.MustParsePrefix("240.0.0.0/4"),     // Reserved and limited broadcast (RFC 6890).
 		netip.MustParsePrefix("::/96"),           // Deprecated IPv4-compatible IPv6 addresses (RFC 4291).
 		netip.MustParsePrefix("::/96"),           // Deprecated IPv4-compatible IPv6 addresses (RFC 4291).
 		netip.MustParsePrefix("::ffff:0:0:0/96"), // Deprecated IPv4-translated IPv6 addresses (RFC 2765).
 		netip.MustParsePrefix("::ffff:0:0:0/96"), // Deprecated IPv4-translated IPv6 addresses (RFC 2765).
+		netip.MustParsePrefix("100::/64"),        // Discard-only (RFC 6666).
+		netip.MustParsePrefix("2001:2::/48"),     // Benchmarking (RFC 5180).
+		netip.MustParsePrefix("2001:db8::/32"),   // Documentation (RFC 3849).
+		netip.MustParsePrefix("3fff::/20"),       // Documentation (RFC 9637).
+		netip.MustParsePrefix("5f00::/16"),       // SRv6 SIDs (RFC 9602).
 		netip.MustParsePrefix("fec0::/10"),
 		netip.MustParsePrefix("fec0::/10"),
 	}
 	}
 )
 )

+ 10 - 0
internal/urllib/url_test.go

@@ -292,6 +292,13 @@ func TestIsNonPublicIP(t *testing.T) {
 		{"loopback IPv6", "::1", true},
 		{"loopback IPv6", "::1", true},
 		{"multicast IPv6", "ff02::1", true},
 		{"multicast IPv6", "ff02::1", true},
 		{"site-local IPv6", "fec0::1", true},
 		{"site-local IPv6", "fec0::1", true},
+		{"discard-only IPv6", "100::1", true},
+		{"benchmarking IPv6", "2001:2::1", true},
+		{"benchmarking IPv6 upper bound", "2001:2:0:ffff:ffff:ffff:ffff:ffff", true},
+		{"documentation IPv6", "2001:db8::1", true},
+		{"documentation IPv6 3fff::/20", "3fff::1", true},
+		{"documentation IPv6 3fff::/20 upper bound", "3fff:fff:ffff:ffff:ffff:ffff:ffff:ffff", true},
+		{"SRv6 SID IPv6", "5f00::1", true},
 		{"NAT64 loopback IPv4", "64:ff9b::7f00:1", true},
 		{"NAT64 loopback IPv4", "64:ff9b::7f00:1", true},
 		{"NAT64 link-local IPv4", "64:ff9b::a9fe:a9fe", true},
 		{"NAT64 link-local IPv4", "64:ff9b::a9fe:a9fe", true},
 		{"NAT64 local-use private IPv4", "64:ff9b:1::a00:1", true},
 		{"NAT64 local-use private IPv4", "64:ff9b:1::a00:1", true},
@@ -312,6 +319,9 @@ func TestIsNonPublicIP(t *testing.T) {
 		{"public IPv4 after this network", "1.0.0.1", false},
 		{"public IPv4 after this network", "1.0.0.1", false},
 		{"public IPv4 before reserved", "223.255.255.254", false},
 		{"public IPv4 before reserved", "223.255.255.254", false},
 		{"public IPv6", "2001:4860:4860::8888", false},
 		{"public IPv6", "2001:4860:4860::8888", false},
+		{"AMT IPv6 after benchmarking", "2001:3::1", false},
+		{"public IPv6 after documentation", "2001:db9::1", false},
+		{"public IPv6 after 3fff::/20", "3fff:1000::1", false},
 		{"NAT64 public IPv4", "64:ff9b::5db8:d822", false},
 		{"NAT64 public IPv4", "64:ff9b::5db8:d822", false},
 		{"NAT64 local-use public IPv4", "64:ff9b:1::5db8:d822", false},
 		{"NAT64 local-use public IPv4", "64:ff9b:1::5db8:d822", false},
 		{"6to4 public IPv4", "2002:5db8:d822::1", false},
 		{"6to4 public IPv4", "2002:5db8:d822::1", false},