Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/api/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4948,7 +4948,11 @@ async function getRoleSummaryForIdentity(env: Env, identity: AuthIdentity) {
async function requireAppRole(c: ProtectedRouteContext, allowedRoles: ControlPanelRoleName[]): Promise<Response | null> {
const identity = await authenticateRequestIdentity(c);
if (!identity) return c.json({ error: "unauthorized" }, 401);
if (identity.kind !== "session") return null;
if (identity.kind !== "session") {
// GITTENSORY_MCP_TOKEN is a shared end-user credential; it must not satisfy app-role gates implicitly.
if (identity.actor === "mcp") return c.json({ error: "insufficient_role" }, 403);
return null;
}
const summary = await loadControlPanelRoleSummary(c.env, identity.actor);
return summary.roles.some((role) => allowedRoles.includes(role)) ? null : c.json({ error: "insufficient_role" }, 403);
}
Expand Down
14 changes: 14 additions & 0 deletions test/unit/routes-kill-switch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ describe("kill-switch operator route (#2359)", () => {
expect(res.status).toBe(401);
});

it("rejects the shared MCP token without changing the global kill-switch", async () => {
const app = createApp();
const env = createTestEnv();
const headers = { authorization: `Bearer ${env.GITTENSORY_MCP_TOKEN}`, "content-type": "application/json" };

const read = await app.request("/v1/app/kill-switch", { headers }, env);
expect(read.status).toBe(403);

const write = await app.request("/v1/app/kill-switch", { method: "POST", headers, body: JSON.stringify({ frozen: true }) }, env);
expect(write.status).toBe(403);
await expect(getGlobalAgentFrozenState(env)).resolves.toMatchObject({ frozen: false, updatedBy: null });
expect(setGlobalAgentFrozen).not.toHaveBeenCalled();
});

it("GET surfaces a clear 503 (never a falsely reassuring unfrozen) when the singleton row is missing", async () => {
const app = createApp();
const env = createTestEnv();
Expand Down
Loading