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.

Pairing: type the code your own ComfyUI shows, and ComfyUI learns who approved it

Adarshcf55e26a0353
diff --git a/docs/gpu-workers.md b/docs/gpu-workers.md
index 08ee3e26..5f430442 100644
--- a/docs/gpu-workers.md
+++ b/docs/gpu-workers.md
@@ -66,15 +66,17 @@ Connect get a refusal that asks them to update it.
1. In ComfyUI, open **Extensions → Connect to Fuobe**. On a PC with no screen, start ComfyUI with
`FUOBE_CONNECT_PAIR=1`. Fuobe Connect asks the studio for a short code: `POST /api/gpu/pair/start`.
-2. The person opens `/connect?code=…`, signs in, checks the computer's name and GPU, and approves the code:
- `POST /api/gpu/pair`. A code is valid for 10 minutes and works only once.
+2. The person opens `/connect?pair=1`, signs in, types the code that their own ComfyUI shows, checks the computer's
+ name and GPU, and approves the code: `POST /api/gpu/pair`. A code is valid for 10 minutes and works only once. The
+ page never fills in a code from its link, so a link that someone else sends can't pair their ComfyUI with the
+ person's account in one click.
3. Fuobe Connect polls with a secret that only it knows: `POST /api/gpu/pair/poll`. After the approval, its next poll
gets a worker token (`fuobe_wkr_…`). The studio makes the token at that moment and keeps only its SHA-256 hash.
The token acts only as that person's own computer. The ComfyUI gets that person's jobs, and nobody else's. The jobs
run with no Fuobe tab open. Fuobe Connect pairs only with a studio the person trusts (or `https://fuobe.com`), and
-checks every job as in direct mode before ComfyUI sees it. If the poll answer names the approving account, ComfyUI
-shows it. The person can pause jobs in ComfyUI. The person can disconnect the ComfyUI in Settings → Your GPU (`DELETE /api/gpu/paired/<id>`)
+checks every job as in direct mode before ComfyUI sees it. The approved poll answer names the approving account,
+masked (`a•••@example.com`, or "the studio's owner"), and ComfyUI shows it. The person can pause jobs in ComfyUI. The person can disconnect the ComfyUI in Settings → Your GPU (`DELETE /api/gpu/paired/<id>`)
or press Disconnect in ComfyUI (`POST /api/gpu/computer/unpair`). A disconnected token gets 401 at its next call.
## Workers (the owner's shared GPUs)
diff --git a/docs/public-signup.md b/docs/public-signup.md
index db8247e4..33859b0e 100644
--- a/docs/public-signup.md
+++ b/docs/public-signup.md
@@ -227,8 +227,9 @@ its own results, once. The server never calls the person's computer. Runs wait w
this one install and connects by itself when ComfyUI is back with it. The setting and the guard
below are under "Advanced". See [gpu-workers.md](gpu-workers.md).
- **Pairing** (Safari, phones, a blocked browser, a PC with no screen): Fuobe Connect shows a code,
- and the person approves it while signed in (`/connect?code=…`). That ComfyUI then runs this
- person's jobs, and only theirs, with no tab open. Settings → Your GPU lists it, with Disconnect.
+ and the person types it and approves it while signed in (`/connect?pair=1`; the page never fills
+ in a code from its link). That ComfyUI then runs this person's jobs, and only theirs, with no tab
+ open. Settings → Your GPU lists it, with Disconnect.
- **Fuobe's setting (Advanced).** Without Fuobe Connect, ComfyUI must run with
`--enable-cors-header <the site's address>`. The card gives the fix for the install it finds: a
start file for Windows portable or Easy-Install (it restarts ComfyUI with the setting and leaves a
diff --git a/integrations/fuobe-connect/README.md b/integrations/fuobe-connect/README.md
index 3af42d43..9acc9a05 100644
--- a/integrations/fuobe-connect/README.md
+++ b/integrations/fuobe-connect/README.md
@@ -117,8 +117,10 @@ with no Fuobe tab open. It opens no port. The token belongs to you alone, so ano
Pairing works only with a studio you trust, or with `https://fuobe.com`. Every job gets the same checks as in direct
mode, before it reaches ComfyUI. The job's inputs leave the input folder when the job is done.
-The **Connect to Fuobe** window shows the studio, the account that approved the code (when the studio says), and the
-last jobs with their node types and times. **Pause jobs** stops this computer from taking new jobs. **Disconnect** tells
+The **Connect to Fuobe** window shows the studio, the account that approved the code (masked, for example
+`a•••@example.com`, when the studio says), and the last jobs with their node types and times. Fuobe doesn't fill in
+the code from a link: you type the code that your own ComfyUI shows, so a link that someone sends you can't connect
+their ComfyUI to your account. **Pause jobs** stops this computer from taking new jobs. **Disconnect** tells
the studio to forget this computer first. If the studio can't be reached, Fuobe Connect keeps trying every minute, and
you can also remove the computer in Fuobe's settings.
diff --git a/integrations/fuobe-connect/tests/pair_and_run.py b/integrations/fuobe-connect/tests/pair_and_run.py
index fc12eb4f..6bc73dcd 100644
--- a/integrations/fuobe-connect/tests/pair_and_run.py
+++ b/integrations/fuobe-connect/tests/pair_and_run.py
@@ -44,7 +44,7 @@ async def main(site_url: str, comfy_url: str, name: str, token: str | None):
if p.status == 200 and p.body.get("state") == "approved":
token = p.body["token"]
shown = token if os.environ.get("FUOBE_CONNECT_TEST_PRINT_TOKEN") == "1" else f"…{token[-4:]}"
- say(event="paired", workerId=p.body["workerId"], token=shown)
+ say(event="paired", workerId=p.body["workerId"], token=shown, account=p.body.get("account"))
break
if p.status == 404:
say(event="gone")
diff --git a/src/app/api/gpu/pair/start/route.ts b/src/app/api/gpu/pair/start/route.ts
index 5d4ef499..ff5cab08 100644
--- a/src/app/api/gpu/pair/start/route.ts
+++ b/src/app/api/gpu/pair/start/route.ts
@@ -31,7 +31,8 @@ export async function POST(request: Request) {
const facts = cleanFacts(body?.facts);
delete facts.loras;
const p = startPairing({ name: typeof body?.name === "string" ? body.name : "ComfyUI", facts });
- const url = new URL(`/connect?code=${encodeURIComponent(p.code)}`, siteOf(request)).toString();
+ // The page asks for the code; it never takes one from its link (someone else's link can't pair their ComfyUI with you).
+ const url = new URL("/connect?pair=1", siteOf(request)).toString();
return Response.json(
{ id: p.id, secret: p.secret, code: p.code, url, expiresAt: p.expiresAt, expiresInS: PAIR_MS / 1000, pollMs: 2000 },
{ headers: { "Cache-Control": "no-store" } },
diff --git a/src/components/gpu/connect-gpu.tsx b/src/components/gpu/connect-gpu.tsx
index 278f5be1..172c0afc 100644
--- a/src/components/gpu/connect-gpu.tsx
+++ b/src/components/gpu/connect-gpu.tsx
@@ -35,8 +35,10 @@ function Card({ children }: { children: React.ReactNode }) {
export function ConnectGpu() {
const params = useSearchParams();
const welcome = params.get("welcome") === "1";
- // Fuobe Connect's pairing link (/connect?code=…): approve that ComfyUI first.
- const code = params.get("code");
+ // Fuobe Connect's pairing link (/connect?pair=1, or an older /connect?code=…): approve that ComfyUI first. The
+ // person types the code their own ComfyUI shows: a code from the link isn't filled in, so a link that someone else
+ // sends can't pair their ComfyUI with this account in one click.
+ const pairing = params.get("pair") === "1" || params.has("code");
const next = safeNext(params.get("next"), typeof window === "undefined" ? "http://localhost" : window.location.origin);
const viewer = useViewer().data;
const isAccount = !!viewer?.account;
@@ -115,7 +117,7 @@ export function ConnectGpu() {
</div>
);
- if (code)
+ if (pairing)
return (
<div className="space-y-6">
<div className="space-y-1">
@@ -123,7 +125,9 @@ export function ConnectGpu() {
<Cpu aria-hidden className="size-5" />
</span>
<h1 className="font-heading text-[30px] leading-tight">Connect your ComfyUI</h1>
- <p className="max-w-2xl text-[15px] text-muted-foreground">Fuobe Connect in your ComfyUI asked to run your Fuobe jobs. Check the computer, then approve it.</p>
+ <p className="max-w-2xl text-[15px] text-muted-foreground">
+ Type the code that your own ComfyUI shows, check the computer, then approve it. Approve only a code you see on your own screen.
+ </p>
</div>
<Card>
{guest ? (
@@ -131,15 +135,15 @@ export function ConnectGpu() {
<p className="text-[14px]">Sign in to approve this ComfyUI. Its runs will be yours.</p>
<div className="flex flex-wrap gap-2">
<Button asChild className="h-11 sm:h-9">
- <Link href={signInHref("login", `/connect?code=${encodeURIComponent(code)}`)}>Log in</Link>
+ <Link href={signInHref("login", "/connect?pair=1")}>Log in</Link>
</Button>
<Button asChild variant="secondary" className="h-11 sm:h-9">
- <Link href={signInHref("signup", `/connect?code=${encodeURIComponent(code)}`)}>Sign up free</Link>
+ <Link href={signInHref("signup", "/connect?pair=1")}>Sign up free</Link>
</Button>
</div>
</div>
) : (
- <PairWithCode initial={code} />
+ <PairWithCode />
)}
</Card>
{done(false)}
diff --git a/src/server/computer/workers.ts b/src/server/computer/workers.ts
index ff37527d..4ddb62c3 100644
--- a/src/server/computer/workers.ts
+++ b/src/server/computer/workers.ts
@@ -2,6 +2,7 @@ import "server-only";
import crypto from "node:crypto";
import { nanoid } from "nanoid";
import type { ComputerFacts } from "@/lib/relay";
+import { accountById } from "../auth";
import { db } from "../db";
import type { Principal } from "./tasks";
@@ -286,7 +287,19 @@ export function denyPairing(code: string): boolean {
return !!c && db().prepare("UPDATE relay_pairings SET state = 'denied' WHERE code = ? AND state = 'waiting'").run(c).changes > 0;
}
-export type PollAnswer = { state: "waiting"; expiresAt: number } | { state: "approved"; token: string; workerId: string; name: string } | { state: "gone" };
+export type PollAnswer = { state: "waiting"; expiresAt: number } | { state: "approved"; token: string; workerId: string; name: string; account: string } | { state: "gone" };
+
+/**
+ * Who approved a pairing, for the ComfyUI's own window ("Approved by a•••@example.com"): the account's email with most
+ * of its name hidden, or the studio's owner.
+ */
+export function approverLabel(principal: string | null): string {
+ if (principal === "owner") return "the studio's owner";
+ const account = principal?.startsWith("acct:") ? accountById(principal.slice(5)) : undefined;
+ if (!account) return "an account";
+ const [name, domain] = account.email.split("@");
+ return `${name.slice(0, name.length > 4 ? 2 : 1)}•••@${domain ?? ""}`;
+}
/**
* The ComfyUI asks whether its code was approved (with its secret). Approved: its token, once (made now; only its hash
@@ -303,6 +316,6 @@ export function pollPairing(id: unknown, secret: unknown, now = Date.now()): Pol
if (row.state !== "approved" || !row.worker_id) return { state: "gone" };
const token = newWorkerToken();
const ok = d.prepare("UPDATE relay_workers SET token_hash = ? WHERE id = ? AND token_hash = ? AND revoked_at IS NULL").run(sha(token), row.worker_id, `pending:${row.id}`).changes > 0;
- return ok ? { state: "approved", token, workerId: row.worker_id, name: row.name } : { state: "gone" };
+ return ok ? { state: "approved", token, workerId: row.worker_id, name: row.name, account: approverLabel(row.principal) } : { state: "gone" };
})();
}
diff --git a/tests/e2e/fuobe-connect.mjs b/tests/e2e/fuobe-connect.mjs
index f9c77239..307bd6e0 100644
--- a/tests/e2e/fuobe-connect.mjs
+++ b/tests/e2e/fuobe-connect.mjs
@@ -103,7 +103,7 @@ try {
// Pairing: a code, approved by Alice while signed in.
const a = connect("alice-pc");
const code = await a.next("code");
- check("Fuobe Connect gets a code and a link to the studio", code && /^[A-Z2-9]{4}-[A-Z2-9]{4}$/.test(code.code) && code.url.startsWith(`${SITE}/connect?code=`), code ? `${code.code} ${code.url}` : a.err());
+ check("Fuobe Connect gets a code and a link to the studio", code && /^[A-Z2-9]{4}-[A-Z2-9]{4}$/.test(code.code) && code.url === `${SITE}/connect?pair=1`, code ? `${code.code} ${code.url}` : a.err());
const anon = await fetch(`${SITE}/api/gpu/pair`, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify({ code: code.code }) });
check("a signed-out visitor can't approve a code", anon.status === 401, `${anon.status}`);
const look = await alice(`/api/gpu/pair?code=${encodeURIComponent(code.code)}`);
@@ -114,6 +114,7 @@ try {
check("Alice approves the code", ok.status === 200 && ok.body?.ok, JSON.stringify(ok.body));
const paired = await a.next("paired");
check("the ComfyUI gets its token once approved", paired?.token?.startsWith("fuobe_wkr_"), paired ? paired.workerId : a.err());
+ check("the ComfyUI learns who approved it, masked", paired?.account === "al•••@example.com", paired?.account);
const again = await alice("/api/gpu/pair", { method: "POST", body: JSON.stringify({ code: code.code }) });
check("an approved code can't be used again", again.status === 404, `${again.status}`);
const gpu = await alice("/api/account/gpu");
diff --git a/tests/workers-pairing.test.ts b/tests/workers-pairing.test.ts
index d4560eba..0015790d 100644
--- a/tests/workers-pairing.test.ts
+++ b/tests/workers-pairing.test.ts
@@ -45,7 +45,7 @@ async function pair(who: string, name = "pc") {
expect(ok.status).toBe(200);
const p = await (await pollRoute.POST(program("/api/gpu/pair/poll", undefined, { body: JSON.stringify({ id: s.id, secret: s.secret }) }))).json();
expect(p.state).toBe("approved");
- return { token: p.token as string, id: p.workerId as string, code: s.code as string, secret: s.secret as string, pairId: s.id as string };
+ return { token: p.token as string, id: p.workerId as string, code: s.code as string, secret: s.secret as string, pairId: s.id as string, account: p.account as string };
}
beforeAll(() => {
@@ -68,7 +68,9 @@ describe("pairing a ComfyUI", () => {
const s = await res.json();
expect(s.code).toMatch(/^[A-HJKMNP-Z2-9]{4}-[A-HJKMNP-Z2-9]{4}$/);
// The studio's own address, as the request reached it.
- expect(s.url).toBe(`${SITE}/connect?code=${s.code}`);
+ // The page asks for the code: the link never carries one to fill in.
+ expect(s.url).toBe(`${SITE}/connect?pair=1`);
+ expect(s.url).not.toContain(s.code);
expect(s.secret).toMatch(/^[0-9a-f]{64}$/);
const p = await (await pollRoute.POST(program("/api/gpu/pair/poll", undefined, { body: JSON.stringify({ id: s.id, secret: s.secret }) }))).json();
expect(p.state).toBe("waiting");
@@ -93,6 +95,8 @@ describe("pairing a ComfyUI", () => {
auth.setAccountGpu(a, null);
const p = await pair("a");
expect(p.token).toMatch(/^fuobe_wkr_[A-Za-z0-9_-]{43}$/);
+ // ComfyUI's window says who approved it, masked.
+ expect(p.account).toBe("a•••@example.com");
expect(auth.accountGpu(a)?.mode).toBe("computer");
const rows = JSON.stringify(db().prepare("SELECT * FROM relay_workers").all()) + JSON.stringify(db().prepare("SELECT * FROM relay_pairings").all());
expect(rows).not.toContain(p.token);
@@ -114,6 +118,7 @@ describe("pairing a ComfyUI", () => {
it("the owner can pair too: ComfyUI then runs on the owner's computer", async () => {
setSetting("comfyWhere", "server");
const p = await pair("owner");
+ expect(p.account).toBe("the studio's owner");
expect(getSetting("comfyWhere")).toBe("computer");
const req = program("/api/gpu/computer/beat", p.token);
expect(principalOf(req)).toBe("owner");