Skip to content

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

Cloud browser: no browser in the sandbox when the policy that blocks file:// could not be written

milind-soni3c029726b31e
diff --git a/server/cloud-browser/cloud-browser.test.ts b/server/cloud-browser/cloud-browser.test.ts
index 27b69a755f..078d3c3d0b 100644
--- a/server/cloud-browser/cloud-browser.test.ts
+++ b/server/cloud-browser/cloud-browser.test.ts
@@ -413,6 +413,17 @@ describe("a personal Cloud's bot browsers in the Cloud's browser sandbox", () =>
expect(fake.requests.length).toBe(asked);
});
+ it("keeps every browser in the home for the day when the sandbox could not take the policy that blocks file://", async () => {
+ fake.policy = false;
+ const cloud = browser();
+ expect(await cloud.open(request())).toEqual({ home: "no-policy" });
+ expect(fake.upgrades, "never dialed").toEqual([]);
+ expect(fake.quits()).toEqual([`quit:${profileKey("scout")}`]);
+ const asked = fake.requests.length;
+ expect(await cloud.open(request("writer"))).toEqual({ home: "no-route" });
+ expect(fake.requests.length).toBe(asked);
+ });
+
it("a Chrome that does not start counts as a failure and opens in the home", async () => {
fake.chromeStarts = false;
expect(await browser().open(request())).toEqual({ home: "start-failed" });
diff --git a/server/cloud-browser/index.ts b/server/cloud-browser/index.ts
index f94e98c756..e33323f108 100644
--- a/server/cloud-browser/index.ts
+++ b/server/cloud-browser/index.ts
@@ -165,6 +165,12 @@ export function createCloudBrowser(deps: CloudBrowserDeps) {
await quit();
return home(request, "start-failed");
}
+ // Without the policy a page could open file:// and read another process's files in the sandbox: no browser runs there today.
+ if (!answer.policy) {
+ rails.noRoute();
+ await quit();
+ return home(request, "no-policy");
+ }
const relay = await ops.host(box.id, COMPUTER_DOOR_PORT).catch(() => null);
const url = relay ? dialable(relay) : null;
if (!url) {
diff --git a/server/cloud-browser/rails.ts b/server/cloud-browser/rails.ts
index 609ba8ffc5..0507483bb8 100644
--- a/server/cloud-browser/rails.ts
+++ b/server/cloud-browser/rails.ts
@@ -16,7 +16,7 @@ export const CLOUD_BROWSER_BACKOFF_MS = 15 * 60_000;
/** Why a browser session opened in the home instead: names only, for the log and the health report. */
export type HomeReason =
- | "lever" | "team" | "not-eligible" | "own-key" | "sign-ins" | "no-machine" | "not-set-up" | "busy" | "lent-connection"
+ | "lever" | "team" | "not-eligible" | "own-key" | "sign-ins" | "no-machine" | "no-policy" | "not-set-up" | "busy" | "lent-connection"
| "old-relay" | "unavailable" | "budget" | "minutes-used" | "sandbox-full" | "backoff" | "account-limit" | "hours-used" | "at-once" | "no-route" | "start-failed" | "unreachable";
interface Day {
diff --git a/server/cloud-browser/remote.ts b/server/cloud-browser/remote.ts
index 10b295b257..77ef65273e 100644
--- a/server/cloud-browser/remote.ts
+++ b/server/cloud-browser/remote.ts
@@ -46,7 +46,8 @@ export interface ComputerOps {
resume(boxId: string): Promise<void>;
state(boxId: string): Promise<string | null>;
/** One bot's Chrome started on its profile, with this open's door secret; `home` is the sandbox's home folder. */
- launch(boxId: string, key: string, secret: string): Promise<{ chrome: boolean; home: string | null }>;
+ /** `policy`: the Chrome policy that blocks file:// and Chrome's own pages could be written in the sandbox. */
+ launch(boxId: string, key: string, secret: string): Promise<{ chrome: boolean; home: string | null; policy: boolean }>;
/** A finished download (a sandbox path) brought into `folder` as `to`, with the cloud computers' copy checks and limits. */
fetchFile(boxId: string, path: string, folder: string, to: string): Promise<CopyOutcome>;
/** A file of the Cloud (`from`, inside `folder`) copied to a sandbox path for an upload. */
@@ -156,7 +157,7 @@ export function providerOps(cfg: () => AppConfig): ComputerOps {
if (!HEX16.test(key) || !HEX48.test(secret)) throw new Error("bad browser profile key or door secret");
const answer = await action(boxId, { action: "launch", key, secret });
const home = typeof answer?.home === "string" && /^\/[^\0\n]*$/.test(answer.home) && !answer.home.split("/").includes("..") ? answer.home.replace(/\/+$/, "") : null;
- return { chrome: answer?.chrome === true, home };
+ return { chrome: answer?.chrome === true, home, policy: answer?.policy === true };
},
fetchFile: (boxId, path, folder, to) => copyFromComputer(cfg(), boxId, folder, { path, to }, AbortSignal.timeout(10 * 60_000)),
sendFile: (boxId, folder, from, path) => copyToComputer(cfg(), boxId, folder, { from, path }, AbortSignal.timeout(10 * 60_000)),
diff --git a/server/cloud-browser/testing/fake-computer.ts b/server/cloud-browser/testing/fake-computer.ts
index a317d21308..24ae08a73e 100644
--- a/server/cloud-browser/testing/fake-computer.ts
+++ b/server/cloud-browser/testing/fake-computer.ts
@@ -29,6 +29,8 @@ export interface FakeComputer {
hostRoute: boolean;
unprotected: boolean;
chromeStarts: boolean;
+ /** Whether the launch could write the Chrome policy (sudo in the sandbox). */
+ policy: boolean;
requests: Request[];
upgrades: Array<{ path: string; host: string | undefined; origin: string | undefined; query?: string }>;
frames: string[];
@@ -63,7 +65,7 @@ export async function startFakeComputer(): Promise<FakeComputer> {
let retired = true;
const fake = {
base: "", state: "ready", exists: true, startStatus: 200, startBody: { ok: true }, oldRelay: false, available: true, unavailableReason: "fleet_starts",
- unavailableUntil: null, hostRoute: true, unprotected: false, chromeStarts: true, requests: [], upgrades: [], frames: [], boxId: "bx_23456789",
+ unavailableUntil: null, hostRoute: true, unprotected: false, chromeStarts: true, policy: true, requests: [], upgrades: [], frames: [], boxId: "bx_23456789",
files: new Map(), cookies: new Map(), commands: [], failing: new Set(),
} as unknown as FakeComputer;
const watchers = new Map<string, Set<import("ws").WebSocket>>();
@@ -128,7 +130,7 @@ export async function startFakeComputer(): Promise<FakeComputer> {
if (rest === `/sandboxes/${boxId}/browser`) {
if (body.action === "launch" && typeof body.key === "string" && typeof body.secret === "string") {
secrets.set(body.key, body.secret);
- return send(200, { ok: true, chrome: fake.chromeStarts, policy: true, home: HOME });
+ return send(200, { ok: true, chrome: fake.chromeStarts, policy: fake.policy, home: HOME });
}
if (body.action === "remove-download") fake.files.delete(`${HOME}/.omb-browser/.downloads/${String(body.key)}/${String(body.name)}`);
return send(200, { ok: true });