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
Security: without a trusted proxy, one guest can't use up every guest's price checks
Adarshb24aa1c747ab
diff --git a/src/proxy.ts b/src/proxy.tsindex 60c55665..3a4cd71d 100644--- a/src/proxy.ts+++ b/src/proxy.ts@@ -98,11 +98,20 @@ const guestHeaders = { [GUEST_HEADER]: "1", "Cache-Control": "no-store" };/** Price checks a guest (per address) or an account may send a minute: free, but each one plans a run. A page sends far fewer. */const PRICE_CHECKS_PER_MINUTE = 120;+/**+ * Without a trusted proxy (FUOBE_TRUST_PROXY) every guest is one shared key: they share a budget ten times larger, so+ * one busy page or script can't stop every other guest's prices, and the 429 says how to give each visitor their own.+ */+const SHARED_PRICE_CHECKS_PER_MINUTE = 10 * PRICE_CHECKS_PER_MINUTE;+const SHARED_GUEST = `guest:${LoginGuard.DIRECT}`;+/** A guest's or an account's price check, within its budget (the owner's are never counted). */function priceCheck(request: NextRequest, who: string): NextResponse {- const r = hit(`price:${who}`, PRICE_CHECKS_PER_MINUTE, 60_000);+ const shared = who === SHARED_GUEST;+ const r = hit(`price:${who}`, shared ? SHARED_PRICE_CHECKS_PER_MINUTE : PRICE_CHECKS_PER_MINUTE, 60_000);if (r.ok) return pass(request);- return NextResponse.json({ error: "Too many price checks. Try again in a minute." }, { status: 429, headers: { "Retry-After": String(r.retryAfterS), "Cache-Control": "no-store" } });+ const hint = shared ? " Behind a reverse proxy? Set FUOBE_TRUST_PROXY=1 so each visitor gets their own limit." : "";+ return NextResponse.json({ error: `Too many price checks. Try again in a minute.${hint}` }, { status: 429, headers: { "Retry-After": String(r.retryAfterS), "Cache-Control": "no-store" } });}/**diff --git a/tests/price-check-reads.test.ts b/tests/price-check-reads.test.tsindex b9cf6de2..05159add 100644--- a/tests/price-check-reads.test.ts+++ b/tests/price-check-reads.test.ts@@ -184,6 +184,15 @@ describe("H-2 / H-3: price checks are rate-limited per visitor", () => {}});+ it("without a trusted proxy (every guest is one shared key), guests share a much larger budget, and the 429 says how to fix it", async () => {+ expect(process.env.FUOBE_TRUST_PROXY).toBeUndefined();+ for (let i = 0; i < 600; i++) expect(passed(proxy(post("/api/ads/multiplier/estimate", undefined, `198.51.100.${i % 250}`))), `check ${i}`).toBe(true);+ for (let i = 600; i < 1200; i++) proxy(post("/api/ads/multiplier/estimate"));+ const r = proxy(post("/api/ads/multiplier/estimate"));+ expect(r.status).toBe(429);+ expect((await r.json()).error).toMatch(/FUOBE_TRUST_PROXY=1/);+ });+it("an account gets its own budget; the owner is never limited", () => {const account = auth.createSession(a).value;for (let i = 0; i < 120; i++) expect(passed(proxy(post("/api/dub?preview=1", account)))).toBe(true);