Skip to content

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

Bot box: an app's connection to a configured server comes under the same rule as Test and turns (#5243)

Milind Soni03cb5c0327a7
diff --git a/server/mcp-app-connections-box.test.ts b/server/mcp-app-connections-box.test.ts
index a6e0bbe632..05d97d5a77 100644
--- a/server/mcp-app-connections-box.test.ts
+++ b/server/mcp-app-connections-box.test.ts
@@ -69,6 +69,35 @@ describe.skipIf(process.platform === "win32")("an app's connection to a command
expect(asBot!.env.BOARD_KEY).toBe("k");
}, 60_000);
+ // Security: the command is one someone configured, so naming a file of the server's own on its command line, or an
+ // engine folder in the data folder in its environment, is not a grant.
+ it("shows a configured server none of the data folder its command line or environment names", async () => {
+ ensureDirs();
+ const scratch = mkdtempSync(join(tmpdir(), "omb-app-named-"));
+ dirs.push(scratch);
+ const fakeBwrap = join(scratch, "fake-bwrap.sh");
+ writeFileSync(fakeBwrap, MARKING_BWRAP);
+ chmodSync(fakeBwrap, 0o755);
+ await botBox.start({
+ dataDir: DATA_DIR, home: homedir(), port: 8799, denyEnv: new Set(), env: {}, log: () => {},
+ detect: () => ({ box: "bwrap", reason: null, tools: { bwrap: fakeBwrap, socat: "/usr/bin/true" } }),
+ });
+ const wrap = vi.spyOn(botBox, "wrap");
+ delete process.env.TMPDIR;
+ const secrets = join(DATA_DIR, "config.json"), engineState = join(DATA_DIR, "engine-state");
+ writeFileSync(secrets, "{}");
+ const named = { command: "/bin/sh", args: ["-c", "exit 0", secrets], env: { XDG_CONFIG_HOME: engineState } };
+ const connections = new AppConnections({ asBot: () => ({ id: "bot-a", cwd: join(DATA_DIR, "workspaces", "bot-a") }) });
+ try {
+ await expect(connections.request("own", named, "resources/list", {}, AbortSignal.timeout(20_000))).rejects.toThrow();
+ } finally {
+ connections.closeAll();
+ }
+ // `configured` is what keeps an environment value naming a data-folder path out of the box (bot-box/plan.ts).
+ expect(wrap.mock.calls[0]![0]).toMatchObject({ botId: "bot-a", allowEnv: ["XDG_CONFIG_HOME"], configured: true });
+ expect(visibleInBox((wrap.mock.results[0]!.value as WrappedSpawn).plan, secrets), "a server file its command line names").toBe("none");
+ }, 60_000);
+
it("with the box off, starts it as it did", async () => {
const scratch = mkdtempSync(join(tmpdir(), "omb-app-nobox-"));
dirs.push(scratch);
diff --git a/server/mcp-app-connections.ts b/server/mcp-app-connections.ts
index cecf75bf71..d3465ceac1 100644
--- a/server/mcp-app-connections.ts
+++ b/server/mcp-app-connections.ts
@@ -51,7 +51,7 @@ class StdioAppClient implements AppClient {
this.child = spawnCli(server.command, server.args, {
...(botBox.enabled() ? (as.cwd ? { cwd: as.cwd } : {}) : { cwd: process.cwd() }),
env: probeEnvironment(server), stdio: ["pipe", "pipe", "pipe"],
- box: { ...(as.id ? { botId: as.id } : {}), allowEnv: Object.keys(server.env) },
+ box: { ...(as.id ? { botId: as.id } : {}), allowEnv: Object.keys(server.env), configured: true },
});
const splitter = createLineSplitter((line) => this.onLine(line, hooks));
this.child.stdout.on("data", (chunk: Buffer) => {