Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(auth): allow clients to list and read their notification feed
Sebastian Bfcdc5d29b66d
diff --git a/server/client-notifications.e2e.test.ts b/server/client-notifications.e2e.test.tsnew file mode 100644index 0000000000..c27cfc7e3a--- /dev/null+++ b/server/client-notifications.e2e.test.ts@@ -0,0 +1,48 @@+import { join } from "node:path";+import { DatabaseSync } from "node:sqlite";+import { expect, it } from "vitest";++import { launchCloudSendFixture } from "../scripts/testing/cloud-send-fixture.ts";+import { personKey } from "./person-key.ts";+import { hostTimeout } from "./testing/host-timeout.ts";++it("lets a Team Cloud member list and read only their own notification feed", async () => {+ const fixture = await launchCloudSendFixture({ onePasswordToken: "synthetic-notifications-token",+ team: { id: "team-notifications", name: "Notifications" } });+ try {+ const team = fixture.team!;+ const owner = await team.pair({ email: "[email protected]", role: "owner" });+ const member = await team.pair({ email: "[email protected]", role: "member" });+ const created = await team.as(owner.token!, "POST", "/api/bots", { name: "Scout" });+ expect(created.status).toBe(201);+ const bot = created.body.bot;+ const opened = await team.as(owner.token!, "POST", `/api/bots/${bot.id}/tasks`, { title: "Ada's private chat" });+ expect(opened.status).toBe(201);+ expect((await team.as(owner.token!, "GET", "/api/notifications")).status).toBe(200);+ const db = new DatabaseSync(join(team.home, ".openmausbot", "messages.db"));+ try {+ const insert = db.prepare("INSERT INTO notification_log(id, at, kind, bot_id, bot_name, thread_id, title, body, for_person) VALUES (?, ?, ?, ?, 'Scout', ?, 'Fixture', '', ?)");+ const ada = personKey({ id: "", email: "[email protected]" });+ for (const [id, kind, threadId, person] of [+ ["own-a", "done", bot.mainThreadId, null], ["own-b", "done", bot.mainThreadId, null],+ ["private", "done", opened.body.task.threadId, null],+ ["owners-ask", "question", bot.mainThreadId, null], ["targeted", "done", bot.mainThreadId, ada],+ ] as const) insert.run(id, Date.now(), kind, bot.id, threadId, person);++ const listed = await team.as(member.token!, "GET", "/api/notifications");+ expect(listed.status).toBe(200);+ expect(listed.body.notifications.map((entry: { id: string }) => entry.id).sort()).toEqual(["own-a", "own-b"]);+ expect((await team.as(member.token!, "POST", "/api/notifications/own-a/read")).status).toBe(200);+ for (const id of ["private", "owners-ask", "targeted"]) {+ expect((await team.as(member.token!, "POST", `/api/notifications/${id}/read`)).status, id).toBe(404);+ }+ expect((await team.as(member.token!, "POST", "/api/notifications/read-all")).status).toBe(200);+ expect(db.prepare("SELECT id FROM notification_log WHERE read = 1 ORDER BY id").all().map((row) => row.id)).toEqual(["own-a", "own-b"]);+ expect(db.prepare("SELECT id FROM notification_log WHERE read = 0 ORDER BY id").all().map((row) => row.id)).toEqual(["owners-ask", "private", "targeted"]);+ } finally {+ db.close();+ }+ } finally {+ await fixture.close();+ }+}, hostTimeout(120_000));diff --git a/server/request-auth.test.ts b/server/request-auth.test.tsindex ad3be825a3..8b90a99679 100644--- a/server/request-auth.test.ts+++ b/server/request-auth.test.ts@@ -92,6 +92,20 @@ describe("request source for the lockout", () => {});describe("scopes", () => {+ it("allows clients to list and read notifications with exactly the feed's methods and paths", () => {+ for (const [method, path] of [+ ["GET", "/api/notifications"],+ ["POST", "/api/notifications/read-all"],+ ["POST", "/api/notifications/n-1/read"],+ ] as const) expect(requiredScope(method, path), `${method} ${path}`).toBe("client");+ for (const [method, path] of [+ ["POST", "/api/notifications"], ["DELETE", "/api/notifications"],+ ["GET", "/api/notifications/read-all"], ["PUT", "/api/notifications/read-all"],+ ["GET", "/api/notifications/n-1/read"], ["DELETE", "/api/notifications/n-1/read"],+ ["POST", "/api/notifications/n-1/read/extra"], ["GET", "/api/notifications/extra"],+ ] as const) expect(requiredScope(method, path), `${method} ${path}`).toBe("admin");+ });+it("keeps full backups, credentials and replacement behind admin scope", () => {for (const path of ["status", "export", "upload", "preview", "restore", "client-state", "download/123"]) {for (const method of ["GET", "POST", "DELETE"]) expect(requiredScope(method, `/api/workspace-backup/${path}`)).toBe("admin");diff --git a/server/request-auth.ts b/server/request-auth.tsindex b51f53ade0..abc2480efe 100644--- a/server/request-auth.ts+++ b/server/request-auth.ts@@ -276,6 +276,9 @@ export function clearSessionCookie(name: string): string {/** What a `client` session may do. Default deny: a new route is admin-only until listed here. */export const CLIENT_ALLOW: ReadonlyArray<{ methods: readonly string[]; path: RegExp; feature?: "sharedComputers" }> = [{ methods: ["GET"], path: /^\/api\/auth\/session$/ },+ { methods: ["GET"], path: /^\/api\/notifications$/ },+ { methods: ["POST"], path: /^\/api\/notifications\/read-all$/ },+ { methods: ["POST"], path: /^\/api\/notifications\/[\w-]+\/read$/ },// the update check only reads a version{ methods: ["GET"], path: /^\/api\/updates\/check$/ },{ methods: ["POST"], path: /^\/api\/auth\/stream-ticket$/ },