Skip to content

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-endpoint): correctly handle bracketed IPv6 hosts with port in allowed list (#330)

Felix-Ayusha3f1284eb475
diff --git a/server/src/agents/endpoint.ts b/server/src/agents/endpoint.ts
index 1a7656b3..39c979d4 100644
--- a/server/src/agents/endpoint.ts
+++ b/server/src/agents/endpoint.ts
@@ -49,7 +49,7 @@ function namedAsAllowed(
return false;
}
const hostname = url.hostname.toLowerCase().replace(/^\[|\]$/g, "");
- const host = url.host.toLowerCase().replace(/^\[/, "").replace(/\]/, "");
+ const host = url.port ? `${hostname}:${url.port}` : hostname;
return allowedHosts.has(host) || allowedHosts.has(hostname);
}
diff --git a/server/src/config.ts b/server/src/config.ts
index aa9d89eb..2779cf89 100644
--- a/server/src/config.ts
+++ b/server/src/config.ts
@@ -636,11 +636,25 @@ function agentEndpointAllowedHosts(
`AGENT_ENDPOINT_ALLOWED_HOSTS entry "${entry}" must name one host. Patterns are not accepted: list each address instead.`,
);
}
- hosts.add(host.replace(/^\[/, "").replace(/\]$/, ""));
+ hosts.add(normalizeAllowedHost(host));
}
return hosts;
}
+function normalizeAllowedHost(host: string): string {
+ // IPv6 is bracketed as [host] or [host]:port. Strip the brackets and keep the port.
+ if (host.startsWith("[")) {
+ const close = host.indexOf("]");
+ if (close === -1) return host.replace(/^\[/, "").replace(/\]$/, "");
+ const ipv6 = host.slice(1, close).toLowerCase();
+ const rest = host.slice(close + 1);
+ if (!rest) return ipv6;
+ if (rest.startsWith(":")) return `${ipv6}${rest.toLowerCase()}`;
+ return `${ipv6}${rest.toLowerCase()}`;
+ }
+ return host;
+}
+
function privateHostsAllowed(environment: Environment): boolean {
if (optional(environment, "AGENT_COMPUTER_ALLOW_PRIVATE_HOSTS") !== "true") {
return false;