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
2 changes: 1 addition & 1 deletion packages/api/src/auth-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"; }
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/static-app.ts
Original file line number Diff line number Diff line change
@@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/api/test/auth-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion 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/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);
Expand Down
2 changes: 1 addition & 1 deletion scripts/hosting-runtime.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion scripts/verify-public-routing.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading