/** * ROUTES-AUDIT 4 (coordinator, 23 Nov 2026): any connected assistant could read saved passwords in plain text. * `grants()` admitted the owner scope, which every OAuth connector token holds, before it refused `dev_` tools, and * dev_reveal_secret opens any secret with the server's vault key under no window. Now a `dev_` tool is refused to every * token, the owner scope too, on a Worker that is not dev or test (live's ENV_LABEL is "production"). */ import { describe, expect, it } from "vitest"; import catalogue from "../src/mcp/catalogue.json"; import { devToolsHere, grants } from "../src/mcp/server.ts"; const tool = (catalogue.tools as { name: string; scope: string }[]).find((t) => t.name === "dev_reveal_secret")!; const caller = (scopes: string[]) => ({ scopes: new Set(scopes), lane: null }) as unknown as Parameters[0]; describe("dev_ tools", () => { it("are refused to every token on live, the owner scope too, and served on dev and the tests alone", () => { expect(tool).toBeDefined(); expect(devToolsHere({ ENV_LABEL: "production" })).toBe(false); expect(devToolsHere({})).toBe(false); expect(devToolsHere({ ENV_LABEL: "dev" })).toBe(true); expect(devToolsHere({ ENV_LABEL: "test" })).toBe(true); const live = devToolsHere({ ENV_LABEL: "production" }); expect(grants(caller(["owner"]), tool as never, live)).toBe(false); expect(grants(caller(["owner"]), tool as never)).toBe(false); expect(grants(caller(["read", "write"]), tool as never, live)).toBe(false); // On dev the owner's token still reaches it, and nothing else does. expect(grants(caller(["owner"]), tool as never, true)).toBe(true); expect(grants(caller(["read", "write"]), tool as never, true)).toBe(false); // Every other tool is as it was for the owner scope on live. const other = (catalogue.tools as { name: string; scope: string }[]).find((t) => t.name === "list_records")!; expect(grants(caller(["owner"]), other as never, live)).toBe(true); }); });