Skip to content

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

Boat sign-in: ask for sandbox.delete; the page check answers nothing in a server-side render

milind-soni43fc7264c9a9
diff --git a/server/boat-call.ts b/server/boat-call.ts
index 02768ffe8c..440a9670a4 100644
--- a/server/boat-call.ts
+++ b/server/boat-call.ts
@@ -18,7 +18,7 @@ export const BOAT_SCOPE_USE: Record<BoatScope, string> = {
"sandbox.resume": "wake a cloud computer",
"sandbox.stop": "stop a cloud computer",
"sandbox.update": "name a cloud computer and set when it stops by itself",
- "sandbox.delete-own": "delete a cloud computer it created",
+ "sandbox.delete": "delete a cloud computer",
exec: "run commands on a cloud computer",
"file.read": "read files and the screen of a cloud computer",
"file.write": "copy files to a cloud computer",
@@ -42,7 +42,7 @@ function words(status: number, code: string, method: string, scope: BoatScope |
return `Your Boat account sign-in does not reach this cloud computer: its organization or environment was not ticked when you signed in. Sign in to Boat again in ${SETTINGS} and tick it, or paste an API key there`;
}
if (method === "DELETE") {
- return `Your Boat account sign-in may delete only the cloud computers it created, and boat.dev did not let it delete this one. Delete it in boat.dev, or paste an API key in ${SETTINGS}`;
+ return `boat.dev did not let your Boat account sign-in delete this cloud computer. Sign in to Boat again in ${SETTINGS} and keep "sandbox.delete" ticked, or delete it in boat.dev`;
}
if (scope) return boatScopeRefusal(scope);
return `boat.dev refused this for your Boat account sign-in. ${AGAIN}`;
diff --git a/server/boat-sign-in.test.ts b/server/boat-sign-in.test.ts
index 567f051e05..f32d4829e4 100644
--- a/server/boat-sign-in.test.ts
+++ b/server/boat-sign-in.test.ts
@@ -99,7 +99,7 @@ describe("signing in", () => {
response_type: "code", client_id: BOAT_SIGN_IN_CLIENT_ID, redirect_uri: `http://127.0.0.1:${PORT}/api/boat/oauth/callback`,
scope: BOAT_SIGN_IN_SCOPES.join(" "), code_challenge_method: "S256",
});
- for (const never of ["billing.write", "ssh", "environment.read", "environment.write", "environment.values.read", "sandbox.delete", "sandbox.fork", "agent.prompt", "host", "network.write", "snapshot.read", "snapshot.write"]) {
+ for (const never of ["billing.write", "ssh", "environment.read", "environment.write", "environment.values.read", "sandbox.delete-own", "sandbox.fork", "agent.prompt", "host", "network.write", "snapshot.read", "snapshot.write"]) {
expect(BOAT_SIGN_IN_SCOPES as readonly string[]).not.toContain(never);
}
expect(signIn.status(false, "owner")).toMatchObject({ available: true, state: "none", pending: true });
@@ -425,10 +425,22 @@ describe("what the person allowed", () => {
expect(status.account).toBeUndefined();
});
- it("sandbox.delete stands in for sandbox.delete-own", async () => {
+ it("a sign-in made when only sandbox.delete-own was asked for stays signed in; Boat's refusal to delete says what to do", async () => {
const signIn = signInWith(memory().persistence);
- await connect(signIn, { scopes: [...BOAT_SIGN_IN_SCOPES.filter((scope) => scope !== "sandbox.delete-own"), "sandbox.delete"] });
- expect(signIn.status(false).missingScopes).toEqual([]);
+ await connect(signIn, { scopes: [...BOAT_SIGN_IN_SCOPES.filter((scope) => scope !== "sandbox.delete"), "sandbox.delete-own"] });
+ expect(signIn.status(false)).toMatchObject({ state: "connected", missingScopes: [] });
+ const refused = await boatFetch(SIGNED_IN, "/sandboxes/bx_made_with_a_key", { method: "DELETE" });
+ expect(refused.status).toBe(403);
+ expect(await refused.json()).toMatchObject({ boatSignIn: true, message: expect.stringContaining("keep \"sandbox.delete\" ticked") });
+ });
+
+ it("with sandbox.delete unticked, a delete is not sent and says which permission is missing", async () => {
+ const signIn = signInWith(memory().persistence);
+ await connect(signIn, { scopes: BOAT_SIGN_IN_SCOPES.filter((scope) => scope !== "sandbox.delete") });
+ expect(signIn.status(false).missingScopes).toEqual(["sandbox.delete"]);
+ const refused = await boatFetch(SIGNED_IN, "/sandboxes/bx_1", { method: "DELETE" });
+ expect(await refused.json()).toMatchObject({ error: "api_key_action_forbidden", message: expect.stringContaining("delete a cloud computer: \"sandbox.delete\" was not allowed") });
+ expect(fake.counts.api).toBe(0);
});
it("Boat's own refusals of a sign-in are put in plain words, not called a rejected API key", async () => {
@@ -448,7 +460,7 @@ describe("what the person allowed", () => {
boatScopeFor("POST", "/sandboxes/bx_1/desktop?vnc=1"), boatScopeFor("GET", "/sandboxes/bx_1/files?path=a"), boatScopeFor("PUT", "/sandboxes/bx_1/files"),
boatScopeFor("POST", "/sandboxes/bx_1/files/download-url"), boatScopeFor("POST", "/sandboxes/bx_1/files/upload-url"), boatScopeFor("GET", "/sandboxes/bx_1/artifacts?path=a"),
boatScopeFor("GET", "/me"), boatScopeFor("GET", "/deletion-operations/op_1"),
- ]).toEqual(["sandbox.read", "sandbox.create", "sandbox.read", "sandbox.update", "sandbox.delete-own", "sandbox.resume", "sandbox.stop", "exec", "exec", "desktop",
+ ]).toEqual(["sandbox.read", "sandbox.create", "sandbox.read", "sandbox.update", "sandbox.delete", "sandbox.resume", "sandbox.stop", "exec", "exec", "desktop",
"file.read", "file.write", "file.read", "file.write", "file.read", "account.read", null]);
});
});
diff --git a/server/boat-sign-in.ts b/server/boat-sign-in.ts
index 55b2016f06..b347d4d07c 100644
--- a/server/boat-sign-in.ts
+++ b/server/boat-sign-in.ts
@@ -20,7 +20,7 @@ export { BOAT_SIGN_IN_PORTS };
/** The least the cloud computer features call (server/boat*.ts, server/cloud-computer-*.ts); one line each in SCOPE_USE. */
export const BOAT_SIGN_IN_SCOPES = [
"account.read", "sandbox.read", "sandbox.create", "sandbox.resume", "sandbox.stop", "sandbox.update",
- "sandbox.delete-own", "exec", "file.read", "file.write", "desktop",
+ "sandbox.delete", "exec", "file.read", "file.write", "desktop",
] as const;
export type BoatScope = (typeof BOAT_SIGN_IN_SCOPES)[number];
@@ -144,7 +144,7 @@ export function boatScopeFor(method: string, path: string): BoatScope | null {
if (!sandbox) return null;
const [, id, rest = ""] = sandbox;
if (!id) return verb === "POST" ? "sandbox.create" : "sandbox.read";
- if (!rest) return verb === "DELETE" ? "sandbox.delete-own" : verb === "PATCH" ? "sandbox.update" : "sandbox.read";
+ if (!rest) return verb === "DELETE" ? "sandbox.delete" : verb === "PATCH" ? "sandbox.update" : "sandbox.read";
if (rest === "/resume") return "sandbox.resume";
if (rest === "/stop") return "sandbox.stop";
if (rest.startsWith("/commands")) return "exec";
@@ -156,7 +156,9 @@ export function boatScopeFor(method: string, path: string): BoatScope | null {
}
const holds = (granted: readonly string[], scope: string): boolean =>
- granted.includes(scope) || (scope === "sandbox.delete-own" && granted.includes("sandbox.delete"));
+ // A sign-in made while the app asked only for "sandbox.delete-own" keeps working: it is not asked to sign in again,
+ // and Boat itself says so if it is asked to delete a computer it did not create.
+ granted.includes(scope) || (scope === "sandbox.delete" && granted.includes("sandbox.delete-own"));
export class BoatSignIn {
private readonly options: BoatSignInOptions;
diff --git a/server/testing/fake-boat-oauth.ts b/server/testing/fake-boat-oauth.ts
index 5297c256b0..05e1dc12a6 100644
--- a/server/testing/fake-boat-oauth.ts
+++ b/server/testing/fake-boat-oauth.ts
@@ -120,7 +120,8 @@ export async function startFakeBoat(clientId: string, redirectUris: string[], ap
if (apiKeys.includes(bearer)) return json(res, 200, url.pathname === "/api/v1/me" ? { ok: true, user: { login: "maya-shah" } } : { ok: true, sandboxes: [] });
const grant = grants.find((one) => one.access === bearer && !one.ended);
if (!grant) return json(res, 401, { ok: false, error: "unauthorized", message: "Invalid token" });
- const needs = url.pathname === "/api/v1/me" ? "account.read" : req.method === "POST" ? "sandbox.create" : "sandbox.read";
+ const needs = url.pathname === "/api/v1/me" ? "account.read" : req.method === "POST" ? "sandbox.create" : req.method === "DELETE" ? "sandbox.delete" : "sandbox.read";
+ // A grant with only "sandbox.delete-own" deletes what it created; the fake has no such computer, so it refuses.
if (!grant.scopes.includes(needs)) return json(res, 403, { ok: false, error: "api_key_action_forbidden", message: "The action is not on the key" });
if (orgRequired && !url.searchParams.get("org") && !req.headers["x-boat-org"]) return json(res, 400, { ok: false, error: "org_required", message: "Name an organization" });
if (url.pathname === "/api/v1/me") return json(res, 200, { ok: true, type: "user.info", user: { login: "maya-shah", email: "[email protected]" } });
diff --git a/src/lib/boat-sign-in.ts b/src/lib/boat-sign-in.ts
index 45e42d02e8..da28049afe 100644
--- a/src/lib/boat-sign-in.ts
+++ b/src/lib/boat-sign-in.ts
@@ -11,10 +11,11 @@ const LOCAL_HOSTS = ["127.0.0.1", "localhost"];
* hosted Cloud, a self-hosted server and a page reached from another device show the key field alone. */
export function boatSignInShown(
config: Pick<ConfigStatus, "box"> | null | undefined,
- page: Pick<Location, "hostname" | "port"> = window.location,
+ page: Pick<Location, "hostname" | "port"> | undefined = typeof window === "undefined" ? undefined : window.location,
): BoatSignInStatus | null {
const status = config?.box?.signIn;
- if (!status?.available || config?.box?.included) return null;
+ // No page (a server-side render): nothing is offered.
+ if (!page || !status?.available || config?.box?.included) return null;
return LOCAL_HOSTS.includes(page.hostname) && BOAT_SIGN_IN_PORTS.includes(Number(page.port)) ? status : null;
}