Files
hyperframes/packages/engine/src/utils/networkPolicy.ts
T
Jerrai 1116077dab fix(cli): capture treats only 192.0.0.0/24 and 192.0.2.0/24 as reserved, via one shared list (#6853)
* fix(cli): capture's public-address check uses the engine's list; 192.0/16 is not all reserved

Only 192.0.0.0/24 and 192.0.2.0/24 are special-use. The capture proxy blocked all of
192.0.0.0/16, so sites on WordPress VIP (192.0.64.0/18, e.g. nasa.gov at 192.0.66.108)
failed every capture with net::ERR_TUNNEL_CONNECTION_FAILED. isPublicIPv4 now reads the
engine's isBlockedNetworkHost, so capture and asset downloads share one list.

— Jerrai (cutroom-debug)

* refactor(engine): one special-use network list, in a light subpath capture imports

Importing all of @hyperframes/engine into capture's publicNetwork slowed the lookup child's
start-up past publicNetwork.process.test's 6 s mid-lookup exit. The list and
isBlockedNetworkHost move to engine/src/utils/networkPolicy.ts, exported as
@hyperframes/engine/network-policy; urlDownloader and the engine index read it there.

— Jerrai (cutroom-debug)

* test(engine): pin 192.0.0.0/24 and 192.0.2.0/24 blocked, the rest of 192.0/16 public

— Jerrai (cutroom-debug)

* fix(cli): alias the engine's network-policy subpath in the CLI bundle

esbuild's root alias rewrote @hyperframes/engine/network-policy to src/index.ts/network-policy;
the exact-subpath list now carries it. The publicNetwork docstring is cut to keep the file's
comment share under its base.

— Jerrai (cutroom-debug)
2026-10-30 16:21:34 +00:00

57 lines
1.5 KiB
TypeScript

import { BlockList, isIP } from "node:net";
// The one list of special-use networks: asset downloads and the capture proxy both read it, so a site one can reach the other can too.
const NON_PUBLIC_IPV4_ADDRESSES = new BlockList();
for (const [network, prefix] of [
["0.0.0.0", 8],
["10.0.0.0", 8],
["100.64.0.0", 10],
["127.0.0.0", 8],
["169.254.0.0", 16],
["172.16.0.0", 12],
["192.0.0.0", 24],
["192.0.2.0", 24],
["192.88.99.0", 24],
["192.168.0.0", 16],
["198.18.0.0", 15],
["198.51.100.0", 24],
["203.0.113.0", 24],
["224.0.0.0", 4],
["240.0.0.0", 4],
] as const) {
NON_PUBLIC_IPV4_ADDRESSES.addSubnet(network, prefix, "ipv4");
}
const NON_PUBLIC_IPV6_ADDRESSES = new BlockList();
for (const [network, prefix] of [
["::", 128],
["::1", 128],
["::ffff:0:0", 96],
["fc00::", 7],
["fe80::", 10],
["fec0::", 10],
["ff00::", 8],
["2001:db8::", 32],
] as const) {
NON_PUBLIC_IPV6_ADDRESSES.addSubnet(network, prefix, "ipv6");
}
/** Literal-host policy shared by rendering and capture; DNS resolution remains trusted. */
export function isBlockedNetworkHost(hostname: string): boolean {
const h = hostname
.toLowerCase()
.replace(/\.$/, "")
.replace(/^\[|\]$/g, "");
if (
h === "localhost" ||
h.endsWith(".localhost") ||
h.endsWith(".local") ||
h.endsWith(".internal")
)
return true;
const addressType = isIP(h);
if (addressType === 0) return false;
return addressType === 4
? NON_PUBLIC_IPV4_ADDRESSES.check(h, "ipv4")
: NON_PUBLIC_IPV6_ADDRESSES.check(h, "ipv6");
}