Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Webhooks: a change to a webhook checks the caller can see its bot (minimal take of #6037)
milind-soni96cbfcd1380e
diff --git a/server/routes/webhooks.test.ts b/server/routes/webhooks.test.tsindex 1d34a12570..fb971e7ade 100644--- a/server/routes/webhooks.test.ts+++ b/server/routes/webhooks.test.ts@@ -64,6 +64,13 @@ describe("a webhook's address for the person", () => {const theirs = hidden.webhooks.create({ name: "Hidden", prompt: "", botId: "bot-hidden" });expect(await hidden.call("GET", `/api/webhooks/${theirs.webhook.id}/address`)).toEqual({ status: 404, body: { error: "no such webhook" } });expect((await hidden.call("GET", "/api/webhooks")).body.webhooks).toEqual([]);+ for (const [method, suffix] of [["POST", "/test"], ["POST", "/rotate"], ["PATCH", ""], ["DELETE", ""]] as const) {+ expect(await hidden.call(method, `/api/webhooks/${theirs.webhook.id}${suffix}`, method === "PATCH" ? { name: "Mine" } : {})).toEqual({ status: 404, body: { error: "no such webhook" } });+ }+ expect(hidden.webhooks.list()).toEqual([expect.objectContaining({ id: theirs.webhook.id, name: "Hidden" })]);+ expect(hidden.webhooks.authorize(theirs.webhook.endpointId, theirs.secret)).toBe(true);+ expect((await hidden.call("POST", "/api/webhooks", { name: "Into theirs", prompt: "", botId: "bot-hidden" })).status).toBe(404);+ expect((await hidden.call("POST", "/api/webhooks", { name: "Mine", prompt: "", botId: "bot-a" })).status).toBe(201);const file = join(folder(), "webhooks.json");const old = manager(file).create({ name: "Old", prompt: "", botId: "bot-a" });diff --git a/server/routes/webhooks.ts b/server/routes/webhooks.tsindex d62c578597..b12fa58547 100644--- a/server/routes/webhooks.ts+++ b/server/routes/webhooks.ts@@ -25,12 +25,17 @@ export function createWebhookRoutes({ webhooks, ingress, visible }: WebhookRoutereturn json(res, 200, { webhooks: shownHooks, attempts: webhooks.listAttempts().filter((attempt) => seen.everything || shownIds.has(attempt.webhookId)), ingress: ingress() });}if (path === "/api/webhooks" && method === "POST") {- const created = webhooks.create(await readBody(req));+ const body = await readBody(req);+ // Security: on a Team Cloud an admin may not see another person's private bot; a webhook into it is refused alike.+ if (body && typeof body === "object" && !Array.isArray(body) && !webhookVisible(body, visible(auth))) return json(res, 404, { error: "no such bot" });+ const created = webhooks.create(body);return json(res, 201, { webhook: created.webhook, ...withCredential(created.webhook, created.secret) });}const match = path.match(/^\/api\/webhooks\/([\w-]+)(?:\/(rotate|test|address))?$/);if (!match) return PASS;const id = match[1]!;+ const known = webhooks.list().find((webhook) => webhook.id === id);+ if (known && !webhookVisible(known, visible(auth))) return json(res, 404, { error: "no such webhook" });if (match[2] === "test" && method === "POST") {const result = webhooks.test(id, await readBody(req));return result ? json(res, 202, result) : json(res, 404, { error: "no such webhook" });