Skip to content

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

fix: accept underscore-prefixed Composio toolkit slugs like _1password

Ooi Pin Junec21410b6bd1
diff --git a/packages/phone-protocol/src/connector-scopes.ts b/packages/phone-protocol/src/connector-scopes.ts
index 22bdf11bc6..131e180666 100644
--- a/packages/phone-protocol/src/connector-scopes.ts
+++ b/packages/phone-protocol/src/connector-scopes.ts
@@ -21,7 +21,7 @@ export interface ConnectorScopes {
accounts?: Record<string, string[]>;
}
-const TOOLKIT_SLUG = /^[a-z0-9][a-z0-9_-]{0,63}$/;
+const TOOLKIT_SLUG = /^(?!__proto__$)[a-z0-9_][a-z0-9_-]{0,63}$/;
const ACCOUNT_ID = /^[A-Za-z0-9][A-Za-z0-9_.:-]{0,127}$/;
/** The toolkit a Composio slug belongs to: the part before the first
diff --git a/packages/phone-protocol/src/wire.ts b/packages/phone-protocol/src/wire.ts
index 5109c10a01..1d132f6c8d 100644
--- a/packages/phone-protocol/src/wire.ts
+++ b/packages/phone-protocol/src/wire.ts
@@ -251,7 +251,7 @@ export interface ConnectorToolGrant {
}
/** Lowercased Composio service slug, e.g. `gmail`. */
-export const CONNECTOR_SLUG_PATTERN = /^[a-z0-9][a-z0-9_-]{0,80}$/;
+export const CONNECTOR_SLUG_PATTERN = /^(?!__proto__$)[a-z0-9_][a-z0-9_-]{0,80}$/;
/** Composio tool names are upper-snake, e.g. `GMAIL_SEND_EMAIL`. */
export const CONNECTOR_TOOL_NAME_PATTERN = /^[A-Z][A-Z0-9_]{0,127}$/;
diff --git a/server/cloud-team-policy.test.ts b/server/cloud-team-policy.test.ts
index dbf0fe3e38..51cbfcb2ea 100644
--- a/server/cloud-team-policy.test.ts
+++ b/server/cloud-team-policy.test.ts
@@ -284,3 +284,10 @@ describe("the managed policy with a team's rules", () => {
managed.close();
});
});
+
+it.each(["_1password", "_" + "a".repeat(63)])("accepts allowed app %s", (slug) => {
+ expect(teamPolicyDocumentSchema.safeParse(doc({ allowedApps: [slug] })).success).toBe(true);
+});
+it.each(["", "-x", "Bad Slug", "a/b", "__proto__", "Uppercase", "a".repeat(65)])("rejects invalid allowed app %s", (slug) => {
+ expect(teamPolicyDocumentSchema.safeParse(doc({ allowedApps: [slug] })).success).toBe(false);
+});
diff --git a/server/cloud-team-policy.ts b/server/cloud-team-policy.ts
index 647254d17e..4fc77ab4cd 100644
--- a/server/cloud-team-policy.ts
+++ b/server/cloud-team-policy.ts
@@ -32,7 +32,7 @@ const allowed = <T extends z.ZodType>(entry: T, max: number) => z.union([z.liter
/** Omitted, or a permissive value: allowed. Only an explicit restriction restricts, and nothing can force anything on. */
const limitsSchema = z.object({
allowedEngines: allowed(z.string().regex(/^[A-Za-z][A-Za-z0-9-]{0,63}$/), 64).optional(),
- allowedApps: allowed(z.string().regex(/^[a-z0-9][a-z0-9_-]{0,63}$/), 200).optional(),
+ allowedApps: allowed(z.string().regex(/^(?!__proto__$)[a-z0-9_][a-z0-9_-]{0,63}$/), 200).optional(),
/** `"team"`: only what the team's admins add; a list: only those, whoever adds them. */
allowedMcpServers: z.union([z.literal("team"), allowed(z.string().trim().min(1).max(200), 100)]).optional(),
allowedComputers: allowed(z.enum(["cloudDesktop", "vps", "memberComputer"]), 3).optional(),
diff --git a/server/composio-inventory-schema.ts b/server/composio-inventory-schema.ts
index d7c5d797ed..a1bceb62b9 100644
--- a/server/composio-inventory-schema.ts
+++ b/server/composio-inventory-schema.ts
@@ -1,7 +1,7 @@
import { z } from "zod";
export const ACCOUNT_ID = /^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$/;
-const TOOLKIT_SLUG = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
+const TOOLKIT_SLUG = /^(?!__proto__$)[A-Za-z0-9_][A-Za-z0-9_-]*$/;
const toolkitItemSchema = z.object({
slug: z.string().optional(),
diff --git a/server/composio-inventory.test.ts b/server/composio-inventory.test.ts
index a23616488b..14546f7367 100644
--- a/server/composio-inventory.test.ts
+++ b/server/composio-inventory.test.ts
@@ -3,6 +3,7 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it, vi } from "vitest";
+import { inventoryAccountSchema, toolkitInventoryPageSchema } from "./composio-inventory-schema.ts";
import * as composio from "./composio.ts";
import type { AppConfig } from "./config.ts";
import { createTeamConnectionsHost } from "./host/team-connections-host.ts";
@@ -135,3 +136,16 @@ describe.each(["connected_accounts", "toolkits"])("self-hosted %s inventory", (w
},
);
});
+
+it.each(["_1password", "_1PASSWORD", "a".repeat(200)])("accepts inventory toolkit %s without adding a length or case restriction", (slug) => {
+ expect(inventoryAccountSchema.safeParse({ id: "ca_fixture", toolkit: { slug } }).success).toBe(true);
+ expect(toolkitInventoryPageSchema.safeParse({ items: [{ slug, connected_account: { id: "ca_fixture" } }] }).success).toBe(true);
+});
+it.each(["", "-x", "Bad Slug", "a/b", "__proto__"])("rejects invalid inventory toolkit %s", (slug) => {
+ expect(inventoryAccountSchema.safeParse({ id: "ca_fixture", toolkit: { slug } }).success).toBe(false);
+ expect(toolkitInventoryPageSchema.safeParse({ items: [{ slug, is_no_auth: true }] }).success).toBe(false);
+});
+it("still rejects leading underscores in account ids", () => {
+ expect(inventoryAccountSchema.safeParse({ id: "_account", toolkit: { slug: "_1password" } }).success).toBe(false);
+ expect(toolkitInventoryPageSchema.safeParse({ items: [{ slug: "_1password", connected_account: { id: "_account" } }] }).success).toBe(false);
+});
diff --git a/server/connector-advertisement.test.ts b/server/connector-advertisement.test.ts
index cd25351ca3..e296c69b31 100644
--- a/server/connector-advertisement.test.ts
+++ b/server/connector-advertisement.test.ts
@@ -152,3 +152,11 @@ describe("the apps' sandbox", () => {
expect(connectorToolAdvertised("SLACK_POST_MESSAGE", full)).toBe(false);
});
});
+
+it.each(["_1password", "_" + "a".repeat(80)])("round-trips connector grants for %s", (slug) => {
+ const record = grants({ [slug]: { tools: "*" } });
+ expect(parseConnectorAllowedToolsEnv(serializeConnectorAllowedTools(record).env)).toEqual(record);
+});
+it.each(["", "-x", "Bad Slug", "a/b", "__proto__", "Uppercase", "a".repeat(82)])("rejects invalid connector grant slug %s", (slug) => {
+ expect(parseConnectorAllowedToolsEnv(JSON.stringify({ [slug]: { tools: "*" } }))).toBeNull();
+});
diff --git a/server/connector-request-items.test.ts b/server/connector-request-items.test.ts
index 076097926a..56dd66e818 100644
--- a/server/connector-request-items.test.ts
+++ b/server/connector-request-items.test.ts
@@ -16,3 +16,10 @@ describe("connector card requests", () => {
}
});
});
+
+it.each(["_1password", "_" + "a".repeat(80), "_1PASSWORD"])("keeps toolkit request %s in every input shape", (slug) => {
+ expect(connectorRequestItems([slug, { slug }, { toolkit: slug }])).toEqual(Array(3).fill({ slug: slug.toLowerCase() }));
+});
+it.each(["", "-x", "Bad Slug", "a/b", "__proto__", "a".repeat(82)])("skips invalid toolkit request %s", (slug) => {
+ expect(connectorRequestItems([slug, { slug }, { toolkit: slug }])).toEqual([]);
+});
diff --git a/server/connector-request-items.ts b/server/connector-request-items.ts
index 217a23b352..09433c71da 100644
--- a/server/connector-request-items.ts
+++ b/server/connector-request-items.ts
@@ -2,7 +2,7 @@ import { AUTH_CONFIG_ID } from "../shared/connector-availability.ts";
import { inputError } from "./composio-project.ts";
import { normalizeAccountAlias } from "./composio.ts";
-const CONNECTOR_SLUG = /^[a-z0-9][a-z0-9_-]{0,80}$/;
+const CONNECTOR_SLUG = /^(?!__proto__$)[a-z0-9_][a-z0-9_-]{0,80}$/;
export interface ConnectorRequestItem {
slug: string;
diff --git a/server/managed-policy.test.ts b/server/managed-policy.test.ts
index c2ebcb37a8..02fa5dc45c 100644
--- a/server/managed-policy.test.ts
+++ b/server/managed-policy.test.ts
@@ -169,3 +169,10 @@ describe("claim-time computer refusal in bindTurnComputer", () => {
await expect(bind(managed)({}, "computer:vm:shared")).resolves.toBe("claimed");
});
});
+
+it.each(["_1password", "_" + "a".repeat(63)])("accepts app allowlist entry %s", (slug) => {
+ expect(parseManagedPolicy(policy({ apps: { allowAll: false, allowlist: [slug] } }))?.apps?.allowlist).toEqual([slug]);
+});
+it.each(["", "-x", "Bad Slug", "a/b", "__proto__", "Uppercase", "a".repeat(65)])("rejects invalid app allowlist entry %s", (slug) => {
+ expect(() => parseManagedPolicy(policy({ apps: { allowAll: false, allowlist: [slug] } }))).toThrow();
+});
diff --git a/server/managed-policy.ts b/server/managed-policy.ts
index 38ee7f3833..a94f20b140 100644
--- a/server/managed-policy.ts
+++ b/server/managed-policy.ts
@@ -17,7 +17,7 @@ const policySchema = z.object({
computers: z.object({ thisComputer: z.boolean(), localVm: z.boolean(), box: z.boolean(), vps: z.boolean() }).strict(),
remoteAccess: z.boolean(),
/** Connected apps by service slug. Absent: this policy says nothing about them. */
- apps: z.object({ allowAll: z.boolean(), allowlist: z.array(z.string().regex(/^[a-z0-9][a-z0-9_-]{0,63}$/)).max(200) }).strict().optional(),
+ apps: z.object({ allowAll: z.boolean(), allowlist: z.array(z.string().regex(/^(?!__proto__$)[a-z0-9_][a-z0-9_-]{0,63}$/)).max(200) }).strict().optional(),
/** Present on a Team Cloud's rules. `requireFresh`: new turns wait while the rules can't be confirmed with the Admin.
* `ownMcpOnly`: bots get only what the team's admins added; a bot can't add one, and a bot's own doesn't start. */
team: z.object({ requireFresh: z.boolean(), ownMcpOnly: z.boolean() }).strict().optional(),
diff --git a/server/routes/team-connections.test.ts b/server/routes/team-connections.test.ts
index f2754718a7..d1f6fb0d34 100644
--- a/server/routes/team-connections.test.ts
+++ b/server/routes/team-connections.test.ts
@@ -7,7 +7,7 @@ import { DATA_DIR, type AppConfig } from "../config.ts";
import type { TeamConnectionsHost } from "../host/team-connections-host.ts";
import { personKey } from "../person-key.ts";
import type { RequestAuth } from "../request-auth.ts";
-import { PeopleConnections } from "../team-connections.ts";
+import { APP_SLUG, PeopleConnections } from "../team-connections.ts";
import { createTeamConnectionRoutes, type TeamConnectionRouteDeps } from "./team-connections.ts";
const URL_A = "https://mail.example.com/mcp";
@@ -72,3 +72,10 @@ it.each(["", 123])("refuses a malformed expected URL (%s)", async (url) => {
expect((await save({ value: KEY, url })).status).toBe(400);
expect(people.key(PERSON, "mail", URL_A)).toBeNull();
});
+
+it.each(["_1password", "_" + "a".repeat(63)])("accepts team app slug %s", (slug) => {
+ expect(APP_SLUG.test(slug)).toBe(true);
+});
+it.each(["", "-x", "Bad Slug", "a/b", "__proto__", "Uppercase", "a".repeat(65)])("rejects invalid team app slug %s", (slug) => {
+ expect(APP_SLUG.test(slug)).toBe(false);
+});
diff --git a/server/team-connections.ts b/server/team-connections.ts
index c257e7ae75..afa3a82d96 100644
--- a/server/team-connections.ts
+++ b/server/team-connections.ts
@@ -27,7 +27,7 @@ export type ConnectionKind = "app" | "mcp";
export const SCOPES_FILE = "team-connection-scopes.json";
export const PEOPLE_CONNECTIONS_DIR = "people-connections";
/** Composio's toolkit slugs; an MCP server's name as mcp-registry.ts allows it. */
-export const APP_SLUG = /^[a-z0-9][a-z0-9_-]{0,63}$/;
+export const APP_SLUG = /^(?!__proto__$)[a-z0-9_][a-z0-9_-]{0,63}$/;
export const MCP_NAME = /^[a-z][a-z0-9_-]{0,31}$/;
const PERSON = /^p_[\w-]{22}$/;
const TOKEN = /^[0-9a-f]{64}$/;
diff --git a/shared/connector-scopes.test.ts b/shared/connector-scopes.test.ts
index b865128a20..31ea96570c 100644
--- a/shared/connector-scopes.test.ts
+++ b/shared/connector-scopes.test.ts
@@ -198,3 +198,10 @@ describe("per-account limits", () => {
expect(widensConnectorScopes(undefined, scopes)).toBe(false);
});
});
+
+it.each(["_1password", "_" + "a".repeat(63), " _1PASSWORD "])("normalizes toolkit scope %s", (slug) => {
+ expect(normalizeConnectorScopes({ apps: { [slug]: "read" } })).toEqual({ apps: { [slug.trim().toLowerCase()]: "read" } });
+});
+it.each(["", "-x", "Bad Slug", "a/b", "__proto__", "a".repeat(65)])("rejects invalid toolkit scope %s", (slug) => {
+ expect(normalizeConnectorScopes({ apps: { [slug]: "read" } })).toBeNull();
+});
diff --git a/shared/package-format.test.ts b/shared/package-format.test.ts
index 6b5b89cdf0..2859b8b695 100644
--- a/shared/package-format.test.ts
+++ b/shared/package-format.test.ts
@@ -306,3 +306,19 @@ describe("files for older apps", () => {
expect(downgradeToV1(document)).toEqual({ error: expect.stringContaining("5 to 240 minutes") });
});
});
+
+it.each(["legacy-team.v1.json", "full-team.v2.json"])("accepts underscore app requirements without widening package keys in %s", (name) => {
+ for (const slug of ["_1password", "_" + "a".repeat(63)]) {
+ const value = fixture(name);
+ value.package.requirements.apps = [{ slug, label: "1Password", reason: "Read vault items." }];
+ expect(parsePackageDocument(value).package.requirements.apps[0]?.slug).toBe(slug);
+ }
+ for (const slug of ["", "-x", "Bad Slug", "a/b", "__proto__", "Uppercase", "a".repeat(65)]) {
+ const value = fixture(name);
+ value.package.requirements.apps = [{ slug, label: "Invalid", reason: "Test validation." }];
+ expect(() => parsePackageDocument(value)).toThrow();
+ }
+ const value = fixture(name);
+ value.package.agents[0].key = "_agent";
+ expect(() => parsePackageDocument(value)).toThrow();
+});
diff --git a/shared/package-format.ts b/shared/package-format.ts
index db3dd5f4ba..f9c75dc29c 100644
--- a/shared/package-format.ts
+++ b/shared/package-format.ts
@@ -166,7 +166,9 @@ const playbookSchema = z.object({
});
const requirementsSchema = z.object({
apps: z.array(z.object({
- slug: key,
+ slug: requiredText(64).regex(/^(?!__proto__$)[a-z0-9_][a-z0-9_-]*$/, {
+ message: "may only contain lowercase letters, numbers, - and _",
+ }),
label: requiredText(100),
reason: requiredText(240),
optional: z.boolean().optional(),