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.
Reach IPv6 addresses over plain HTTP and through an IPv6 upstream in the egress filter (#710)
Omkar Chebalee8993eab7de0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1a011346..cedda2c6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -50,6 +50,13 @@ the sentence a malformed range already got. A rule like this saved earlier match- An existing Windows clone checks text files out with LF only after`git rm -r --cached . && git reset --hard` on a clean tree.+### The egress filter reaches an IPv6 upstream proxy and asks it for IPv6 hosts correctly++An upstream proxy configured at an IPv6 address, such as `http://[fd00::1]:3128`, could not be+reached: the filter handed the address to the socket with its brackets, and the socket looked it up+as a name. A `CONNECT` to an IPv6 host was also sent to the upstream without the brackets an+authority needs, as `CONNECT ::1:443`. Both now work.+### The Helm chart configures Slack, Teams, text messages, push, SCIM, inbound email and OpenTelemetryThese settings had no chart values and could only be passed through `config.extraEnv`. They now havediff --git a/agent-computer/src/egress.ts b/agent-computer/src/egress.tsindex 14a961a2..bbd1192a 100644--- a/agent-computer/src/egress.ts+++ b/agent-computer/src/egress.ts@@ -609,7 +609,7 @@ function upstreamAddress(upstream: Egress): { host: string; port: number } {? upstream.server: `http://${upstream.server}`,);- return { host: url.hostname, port: Number(url.port || 80) };+ return { host: unbracketed(url.hostname), port: Number(url.port || 80) };}function refuse(socket: Socket, reason: string) {@@ -640,8 +640,10 @@ function tunnel(const via = upstreamAddress(upstream);const socket = connect(via.port, via.host, () => {const auth = basic(upstream.username, upstream.password);+ // An IPv6 host is bracketed in an authority: `CONNECT ::1:443` cannot be read.+ const host = isIP(target.host) === 6 ? `[${target.host}]` : target.host;socket.write(- `CONNECT ${target.host}:${target.port} HTTP/1.1\r\nHost: ${target.host}:${target.port}\r\n${auth ? `Proxy-Authorization: ${auth}\r\n` : ""}\r\n`,+ `CONNECT ${host}:${target.port} HTTP/1.1\r\nHost: ${host}:${target.port}\r\n${auth ? `Proxy-Authorization: ${auth}\r\n` : ""}\r\n`,);});let head = Buffer.alloc(0);@@ -810,6 +812,11 @@ export async function stopEgressFilter(): Promise<void> {}}+/** `URL.hostname` keeps an IPv6 address's brackets, and a socket given them looks the name up. */+function unbracketed(hostname: string): string {+ return hostname.replace(/^\[|\]$/g, "");+}+function splitHostPort(value: string): [string, string] {if (value.startsWith("[")) {const end = value.indexOf("]");@@ -839,7 +846,7 @@ function forwardPlain({// Reached through the checked addresses only (see `pinnedTo`): a second lookup could answer// something else. The Host header still names the site.- host: via ? via.host : target.hostname,+ host: via ? via.host : unbracketed(target.hostname),port: via ? via.port : Number(target.port || 80),...(via ? {} : (pinnedTo(addresses) as object)),method: request.method,diff --git a/agent-computer/tests/egress-policy.test.ts b/agent-computer/tests/egress-policy.test.tsindex d5baa4bc..b9bc5415 100644--- a/agent-computer/tests/egress-policy.test.ts+++ b/agent-computer/tests/egress-policy.test.ts@@ -1,6 +1,6 @@import { afterEach, describe, expect, test } from "bun:test";-import { createServer } from "node:http";-import { connect } from "node:net";+import { createServer, type IncomingMessage, type Server } from "node:http";+import { connect, type Socket } from "node:net";import {egressDecision,egressFor,@@ -417,6 +417,83 @@ describe("the filter proxy", () => {}});+ /** Send one raw request through the filter as Bot "sales" and read the whole answer. */+ function throughFilter(filterPort: number, request: string) {+ const secret = egressFor("sales", {})?.password;+ const auth = `Proxy-Authorization: Basic ${Buffer.from(`sales:${secret}`).toString("base64")}\r\n`;+ return new Promise<string>((resolve, reject) => {+ const socket = connect(filterPort, "127.0.0.1", () => {+ socket.write(request.replace("\r\n\r\n", `\r\n${auth}\r\n`));+ });+ let seen = "";+ socket.setTimeout(5_000, () => socket.destroy(new Error("timed out")));+ socket.on("data", (chunk) => {+ seen += chunk.toString();+ if (seen.includes("reached")) socket.end();+ });+ socket.on("end", () => resolve(seen));+ socket.on("error", reject);+ });+ }++ async function listenOnIpv6Loopback(server: Server) {+ await new Promise<void>((resolve) => server.listen(0, "::1", resolve));+ const address = server.address();+ return typeof address === "object" && address ? address.port : 0;+ }++ test("a plain-HTTP request to an IPv6 address is forwarded, not looked up as a name", async () => {+ const server = createServer((_request, response) =>+ response.end("reached"),+ );+ const port = await listenOnIpv6Loopback(server);+ const filter = await startEgressFilter({ env: {} });+ setEgressPolicy("sales", { mode: "allow_all", rules: [] });+ try {+ const answer = await throughFilter(+ filter.port,+ `GET http://[::1]:${port}/ HTTP/1.1\r\nHost: [::1]:${port}\r\nConnection: close\r\n\r\n`,+ );+ expect(answer).toContain("reached");+ } finally {+ await new Promise<void>((resolve) => server.close(() => resolve()));+ }+ });++ test("an upstream proxy at an IPv6 address is reached, and is asked for an IPv6 host in brackets", async () => {+ const asked: string[] = [];+ const upstream = createServer((request, response) => {+ asked.push(request.url ?? "");+ response.end("reached");+ });+ upstream.on("connect", (request: IncomingMessage, socket: Socket) => {+ asked.push(request.url ?? "");+ socket.end("HTTP/1.1 200 Connection Established\r\n\r\nreached");+ });+ const port = await listenOnIpv6Loopback(upstream);+ const filter = await startEgressFilter({+ env: { EGRESS_PROXY_DEFAULT: `http://[::1]:${port}` },+ });+ setEgressPolicy("sales", { mode: "allow_all", rules: [] });+ try {+ expect(+ await throughFilter(+ filter.port,+ "GET http://site.example.test/ HTTP/1.1\r\nHost: site.example.test\r\nConnection: close\r\n\r\n",+ ),+ ).toContain("reached");+ expect(+ await throughFilter(+ filter.port,+ "CONNECT [2001:db8::1]:443 HTTP/1.1\r\nHost: [2001:db8::1]:443\r\n\r\n",+ ),+ ).toContain("reached");+ expect(asked).toEqual(["http://site.example.test/", "[2001:db8::1]:443"]);+ } finally {+ await new Promise<void>((resolve) => upstream.close(() => resolve()));+ }+ });+test("the shell is pointed at the filter, and this process is not", async () => {const { egressShellEnvironment } = await import("../src/egress");const before = process.env.HTTP_PROXY;