Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Fix browser proxy review findings

jdfcb09c84ddcd
diff --git a/server/browser/chrome/launcher.test.ts b/server/browser/chrome/launcher.test.ts
index 6463e4b16e..01f167d4c0 100644
--- a/server/browser/chrome/launcher.test.ts
+++ b/server/browser/chrome/launcher.test.ts
@@ -99,6 +99,20 @@ describe("the Chrome launcher", () => {
expect(readFileSync(chrome.path, "utf8")).toContain("'--lang=ko-KR'");
});
+ it("refreshes the launcher language between env and a cached ready call", async () => {
+ const machine = mac({ env: { LANG: "en_US.UTF-8" } });
+ let appLanguage = "en";
+ const chrome = launcher(machine, { language: () => appLanguage });
+ await chrome.ready(headless(chrome.path));
+ expect(readFileSync(chrome.path, "utf8")).toContain("'--lang=en'");
+
+ expect(chrome.env()).toEqual({ AGENT_BROWSER_EXECUTABLE_PATH: chrome.path, AGENT_BROWSER_HIDE_SCROLLBARS: "0" });
+ appLanguage = "ko";
+ await chrome.ready(headless(chrome.path));
+
+ expect(readFileSync(chrome.path, "utf8")).toContain("'--lang=ko-KR'");
+ });
+
it("reads the identity again after Chrome updated itself in place", async () => {
const machine = mac();
const calibrate = vi.fn(async () => identity("155"));
diff --git a/server/browser/chrome/launcher.ts b/server/browser/chrome/launcher.ts
index bb1ab8cb86..d16afa6f4d 100644
--- a/server/browser/chrome/launcher.ts
+++ b/server/browser/chrome/launcher.ts
@@ -202,6 +202,7 @@ export class ChromeLauncher implements BrowserLaunch {
: "Getting the browser ready. Try again in a moment.");
}
if (this.state.kind === "failed") throw new Error(`Chrome could not be started (${this.state.reason}). Try again: your next browser call uses the built-in browser.`);
+ this.followLanguage();
}
async started(session: string, spec: LaunchSpec): Promise<void> {
diff --git a/server/browser/egress/gate.test.ts b/server/browser/egress/gate.test.ts
index fd991cdfa8..ea88141372 100644
--- a/server/browser/egress/gate.test.ts
+++ b/server/browser/egress/gate.test.ts
@@ -230,6 +230,94 @@ describe("egress gate", () => {
await new Promise<void>((resolve) => upstream.close(() => resolve()));
});
+ it("preserves destination bytes sent with a SOCKS5 CONNECT reply", async () => {
+ const first = Buffer.from("first-bytes");
+ const upstream = NodeNet.createServer((socket) => {
+ let data = Buffer.alloc(0);
+ let greeted = false;
+ socket.on("data", (chunk) => {
+ data = Buffer.concat([data, chunk]);
+ if (!greeted && data.length >= 3) {
+ data = data.subarray(3);
+ greeted = true;
+ socket.write(Buffer.from([5, 0]));
+ }
+ if (greeted && data.length >= 10 && data[0] === 5 && data[1] === 1) {
+ socket.write(Buffer.concat([Buffer.from([5, 0, 0, 1, 0, 0, 0, 0, 0, 0]), first]));
+ socket.removeAllListeners("data");
+ }
+ });
+ });
+ await new Promise<void>((resolve) => upstream.listen(0, "127.0.0.1", resolve));
+ const proxyPort = (upstream.address() as NodeNet.AddressInfo).port;
+ const opened = await openGate({
+ decide: async () => null,
+ resolve: async () => [{ address: "93.184.215.14", family: 4 }],
+ upstreamProxy: () => ({ host: "127.0.0.1", port: proxyPort }),
+ });
+ gates.push(opened);
+ const socket = NodeNet.connect(opened.port, "127.0.0.1");
+ socket.on("error", () => {});
+ let received = Buffer.alloc(0);
+ const response = new Promise<Buffer>((resolve) => {
+ socket.on("data", (chunk) => {
+ received = Buffer.concat([received, chunk]);
+ if (received.includes(first)) resolve(received);
+ });
+ });
+ await new Promise<void>((resolve) => socket.once("connect", resolve));
+ socket.write(Buffer.concat([Buffer.from([5, 1, 0, 5, 1, 0]), domainTarget("example.com", 443)]));
+ const bytes = await response;
+ expect(bytes.subarray(0, 2)).toEqual(Buffer.from([5, 0]));
+ expect(bytes.subarray(2, 12)).toEqual(Buffer.from([5, 0, 0, 1, 0, 0, 0, 0, 0, 0]));
+ expect(bytes.subarray(12)).toEqual(first);
+ socket.destroy();
+ await new Promise<void>((resolve) => upstream.close(() => resolve()));
+ });
+
+ it("proxies checked public answers in mixed DNS results and keeps permitted local answers direct", async () => {
+ const requested: string[] = [];
+ const proxy = NodeNet.createServer((socket) => {
+ let data = Buffer.alloc(0);
+ let greeted = false;
+ socket.on("data", (chunk) => {
+ data = Buffer.concat([data, chunk]);
+ if (!greeted && data.length >= 3) {
+ data = data.subarray(3);
+ greeted = true;
+ socket.write(Buffer.from([5, 0]));
+ }
+ if (greeted && data.length >= 10 && data[0] === 5 && data[1] === 1) {
+ requested.push([...data.subarray(4, 8)].join("."));
+ socket.write(Buffer.from([5, 5, 0, 1, 0, 0, 0, 0, 0, 0]));
+ socket.removeAllListeners("data");
+ }
+ });
+ });
+ const local = NodeNet.createServer((socket) => socket.pipe(socket));
+ await new Promise<void>((resolve) => proxy.listen(0, "127.0.0.1", resolve));
+ await new Promise<void>((resolve) => local.listen(0, "127.0.0.1", resolve));
+ const proxyPort = (proxy.address() as NodeNet.AddressInfo).port;
+ const localPort = (local.address() as NodeNet.AddressInfo).port;
+ const opened = await openGate({
+ decide: async () => null,
+ resolve: async () => [{ address: "93.184.215.14", family: 4 }, { address: "127.0.0.1", family: 4 }],
+ upstreamProxy: () => ({ host: "127.0.0.1", port: proxyPort }),
+ });
+ gates.push(opened);
+ const { code, socket } = await connectThrough(opened.port, domainTarget("mixed.example", localPort));
+ expect(code).toBe(0);
+ expect(requested).toEqual(["93.184.215.14"]);
+ const echoed = new Promise<Buffer>((resolve) => socket.once("data", resolve));
+ socket.write("direct-local");
+ expect((await echoed).toString()).toBe("direct-local");
+ socket.destroy();
+ await Promise.all([
+ new Promise<void>((resolve) => proxy.close(() => resolve())),
+ new Promise<void>((resolve) => local.close(() => resolve())),
+ ]);
+ });
+
it("does not contact the configured upstream when the destination policy refuses", async () => {
let proxyConnections = 0;
const upstream = NodeNet.createServer(() => { proxyConnections++; });
diff --git a/server/browser/egress/gate.ts b/server/browser/egress/gate.ts
index db87e5134d..f4eb3fc817 100644
--- a/server/browser/egress/gate.ts
+++ b/server/browser/egress/gate.ts
@@ -156,6 +156,7 @@ async function connectSocks5(proxy: { host: string; port: number }, target: Gate
if (!length) throw new Error("SOCKS5 proxy returned an invalid response.");
await readAtLeast(length + 2);
if (head[1] !== 0) throw Object.assign(new Error("SOCKS5 proxy refused the connection."), { code: head[1] === 2 ? "EACCES" : "ECONNREFUSED" });
+ if (pending.length) socket.unshift(pending);
socket.setTimeout(0);
return socket;
} catch (error) {
@@ -308,13 +309,13 @@ export function openGate(options: GateOptions): Promise<EgressGate> {
}
if (!addresses.length) return refuse(client, HOST_UNREACHABLE);
const own = options.own?.();
- const publicTarget = addresses.every(({ address }) => addressClass(address, own) === "public");
const configuredProxy = options.upstreamProxy?.() ?? null;
- const proxy = configuredProxy && publicTarget && !staysHere(target.host, own) ? configuredProxy : null;
+ const proxy = configuredProxy && !staysHere(target.host, own) ? configuredProxy : null;
if (proxy) {
let tunnel: Socket | null = null;
let lastError: unknown;
- for (const { address } of addresses) {
+ const publicAddresses = addresses.filter(({ address }) => addressClass(address, own) === "public");
+ for (const { address } of publicAddresses) {
if (client.destroyed) return;
try {
// The proxy receives only the checked IPs above, not a hostname it could resolve differently.
@@ -326,9 +327,21 @@ export function openGate(options: GateOptions): Promise<EgressGate> {
if ((error as NodeJS.ErrnoException).code === "EACCES") return refuse(client, NOT_ALLOWED);
}
}
+ if (!tunnel) {
+ const directAddresses = addresses.filter(({ address }) => addressClass(address, own) !== "public");
+ if (directAddresses.length) {
+ try {
+ client.pause();
+ tunnel = await connectChecked(target.port, directAddresses, track, client);
+ } catch (error) {
+ if (client.destroyed) return;
+ lastError = error;
+ }
+ }
+ }
if (!tunnel) {
const code = (lastError as NodeJS.ErrnoException | undefined)?.code;
- return refuse(client, code === "ECONNREFUSED" ? CONNECTION_REFUSED : HOST_UNREACHABLE);
+ return refuse(client, code === "ECONNREFUSED" || lastError === undefined ? CONNECTION_REFUSED : HOST_UNREACHABLE);
}
if (client.destroyed) return void tunnel.destroy();
client.off("data", holdEarly);
diff --git a/server/index.ts b/server/index.ts
index 8a3b110182..4340d141d4 100644
--- a/server/index.ts
+++ b/server/index.ts
@@ -11827,7 +11827,10 @@ function configStatus() {
/** `session`: who is asking. On a Team Cloud the profile is theirs alone, never the server's. */
function configForAccess(status: ReturnType<typeof configStatus>, admin: boolean, session?: SessionRecord | null) {
const profile: MemberProfile = CLOUD_TEAM ? (session ? teamHost.memberProfile(session) : NOBODY_PROFILE) : status.profile;
- if (admin) return CLOUD_TEAM ? { ...status, profile } : status;
+ if (admin) return CLOUD_TEAM ? {
+ ...status, profile,
+ browserEngine: status.browserEngine ? { ...status.browserEngine, proxyEditable: session?.teamRole === "owner" } : undefined,
+ } : status;
// Client sessions get configured-or-not only: no SSH alias, email, browser partition id or sign-in list.
return {
...withoutKeyHints(status),
@@ -12389,7 +12392,7 @@ const postiz = createPostiz({ cfg: () => cfg, mcpOAuth, persistMcpServers: persi
store, cfg, registry, sessions, browserCleanup, browserLive, browserRuntime, usedBrowserSessions, decider,
sharedComputers, sharedComputerControl, closeBrowser, browserEngineSwitched,
hostedModels: Boolean(hostedModels),
- cloudHome: Boolean(CLOUD_HOME), sharedMembership,
+ cloudHome: Boolean(CLOUD_HOME), cloudTeam: CLOUD_TEAM !== null, sharedMembership,
lendingEnabled: () => lendingEnabled() || ownerLends(), providerConfigs, localVmIdleMs, localVmIdles, localVmActiveThreads, localVmLifecycleBusy,
localVmImageBusy: { get: () => localVmImageBusy },
localVmModeChangeBusy: { set: (busy) => { localVmModeChangeBusy = busy; } },
diff --git a/server/routes/config-browser-proxy.test.ts b/server/routes/config-browser-proxy.test.ts
new file mode 100644
index 0000000000..20f9737402
--- /dev/null
+++ b/server/routes/config-browser-proxy.test.ts
@@ -0,0 +1,25 @@
+import { describe, expect, it } from "vitest";
+
+import type { RequestAuth } from "../request-auth.ts";
+import { createConfigRoutes, type ConfigRouteDeps } from "./config.ts";
+
+describe("Team Cloud browser proxy configuration", () => {
+ it("refuses an admin's proxy change before writing shared config", async () => {
+ const replies: Array<{ status: number; body: unknown }> = [];
+ const route = createConfigRoutes({ cloudTeam: true } as unknown as ConfigRouteDeps);
+ const auth: RequestAuth = {
+ kind: "session",
+ session: { id: "admin", scopes: ["admin", "client"], teamRole: "admin" } as never,
+ via: "bearer",
+ scopes: ["admin", "client"],
+ };
+
+ await route({
+ req: {}, res: {}, url: new URL("http://host/api/config"), path: "/api/config", method: "PATCH", auth,
+ json: (_res: unknown, status: number, body: unknown) => { replies.push({ status, body }); },
+ readBody: async () => ({ browserEngine: { egress: { proxy: "socks5://127.0.0.1:1080" } } }),
+ } as unknown as Parameters<typeof route>[0]);
+
+ expect(replies).toEqual([{ status: 403, body: { error: "Only the Team Cloud owner can configure the browser proxy." } }]);
+ });
+});
diff --git a/server/routes/config.ts b/server/routes/config.ts
index 23d84fc554..b3a6f60689 100644
--- a/server/routes/config.ts
+++ b/server/routes/config.ts
@@ -73,6 +73,8 @@ export interface ConfigRouteDeps {
sharedComputerControl: Pick<SharedComputerControl, "close">;
hostedModels: boolean;
cloudHome: boolean;
+ /** A Team Cloud shares one browser egress policy across every member. */
+ cloudTeam?: boolean;
/** Security: a Team Cloud never takes over another installation's Composio user, since every member's bots would then get that person's apps. */
sharedMembership: () => boolean;
lendingEnabled(): boolean;
@@ -124,6 +126,9 @@ export function createConfigRoutes(deps: ConfigRouteDeps): RouteHandler {
const body = await readBody(req);
if (hostedModels && ["instances", "anthropic", "openai", "openrouter", "openaiCompat", "xai", "mistral", "cerebras", "groq", "greenference", "meta", "opencodeGo"].some(key => Object.hasOwn(body, key))) return json(res, 403, { error: HOSTED_PROVIDER_SETTINGS_ERROR });
const patch = parseConfigPatchForPerson(body);
+ if (deps.cloudTeam && patch.browserEngine?.egress?.proxy !== undefined && !(auth.kind === "session" && auth.session.teamRole === "owner")) {
+ return json(res, 403, { error: "Only the Team Cloud owner can configure the browser proxy." });
+ }
if (patch.profile && ownProfile) {
// The address is the verified claim's; a profile names no other.
const { email: _email, ...own } = patch.profile;
diff --git a/src/components/BrowserSettingsRows.test.ts b/src/components/BrowserSettingsRows.test.ts
index 73e624ba5b..331d603e71 100644
--- a/src/components/BrowserSettingsRows.test.ts
+++ b/src/components/BrowserSettingsRows.test.ts
@@ -140,4 +140,15 @@ describe("Built-in browser proxy setting", () => {
expect(body.browserEngine.egress.proxy).toBe("socks5://127.0.0.1:1080");
expect(fixture.dispatch.mock.calls[0]![0].config.browserEngine.proxyConfigured).toBe(true);
});
+
+ it("hides the shared proxy control from Team Cloud admins who are not the owner", () => {
+ owner.value = true;
+ fixture.config = { team: { id: "team", name: "Team" }, features: { browser: true }, browserEngine: { kind: "engine", proxyEditable: false } };
+ show();
+ expect(host.querySelector('input[aria-label="SOCKS5 proxy"]')).toBeNull();
+
+ fixture.config = { team: { id: "team", name: "Team" }, features: { browser: true }, browserEngine: { kind: "engine", proxyEditable: true } };
+ show();
+ expect(host.querySelector('input[aria-label="SOCKS5 proxy"]')).not.toBeNull();
+ });
});
diff --git a/src/components/BrowserSettingsRows.tsx b/src/components/BrowserSettingsRows.tsx
index 5e66e1dd0a..de58cd7197 100644
--- a/src/components/BrowserSettingsRows.tsx
+++ b/src/components/BrowserSettingsRows.tsx
@@ -91,11 +91,12 @@ export function ServerSitesRow() {
export function BrowserProxyRow() {
const { state } = useStore();
const owner = useOwnerOrAdmin();
+ const canEditProxy = state.config?.team ? state.config.browserEngine?.proxyEditable === true : owner === true;
const configured = state.config?.browserEngine?.proxyConfigured === true;
const saved = state.config?.browserEngine?.proxySaved === true || configured;
const [endpoint, setEndpoint] = useState("");
const { saving, error, save } = useConfigSave();
- if (owner !== true || (!builtInBrowserEnabled(state.config) && !saved)) return null;
+ if (!canEditProxy || (!builtInBrowserEnabled(state.config) && !saved)) return null;
return (
<SettingRow
diff --git a/src/state/config-status.ts b/src/state/config-status.ts
index 3a0ee78fd0..ccd20a7f8b 100644
--- a/src/state/config-status.ts
+++ b/src/state/config-status.ts
@@ -206,6 +206,8 @@ export interface BrowserEngineSummary {
proxyConfigured?: boolean;
/** Whether an owner-configured SOCKS5 upstream is saved, even if the current browser engine cannot use it. */
proxySaved?: boolean;
+ /** Team Cloud only: whether this caller may change the shared SOCKS5 upstream. */
+ proxyEditable?: boolean;
}
export interface BrowserProfile {