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
Public sign-up: accounts get the guest view of the owner's library
Adarsh28ac3e871e5e
diff --git a/docs/public-signup.md b/docs/public-signup.mdindex c3783ddb..aeb8eb63 100644--- a/docs/public-signup.md+++ b/docs/public-signup.md@@ -44,19 +44,19 @@ studios can show prices.- Sign-up and log-in attempts are rate limited per visitor (set `FUOBE_TRUST_PROXY=1` behind areverse proxy, so that each visitor gets their own limit).-An account's session works across the studio, with two limits:+An account is signed in, but it sees the owner's studio as a guest does:+- **The owner's library stays the owner's.** An account opens every page and the catalog, but the+ owner's results, files, uploads, folders, shares, projects (Layers, Cinema, Canvas, storyboards,+ elements…) and Assist threads are hidden: the lists come back empty, and other reads answer 403.+ Every change to them (create, rename, move, share, delete, upload) answers 403 with+ `code: "library"`. Accounts don't have a library of their own yet.- **Settings, keys and tokens are the owner's.** Changing settings or model switches, the password,API tokens, Public sign-up, LoRA downloads, Assist connectors and the MCP endpoint answer 403 foran account.- **Accounts never run on the owner's keys or GPU.** Anything that would reach a model (ageneration, an AI helper, a retry) answers 403 with `code: "connect-gpu"`, and the studio shows a- "Connect your GPU to run this" card. An account's own GPU connection comes in a later change. An- account can still upload, organise, share and delete in the library, and create and edit- projects.--Accounts share the studio's one library: an account sees the owner's results and can change them.-Use public sign-up on a studio whose library you are happy to show.+ "Connect your GPU to run this" card. An account's own GPU connection comes in a later change.`GET /api/auth/me` (open to everyone) says who is looking: `{ signedIn, owner, publicSignup,account? }`.diff --git a/src/lib/guest-access.ts b/src/lib/guest-access.tsindex b97ea935..28e12fa6 100644--- a/src/lib/guest-access.ts+++ b/src/lib/guest-access.ts@@ -5,9 +5,10 @@* - A guest opens every page and the catalog and status reads the pages need. The owner's library* comes back empty (or 401 "Sign up to see your library"), and every change is a 401 that the* client turns into "Create a free account" (src/components/guest-prompt.tsx).- * - An account browses the whole studio and keeps its own library and projects (ACCOUNT_CHANGES),- * but never runs on the owner's cloud keys or GPU ("Connect your GPU"), and never changes- * install-wide settings, keys or tokens (owner only).+ * - An account sees what a guest sees of the owner's studio: the owner's library and projects stay+ * hidden (empty lists, 403) and can't be changed (403, LIBRARY_CHANGES). It never runs on the+ * owner's cloud keys or GPU ("Connect your GPU"), and never changes install-wide settings, keys or+ * tokens (owner only).*//** Set by the proxy on a guest's request to a route that answers guests itself (GUEST_FILTERED), and on its 401s. */@@ -97,13 +98,12 @@ export function isPriceCheck(method: string, pathname: string, search: string):}/**- * Changes an account may make: its own library and projects (create, rename, move, share, delete,- * upload), never anything that reaches a model. Everything else an account sends (a run, an AI- * helper, a connector, the MCP endpoint…) is refused with "Connect your GPU": an account never- * spends the owner's cloud keys or GPU.+ * Changes to the studio's library and projects (create, rename, move, share, delete, upload). The+ * library is the owner's, and accounts don't have one of their own yet, so an account is refused+ * them with LIBRARY_MESSAGE. Everything else an account sends (a run, an AI helper, a connector,+ * the MCP endpoint…) is refused with "Connect your GPU": it never spends the owner's keys or GPU.*/-const ACCOUNT_CHANGES: [methods: string, path: RegExp][] = [- ["POST", /^\/api\/auth\/logout$/],+const LIBRARY_CHANGES: [methods: string, path: RegExp][] = [["POST", /^\/api\/uploads$/],["POST", /^\/api\/media\/probe$/],["POST", /^\/api\/folders$/],@@ -132,12 +132,19 @@ const ACCOUNT_CHANGES: [methods: string, path: RegExp][] = [["DELETE", /^\/api\/assist\/projects\/[^/]+\/sources\/[^/]+$/],];-/** May an account make this change itself? (Reads are always fine; price checks are free.) */+/** A change an account may send: signing out, and price checks (reads go by guestRead, as a guest's). */export function accountMayChange(method: string, pathname: string, search: string): boolean {- if (method === "GET" || method === "HEAD" || isPriceCheck(method, pathname, search)) return true;- return ACCOUNT_CHANGES.some(([methods, path]) => methods.split(" ").includes(method) && path.test(pathname));+ return (method === "POST" && pathname === "/api/auth/logout") || isPriceCheck(method, pathname, search);}+/** A change to the studio's library or projects (refused for an account with LIBRARY_MESSAGE, not "Connect your GPU"). */+export function isLibraryChange(method: string, pathname: string): boolean {+ return LIBRARY_CHANGES.some(([methods, path]) => methods.split(" ").includes(method) && path.test(pathname));+}++export const ACCOUNT_LIBRARY_MESSAGE = "This studio's library is its owner's. Free accounts can't open or change it.";+export const LIBRARY_MESSAGE = "Free accounts can't save to this studio's library yet.";+/** Set on an account's refused run: the client shows "Connect your GPU to run this". */export const CONNECT_GPU_HEADER = "x-fuobe-connect-gpu";export const CONNECT_GPU_MESSAGE = "Connect your GPU to run this. Free accounts run on their own ComfyUI.";diff --git a/src/proxy.ts b/src/proxy.tsindex 5115a47f..556146ed 100644--- a/src/proxy.ts+++ b/src/proxy.ts@@ -3,6 +3,7 @@ import { APPS } from "@/lib/catalog/apps";import { recordForPath, unknownHubMode } from "@/lib/record-pages";import { countsAsView, SHARE_VIEW_HEADER, shareRoute } from "@/lib/share";import {+ ACCOUNT_LIBRARY_MESSAGE,accountMayChange,CONNECT_GPU_HEADER,CONNECT_GPU_MESSAGE,@@ -10,7 +11,9 @@ import {GUEST_LIBRARY_MESSAGE,GUEST_RUN_MESSAGE,guestRead,+ isLibraryChange,isPriceCheck,+ LIBRARY_MESSAGE,ownerOnly,} from "@/lib/guest-access";import { authEnabled, crossSite, hostAllowed, LoginGuard, publicSignup, SESSION_COOKIE, sessionViewer, validSession, validToken, type Viewer } from "@/server/auth";@@ -64,36 +67,44 @@ const guestHeaders = { [GUEST_HEADER]: "1", "Cache-Control": "no-store" };*/function guest(request: NextRequest): NextResponse {const { pathname, search } = request.nextUrl;- if (request.method === "GET" || request.method === "HEAD") {- const read = guestRead(pathname);- if (read.kind === "pass") return pass(request);- if (read.kind === "filtered") {- const headers = new Headers(request.headers);- headers.set(GUEST_HEADER, "1");- return NextResponse.next({ request: { headers } });- }- if (read.kind === "empty") return NextResponse.json(read.body, { headers: guestHeaders });- if (read.kind === "none") return NextResponse.json({ error: "Not for guests" }, { status: 404, headers: guestHeaders });- return NextResponse.json({ error: GUEST_LIBRARY_MESSAGE }, { status: 401, headers: guestHeaders });- }+ if (request.method === "GET" || request.method === "HEAD") return readAsGuest(request, false);if (isPriceCheck(request.method, pathname, search)) return pass(request);return NextResponse.json({ error: GUEST_RUN_MESSAGE }, { status: 401, headers: guestHeaders });}/**- * An account: browses the whole studio and keeps its own library and projects, but install-wide- * settings, keys and tokens are the owner's, and anything that would reach a model is refused- * ("Connect your GPU"): an account never runs on the owner's cloud keys or GPU.+ * A read by a guest or an account: pages and catalog reads go through, the owner's lists come back+ * empty, and the rest of the owner's library is refused (401 for a guest, who can sign up; 403 for an account).+ */+function readAsGuest(request: NextRequest, isAccount: boolean): NextResponse {+ const read = guestRead(request.nextUrl.pathname);+ if (read.kind === "pass") return pass(request);+ if (read.kind === "filtered") {+ const headers = new Headers(request.headers);+ headers.set(GUEST_HEADER, "1");+ return NextResponse.next({ request: { headers } });+ }+ if (read.kind === "empty") return NextResponse.json(read.body, { headers: guestHeaders });+ if (read.kind === "none") return NextResponse.json({ error: "Not for guests" }, { status: 404, headers: guestHeaders });+ if (isAccount) return NextResponse.json({ error: ACCOUNT_LIBRARY_MESSAGE }, { status: 403, headers: { "Cache-Control": "no-store" } });+ return NextResponse.json({ error: GUEST_LIBRARY_MESSAGE }, { status: 401, headers: guestHeaders });+}++/**+ * An account sees the owner's studio as a guest does: every page, the catalog, and none of the+ * owner's library or projects (hidden, and every change to them refused). Install-wide settings,+ * keys and tokens are the owner's, and anything that would reach a model is refused ("Connect your+ * GPU"): an account never runs on the owner's cloud keys or GPU.*/function account(request: NextRequest): NextResponse {const { pathname, search } = request.nextUrl;if (ownerOnly(request.method, pathname)) {return NextResponse.json({ error: "Only the studio's owner can change settings, keys and tokens." }, { status: 403 });}- if (!accountMayChange(request.method, pathname, search)) {- return NextResponse.json({ error: CONNECT_GPU_MESSAGE, code: "connect-gpu" }, { status: 403, headers: { [CONNECT_GPU_HEADER]: "1" } });- }- return pass(request);+ if (request.method === "GET" || request.method === "HEAD") return readAsGuest(request, true);+ if (accountMayChange(request.method, pathname, search)) return pass(request);+ if (isLibraryChange(request.method, pathname)) return NextResponse.json({ error: LIBRARY_MESSAGE, code: "library" }, { status: 403 });+ return NextResponse.json({ error: CONNECT_GPU_MESSAGE, code: "connect-gpu" }, { status: 403, headers: { [CONNECT_GPU_HEADER]: "1" } });}const tooMany = (seconds: number) =>diff --git a/tests/public-signup.test.ts b/tests/public-signup.test.tsindex 7ea03c58..9e5beaca 100644--- a/tests/public-signup.test.ts+++ b/tests/public-signup.test.ts@@ -147,12 +147,9 @@ describe("proxy with public sign-up on", () => {expect(passed(proxy(req("/api/shorts/estimate", { method: "POST" })))).toBe(true);});- it("lets an account use the studio, but not settings, keys or tokens", async () => {+ it("lets an account open every page, but never settings, keys or tokens", async () => {process.env.FUOBE_PUBLIC_SIGNUP = "1";- expect(passed(proxy(req("/api/generations", { cookie: account })))).toBe(true);- expect(passed(proxy(req("/api/files/outputs/a.png", { cookie: account })))).toBe(true);- expect(passed(proxy(req("/api/uploads", { method: "POST", cookie: account })))).toBe(true);- expect(passed(proxy(req("/api/layers", { method: "POST", cookie: account })))).toBe(true);+ for (const p of ["/", "/motions", "/layers", "/settings", "/api/status", "/api/models"]) expect(passed(proxy(req(p, { cookie: account }))), p).toBe(true);for (const [method, p] of [["PUT", "/api/settings"],["PUT", "/api/settings/models"],@@ -231,24 +228,66 @@ describe("accounts never run on the owner's keys or GPU", () => {}// Owner-only routes say so (not "connect your GPU").expect(proxy(req("/api/mcp", { method: "POST", cookie })).headers.get(access.CONNECT_GPU_HEADER)).toBeNull();- // Its own library, price checks and reads are fine.+ // Price checks and signing out are fine.for (const [method, p] of [["POST", "/api/generations?preview=1"],["POST", "/api/ads/estimate"],["POST", "/api/assist/skills/s1/estimate"],- ["POST", "/api/folders"],- ["PATCH", "/api/folders/f1"],- ["POST", "/api/generations/bulk"],- ["DELETE", "/api/generations/g1"],- ["POST", "/api/shares"],- ["POST", "/api/cinema/projects"],- ["PATCH", "/api/layers/l1"],["POST", "/api/auth/logout"],- ["GET", "/api/generations"],]) {expect(passed(proxy(req(p, { method, cookie }))), `${method} ${p}`).toBe(true);}});+});++describe("accounts never see or change the owner's library", () => {+ const families: Record<string, { lists: string[]; records: string[]; changes: [string, string][] }> = {+ generations: {+ lists: ["/api/generations", "/api/generations/trash", "/api/generations/facets"],+ records: ["/api/generations/g1", "/api/generations/zip?ids=g1"],+ changes: [["PATCH", "/api/generations/g1"], ["DELETE", "/api/generations/g1"], ["POST", "/api/generations/bulk"], ["DELETE", "/api/generations/trash"], ["POST", "/api/generations/g1/cancel"]],+ },+ files: { lists: ["/api/assets"], records: ["/api/files/outputs/a.png", "/api/assets/a1", "/api/uploads"], changes: [["POST", "/api/uploads"], ["DELETE", "/api/assets/a1"]] },+ folders: { lists: ["/api/folders"], records: ["/api/folders/f1", "/api/folders/f1/zip"], changes: [["POST", "/api/folders"], ["PATCH", "/api/folders/f1"], ["DELETE", "/api/folders/f1"]] },+ shares: { lists: ["/api/shares"], records: ["/api/shares/s1"], changes: [["POST", "/api/shares"], ["PATCH", "/api/shares/s1"], ["DELETE", "/api/shares/s1"]] },+ layers: { lists: ["/api/layers"], records: ["/api/layers/l1"], changes: [["POST", "/api/layers"], ["PATCH", "/api/layers/l1"], ["DELETE", "/api/layers/l1"], ["POST", "/api/layers/l1/versions"]] },+ elements: { lists: ["/api/elements"], records: ["/api/elements/e1"], changes: [["POST", "/api/elements"], ["PATCH", "/api/elements/e1"], ["DELETE", "/api/elements/e1"]] },+ canvases: { lists: ["/api/canvases"], records: ["/api/canvases/c1"], changes: [["POST", "/api/canvases"], ["PATCH", "/api/canvases/c1"], ["DELETE", "/api/canvases/c1"], ["POST", "/api/canvases/c1/duplicate"]] },+ cinema: { lists: ["/api/cinema/projects"], records: ["/api/cinema/projects/p1", "/api/cinema/projects/p1/items"], changes: [["POST", "/api/cinema/projects"], ["PATCH", "/api/cinema/projects/p1"], ["DELETE", "/api/cinema/projects/p1"]] },+ storyboards: { lists: [], records: ["/api/storyboards"], changes: [["POST", "/api/storyboards"]] },+ assist: { lists: ["/api/assist/projects"], records: ["/api/assist", "/api/assist/t1", "/api/assist/memory"], changes: [["PATCH", "/api/assist/t1"], ["DELETE", "/api/assist/t1"], ["POST", "/api/assist/projects"]] },+ brands: { lists: ["/api/brands", "/api/products"], records: ["/api/brands/b1"], changes: [["POST", "/api/brands"], ["DELETE", "/api/brands/b1"], ["POST", "/api/products"]] },+ };++ for (const [family, f] of Object.entries(families)) {+ it(`hides and protects ${family}`, async () => {+ process.env.FUOBE_PUBLIC_SIGNUP = "1";+ const cookie = auth.createSession(auth.createAccount(`lib-${family}@example.com`, "long enough").id).value;+ for (const p of f.lists) {+ const r = proxy(req(p, { cookie }));+ expect(r.status, p).toBe(200);+ const body = (await r.json()) as { items?: unknown[]; total?: number };+ expect(body.items ?? [], p).toEqual([]);+ if ("total" in body) expect(body.total).toBe(0);+ }+ for (const p of f.records) expect(proxy(req(p, { cookie })).status, p).toBe(403);+ for (const [method, p] of f.changes) {+ const r = proxy(req(p, { method, cookie }));+ expect(r.status, `${method} ${p}`).toBe(403);+ }+ });+ }++ it("says the library isn't theirs, not \"connect your GPU\", for a library change", async () => {+ process.env.FUOBE_PUBLIC_SIGNUP = "1";+ const cookie = auth.createSession(auth.createAccount("[email protected]", "long enough").id).value;+ const r = proxy(req("/api/folders", { method: "POST", cookie }));+ expect(r.headers.get(access.CONNECT_GPU_HEADER)).toBeNull();+ expect((await r.json()).code).toBe("library");+ const read = proxy(req("/api/generations/g1", { cookie }));+ expect(read.headers.get(access.GUEST_HEADER)).toBeNull();+ expect((await read.json()).error).toMatch(/owner/);+ });it("keeps the owner's runs unchanged", () => {process.env.FUOBE_PUBLIC_SIGNUP = "1";