From 9dcc041137b0d311f295785d5211681c540a70b7 Mon Sep 17 00:00:00 2001 From: "exe.dev user" Date: Tue, 20 Oct 2026 06:45:36 +0000 Subject: [PATCH] fix: return 404 for unknown static routes --- packages/api/src/static-app.ts | 6 +++++- packages/api/test/static-routing.test.ts | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/api/src/static-app.ts b/packages/api/src/static-app.ts index 9eebdb0c..521210e5 100644 --- a/packages/api/src/static-app.ts +++ b/packages/api/src/static-app.ts @@ -7,7 +7,11 @@ function isBackendNamespace(path: string) { return backendNamespaces.some(namespace => path === namespace || path.startsWith(`${namespace}/`)); } export function isStaticPage(path: string) { - return pages.has(path) || (!isBackendNamespace(path) && !path.startsWith("/assets/") && path !== "/styles.css"); + return pages.has(path) || + /^\/jobs\/[^/]+(?:\/edit|\/settings)?$/.test(path) || + /^\/projects\/[^/]+$/.test(path) || + /^\/job-runs\/[^/]+$/.test(path) || + path.startsWith("/settings/"); } export function isStaticAsset(path: string) { return /^\/assets\/[A-Za-z0-9_.-]+$/.test(path) || path === "/styles.css"; diff --git a/packages/api/test/static-routing.test.ts b/packages/api/test/static-routing.test.ts index 23bfff2f..c2dd530a 100644 --- a/packages/api/test/static-routing.test.ts +++ b/packages/api/test/static-routing.test.ts @@ -6,7 +6,7 @@ describe("same-origin static ownership", () => { it("serves explicit deep links with an external-bundle policy and revalidated entry HTML", async () => { const fetch = vi.fn(async (request: Request) => new Response(request.method === "HEAD" ? null : "entry", { headers: { "Content-Type": "text/html" } })); const env = { ASSETS: { fetch } } as unknown as Env; - for (const path of ["/", "/jobs", "/jobs/new", "/jobs/id/edit", "/jobs/id/settings", "/projects", "/projects/new", "/projects/id", "/job-runs", "/job-runs/id", "/settings/authorized-clients", "/settings/targets", "/unknown", "/auth/verify?token=one-time", "/authorize?client_id=test", "/device?user_code=ABCD-2345"]) { + for (const path of ["/", "/jobs", "/jobs/new", "/jobs/id/edit", "/jobs/id/settings", "/projects", "/projects/new", "/projects/id", "/job-runs", "/job-runs/id", "/settings/authorized-clients", "/settings/targets", "/auth/verify?token=one-time", "/authorize?client_id=test", "/device?user_code=ABCD-2345"]) { const response = await staticApp(new Request(`https://app.factorize.sh${path}`), env); expect(response?.status).toBe(200); expect(response?.headers.get("content-security-policy")).toBe(STATIC_CSP); @@ -16,6 +16,7 @@ describe("same-origin static ownership", () => { expect(new URL(fetch.mock.calls.at(-1)![0].url).pathname).toBe("/index.html"); expect(new URL(fetch.mock.calls.at(-1)![0].url).search).toBe(""); } + expect(await staticApp(new Request("https://app.factorize.sh/unknown"), env)).toBeNull(); const head = await staticApp(new Request("https://app.factorize.sh/jobs/id", { method: "HEAD" }), env); expect(await head?.text()).toBe(""); });