Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Security: a visitor prices only built-in skills

Adarsh009139e3144c
diff --git a/src/app/api/assist/skills/[name]/estimate/route.ts b/src/app/api/assist/skills/[name]/estimate/route.ts
index d07f5cc7..396ed51f 100644
--- a/src/app/api/assist/skills/[name]/estimate/route.ts
+++ b/src/app/api/assist/skills/[name]/estimate/route.ts
@@ -1,14 +1,20 @@
+import { requestViewer } from "@/server/auth";
import { badBody, recipeFailure, RunBody } from "@/server/recipe-routes";
import { estimateRecipe } from "@/server/recipes";
+import { getSkill } from "@/server/skills";
import { priceAs } from "@/server/visitor";
/** Price a run of a skill's recipe, or many (`rows` or `csv`, priced together with a total). Starts nothing. */
async function post(request: Request, ctx: RouteContext<"/api/assist/skills/[name]/estimate">) {
+ const { name } = await ctx.params;
+ // A guest or an account prices the built-in skills only, as the skill's other routes show them: the owner's own skills
+ // (their steps and prompts) stay the owner's, and a visitor isn't told whether one exists.
+ if (requestViewer(request).kind !== "owner" && getSkill(name)?.source !== "builtin") return Response.json({ error: "No such skill" }, { status: 404 });
const parsed = RunBody.safeParse(await request.json().catch(() => ({})));
if (!parsed.success) return badBody(parsed.error.issues);
try {
const { engine, ...input } = parsed.data;
- return Response.json(estimateRecipe((await ctx.params).name, input, engine));
+ return Response.json(estimateRecipe(name, input, engine));
} catch (e) {
return recipeFailure(e);
}
diff --git a/tests/public-signup-visitors.test.ts b/tests/public-signup-visitors.test.ts
index 1f29af99..84b70504 100644
--- a/tests/public-signup-visitors.test.ts
+++ b/tests/public-signup-visitors.test.ts
@@ -82,6 +82,34 @@ describe("a built-in skill opens for a guest and an account", () => {
// The owner still opens their own.
expect((await one.GET(new Request("http://localhost:3000/api/assist/skills/owners-secret"), ctx("owners-secret"))).status).toBe(200);
});
+
+ it("prices only a built-in skill for a guest or an account, and never says whether the owner's own exists", async () => {
+ const { createSkill, setSkillFile } = await import("@/server/skills");
+ createSkill({ name: "owners-recipe", title: "Owner's recipe", description: "d", body: "b" });
+ setSkillFile("owners-recipe", "recipe.json", JSON.stringify({ inputs: [{ id: "topic", label: "Topic", type: "text" }], steps: [{ tool: "generate", input: { model_id: "m", prompt: "secret prompt about {topic}" } }] }));
+ const estimate = await import("@/app/api/assist/skills/[name]/estimate/route");
+ const ctx = (name: string) => ({ params: Promise.resolve({ name }) });
+ const post = (name: string, cookie?: string) =>
+ estimate.POST(
+ new Request(`http://localhost:3000/api/assist/skills/${name}/estimate`, {
+ method: "POST",
+ headers: { "content-type": "application/json", ...(cookie && { cookie: `${auth.SESSION_COOKIE}=${cookie}` }) },
+ body: JSON.stringify({ values: { topic: "x" } }),
+ }),
+ ctx(name),
+ );
+ for (const cookie of [undefined, account]) {
+ for (const name of ["owners-recipe", "owners-secret", "no-such-skill"]) {
+ const r = await post(name, cookie);
+ expect(r.status, `${name} ${cookie ? "account" : "guest"}`).toBe(404);
+ expect(await r.json()).toEqual({ error: "No such skill" });
+ }
+ // A built-in skill is still priced (here: it has no recipe, so the route says so).
+ expect((await (await post("product-photoshoot", cookie)).json()).error).not.toBe("No such skill");
+ }
+ // The owner prices their own.
+ expect((await (await post("owners-recipe", owner)).json()).error).not.toBe("No such skill");
+ });
});
describe("Assist is the owner's", () => {