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.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Proxy: a guest's tool run gets the account's answer, not an offer to sign up
Adarshc69381709a9e
diff --git a/docs/public-signup.md b/docs/public-signup.mdindex ef543c7d..3b6fb80d 100644--- a/docs/public-signup.md+++ b/docs/public-signup.md@@ -28,7 +28,10 @@ built-in skills). The owner's library stays private: the lists come back empty,it (files, uploads, projects, settings values, tokens) answer 401 "Sign up to see your library".Every change a guest sends (generate, upload, save a setting, create a project…) answers 401. The-studio shows a "Create a free account to run this" card with **Sign up** and **Log in**. Price+studio shows a "Create a free account to run this" card with **Sign up** and **Log in**. Where+signing up wouldn't help, a guest gets an account's answer instead: 403 `assist-owner` for Assist,+and 403 `own-gpu-tool` for a tool an account's own GPU or key doesn't run (Shorts, Katana,+Marketing…). The pages of those tools say so up front and turn off their upload and Generate. Pricechecks (the estimate routes, and `?preview=1` on the run routes that support it) stay open, so thestudios can show prices. A guest may send 120 price checks a minute (per visitor behind a trustedreverse proxy; see below), and so may each account. A price check reads only the header of a filediff --git a/src/proxy.ts b/src/proxy.tsindex dee1441f..e410c6e1 100644--- a/src/proxy.ts+++ b/src/proxy.ts@@ -156,16 +156,23 @@ function priceCheck(request: NextRequest, who: string): NextResponse {/*** A guest (public sign-up on, signed out): every page and the catalog reads, the owner's lists* empty, the rest of the library 401, and every change 401 (the client offers to sign up), but- * Assist's: signing up wouldn't let it use Assist, so it gets the account's answer (assistOwner).+ * where signing up wouldn't let it in: Assist (assistOwner) and the tools an account's own GPU or+ * key doesn't run (ownGpuTool) get the account's answer.*/function guest(request: NextRequest): NextResponse {const { pathname, search } = request.nextUrl;- if (request.method === "GET" || request.method === "HEAD") return readAsGuest(request, false);- if (isPriceCheck(request.method, pathname, search)) return priceCheck(request, `guest:${LoginGuard.clientKey(request.headers)}`);- if (isAssistChange(request.method, pathname)) return assistOwner();+ const { method } = request;+ if (method === "GET" || method === "HEAD") return readAsGuest(request, false);+ if (isPriceCheck(method, pathname, search)) return priceCheck(request, `guest:${LoginGuard.clientKey(request.headers)}`);+ if (isAssistChange(method, pathname)) return assistOwner();+ // What an account may send, the library, the owner's settings and the studios' runs: signing up is the next step.+ if (!accountMayChange(method, pathname, search) && !isLibraryChange(method, pathname) && !ownerOnly(method, pathname) && !ownGpuRun(method, pathname)) return ownGpuTool();return NextResponse.json({ error: GUEST_RUN_MESSAGE }, { status: 401, headers: guestHeaders });}+/** A tool that doesn't run on an account's own GPU or key yet, for a guest or an account: one answer (no sign-up card). */+const ownGpuTool = () => NextResponse.json({ error: OWN_GPU_TOOL_MESSAGE, code: "own-gpu-tool" }, { status: 403, headers: { "Cache-Control": "no-store" } });+/** Any change to Assist by a visitor (a guest, or an account with or without a GPU): one answer, which the Assist pages also show. */const assistOwner = () => NextResponse.json({ error: ASSIST_OWNER_MESSAGE, code: "assist-owner" }, { status: 403, headers: { "Cache-Control": "no-store" } });@@ -216,7 +223,7 @@ function account(request: NextRequest, who: Account): NextResponse {if (isAssistChange(request.method, pathname)) return assistOwner();if (isLibraryChange(request.method, pathname)) return NextResponse.json({ error: LIBRARY_MESSAGE, code: "library" }, { status: 403 });// A tool its own GPU or key wouldn't run says so first: "Connect your GPU" only for what a GPU or a key unlocks.- if (!ownGpuRun(request.method, pathname)) return NextResponse.json({ error: OWN_GPU_TOOL_MESSAGE, code: "own-gpu-tool" }, { status: 403 });+ if (!ownGpuRun(request.method, pathname)) return ownGpuTool();// Neither its own GPU nor its own key: nothing it could run on. (Which one a run needs, the route says.)if (!who.gpu && !hasCloudKey(who)) return NextResponse.json({ error: CONNECT_GPU_OR_KEY_MESSAGE, code: "connect-gpu" }, { status: 403, headers: { [CONNECT_GPU_HEADER]: "1" } });return pass(request);diff --git a/tests/public-signup-tools.test.ts b/tests/public-signup-tools.test.tsindex 5e153a61..8612767b 100644--- a/tests/public-signup-tools.test.ts+++ b/tests/public-signup-tools.test.ts@@ -111,10 +111,18 @@ describe("the proxy: PR #15's routes as main treats their kind", () => {expect(access.isPriceCheck("GET", "/api/turnaround/estimate", "")).toBe(false);});- it("opens the price checks to guests and refuses their runs and saves with the sign-up prompt", async () => {+ it("opens the price checks to guests, gives their tool runs the account's own-gpu-tool, and their saves the sign-up prompt", async () => {process.env.FUOBE_PUBLIC_SIGNUP = "1";for (const p of ["/api/turnaround/estimate", "/api/turnaround?preview=1", "/api/audio-tools?preview=1"]) expect(passed(proxy(req(p, { method: "POST" }))), p).toBe(true);- for (const p of ["/api/turnaround", "/api/audio-tools", "/api/audio-tools/export?offset=0"]) {+ // Signing up wouldn't run these (an account's own GPU or key doesn't either): the account's answer, not the card.+ for (const p of ["/api/turnaround", "/api/audio-tools", "/api/shorts/sessions", "/api/katana", "/api/marketing/runs", "/api/layers/l1/jobs"]) {+ const r = proxy(req(p, { method: "POST" }));+ expect(r.status, p).toBe(403);+ expect(r.headers.get(access.GUEST_HEADER), p).toBeNull();+ expect(await r.json(), p).toEqual({ error: access.OWN_GPU_TOOL_MESSAGE, code: "own-gpu-tool" });+ }+ // The studios' runs, an upload and a save to the library: signing up is the next step there.+ for (const p of ["/api/generations", "/api/media/probe", "/api/audio-tools/export?offset=0", "/api/canvases"]) {const r = proxy(req(p, { method: "POST" }));expect(r.status, p).toBe(401);expect(r.headers.get(access.GUEST_HEADER), p).toBe("1");diff --git a/tests/public-signup.test.ts b/tests/public-signup.test.tsindex 2ec78ebe..4ad0c18f 100644--- a/tests/public-signup.test.ts+++ b/tests/public-signup.test.ts@@ -339,7 +339,8 @@ describe("accounts never see or change the owner's library", () => {const cookie = auth.createSession(auth.createAccount("[email protected]", "long enough").id).value;expect(passed(proxy(req("/api/influencer?preview=1", { method: "POST" })))).toBe(true);expect(passed(proxy(req("/api/influencer?preview=1", { method: "POST", cookie })))).toBe(true);- expect(proxy(req("/api/influencer", { method: "POST" })).status).toBe(401);+ // Its run isn't one an account's GPU runs either: the account's own-gpu-tool, not the sign-up card.+ expect(proxy(req("/api/influencer", { method: "POST" })).status).toBe(403);});});diff --git a/tests/request-body-limits.test.ts b/tests/request-body-limits.test.tsindex 7c437ce0..98bfa340 100644--- a/tests/request-body-limits.test.ts+++ b/tests/request-body-limits.test.ts@@ -77,8 +77,9 @@ describe("M-3: the proxy holds at most a few MB of any request body", () => {it("each of those routes refuses a guest, an account and another website as the proxy would", async () => {for (const r of BIG) {- // Assist's answer to a guest is an account's (403): signing up wouldn't let it in.- expect((await r.call(form(r.path))).status, `${r.name}: guest`).toBe(r.path.startsWith("/api/assist/") ? 403 : 401);+ // Assist and the tools an account's own GPU doesn't run give a guest the account's answer (403): signing up+ // wouldn't let it in. A run's finish and a save to the library offer to sign up (401).+ expect((await r.call(form(r.path))).status, `${r.name}: guest`).toBe(["finish", "mix export"].includes(r.name) ? 401 : 403);expect((await r.call(form(r.path, { cookie: owner, headers: { origin: "http://evil.example" } }))).status, `${r.name}: cross-site`).toBe(403);}// An account: only its own run's finish passes the proxy's rules, and "g1" isn't its own.