Skip to content

Open-source AI coworkers that each get a computer of their own: a browser, files and tools, with every action decided before it happens and recorded after. Bring any AG-UI agent.

Refuse an administrator's grant of a skill nobody has written (#657)

Asem ahmed097be181964f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index af2dece1..25596c21 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,14 @@ Take control or Hand back controls. The same ownership state is shown in the cha
sidebar, and full-size viewer. Standalone Bot chats can open the current live browser alongside
the conversation without losing the selected Bot or chat history.
+### An administrator cannot grant a skill nobody has written
+
+`POST /api/plugins/grants` checked that a skill existed for everybody except an administrator, whose
+grant was stored whatever it named. A Bot's skills are read by slug alone, so the row waited for
+whoever wrote a skill under that name next, and on a Bot the deployment shares that was one person's
+instructions answering everybody. It is now refused with "There is no skill called …", as a grant
+naming no app already was. Revoking one by hand still works.
+
### Browser challenges can be handed to a person without losing the Bot's page
Bots pause for actionable browser challenges and resume from a fresh page snapshot after an explicit
diff --git a/server/src/plugins/routes.ts b/server/src/plugins/routes.ts
index ed545f3a..21cd8702 100644
--- a/server/src/plugins/routes.ts
+++ b/server/src/plugins/routes.ts
@@ -2352,7 +2352,22 @@ export function createPluginRoutes(
return null;
}
- if (actor.isAdmin) return null;
+ if (actor.isAdmin) {
+ // Taking something away is always allowed: see the note on `intent`.
+ if (intent === "revoke") return null;
+ /*
+ * A grant naming no skill is refused for an administrator too, as the `mcp` branch refuses a
+ * grant naming no app. `store.grant` is a bare upsert and a Bot's skills are read by slug
+ * alone, so the row sat there granting nothing until somebody wrote a skill under that name,
+ * and then that skill was on this Bot with nobody having put it there. On a Bot the
+ * deployment shares, that is one person's instructions answering everybody:
+ * `skill-uninstall-grants.integration.test.ts` guards the same room from the uninstall side.
+ */
+ if ((await store.skillOwner(ref)) === undefined) {
+ return `There is no skill called ${ref}.`;
+ }
+ return null;
+ }
const owner = await store.skillOwner(ref);
if (owner === undefined) return `There is no skill called ${ref}.`;
diff --git a/server/tests/plugin-grants-validation.test.ts b/server/tests/plugin-grants-validation.test.ts
index 3760c5a2..231501a8 100644
--- a/server/tests/plugin-grants-validation.test.ts
+++ b/server/tests/plugin-grants-validation.test.ts
@@ -11,15 +11,22 @@ function appWith(
toolCalls: unknown[];
revokes?: unknown[];
serverLookups?: unknown[];
+ skillLookups?: unknown[];
},
/** The apps this deployment has added, for the grant path's existence check. */
servers: string[] = ["tool"],
+ /** The skills that exist, all of them the deployment's own. */
+ skills: string[] = [],
) {
const store = {
serverExists: async (serverId: string) => {
calls.serverLookups?.push(serverId);
return servers.includes(serverId);
},
+ skillOwner: async (slug: string) => {
+ calls.skillLookups?.push(slug);
+ return skills.includes(slug) ? null : undefined;
+ },
grant: async (kind: unknown, ref: unknown, agentId: unknown) => {
calls.grants.push({ kind, ref, agentId });
return { ok: true };
@@ -206,6 +213,72 @@ describe("POST /api/plugins/grants, for an app this deployment does not have", (
});
});
+/**
+ * A GRANT NAMING NO SKILL, from an administrator.
+ *
+ * Every other caller's skill grant is checked against the skill; an administrator's returned before
+ * the lookup. A Bot's skills are read by slug alone, so the stored row waited for whoever wrote a
+ * skill under that name next — on a shared Bot, one person's instructions answering everybody.
+ */
+describe("POST /api/plugins/grants, for a skill nobody has written", () => {
+ const grantSkill = (ref: string) => ({
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({ kind: "skill", ref, agentId: "bot-1" }),
+ });
+
+ test("refuses an administrator's grant and never reaches the store", async () => {
+ const calls = {
+ grants: [] as unknown[],
+ toolCalls: [] as unknown[],
+ skillLookups: [] as unknown[],
+ };
+ const response = await appWith(calls, [], ["triage"]).request(
+ "http://openbot.test/grants",
+ grantSkill("standup"),
+ );
+
+ expect(response.status).toBe(403);
+ await expect(response.json()).resolves.toEqual({
+ error: "There is no skill called standup.",
+ });
+ expect(calls.grants).toEqual([]);
+ expect(calls.skillLookups).toEqual(["standup"]);
+ });
+
+ test("a skill that is here is granted as before", async () => {
+ const calls = { grants: [] as unknown[], toolCalls: [] as unknown[] };
+ const response = await appWith(calls, [], ["triage"]).request(
+ "http://openbot.test/grants",
+ grantSkill("triage"),
+ );
+
+ expect(response.status).toBe(200);
+ expect(calls.grants).toEqual([
+ { kind: "skill", ref: "triage", agentId: "bot-1" },
+ ]);
+ });
+
+ test("a grant naming no skill can still be revoked by hand", async () => {
+ const calls = {
+ grants: [] as unknown[],
+ toolCalls: [] as unknown[],
+ revokes: [] as unknown[],
+ skillLookups: [] as unknown[],
+ };
+ const response = await appWith(calls, [], []).request(
+ "http://openbot.test/grants?kind=skill&ref=standup&agentId=bot-1",
+ { method: "DELETE" },
+ );
+
+ expect(response.status).toBe(200);
+ expect(calls.revokes).toEqual([
+ { kind: "skill", ref: "standup", agentId: "bot-1" },
+ ]);
+ expect(calls.skillLookups).toEqual([]);
+ });
+});
+
describe("DELETE /api/plugins/grants", () => {
/**
* Query params are always strings, so truthiness is not enough.
diff --git a/server/tests/skill-uninstall-grants.integration.test.ts b/server/tests/skill-uninstall-grants.integration.test.ts
index a5e588a3..82298454 100644
--- a/server/tests/skill-uninstall-grants.integration.test.ts
+++ b/server/tests/skill-uninstall-grants.integration.test.ts
@@ -35,6 +35,7 @@ const sharedBot = `agent_shared_${suite}`;
const personalSlug = `standup-${suite}`;
const keptSlug = `kept-${suite}`;
const deploymentSlug = `triage-${suite}`;
+const unwrittenSlug = `unwritten-${suite}`;
beforeAll(async () => {
for (const id of [alice, bob]) {
@@ -68,7 +69,14 @@ beforeAll(async () => {
afterAll(async () => {
await database
.delete(skills)
- .where(inArray(skills.slug, [personalSlug, keptSlug, deploymentSlug]));
+ .where(
+ inArray(skills.slug, [
+ personalSlug,
+ keptSlug,
+ deploymentSlug,
+ unwrittenSlug,
+ ]),
+ );
await database
.delete(agents)
.where(inArray(agents.id, [aliceBot, sharedBot]));
@@ -175,6 +183,25 @@ describe("a skill name written again after the skill was uninstalled", () => {
expect(await offered(asAdmin(), sharedBot)).toEqual([]);
});
+ /*
+ * The same room, entered before any skill exists rather than after one is uninstalled. An
+ * administrator's grant skipped the existence check every other caller gets, and a Bot's skills are
+ * read by slug alone, so the grant waited for whoever wrote a skill under that name next.
+ */
+ test("a shared Bot cannot be granted a skill nobody has written yet", async () => {
+ const refused = await grant(asAdmin(), unwrittenSlug, sharedBot);
+ expect(refused.status).toBe(403);
+ expect(await refused.json()).toEqual({
+ error: `There is no skill called ${unwrittenSlug}.`,
+ });
+
+ expect(
+ (await writeSkill(asAlice(), unwrittenSlug, "Alice's words.")).status,
+ ).toBe(200);
+
+ expect(await offered(asAdmin(), sharedBot)).toEqual([]);
+ });
+
test("uninstalling removes that skill's grants and no other", async () => {
const held = await database
.select({ ref: pluginGrants.ref, agentId: pluginGrants.agentId })