fix(engine): render refusals name the address an IPv6-mapped or NAT64 host carries (#7802)

* fix(engine): render refusals name the address an IPv6-mapped or NAT64 host carries

* chore(engine): raise the engine size budget for bounded downloads and refusal classes
This commit is contained in:
Miguel Ángel
2026-11-14 23:02:07 -05:00
committed by GitHub
parent 03e6a1a180
commit 04ee926d97
4 changed files with 21 additions and 3 deletions
@@ -193,6 +193,11 @@ describe("refusal class", () => {
["metadata.google.internal", "internal-name"],
["localhost", "internal-name"],
["[::1]", "ipv6"],
["[::ffff:a9fe:a9fe]", "link-local"],
["[::ffff:169.254.169.254]", "link-local"],
["[64:ff9b::a00:1]", "private"],
["[::ffff:808:808]", "ipv6"],
["[2001:db8::1]", "ipv6"],
])("names %s as %s", (host, hostClass) =>
expect(refusedClass(() => assertPublicHostname(host))).toBe(hostClass),
);
@@ -6,6 +6,7 @@ import { request as httpRequest, type IncomingMessage, type ClientRequest } from
import { request as httpsRequest, type RequestOptions } from "node:https";
import { connect as tlsConnect } from "node:tls";
import {
carriedIPv4,
ipv4HostClass,
isBlockedNetworkHost,
type NonPublicIPv4Class,
@@ -45,13 +46,21 @@ function refusedIPv4Class(address: string): RefusedHostClass {
return hostClass === "public" ? "reserved" : hostClass;
}
function refusedIPv6Class(address: string): RefusedHostClass {
const ipv4 = carriedIPv4(address);
const hostClass = ipv4 === undefined ? "public" : ipv4HostClass(ipv4);
return hostClass === "public" ? "ipv6" : hostClass;
}
export function assertPublicHostname(hostname: string): string {
const host = hostname.toLowerCase().replace(/\.$/, "");
if (isIP(host) === 4) {
if (!isPublicIPv4(host)) throw new NonPublicHostError(PUBLIC_IPV4, refusedIPv4Class(host));
return host;
}
if (host.startsWith("[")) throw new NonPublicHostError(PUBLIC_HOSTNAME, "ipv6");
if (host.startsWith("[")) {
throw new NonPublicHostError(PUBLIC_HOSTNAME, refusedIPv6Class(host.slice(1, -1)));
}
if (
!host.includes(".") ||
!/^[a-z0-9.-]+$/.test(host) ||
+5 -1
View File
@@ -100,6 +100,10 @@ function embeddedIPv4(address: string): string | undefined {
return [high! >> 8, high! & 255, low! >> 8, low! & 255].join(".");
}
export function carriedIPv4(address: string): string | undefined {
return MAPPED_OR_NAT64_IPV6.check(address, "ipv6") ? embeddedIPv4(address) : undefined;
}
const NON_PUBLIC_IPV6_ADDRESSES = new BlockList();
for (const [network, prefix] of [
["::", 128],
@@ -131,7 +135,7 @@ export function isBlockedNetworkHost(hostname: string): boolean {
if (addressType === 0) return false;
if (inOperatorRange(h, addressType === 4 ? "ipv4" : "ipv6")) return true;
if (addressType === 6 && MAPPED_OR_NAT64_IPV6.check(h, "ipv6")) {
const ipv4 = embeddedIPv4(h);
const ipv4 = carriedIPv4(h);
return ipv4 === undefined || isBlockedNetworkHost(ipv4);
}
return addressType === 4
+1 -1
View File
@@ -13,7 +13,7 @@
},
"@hyperframes/engine": {
"packed": 490452,
"unpacked": 1643000
"unpacked": 1742862
},
"@hyperframes/gcp-cloud-run": {
"packed": 49412,