Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
fix: Remove hardcoded template allowlist and require authorization tokens (#6041)
Kathir Eswarance84ddcf12f9
diff --git a/packages/trpc-interface/src/authorize/project.server.test.ts b/packages/trpc-interface/src/authorize/project.server.test.tsindex c9294a3a15..60262c9c12 100644--- a/packages/trpc-interface/src/authorize/project.server.test.ts+++ b/packages/trpc-interface/src/authorize/project.server.test.ts@@ -242,6 +242,76 @@ describe("checkProjectPermit — user direct owner (msw)", () => {});});+// ---------------------------------------------------------------------------+// Legacy template allowlist no longer bypasses auth+// ---------------------------------------------------------------------------++// One of the project IDs that used to be hardcoded in the allowlist.+const legacyTemplateId = "5e086cf4-4293-471c-8eab-ddca8b5cd4db";++describe("checkProjectPermit — template projects no longer bypass auth", () => {+ test("denies view without a real owner, workspace, or token relation", async () => {+ server.use(+ db.get("Project", () => json(null)),+ db.get("WorkspaceProjectAuthorization", () => json([]))+ );+ const allowed = await checkProjectPermit({+ projectId: legacyTemplateId,+ permit: "view",+ authInfo: { type: "user", userId: "unrelated-user" },+ postgrestClient: testContext.postgrest.client,+ });+ expect(allowed).toBe(false);+ });++ test("denies edit for an unrelated user on a template project", async () => {+ server.use(+ db.get("Project", () => json(null)),+ db.get("WorkspaceProjectAuthorization", () => json([]))+ );+ const allowed = await checkProjectPermit({+ projectId: legacyTemplateId,+ permit: "edit",+ authInfo: { type: "user", userId: "unrelated-user" },+ postgrestClient: testContext.postgrest.client,+ });+ expect(allowed).toBe(false);+ });++ test("allows view when a real token grants it", async () => {+ server.use(+ db.get("AuthorizationToken", ({ request }) => {+ const url = new URL(request.url);+ // The token branch must filter by the relations that grant "view".+ // A regression in this gate (e.g. dropping the .in("relation") filter)+ // would let any existing token succeed, so we assert the filter is sent.+ expect(url.searchParams.get("relation")).toContain(+ "in.(viewers,editors,builders,administrators)"+ );+ return json({ token: "template-tok" });+ })+ );+ const allowed = await checkProjectPermit({+ projectId: legacyTemplateId,+ permit: "view",+ authInfo: { type: "token", authToken: "template-tok" },+ postgrestClient: testContext.postgrest.client,+ });+ expect(allowed).toBe(true);+ });++ test("denies view when the token does not exist", async () => {+ server.use(db.get("AuthorizationToken", () => json(null)));+ const allowed = await checkProjectPermit({+ projectId: legacyTemplateId,+ permit: "view",+ authInfo: { type: "token", authToken: "missing-tok" },+ postgrestClient: testContext.postgrest.client,+ });+ expect(allowed).toBe(false);+ });+});+// ---------------------------------------------------------------------------// checkProjectPermit — token auth// ---------------------------------------------------------------------------@@ -271,6 +341,26 @@ describe("checkProjectPermit — token auth (msw)", () => {expect(allowed).toBe(false);});+ test("denies when token belongs to another project", async () => {+ const projectId = uid();+ server.use(+ db.get("AuthorizationToken", ({ request }) => {+ const url = new URL(request.url);+ if (url.searchParams.get("projectId") === `eq.${projectId}`) {+ return json(null);+ }+ return json({ token: "other-project-token" });+ })+ );+ const allowed = await checkProjectPermit({+ projectId,+ permit: "view",+ authInfo: { type: "token", authToken: "other-project-token" },+ postgrestClient: testContext.postgrest.client,+ });+ expect(allowed).toBe(false);+ });+test("denies 'own' permit for tokens regardless of DB", async () => {const projectId = uid();const allowed = await checkProjectPermit({diff --git a/packages/trpc-interface/src/authorize/project.server.ts b/packages/trpc-interface/src/authorize/project.server.tsindex 3f9dc1f577..ab947b3a68 100644--- a/packages/trpc-interface/src/authorize/project.server.ts+++ b/packages/trpc-interface/src/authorize/project.server.ts@@ -97,6 +97,7 @@ const check = async (.from("AuthorizationToken").select("token").eq("token", subjectSet.id)+ .eq("projectId", input.id).in("relation", [...permitToRelationRewrite[input.permit]]).maybeSingle();@@ -146,32 +147,6 @@ export const checkProjectPermit = async ({return permit === "view";}- // @todo Delete and use tokens- const templateIds = [- // Production- "5e086cf4-4293-471c-8eab-ddca8b5cd4db",- "94e6e1b8-c6c4-485a-9d7a-8282e11920c0",- "05954204-fcee-407e-b47f-77a38de74431",- "afc162c2-6396-41b7-a855-8fc04604a7b1",- "3f260731-825b-486a-b534-e747f0ed6106",- "400b1bde-def1-49e0-9b64-e26416d326fa",- "2e802ad7-ef32-48e6-8706-3a162785ef95",- "01f6f1d8-06f5-4a6c-a3b1-89a0448046c7",- "5b33acf4-53cf-4f03-8973-d5679772edee",- "909a139b-1f2d-415a-ac90-382fa19fa7d8",- "ef82ee51-e4d6-4a69-a4cc-7bf1dee65ed7",- "e761178f-6ac6-47f6-b881-56cc75640d73",- // Staging IDs- "c236999d-be6b-43fb-9edc-78a2ba59e56d",- "a1371dce-752c-4ccf-8ea4-88bab577fe50",- "6204396c-3f9e-4d29-8d19-ff0f76960a74",- ];-- // @todo Delete and use tokens- if (permit === "view" && templateIds.includes(projectId)) {- return true;- }-if (authInfo.type === "token") {// Token doesn't have "own" permit, do not check itif (permit === "own") {