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(computer): refuse names under .localhost as the loopback they are (#743)

Charan Rathorefa6465861cf7
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 65aa4ea3..18b32c3e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,11 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.
## Unreleased
+- A Bot's browser is now refused names under `.localhost`, such as `http://admin.localhost:5432`, the
+ same as bare `localhost`. The whole `.localhost` zone is loopback and Chromium resolves it without
+ DNS, but only the exact name `localhost` was on the refused list, so a deployment that had not opted
+ into private hosts could still be pointed at its own services this way.
+
- `OPENBOT_SINGLE_USER` is now refused with a public name that starts with `127.`, such as
`https://127.example.com` or `https://127.0.0.1.nip.io`. The check for a loopback address matched
any host beginning `127.`, so a public address like that read as this machine and the no-sign-in
@@ -25,6 +30,7 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.
download budget, so a computer reached through a proxy that re-chunks left a transfer running and a
connection checked out of the pool on every attempt.
+
- A conversation title cut at 60 characters no longer ends in half an emoji. `slice` counts UTF-16
code units and an emoji is two of them, so a title cut between the halves rendered a replacement
character in the sidebar and the picker, where the character itself should have been.
diff --git a/server/src/computer/target.ts b/server/src/computer/target.ts
index 0304b9a9..e6f435e3 100644
--- a/server/src/computer/target.ts
+++ b/server/src/computer/target.ts
@@ -61,6 +61,17 @@ const INTERNAL_HOSTNAMES = new Set([
"::1",
]);
+/**
+ * Any name under `.localhost`.
+ *
+ * RFC 6761 reserves the whole `.localhost` zone for loopback, and Chromium resolves `app.localhost`
+ * to 127.0.0.1 without asking DNS, so `http://admin.localhost:5432` reaches the same service as
+ * `http://localhost:5432`. The exact-name list above only holds the bare `localhost`.
+ */
+function isLocalhostName(hostname: string): boolean {
+ return hostname === "localhost" || hostname.endsWith(".localhost");
+}
+
export type TargetVerdict =
| { allowed: true; url: string }
| { allowed: false; reason: string };
@@ -272,6 +283,7 @@ export function checkNavigationTarget(
if (
INTERNAL_HOSTNAMES.has(hostname) ||
+ isLocalhostName(hostname) ||
isPrivateIpv4(hostname) ||
isPrivateIpv6(hostname)
) {
diff --git a/server/tests/computer-target.test.ts b/server/tests/computer-target.test.ts
index 5509a629..20ef0c53 100644
--- a/server/tests/computer-target.test.ts
+++ b/server/tests/computer-target.test.ts
@@ -16,6 +16,11 @@ describe("navigation targets", () => {
// the whole reason a browser running inside the deployment needs a floor under it.
test.each([
["http://localhost:5432", "loopback by name"],
+ ["http://admin.localhost:5432", "loopback by a name under .localhost"],
+ [
+ "http://a.b.localhost./",
+ "loopback by a deep .localhost name with a root dot",
+ ],
["http://127.0.0.1/admin", "loopback by address"],
["http://10.0.0.5/", "RFC1918 10/8"],
["http://192.168.1.1/", "RFC1918 192.168/16"],