Skip to content

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

fix(browser): limit the hosted-workspace egress override to hosted servers

AdityaUmale61849307ca5c
diff --git a/server/host/browser.test.ts b/server/host/browser.test.ts
index 329d6a1f3f..478cef7375 100644
--- a/server/host/browser.test.ts
+++ b/server/host/browser.test.ts
@@ -141,11 +141,16 @@ describe("the bots' browser host with browserEngine.engine set to chrome", () =>
const unavailable = { kind: "unavailable" as const, reason: "agent-browser is not installed", myChrome: false };
for (const hosted of [false, true]) {
const { cfg, host } = setup("agent-browser", { server: true, hosted });
- cfg.browserEngine = { engine: "agent-browser", egress: { localNetwork: true } };
+ cfg.browserEngine = { engine: "agent-browser", egress: { localNetwork: true, allow: ["10.0.0.5"] } };
expect(host.engineSummary(unavailable).serverSites).toBe(hosted ? undefined : true);
expect(browserEgress.rules().localNetwork).toBe(!hosted);
+ expect(browserEgress.rules().allowed("10.0.0.5", 80)).toBe(!hosted);
}
- expect(setup("agent-browser").host.engineSummary(unavailable).serverSites).toBeUndefined();
+ const desktop = setup("agent-browser");
+ desktop.cfg.browserEngine = { engine: "agent-browser", egress: { allow: ["10.0.0.5"] } };
+ expect(desktop.host.engineSummary(unavailable).serverSites).toBeUndefined();
+ // The desktop's own default stays: its browsers reach the local network unless egress.localNetwork is false.
+ expect(browserEgress.rules().localNetwork).toBe(true);
});
it("forgets the new engine's sessions when the engine is switched back", async () => {
diff --git a/server/host/browser.ts b/server/host/browser.ts
index f152eada27..429b523c64 100644
--- a/server/host/browser.ts
+++ b/server/host/browser.ts
@@ -62,7 +62,7 @@ export interface BrowserHostDeps {
}): string;
DESKTOP_MANAGED: boolean;
CLOUD_HOME: unknown;
- /** A shared company workspace: the server's network is the operator's, so the owner's local-sites switch stays off. */
+ /** A shared company workspace: the server's network is the operator's, so the stored local-sites switch and allow-list are ignored. */
HOSTED_WORKSPACE?: boolean;
PORT: number;
/** A Cloud home's way out through the person's own lent computer. */
@@ -206,10 +206,11 @@ export function createBrowserHost(deps: BrowserHostDeps) {
const browserAudience = (threadId: string | undefined): Audience => (threadId && deps.audienceOf ? deps.audienceOf(threadId) : "team");
const device = deps.device && lentDevice(deps.device, (session) => turnResources.holder(`browser:${session}`), mayLend);
const egressHost = DESKTOP_MANAGED ? "desktop" : CLOUD_HOME ? "cloud" : "server";
- // Self-hosted servers only: the owner's switch for this server's own sites and its local network.
- const sitesSwitch = egressHost === "server" && !deps.HOSTED_WORKSPACE;
- const egressConfig = () => (sitesSwitch || !cfg.browserEngine?.egress ? cfg.browserEngine?.egress : { ...cfg.browserEngine.egress, localNetwork: false });
- browserEgress.configure({ host: egressHost, config: egressConfig, ...(device ? { device } : {}) });
+ // Self-hosted servers only: the owner's switch for this server's own sites and its local network. A shared company
+ // workspace's network is the operator's, so its stored switch and allow-list are ignored, like MausBot Cloud's.
+ const hostedServer = egressHost === "server" && Boolean(deps.HOSTED_WORKSPACE);
+ const sitesSwitch = egressHost === "server" && !hostedServer;
+ browserEgress.configure({ host: egressHost, config: () => (hostedServer ? undefined : cfg.browserEngine?.egress), ...(device ? { device } : {}) });
/** A live bot's, profile's or temporary browser of this data dir, for any audience. */
const belongs = (session: string) => isTemporaryBrowserSession(session) || audiences.variants().some((suffix) =>
store.bots.some((bot) => browserSessionId(bot.id + suffix, "") === session)