Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/api/src/static-app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
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", "/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"]);
const pages = new Set(["/", "/jobs", "/jobs/new", "/projects", "/projects/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);
return pages.has(path) || /^\/jobs\/[^/]+(?:\/(?:edit|settings))?$/.test(path) || /^\/projects\/[^/]+$/.test(path) || /^\/job-runs\/[^/]+$/.test(path);
}
export function isStaticAsset(path: string) {
return /^\/assets\/[A-Za-z0-9_.-]+$/.test(path) || path === "/styles.css";
Expand Down
4 changes: 2 additions & 2 deletions packages/api/test/static-routing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", "/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", "/projects", "/projects/new", "/projects/id", "/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);
Expand All @@ -21,7 +21,7 @@ describe("same-origin static ownership", () => {
});
it("never forwards backend namespaces, unknown routes or mutations to static hosting", async () => {
const fetch = vi.fn(); const env = { ASSETS: { fetch } } as unknown as Env;
for (const path of ["/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", "/unknown", "/assets/subdir/file.js", "/index.html", "/jobs/id/edit/extra", "/jobs/id/settings/extra", "/jobs/id/unknown"]) {
for (const path of ["/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", "/unknown", "/assets/subdir/file.js", "/index.html", "/jobs/id/edit/extra", "/jobs/id/settings/extra", "/jobs/id/unknown", "/projects/id/unknown"]) {
expect(await staticApp(new Request(`https://app.factorize.sh${path}`), env)).toBeNull();
}
for (const method of ["POST", "PUT", "DELETE", "OPTIONS"]) for (const path of ["/jobs", "/authorize", "/device", "/assets/index-hash.js", "/auth/login"]) expect(await staticApp(new Request(`https://app.factorize.sh${path}`, { method }), env)).toBeNull();
Expand Down
Loading