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.

Assist: a guest gets the owner's answer, not an offer to sign up

Adarshd0792a0d0e59
diff --git a/src/lib/guest-access.ts b/src/lib/guest-access.ts
index fd8a3929..733a2d01 100644
--- a/src/lib/guest-access.ts
+++ b/src/lib/guest-access.ts
@@ -212,7 +212,8 @@ export function isAssistChange(method: string, pathname: string): boolean {
/**
* Assist plans with the install's own AI helpers and keeps the owner's chats, memory and projects, so an account gets
* this one answer to any change there (code "assist-owner"; price checks still go through), with or without its own
- * GPU. A guest's change is a 401, as everywhere. The Assist pages say the same to both (src/components/assist/visitor-note.tsx).
+ * GPU. A guest gets it too, not the 401 that offers to sign up: an account couldn't use Assist either. The Assist
+ * pages say the same to both (src/components/assist/visitor-note.tsx).
*/
export const ASSIST_OWNER_MESSAGE = "Assist runs on the studio owner's AI, so only the owner can use it here. Fuobe is open source: run it yourself for your own chats, skills, memory and schedules.";
diff --git a/src/proxy.ts b/src/proxy.ts
index ea2bba13..dee1441f 100644
--- a/src/proxy.ts
+++ b/src/proxy.ts
@@ -155,16 +155,18 @@ 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).
+ * 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).
*/
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();
return NextResponse.json({ error: GUEST_RUN_MESSAGE }, { status: 401, headers: guestHeaders });
}
-/** Any change to Assist by an account: one answer, which the Assist pages also show (a GPU doesn't change it). */
+/** 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" } });
/**
diff --git a/tests/e2e/guest-prompt.mjs b/tests/e2e/guest-prompt.mjs
index 2845241c..b0eaffb7 100644
--- a/tests/e2e/guest-prompt.mjs
+++ b/tests/e2e/guest-prompt.mjs
@@ -1,10 +1,11 @@
// A refused change shows one card, in the browser. A guest uploads a picture in Color Grading: "Create a free account
// to run this" opens alone (no error toast, no trip to the sign-in page). Its Log in and Sign up free open the sign-in
// page with the card closed, Back closes it too, and a wrong password on the sign-in page is the form's own error.
-// The same in the studios with their own fetch helpers: a guest presses New canvas in Canvas and sends a message in Assist.
+// The same in a studio with its own fetch helper: a guest presses New canvas in Canvas. A guest's message in Assist opens
+// no card (it's the owner's: "Assist runs on the studio owner's AI…" is its toast, as an account's).
// Then an account without its GPU: "Connect your GPU" opens alone, its form inside it, and closes when the page changes.
-// None on a message in Assist (it's the owner's: "Assist runs on the studio owner's AI…" is its toast), and none on New
-// canvas, whose refusal ("Free accounts can't save…") is its toast.
+// None on a message in Assist (it's the owner's, the same toast), and none on New canvas, whose refusal ("Free accounts
+// can't save…") is its toast.
// Usage: node tests/e2e/guest-prompt.mjs [appUrl] [--shots <dir>] (the app with a password and FUOBE_PUBLIC_SIGNUP=1).
// Signs up one throwaway account. Exits 1 on a failed check.
import fs from "node:fs";
@@ -145,14 +146,14 @@ try {
check("Canvas: one card opens: Create a free account", s.cards.length === 1 && s.cards[0] === GUEST_CARD, JSON.stringify(s.cards));
check("Canvas: no error toast on top of it", s.errors.length === 0, JSON.stringify(s.errors));
+ // Assist is the owner's: signing up wouldn't let the guest use it, so it gets the account's answer, not the card.
const sent = await sendInAssist(page);
- check("the guest's message in Assist is refused (401)", sent.status() === 401, String(sent.status()));
- await page.getByRole("dialog").waitFor();
+ check("the guest's message in Assist is refused (403, Assist is the owner's)", sent.status() === 403 && !sent.headers()["x-fuobe-guest"], String(sent.status()));
+ await page.locator("[data-sonner-toast][data-type=error]").first().waitFor();
await settled(page);
s = await seen(page);
await shot(page, "7-guest-assist-send");
- check("Assist: one card opens: Create a free account", s.cards.length === 1 && s.cards[0] === GUEST_CARD, JSON.stringify(s.cards));
- check("Assist: no error toast on top of it", s.errors.length === 0, JSON.stringify(s.errors));
+ check("Assist: its own error toast, with no card", s.cards.length === 0 && s.errors.length === 1 && /owner/.test(s.errors[0]), JSON.stringify(s));
await context.close();
}
diff --git a/tests/llm-settings-security.test.ts b/tests/llm-settings-security.test.ts
index 619ef75f..132010d5 100644
--- a/tests/llm-settings-security.test.ts
+++ b/tests/llm-settings-security.test.ts
@@ -132,7 +132,8 @@ describe("only the owner", () => {
["POST", "/api/assist"],
]) {
expect(proxy(req(p, m, account)).status, `account ${m} ${p}`).toBe(403);
- expect(proxy(req(p, m)).status, `guest ${m} ${p}`).toBe(401);
+ // A guest is offered to sign up (401), but not for Assist: an account can't use it either (403, as an account's).
+ expect(proxy(req(p, m)).status, `guest ${m} ${p}`).toBe(p === "/api/assist" ? 403 : 401);
}
const owner = auth.createSession().value;
expect(proxy(req("/api/llm", "GET", owner)).headers.get("x-middleware-next")).toBe("1");
diff --git a/tests/public-signup-visitors.test.ts b/tests/public-signup-visitors.test.ts
index bd5c2705..b541c002 100644
--- a/tests/public-signup-visitors.test.ts
+++ b/tests/public-signup-visitors.test.ts
@@ -106,7 +106,7 @@ describe("Assist is the owner's", () => {
["POST", "/api/assist/schedules"],
];
- it("gives an account, with or without its own GPU, one answer to every change", async () => {
+ it("gives a guest and an account, with or without its own GPU, one answer to every change", async () => {
for (const cookie of [account, gpuAccount]) {
for (const [method, p] of changes) {
const r = proxy(req(p, { method, cookie }));
@@ -117,11 +117,12 @@ describe("Assist is the owner's", () => {
expect(await r.json(), who).toEqual({ error: access.ASSIST_OWNER_MESSAGE, code: "assist-owner" });
}
}
- // A guest's change is a 401, as everywhere (the client offers to sign up).
+ // A guest gets the same answer, not the 401 that offers to sign up: an account couldn't use Assist either.
for (const [method, p] of changes) {
const r = proxy(req(p, { method }));
- expect(r.status, `${method} ${p}`).toBe(401);
- expect(r.headers.get(access.GUEST_HEADER)).toBe("1");
+ expect(r.status, `${method} ${p}`).toBe(403);
+ expect(r.headers.get(access.GUEST_HEADER), `${method} ${p}`).toBeNull();
+ expect(await r.json(), `${method} ${p}`).toEqual({ error: access.ASSIST_OWNER_MESSAGE, code: "assist-owner" });
}
});
diff --git a/tests/request-body-limits.test.ts b/tests/request-body-limits.test.ts
index 4690c1fd..7c437ce0 100644
--- a/tests/request-body-limits.test.ts
+++ b/tests/request-body-limits.test.ts
@@ -77,7 +77,8 @@ 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) {
- expect((await r.call(form(r.path))).status, `${r.name}: guest`).toBe(401);
+ // 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);
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.