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: unknown pages and share links answer 404 behind an HTTPS proxy
Adarsh66ddc3b16036
diff --git a/src/proxy.ts b/src/proxy.tsindex 502485ef..60c55665 100644--- a/src/proxy.ts+++ b/src/proxy.ts@@ -50,7 +50,35 @@ function pass(request: NextRequest): NextResponse {return NextResponse.next();}-const notFound = (request: NextRequest) => NextResponse.rewrite(new URL("/_fuobe-not-found", request.url), { status: 404 });+/**+ * A 404 page made here, for a request that reached the server through an HTTPS reverse proxy. Next builds the+ * proxy's request address from its own name for the server ("localhost") and the forwarded protocol, and the address+ * it routes by from the host it listens on (`next start -H 127.0.0.1`): when they differ, a rewrite to the app's own+ * 404 page goes out as a request to another server, which fails over HTTPS and answered 500. Plain HTTP (a local+ * install) keeps the rewrite to the app's own pages.+ */+function plain404(title: string, text: string, home: boolean): NextResponse {+ const html = `<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="robots" content="noindex"><title>${title} · Fuobe</title><style>+:root{color-scheme:light dark;--bg:#fafafa;--fg:#111113;--muted:#6b6b73;--btn:#111113;--btn-fg:#fafafa}+@media (prefers-color-scheme:dark){:root{--bg:#0b0b0c;--fg:#ededef;--muted:#9a9aa2;--btn:#ededef;--btn-fg:#0b0b0c}}+body{margin:0;min-height:100svh;display:grid;place-items:center;background:var(--bg);color:var(--fg);font:15px/1.5 system-ui,-apple-system,"Segoe UI",sans-serif;text-align:center}+main{max-width:460px;padding:24px 16px 10vh}h1{margin:0;font-size:30px;line-height:1.2;font-weight:600;text-wrap:balance}+p{margin:10px 0 0;color:var(--muted);text-wrap:pretty}a{display:inline-block;margin-top:22px;padding:9px 16px;border-radius:10px;background:var(--btn);color:var(--btn-fg);text-decoration:none;font-weight:500}+</style></head><body><main><h1>${title}</h1><p>${text}</p>${home ? '<a href="/">Back to Home</a>' : ""}</main></body></html>`;+ return new NextResponse(html, { status: 404, headers: { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "no-store" } });+}++const behindHttps = (request: NextRequest) => request.nextUrl.protocol === "https:";++const notFound = (request: NextRequest) =>+ behindHttps(request)+ ? plain404("Nothing here", "The page you’re looking for moved, or never existed. Everything you made is still in your library.", true)+ : NextResponse.rewrite(new URL("/_fuobe-not-found", request.url), { status: 404 });++const shareGone = (request: NextRequest) =>+ behindHttps(request)+ ? plain404("This link isn’t available", "It may have expired or been turned off, or what it shared was removed. Ask the person who sent it for a new link.", false)+ : NextResponse.rewrite(new URL("/s/gone", request.url), { status: 404 });/** Share pages and their files: never indexed, and the token never leaks to another site in a Referer. */const SHARE_HEADERS = { "X-Robots-Tag": "noindex, nofollow, noarchive", "Referrer-Policy": "no-referrer" };@@ -163,7 +191,7 @@ function openShare(request: NextRequest, token: string, file: boolean): NextRespguard.miss(key, token, key === LoginGuard.DIRECT);if (spent) return tooMany(60);}- res = NextResponse.rewrite(new URL("/s/gone", request.url), { status: 404 });+ res = shareGone(request);} else {// Only the proxy says what counts as a view: a visitor can't send the header themselves.const headers = new Headers(request.headers);diff --git a/tests/security-lows.test.ts b/tests/security-lows.test.tsindex 6f09b59d..8c4345ea 100644--- a/tests/security-lows.test.ts+++ b/tests/security-lows.test.ts@@ -183,3 +183,26 @@ describe("L-4: the local deploy notes can't be committed by accident", () => {expect(ignore).toContain("/deploy/");});});++describe("L-2: an unknown record or link answers 404 behind an HTTPS reverse proxy", () => {+ it("makes the 404 page itself instead of a rewrite Next would send to another server", async () => {+ const { proxy } = await import("@/proxy");+ const { NextRequest } = await import("next/server");+ process.env.FUOBE_PUBLIC_SIGNUP = "1";+ const at = (url: string) => proxy(new NextRequest(url, { headers: { host: "fuobe.example", "x-forwarded-proto": "https" } }));+ for (const p of ["/apps/does-not-exist", "/canvas/nope-nope-nope"]) {+ const r = at(`https://fuobe.example${p}`);+ expect(r.status, p).toBe(404);+ expect(r.headers.get("x-middleware-rewrite"), p).toBeNull();+ expect(r.headers.get("content-type")).toMatch(/text\/html/);+ expect(await r.text()).toMatch(/Nothing here/);+ }+ const share = at(`https://fuobe.example/s/${"A".repeat(44)}`);+ expect(share.status).toBe(404);+ expect(share.headers.get("x-middleware-rewrite")).toBeNull();+ expect(share.headers.get("x-robots-tag")).toMatch(/noindex/);+ expect(await share.text()).toMatch(/This link isn.t available/);+ // A plain-HTTP install keeps the rewrite to the app's own 404 pages.+ expect(proxy(new NextRequest("http://localhost:3000/apps/does-not-exist")).headers.get("x-middleware-rewrite")).toMatch(/_fuobe-not-found$/);+ });+});