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 a non-string skill slug or summary before the store (#494) (#498)
Felix-Ayush89e9b7d12579
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e4ae1eec..b847e6d5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -8,6 +8,14 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.## Unreleased+### A skill written with a non-string slug or summary is refused instead of failing the insert++`POST /api/plugins/skills` checked presence with truthiness and then ran the slug regex, which+coerces: `{"slug":123}` tested the string `"123"` and passed validation, and `{"summary":{}}` had+no check at all. Both reached the store, where the insert threw an uncaught error — a 500 for a+caller error. A slug, a title and instructions must be non-empty strings now, the slug pattern is+tested only after that, and a summary must be absent or a string; anything else is a 400 naming+the field, before any refusal check, store write, or audit row.### Generated interfaces, tables and formsGenerative UI is enabled by default; set `OPENBOT_GENERATIVE_UI=false` or `0` to disable it.diff --git a/server/src/plugins/routes.ts b/server/src/plugins/routes.tsindex 64d7eb18..df7918e9 100644--- a/server/src/plugins/routes.ts+++ b/server/src/plugins/routes.ts@@ -567,14 +567,27 @@ export function createPluginRoutes(*/routes.post("/skills", requireUser, async (context) => {const body = (await context.req.json().catch(() => null)) as {- slug?: string;- title?: string;- summary?: string;- instructions?: string;+ slug?: unknown;+ title?: unknown;+ summary?: unknown;+ instructions?: unknown;global?: boolean;tools?: unknown;} | null;- if (!body?.slug || !body?.title?.trim() || !body?.instructions?.trim()) {+ /*+ * The body is JSON, so the annotations are wishes: `{"slug":123}` passes a truthiness+ * check and `RegExp.test` then coerces it to `"123"`, and `{"summary":{}}` reaches the+ * store where the insert throws a 500. A slug, a title and instructions are non-empty+ * strings here, and a summary is absent or a string. Anything else is a 400 before+ * any refusal check, store write, or audit row.+ */+ if (+ typeof body?.slug !== "string" ||+ typeof body?.title !== "string" ||+ !body.title.trim() ||+ typeof body?.instructions !== "string" ||+ !body.instructions.trim()+ ) {return context.json({ error: "A slug, a title and instructions are required." },400,@@ -586,6 +599,12 @@ export function createPluginRoutes(400,);}+ if (body.summary !== undefined && typeof body.summary !== "string") {+ return context.json(+ { error: "A summary is text when it is present." },+ 400,+ );+ }const actor = skillActor(context);if (body.global && !actor.isAdmin) {diff --git a/server/tests/plugin-grants-validation.test.ts b/server/tests/plugin-grants-validation.test.tsindex 6b57b966..1a022160 100644--- a/server/tests/plugin-grants-validation.test.ts+++ b/server/tests/plugin-grants-validation.test.ts@@ -65,6 +65,103 @@ describe("POST /api/plugins/grants", () => {});});+describe("POST /api/plugins/skills", () => {+ function skillsApp(calls: { installs: unknown[] }) {+ const store = {+ grant: async () => ({ ok: true }),+ callTool: async () => ({ ok: true }),+ skillOwner: async () => null,+ installSkill: async (input: unknown) => {+ calls.installs.push(input);+ },+ listSkills: async () => [],+ } as unknown as PluginStore;+ const requireUser: MiddlewareHandler<{ Variables: AppVariables }> = async (+ context,+ next,+ ) => {+ context.set("actor", {+ id: "user-1",+ email: "[email protected]",+ role: "admin",+ });+ await next();+ };+ const canUseBot: BotAccessCheck = async () => true;+ return createPluginRoutes(store, requireUser, canUseBot);+ }++ /**+ * The body is JSON, so the annotations are wishes.+ *+ * `{"slug":123,...}` is truthy and `RegExp.test` coerces it to `"123"`, so it used to pass+ * validation; `{"summary":{}}` reached the store where the insert threw a 500. Both are caller+ * errors and answer 400 before any refusal check, store write, or audit row.+ */+ test.each([+ ["a number slug", { slug: 123, title: "t", instructions: "i" }],+ ["an object slug", { slug: {}, title: "t", instructions: "i" }],+ ["a number title", { slug: "ok-slug", title: 42, instructions: "i" }],+ [+ "a number instructions",+ { slug: "ok-slug", title: "t", instructions: 42 },+ ],+ [+ "an object summary",+ { slug: "ok-slug", title: "t", instructions: "i", summary: {} },+ ],+ [+ "an array summary",+ { slug: "ok-slug", title: "t", instructions: "i", summary: [] },+ ],+ [+ "a number summary",+ { slug: "ok-slug", title: "t", instructions: "i", summary: 42 },+ ],+ [+ "a whitespace title",+ { slug: "ok-slug", title: " ", instructions: "i" },+ ],+ [+ "a whitespace instructions",+ { slug: "ok-slug", title: "t", instructions: " " },+ ],+ ])("refuses %s with 400 and never reaches the store", async (_n, body) => {+ const calls = { installs: [] as unknown[] };+ const response = await skillsApp(calls).request(+ "http://openbot.test/skills",+ {+ method: "POST",+ headers: { "content-type": "application/json" },+ body: JSON.stringify(body),+ },+ );++ expect(response.status).toBe(400);+ expect(calls.installs).toEqual([]);+ });++ test("a well-formed skill still installs", async () => {+ const calls = { installs: [] as unknown[] };+ const response = await skillsApp(calls).request(+ "http://openbot.test/skills",+ {+ method: "POST",+ headers: { "content-type": "application/json" },+ body: JSON.stringify({+ slug: "ok-slug",+ title: "t",+ instructions: "i",+ summary: "s",+ }),+ },+ );++ expect(response.status).toBe(200);+ expect(calls.installs).toHaveLength(1);+ });+});+describe("POST /api/plugins/call", () => {test.each([["a number ref", { ref: 123, agentId: "bot-1" }],