From 227e2ffa4a299875da64c4efe7df8ab1c5160e52 Mon Sep 17 00:00:00 2001 From: "exe.dev user" Date: Mon, 26 Oct 2026 16:29:59 +0000 Subject: [PATCH] Fix static routing deployment verification --- packages/api/src/static-app.ts | 11 +++++++---- packages/api/test/static-routing.test.ts | 7 ++++--- scripts/hosting-runtime.test.mjs | 3 ++- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/api/src/static-app.ts b/packages/api/src/static-app.ts index f3e07dc6..e3404858 100644 --- a/packages/api/src/static-app.ts +++ b/packages/api/src/static-app.ts @@ -1,15 +1,18 @@ import type { Env } from "./types"; export const STATIC_CSP = "default-src 'self'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self'; base-uri 'none'; frame-ancestors 'none'; form-action 'self'"; -// Browser auth screens share /auth with backend callbacks and form handlers. -const authPages = new Set(["/auth/login", "/auth/signup", "/auth/password-reset", "/auth/verify", "/auth/verify/request"]); +const pages = new Set(["/", "/jobs", "/jobs/new", "/projects", "/projects/new", "/job-runs", "/settings", "/settings/integrations", "/settings/api-keys", "/settings/api-keys/new", "/settings/authorized-clients", "/settings/password", "/auth/login", "/auth/signup", "/auth/password-reset", "/auth/verify", "/auth/verify/request", "/authorize", "/device"]); const backendNamespaces = ["/api", "/healthz", "/auth", "/oauth", "/webhooks", "/internal", "/mcp", "/.well-known"]; function isBackendNamespace(path: string) { return backendNamespaces.some(namespace => path === namespace || path.startsWith(`${namespace}/`)); } export function isStaticPage(path: string) { - if (authPages.has(path)) return true; - return !isBackendNamespace(path) && path !== "/assets" && !path.startsWith("/assets/") && path !== "/styles.css"; + return pages.has(path) || + /^\/jobs\/[^/]+(?:\/edit|\/settings)?$/.test(path) || + /^\/projects\/[^/]+$/.test(path) || + /^\/job-runs\/[^/]+(?:\/(?:trace|info|context|settings))?$/.test(path) || + /^\/skills(?:\/[^/]+)?$/.test(path) || + (path.startsWith("/settings/") && !isBackendNamespace(path)); } 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 c10616fd..a1451d2a 100644 --- a/packages/api/test/static-routing.test.ts +++ b/packages/api/test/static-routing.test.ts @@ -3,10 +3,10 @@ import { isStaticPage, staticApp, STATIC_CSP } from "../src/static-app"; import type { Env } from "../src/types"; describe("same-origin static ownership", () => { - it("serves frontend deep links without a page allowlist with an external-bundle policy and revalidated entry HTML", async () => { + it("serves supported frontend 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 ["/skills", "/skills/new", "/skills/id", "/future-feature/nested/page", "/unknown", "/", "/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"]) { + for (const path of ["/skills", "/skills/id", "/", "/jobs", "/jobs/new", "/jobs/id/edit", "/jobs/id/settings", "/projects", "/projects/new", "/projects/id", "/job-runs", "/job-runs/id", "/job-runs/id/trace", "/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(""); }); @@ -24,7 +25,7 @@ describe("same-origin static ownership", () => { for (const path of ["/api", "/assets", "/auth/unknown", "/healthz/unknown", "/api/v1", "/api/v1/unknown", "/api/v1/jobs", "/oauth/token", "/auth/linear", "/auth/github/setup", "/webhooks/github", "/internal/missing", "/mcp", "/healthz", "/.well-known/oauth-authorization-server", "/assets/subdir/file.js"]) { expect(await staticApp(new Request(`https://app.factorize.sh${path}`), env)).toBeNull(); } - for (const method of ["POST", "PUT", "DELETE", "OPTIONS"]) for (const path of ["/skills", "/future-feature/nested/page", "/jobs", "/authorize", "/device", "/assets/index-hash.js", "/auth/login"]) expect(await staticApp(new Request(`https://app.factorize.sh${path}`, { method }), env)).toBeNull(); + for (const method of ["POST", "PUT", "DELETE", "OPTIONS"]) for (const path of ["/skills", "/unknown", "/jobs", "/authorize", "/device", "/assets/index-hash.js", "/auth/login"]) expect(await staticApp(new Request(`https://app.factorize.sh${path}`, { method }), env)).toBeNull(); expect(fetch).not.toHaveBeenCalled(); expect(isStaticPage("/settings/unknown")).toBe(true); }); diff --git a/scripts/hosting-runtime.test.mjs b/scripts/hosting-runtime.test.mjs index d1582961..0f7f1791 100644 --- a/scripts/hosting-runtime.test.mjs +++ b/scripts/hosting-runtime.test.mjs @@ -41,11 +41,12 @@ test("actual Cloudflare local runtime enforces static/API/protocol ownership, he }); try { await ready; - for (const path of ["/skills", "/skills/new", "/skills/id", "/future-feature/nested/page", "/unknown", "/jobs/id/edit", "/jobs/id/settings", "/job-runs", "/job-runs/id", "/settings/authorized-clients", "/auth/verify?token=test-token"]) { + for (const path of ["/skills", "/skills/id", "/jobs/id/edit", "/jobs/id/settings", "/job-runs", "/job-runs/id", "/settings/authorized-clients", "/auth/verify?token=test-token"]) { const page = await read(port, path); assert.equal(page.status, 200); assert.match(page.headers["content-type"], /text\/html/); assert.equal(page.headers["cache-control"], "no-cache, must-revalidate"); assert.match(page.headers["content-security-policy"], /script-src 'self'/); assert.ok(!page.headers["content-security-policy"].includes("unsafe-inline")); assert.equal(page.headers["x-content-type-options"], "nosniff"); const assetPath = page.body.match(/src="(\/assets\/[^"/]+\.js)"/)?.[1]; assert.ok(assetPath); const asset = await read(port, assetPath); assert.equal(asset.status, 200); assert.equal(asset.headers["cache-control"], "public, max-age=31536000, immutable"); } + const unknownPage = await read(port, "/unknown"); assert.equal(unknownPage.status, 404); assert.ok(!unknownPage.headers["content-type"]?.includes("text/html")); const head = await read(port, "/jobs/id", "HEAD"); assert.equal(head.status, 200); assert.equal(head.body, ""); const health = await read(port, "/healthz"); assert.equal(health.status, 200); assert.deepEqual(JSON.parse(health.body), { ok: true }); const session = await read(port, "/api/v1/session"); assert.equal(session.status, 200); assert.equal(session.headers["x-factorize-contract"], "gen-2157-static-v1"); assert.deepEqual(JSON.parse(session.body), { authenticated: false });