Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(web): keep the /favicon.ico redirect relative (MUL-6326) (#7117)

popWheatdb0f6c5fe22d
diff --git a/apps/web/app/favicon.ico/route.test.ts b/apps/web/app/favicon.ico/route.test.ts
new file mode 100644
index 0000000000..1655ad809a
--- /dev/null
+++ b/apps/web/app/favicon.ico/route.test.ts
@@ -0,0 +1,38 @@
+// @vitest-environment node
+import { describe, expect, it } from "vitest";
+import { dynamic, GET } from "./route";
+
+describe("GET /favicon.ico", () => {
+ it("redirects to the SVG favicon", () => {
+ const response = GET();
+
+ expect(response.status).toBe(308);
+ expect(response.headers.get("location")).toBe("/favicon.svg");
+ });
+
+ it("keeps the location relative so it survives a reverse proxy", () => {
+ // Regression: the route used to build the location from `request.url`,
+ // which on a self-hosted deployment is the server's listen address
+ // (`HOSTNAME=0.0.0.0` / `PORT=3000` in Dockerfile.web) rather than the
+ // origin the client used. That shipped `http://0.0.0.0:3000/favicon.svg`
+ // to every browser — a dead link, and the internal bind address leaked.
+ const location = GET().headers.get("location") ?? "";
+
+ expect(location.startsWith("/")).toBe(true);
+ expect(location).not.toMatch(/^https?:\/\//);
+ });
+
+ it("stays off the prerender cache path", () => {
+ // Regression: `GET()` takes no arguments, so nothing marks the route
+ // dynamic the way the old `request.url` read did. Next then tried to cache
+ // a zero-byte body, which the prerender LRU rejects — one
+ // "calculateSize returned 0" error per request, and every browser asks for
+ // /favicon.ico unprompted.
+ //
+ // This asserts the export, not the framework behaviour it buys: a unit test
+ // cannot observe Next's caching lifecycle. The behaviour itself is checked
+ // against a production build (`pnpm build && pnpm start`), where the fix
+ // removes both `cache-control: s-maxage=31536000` and the error.
+ expect(dynamic).toBe("force-dynamic");
+ });
+});
diff --git a/apps/web/app/favicon.ico/route.ts b/apps/web/app/favicon.ico/route.ts
index 00890acb23..11fee636cc 100644
--- a/apps/web/app/favicon.ico/route.ts
+++ b/apps/web/app/favicon.ico/route.ts
@@ -1,3 +1,39 @@
-export function GET(request: Request) {
- return Response.redirect(new URL("/favicon.svg", request.url), 308);
+/**
+ * Legacy `/favicon.ico` requests point at the real SVG favicon.
+ *
+ * The `Location` is deliberately relative. `Response.redirect()` only accepts
+ * an absolute URL, which forces resolving against `request.url` — and on a
+ * self-hosted deployment that carries the server's own listen address, not the
+ * public origin. `Dockerfile.web` sets `HOSTNAME=0.0.0.0` / `PORT=3000`, and a
+ * plain `next start` defaults to the same, so the redirect came back as
+ * `http://0.0.0.0:3000/favicon.svg`: unreachable for every client, and a leak
+ * of the internal bind address. A relative `Location` is valid per RFC 7231
+ * §7.1.2 and resolves against whatever origin the client actually used, so it
+ * needs no trust in `Host` / `X-Forwarded-Host`.
+ */
+
+/**
+ * Keep the handler off the prerender cache path.
+ *
+ * Reading `request.url` used to mark this route dynamic implicitly. Dropping
+ * that argument left nothing dynamic for Next to detect, so it treated the
+ * route as cacheable and tried to store the response — whose body is zero
+ * bytes, which the prerender LRU rejects outright:
+ *
+ * Failed to update prerender cache for /favicon.ico
+ * Error: LRUCache: calculateSize returned 0, but size must be > 0.
+ *
+ * Every browser requests `/favicon.ico` unprompted, so that is one error line
+ * per request in every deployment, against a cache write that can never
+ * succeed. Forcing dynamic restores the per-request semantics the old
+ * `request.url` read gave us by accident, without reintroducing the absolute
+ * URL. Do not remove this alongside a "the handler takes no arguments" tidy-up.
+ */
+export const dynamic = "force-dynamic";
+
+export function GET() {
+ return new Response(null, {
+ status: 308,
+ headers: { Location: "/favicon.svg" },
+ });
}