Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

fix(infra): validate Composio Connect keys at the Connect MCP endpoint (#148)

Abdurrahman Fakhrul094c6358818a
diff --git a/lib/infra/composio.test.ts b/lib/infra/composio.test.ts
index dc2e05f0..f5756b49 100644
--- a/lib/infra/composio.test.ts
+++ b/lib/infra/composio.test.ts
@@ -1,8 +1,46 @@
import { afterEach, describe, expect, it, vi } from "vitest";
vi.mock("server-only", () => ({}));
+const connect = vi.hoisted(() => ({ urls: [] as string[], status: 200 }));
+vi.mock("@/lib/host/ssrf", () => ({
+ safeProviderFetch: vi.fn(async (url: string, init?: RequestInit) => {
+ connect.urls.push(String(url));
+ if (connect.status !== 200) return new Response("{}", { status: connect.status });
+ const body = JSON.parse(String(init?.body)) as { id?: unknown; method: string };
+ const payload = body.method === "server/discover"
+ ? { result: { resultType: "complete", protocolVersion: "2026-07-28" } }
+ : { result: { resultType: "complete", tools: [{ name: "COMPOSIO_SEARCH_TOOLS", description: "Search", inputSchema: { type: "object" } }] } };
+ return new Response(JSON.stringify({ jsonrpc: "2.0", id: body.id, ...payload }), { status: 200, headers: { "content-type": "application/json" } });
+ }),
+}));
import { COMPOSIO_CONNECT_KEY_MESSAGE, composioAuthHeader, composioKeyKind, doctorComposio } from "./composio";
-afterEach(() => vi.unstubAllGlobals());
+afterEach(() => { vi.unstubAllGlobals(); connect.urls = []; connect.status = 200; });
+
+describe("composio Connect key validation", () => {
+ it("accepts a ck_ key by proving reach at the Connect MCP endpoint", async () => {
+ const detail = await doctorComposio({ apiKey: "ck_synthetic_connect_validate_key" });
+ expect(detail).toContain("Connect");
+ expect(detail).toContain("1 tool(s) available");
+ expect(detail).not.toContain("Platform key accepted");
+ for (const url of connect.urls) expect(new URL(url).hostname).toBe("connect.composio.dev");
+ expect(connect.urls.length).toBeGreaterThan(0);
+ });
+
+ it("never sends a ck_ key to the Platform API", async () => {
+ const platform: string[] = [];
+ vi.stubGlobal("fetch", vi.fn(async (url: RequestInfo | URL) => { platform.push(String(url)); return new Response("{}", { status: 200 }); }));
+ await doctorComposio({ apiKey: "ck_synthetic_connect_validate_key" });
+ expect(platform).toHaveLength(0);
+ });
+
+ it("reports a rejected Connect key without echoing it", async () => {
+ connect.status = 401;
+ const failure = await doctorComposio({ apiKey: "ck_synthetic_connect_validate_key" }).catch((error: Error) => error);
+ expect(failure).toBeInstanceOf(Error);
+ expect(String(failure)).toContain("Composio rejected this Connect key");
+ expect(String(failure)).not.toContain("ck_synthetic_connect_validate_key");
+ });
+});
describe("composio credential routing", () => {
it("routes each key kind to its own header", () => {
@@ -28,6 +66,28 @@ describe("composio credential routing", () => {
vi.stubGlobal("fetch", vi.fn(async () => new Response("{}", { status: 401 })));
await expect(doctorComposio({ apiKey: "uak_synthetic_user_key" })).rejects.toThrow("Composio rejected this user key (401)");
});
+
+ it("keeps the ak_ project key on backend.composio.dev /tools", async () => {
+ const mock = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
+ expect(new Headers(init?.headers).get("x-api-key")).toBe("ak_synthetic_project_key");
+ return new Response("{}", { status: 200 });
+ });
+ vi.stubGlobal("fetch", mock);
+ await expect(doctorComposio({ apiKey: "ak_synthetic_project_key" })).resolves.toBe("Composio project key accepted");
+ expect(String(mock.mock.calls[0]?.[0])).toBe("https://backend.composio.dev/api/v3.1/tools?limit=1");
+ });
+
+ it("keeps the organisation key on x-org-api-key and its project list target", async () => {
+ const mock = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
+ const headers = new Headers(init?.headers);
+ expect(headers.get("x-org-api-key")).toBe("org_synthetic_admin_key");
+ expect(headers.has("x-api-key")).toBe(false);
+ return new Response("{}", { status: 200 });
+ });
+ vi.stubGlobal("fetch", mock);
+ await expect(doctorComposio({ orgApiKey: "org_synthetic_admin_key", apiKey: "ak_synthetic_project_key" })).resolves.toBe("Composio organization key accepted");
+ expect(String(mock.mock.calls[0]?.[0])).toBe("https://backend.composio.dev/api/v3.1/org/owner/project/list");
+ });
});
describe("composio connect consumer keys", () => {
diff --git a/lib/infra/composio.ts b/lib/infra/composio.ts
index 273b0038..41f4a815 100644
--- a/lib/infra/composio.ts
+++ b/lib/infra/composio.ts
@@ -43,6 +43,20 @@ export function composioKeyKind(values: InfraProviderValues): "organization" | "
export async function doctorComposio(candidate?: InfraProviderValues): Promise<string | null> {
const values = candidate ?? await readInfraProvider("composio");
+ // Detect the Connect kind before composioAuthHeader, which correctly refuses it:
+ // a ck_ key is a Connect MCP credential, so reach at the MCP endpoint is the proof.
+ // Lazy imports keep this module cycle-free (composio-connect imports composio).
+ if (composioKeyKind(values) === "connect") {
+ const { listComposioConnectTools } = await import("./composio-connect");
+ try {
+ const { tools } = await listComposioConnectTools(values);
+ return `Composio Connect key accepted; ${tools.length} tool(s) available. Connect keys cannot authorize Platform connected accounts.`;
+ } catch (error) {
+ const { redactComposioMessage } = await import("./composio-session-contract");
+ const detail = redactComposioMessage(error instanceof Error ? error.message : "composio_connect_validation_failed", [values.apiKey, values.orgApiKey]);
+ throw new Error(`${/\b40[13]\b/.test(detail) ? "Composio rejected this Connect key" : "Composio Connect validation failed"}: ${detail}`);
+ }
+ }
const auth = composioAuthHeader(values);
if (!auth) return null;
// Session-info proves the key kind and works for all three kinds; tool listing