Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.
fix(agent-computer): refuse the metadata address written through the NAT64 prefix (#745)
Charan Rathore2235ca53a859
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d955a295..3e8e0745 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,14 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.## Unreleased+### A computer refuses the cloud metadata address written through the NAT64 prefix++A Bot's computer is now refused the cloud metadata address when it is written through the NAT64+prefix (`64:ff9b::a9fe:a9fe` is 169.254.169.254), under every network policy including allow-all.+Only the plain and IPv4-mapped spellings were refused, so on a network with a NAT64 gateway the+metadata endpoint was one rewrite away. Browsing already refused this spelling; the computer's+filter now agrees.+### `?sslmode=require` on `DATABASE_URL` now connects to a managed databaseA deployment pointed at RDS, Cloud SQL or Azure Database could not start. The server sentdiff --git a/agent-computer/src/egress.ts b/agent-computer/src/egress.tsindex bbd1192a..a1fe5635 100644--- a/agent-computer/src/egress.ts+++ b/agent-computer/src/egress.ts@@ -371,11 +371,39 @@ const alwaysDenied = new BlockList();for (const [address, prefix, family] of ALWAYS_DENIED)alwaysDenied.addSubnet(address, prefix, family);-/** True for a metadata or link-local address, including one written as IPv4-mapped IPv6. */+/** The NAT64 well-known prefix. On a network with a NAT64 gateway it reaches the IPv4 address in its last 32 bits. */+const nat64 = new BlockList();+nat64.addSubnet("64:ff9b::", 96, "ipv6");++/** The IPv4 address a NAT64 address carries, or null when it is not one. */+function nat64Ipv4(address: string): string | null {+ if (isIP(address) !== 6 || !nat64.check(address, "ipv6")) return null;+ // Let URL spell it in hex groups (`64:ff9b::1.2.3.4` becomes `64:ff9b::102:304`), then expand `::`+ // so the last two groups are the IPv4 address however the address was written.+ const hex = new URL(`http://[${address}]/`).hostname.slice(1, -1);+ const [head = "", tail] = hex.split("::");+ const groups = (part: string) => (part ? part.split(":") : []);+ const all =+ tail === undefined+ ? groups(head)+ : [+ ...groups(head),+ ...Array(8 - groups(head).length - groups(tail).length).fill("0"),+ ...groups(tail),+ ];+ const high = Number.parseInt(all[6] ?? "0", 16);+ const low = Number.parseInt(all[7] ?? "0", 16);+ return [high >> 8, high & 255, low >> 8, low & 255].join(".");+}++/**+ * True for a metadata or link-local address, including one written as IPv4-mapped IPv6 or reached+ * through the NAT64 prefix.+ */export function isAlwaysDenied(addressInput: string): boolean {const address = normalizeHost(addressInput);const mapped = /^::ffff:(\d+\.\d+\.\d+\.\d+)$/i.exec(address)?.[1];- const candidate = mapped ?? address;+ const candidate = mapped ?? nat64Ipv4(address) ?? address;const version = isIP(candidate);if (version === 0) return false;return alwaysDenied.check(candidate, version === 4 ? "ipv4" : "ipv6");diff --git a/agent-computer/tests/egress-policy.test.ts b/agent-computer/tests/egress-policy.test.tsindex b9bc5415..9a707900 100644--- a/agent-computer/tests/egress-policy.test.ts+++ b/agent-computer/tests/egress-policy.test.ts@@ -278,6 +278,9 @@ describe("the filter proxy", () => {"100.100.100.200:80","[::ffff:169.254.169.254]:80","[fe80::1]:80",+ // The NAT64 prefix reaches the IPv4 address in its last 32 bits.+ "[64:ff9b::a9fe:a9fe]:80",+ "[64:ff9b::6464:64c8]:80",]) {expect(await connectThrough(filter.port, target, "sales", secret),