Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion pkgs/lab-ops-hub/container/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,22 @@ def validate_crawl_url(raw):
if embedded is not None:
# Translation/mapped prefixes are judged by the IPv4 they embed,
# not by ipaddress's wholesale verdict on the prefix (#472).
if not embedded.is_global:
# is_global alone passes multicast and the 192.88.99.0/24 6to4
# relay anycast range, so refuse those explicitly (#476).
if (
not embedded.is_global
or embedded.is_multicast
or embedded in _IPV4_6TO4_RELAY_ANYCAST
):
raise ValueError(
f"refusing to crawl address {host} embedding non-public IPv4 {embedded}"
)
elif isinstance(ip, ipaddress.IPv4Address) and (
ip.is_multicast or ip in _IPV4_6TO4_RELAY_ANYCAST
):
# ipaddress reports multicast (224.0.0.0/4) and 192.88.99.0/24 as
# is_global; neither is a public unicast crawl target (#476).
raise ValueError(f"refusing to crawl non-public address {host}")
elif isinstance(ip, ipaddress.IPv6Address) and ip not in _GLOBAL_UNICAST_V6:
# ipaddress.is_global is True for any IPv6 address outside its
# narrow private list — multicast (ff00::/8), site-local
Expand All @@ -75,6 +87,8 @@ def validate_crawl_url(raw):

_NAT64_WELL_KNOWN = ipaddress.IPv6Network("64:ff9b::/96")

_IPV4_6TO4_RELAY_ANYCAST = ipaddress.IPv4Network("192.88.99.0/24")


def _embedded_ipv4(ip):
# Prefixes that embed an IPv4 address are judged by that address, the
Expand Down
13 changes: 9 additions & 4 deletions pkgs/lab-ops-hub/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,21 @@ function ipv4ToInt(host: string): number | null {
function ipv4IsGlobal(n: number): boolean {
const a = Math.floor(n / 2 ** 24);
const b = Math.floor(n / 2 ** 16) % 256;
const c = Math.floor(n / 2 ** 8) % 256;
const d = n % 256;
if (a === 0 || a === 10 || a === 127) return false; // "this" net, private, loopback
if (a === 100 && b >= 64 && b <= 127) return false; // CGNAT 100.64.0.0/10
if (a === 169 && b === 254) return false; // link-local (cloud metadata)
if (a === 172 && b >= 16 && b <= 31) return false; // private 172.16.0.0/12
if (a === 192 && b === 0) return false; // 192.0.0.0/24 + TEST-NET-1 192.0.2.0/24
if (a === 192 && b === 88) return false; // 6to4 relay anycast (deprecated)
// The /24 special ranges are keyed on the third octet (#476): keying
// them on b alone widened each to a /16 and refused public neighbours.
if (a === 192 && b === 0 && c === 0) return d === 9 || d === 10; // 192.0.0.0/24, except PCP/DNS anycast .9/.10
if (a === 192 && b === 0 && c === 2) return false; // TEST-NET-1 192.0.2.0/24
if (a === 192 && b === 88 && c === 99) return false; // 6to4 relay anycast 192.88.99.0/24 (deprecated)
if (a === 192 && b === 168) return false; // private
if (a === 198 && (b === 18 || b === 19)) return false; // benchmarking
if (a === 198 && b === 51) return false; // TEST-NET-2
if (a === 203 && b === 0) return false; // TEST-NET-3 203.0.113.0/24
if (a === 198 && b === 51 && c === 100) return false; // TEST-NET-2 198.51.100.0/24
if (a === 203 && b === 0 && c === 113) return false; // TEST-NET-3 203.0.113.0/24
if (a >= 224) return false; // multicast + reserved
return true;
}
Expand Down
31 changes: 31 additions & 0 deletions pkgs/lab-ops-hub/test/lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,37 @@ test("validateCrawlUrl judges NAT64 / 6to4 literals by their embedded IPv4 (#472
}
});

test("validateCrawlUrl agrees with the container validator on IPv4 ranges (#476)", () => {
// Multicast is not a public unicast target, and the /24 special ranges
// must not widen to /16s: their public neighbours stay crawlable.
const blocked = [
"http://224.0.0.1/", // multicast 224.0.0.0/4
"http://230.1.2.3/", // multicast
"http://239.255.255.255/", // multicast
"https://[::ffff:224.0.0.1]/", // IPv4-mapped multicast
"http://192.0.0.1/", // 192.0.0.0/24
"http://192.0.2.1/", // TEST-NET-1
"http://192.88.99.1/", // 6to4 relay anycast (deprecated)
"http://198.51.100.1/", // TEST-NET-2
"http://203.0.113.1/", // TEST-NET-3
];
for (const u of blocked) {
assert.equal(validateCrawlUrl(u).ok, false, u);
}
const allowed = [
"http://192.0.0.9/", // PCP anycast exception in 192.0.0.0/24
"http://192.0.0.10/", // DNS anycast exception in 192.0.0.0/24
"http://192.0.1.1/", // public neighbour of 192.0.0.0/24 + 192.0.2.0/24
"http://192.88.0.1/", // public neighbour of 192.88.99.0/24
"http://198.51.0.1/", // public neighbour of TEST-NET-2
"http://203.0.0.1/", // public neighbour of TEST-NET-3
"http://8.8.8.8/", // ordinary public
];
for (const u of allowed) {
assert.equal(validateCrawlUrl(u).ok, true, u);
}
});

test("validateCrawlUrl agrees with the container validator on special IPv6 ranges (#474)", () => {
// Verdicts must match the Python validator's suite case for case:
// multicast/reserved/site-local/SRv6 space is not global unicast, and
Expand Down
28 changes: 28 additions & 0 deletions pkgs/lab-ops-hub/test/test_container_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,34 @@ def test_judges_translation_prefixes_by_embedded_ipv4(self):
):
self.assertAccepted(url)

def test_agrees_with_worker_validator_on_ipv4_ranges(self):
# Verdicts must match the TypeScript validator's suite case for
# case (#476): ipaddress.is_global passes multicast and
# 192.88.99.0/24, and the /24 special ranges' public neighbours
# stay crawlable.
for url in (
"http://224.0.0.1/", # multicast 224.0.0.0/4
"http://230.1.2.3/", # multicast
"http://239.255.255.255/", # multicast
"https://[::ffff:224.0.0.1]/", # IPv4-mapped multicast
"http://192.0.0.1/", # 192.0.0.0/24
"http://192.0.2.1/", # TEST-NET-1
"http://192.88.99.1/", # 6to4 relay anycast (deprecated)
"http://198.51.100.1/", # TEST-NET-2
"http://203.0.113.1/", # TEST-NET-3
):
self.assertRefused(url)
for url in (
"http://192.0.0.9/", # PCP anycast exception in 192.0.0.0/24
"http://192.0.0.10/", # DNS anycast exception in 192.0.0.0/24
"http://192.0.1.1/", # public neighbour of the 192.0 /24s
"http://192.88.0.1/", # public neighbour of 192.88.99.0/24
"http://198.51.0.1/", # public neighbour of TEST-NET-2
"http://203.0.0.1/", # public neighbour of TEST-NET-3
"http://8.8.8.8/", # ordinary public
):
self.assertAccepted(url)

def test_agrees_with_worker_validator_on_special_ipv6_ranges(self):
# Verdicts must match the TypeScript validator's suite case for
# case (#474): ipaddress.is_global alone passes multicast,
Expand Down
Loading