Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix: read-only HighLevel grant lets HighLevel's reads through
AdityaUmalec042bf3a3b34
diff --git a/server/connected-app-tools.e2e.test.ts b/server/connected-app-tools.e2e.test.tsindex 0c5b2f5d6c..a87f9ca865 100644--- a/server/connected-app-tools.e2e.test.ts+++ b/server/connected-app-tools.e2e.test.ts@@ -32,6 +32,17 @@ async function ask(bridge: Bridge, call: { name: string; arguments: Record<strin}}+/** The app's HTTP API at `url`, expecting `expected` back. */+const apiOn = (url: string) => async (method: string, path: string, body?: unknown, expected = 200) => {+ const response = await fetch(url + path, {+ method, headers: { "content-type": "application/json", origin: url },+ ...(body === undefined ? {} : { body: JSON.stringify(body) }),+ });+ const result = await response.json() as any;+ expect(response.status, `${method} ${path}: ${JSON.stringify(result).slice(0, 400)}`).toBe(expected);+ return result;+};+const acpBridge = (entry: { command: string; args: string[]; env: Array<{ name: string; value: string }> }): Bridge =>({ command: entry.command, args: entry.args, env: Object.fromEntries(entry.env.map(({ name, value }) => [name, value])) });@@ -44,15 +55,7 @@ it("a bot given Gmail by its app switch reaches gmail.search_emails by name on C...process.env, OMB_COMPOSIO_BROKER_URL: apps.url, OMB_COMPOSIO_BROKER_TOKEN: apps.token,FAKE_CLAUDE_MODE: "slow", FAKE_CLAUDE_SLOW_FINISH_GATE: gate, FAKE_ACP_HANG_ON: "Find Ada's mail again",}, undefined, undefined, undefined, undefined, undefined, ["cline"]);- const api = async (method: string, path: string, body?: unknown, expected = 200) => {- const response = await fetch(fixture.info.url + path, {- method, headers: { "content-type": "application/json", origin: fixture.info.url },- ...(body === undefined ? {} : { body: JSON.stringify(body) }),- });- const result = await response.json() as any;- expect(response.status, `${method} ${path}: ${JSON.stringify(result).slice(0, 400)}`).toBe(expected);- return result;- };+ const api = apiOn(fixture.info.url);try {const bot = (await api("POST", "/api/bots", { name: "Paul" }, 201)).bot;// The record an Apps switch left before it also wrote the tool list: Gmail on by scope, no tool granted.@@ -92,3 +95,40 @@ it("a bot given Gmail by its app switch reaches gmail.search_emails by name on CrmSync(scratch, { recursive: true, force: true });}}, 120_000);++it("a bot with HighLevel read only runs HighLevel's reads, which name the resource before the verb, and is refused its writes", async () => {+ const apps = await startFakeConnectedApps();+ apps.connected = { highlevel_mcp: true };+ const scratch = mkdtempSync(join(tmpdir(), "omb-app-tools-"));+ const gate = join(scratch, "finish");+ const fixture = await launchVerificationServer({+ ...process.env, OMB_COMPOSIO_BROKER_URL: apps.url, OMB_COMPOSIO_BROKER_TOKEN: apps.token, FAKE_CLAUDE_MODE: "slow", FAKE_CLAUDE_SLOW_FINISH_GATE: gate,+ });+ const api = apiOn(fixture.info.url);+ try {+ const bot = (await api("POST", "/api/bots", { name: "Boomer" }, 201)).bot;+ await api("PATCH", `/api/bots/${bot.id}`, { composio: true, connectorTools: { highlevel_mcp: { tools: "*" } }, connectorScopes: { apps: { highlevel_mcp: "read" } } });+ await api("POST", `/api/bots/${bot.id}/messages`, { threadId: bot.threadId, text: "List the pipelines", sendId: "highlevel-read-e2e-0001" }, 202);+ let dump: any;+ await expect.poll(() => {+ try { dump = JSON.parse(readFileSync(fixture.fixtureDumpPath, "utf8")); } catch { return false; }+ return Boolean(dump.mcpConfig?.mcpServers?.composio);+ }, { timeout: 20_000 }).toBe(true);+ const run = (tool_slug: string) => ask(dump.mcpConfig.mcpServers.composio, { name: "COMPOSIO_MULTI_EXECUTE_TOOL", arguments: { tools: [{ tool_slug, arguments: {} }] } });+ for (const slug of ["HIGHLEVEL_MCP_CONTACTS_GET_CONTACTS", "HIGHLEVEL_MCP_OPPORTUNITIES_GET_PIPELINES", "HIGHLEVEL_MCP_OPPORTUNITIES_SEARCH_OPPORTUNITY"]) {+ const { answer } = await run(slug);+ expect(JSON.stringify(answer), slug).not.toContain("would write");+ expect(apps.calls.at(-1)).toMatchObject({ tool: slug });+ }+ const before = apps.calls.length;+ const { answer } = await run("HIGHLEVEL_MCP_CONTACTS_UPDATE_CONTACT");+ expect(answer.result.isError).toBe(true);+ expect(answer.result.content[0].text).toContain("would write to it");+ expect(apps.calls.length, "the write never reached the app").toBe(before);+ writeFileSync(gate, "");+ } finally {+ await fixture.close();+ await apps.close();+ rmSync(scratch, { recursive: true, force: true });+ }+}, 120_000);diff --git a/shared/connector-scopes.test.ts b/shared/connector-scopes.test.tsindex ca150d796d..02206039ae 100644--- a/shared/connector-scopes.test.ts+++ b/shared/connector-scopes.test.ts@@ -27,6 +27,15 @@ describe("isReadOnlyAction", () => {expect(isReadOnlyAction("GMAIL_CREATE_EMAIL_DRAFT")).toBe(false);expect(isReadOnlyAction("COMPOSIO_PROXY_EXECUTE")).toBe(false);});++ it("takes the second word as the verb only for toolkits that name the resource first", () => {+ expect(isReadOnlyAction("HIGHLEVEL_MCP_CONTACTS_GET_CONTACTS", "highlevel_mcp")).toBe(true);+ expect(isReadOnlyAction("HIGHLEVEL_MCP_CONTACTS_GET_CONTACTS")).toBe(true);+ expect(isReadOnlyAction("HIGHLEVEL_MCP_CONTACTS_ADD_TAGS", "highlevel_mcp")).toBe(false);+ expect(isReadOnlyAction("MAILCHIMP_CREATE_LIST")).toBe(false);+ expect(isReadOnlyAction("SOMEAPP_CONTACTS_GET_CONTACTS")).toBe(false);+ expect(isReadOnlyAction("HIGHLEVEL_MCP_CONTACTS_GET_CONTACTS", "highlevel")).toBe(false);+ });});describe("normalizeConnectorScopes", () => {@@ -82,6 +91,16 @@ describe("connectorAccessDecision", () => {});});+ it("reads HighLevel MCP actions, which name the resource before the verb, on a read-only grant", () => {+ const highlevel = { apps: { highlevel_mcp: "read" as const } };+ for (const slug of ["HIGHLEVEL_MCP_CONTACTS_GET_CONTACTS", "HIGHLEVEL_MCP_OPPORTUNITIES_GET_PIPELINES", "HIGHLEVEL_MCP_OPPORTUNITIES_SEARCH_OPPORTUNITY"]) {+ expect(connectorAccessDecision(highlevel, calls(slug), ["highlevel_mcp"])).toEqual({ ok: true });+ }+ for (const slug of ["HIGHLEVEL_MCP_CONTACTS_UPDATE_CONTACT", "HIGHLEVEL_MCP_CONVERSATIONS_SEND_A_NEW_MESSAGE", "HIGHLEVEL_MCP_SOCIAL_MEDIA_POSTING_GET_POSTS"]) {+ expect(connectorAccessDecision(highlevel, calls(slug), ["highlevel_mcp"])).toMatchObject({ ok: false, reason: "write" });+ }+ });+it("never lets a raw API proxy through a scoped bot", () => {expect(connectorAccessDecision({ apps: { gmail: "write" } }, calls("COMPOSIO_PROXY_EXECUTE"))).toMatchObject({ ok: false, reason: "app" });});diff --git a/shared/connector-scopes.ts b/shared/connector-scopes.tsindex 8d70629f64..e7a64f3f19 100644--- a/shared/connector-scopes.ts+++ b/shared/connector-scopes.ts@@ -26,15 +26,21 @@ export function toolkitOf(slug: string): string {return (cut > 0 ? slug.slice(0, cut) : slug).toLowerCase();}+/** Toolkits whose actions name a one-word resource before the verb+ * (HIGHLEVEL_MCP_CONTACTS_GET_CONTACTS lists contacts). Anything else there,+ * such as a longer resource name, stays a write. */+const RESOURCE_FIRST_TOOLKITS = ["highlevel_mcp"];+/** A read verb first means the tool reads. Creating a draft writes to the* account even though it sends nothing, so it is a write here. */export function isReadOnlyAction(slug: string, toolkit?: string): boolean {if (slug === "COMPOSIO_PROXY_EXECUTE") return false;if (KNOWN_READ_SLUGS.has(slug)) return true;- const cut = toolkit ? toolkit.length : slug.indexOf("_");+ const resourceFirst = RESOURCE_FIRST_TOOLKITS.find((candidate) => (toolkit ?? candidate) === candidate && slug.startsWith(candidate.toUpperCase() + "_"));+ const cut = resourceFirst ? resourceFirst.length : toolkit ? toolkit.length : slug.indexOf("_");const action = cut > 0 ? slug.slice(cut + 1) : "";- const first = action.toUpperCase().split(/[^A-Z0-9]+/).find(Boolean);- return first !== undefined && READ_VERBS.has(first);+ const verb = action.toUpperCase().split(/[^A-Z0-9]+/).filter(Boolean)[resourceFirst ? 1 : 0];+ return verb !== undefined && READ_VERBS.has(verb);}/** The stored shape, or null when the value is not one. */