From 7322b1252b45bd4db9412fafb83aab414096ca61 Mon Sep 17 00:00:00 2001 From: "exe.dev user" Date: Sat, 10 Oct 2026 19:23:30 +0000 Subject: [PATCH] GEN-2273: serve top-level SPA deep links --- packages/api/src/auth-api.ts | 2 +- packages/api/src/static-app.ts | 2 +- packages/api/test/auth-api.test.ts | 2 +- packages/api/test/static-routing.test.ts | 2 +- scripts/hosting-runtime.test.mjs | 2 +- scripts/verify-public-routing.mjs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/api/src/auth-api.ts b/packages/api/src/auth-api.ts index cdbcd3bb..5940fc11 100644 --- a/packages/api/src/auth-api.ts +++ b/packages/api/src/auth-api.ts @@ -45,7 +45,7 @@ export function safeReturnTo(value: string | undefined): string { try { const url = new URL(value, "https://local.invalid"); if (url.origin !== "https://local.invalid") return "/settings/integrations"; - if (!/^\/(?:authorize|device|jobs(?:\/[^/]+(?:\/(?:edit|settings))?)?|job-runs\/[^/]+|settings(?:\/(?:integrations|api-keys|password))?)$/.test(url.pathname)) return "/settings/integrations"; + if (!/^\/(?:authorize|device|jobs(?:\/[^/]+(?:\/(?:edit|settings))?)?|job-runs(?:\/[^/]+)?|settings(?:\/(?:integrations|api-keys|password))?)$/.test(url.pathname)) return "/settings/integrations"; return url.pathname + url.search + url.hash; } catch { return "/settings/integrations"; } } diff --git a/packages/api/src/static-app.ts b/packages/api/src/static-app.ts index d63f4fef..b7ab0ec3 100644 --- a/packages/api/src/static-app.ts +++ b/packages/api/src/static-app.ts @@ -1,7 +1,7 @@ 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'"; -const pages = new Set(["/", "/jobs", "/jobs/new", "/settings", "/settings/integrations", "/settings/api-keys", "/settings/authorized-clients", "/settings/password", "/auth/login", "/auth/signup", "/auth/password-reset", "/auth/verify", "/auth/verify/request", "/authorize", "/device"]); +const pages = new Set(["/", "/jobs", "/jobs/new", "/job-runs", "/settings", "/settings/integrations", "/settings/api-keys", "/settings/authorized-clients", "/settings/password", "/auth/login", "/auth/signup", "/auth/password-reset", "/auth/verify", "/auth/verify/request", "/authorize", "/device"]); export function isStaticPage(path: string) { return pages.has(path) || /^\/jobs\/[^/]+(?:\/(?:edit|settings))?$/.test(path) || /^\/job-runs\/[^/]+$/.test(path); } diff --git a/packages/api/test/auth-api.test.ts b/packages/api/test/auth-api.test.ts index beb00d64..61055e87 100644 --- a/packages/api/test/auth-api.test.ts +++ b/packages/api/test/auth-api.test.ts @@ -204,7 +204,7 @@ describe("public auth API and cookie security", () => { describe("safe interrupted-flow navigation", () => { it.each(["//evil.test", "https://evil.test", "/\\evil.test", "/device-evil", "/jobs/job-a/settings/extra", "/auth/logout", "/jobs\nLocation:evil", "/%2f%2fevil.test"])("rejects %s", value => expect(safeReturnTo(value)).toBe("/settings/integrations")); - it.each(["/authorize?client_id=a&state=b", "/device?user_code=ABCD-EFGH", "/jobs/job-a/edit", "/jobs/job-a/settings?tab=prompt", "/job-runs/run-a"])("preserves %s", value => expect(safeReturnTo(value)).toBe(value)); + it.each(["/authorize?client_id=a&state=b", "/device?user_code=ABCD-EFGH", "/jobs/job-a/edit", "/jobs/job-a/settings?tab=prompt", "/job-runs", "/job-runs/run-a"])("preserves %s", value => expect(safeReturnTo(value)).toBe(value)); }); describe("cookie-only consent and device API boundaries", () => { diff --git a/packages/api/test/static-routing.test.ts b/packages/api/test/static-routing.test.ts index 73a46487..2ff05ba0 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", "/job-runs/id", "/settings/authorized-clients", "/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", "/job-runs", "/job-runs/id", "/settings/authorized-clients", "/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); diff --git a/scripts/hosting-runtime.test.mjs b/scripts/hosting-runtime.test.mjs index 686ce27f..39607329 100644 --- a/scripts/hosting-runtime.test.mjs +++ b/scripts/hosting-runtime.test.mjs @@ -41,7 +41,7 @@ test("actual Cloudflare local runtime enforces static/API/protocol ownership, he }); try { await ready; - for (const path of ["/jobs/id/edit", "/jobs/id/settings", "/job-runs/id", "/settings/authorized-clients", "/auth/verify?token=test-token"]) { + for (const path of ["/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"); diff --git a/scripts/verify-public-routing.mjs b/scripts/verify-public-routing.mjs index 60f5c5b2..449b7adb 100644 --- a/scripts/verify-public-routing.mjs +++ b/scripts/verify-public-routing.mjs @@ -9,7 +9,7 @@ export async function requireApiReady(origin, fetcher = fetch) { } export async function verifyPublicRouting(origin) { await requireApiReady(origin); - for (const path of ["/jobs", "/jobs/route-probe/edit", "/job-runs/route-probe", "/settings/api-keys", "/auth/password-reset?token=route-probe"]) { + for (const path of ["/jobs", "/jobs/route-probe/edit", "/job-runs", "/job-runs/route-probe", "/settings/api-keys", "/auth/password-reset?token=route-probe"]) { const response = await fetch(origin + path, { redirect: "manual", signal: AbortSignal.timeout(15_000) }); assert.equal(response.status, 200, path); assert.match(response.headers.get("Content-Type"), /text\/html/); assert.equal(response.headers.get("Cache-Control"), "no-cache, must-revalidate");