⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
fix(project): secure integrations across workspace moves (#1801)
Tin Sever1edb6634f7aa
diff --git a/apps/api/src/project/index.ts b/apps/api/src/project/index.tsindex 6dd385c7d..2689ac375 100644--- a/apps/api/src/project/index.ts+++ b/apps/api/src/project/index.ts@@ -64,7 +64,7 @@ const moveProjectRoute = createRoute({tags: ["Projects"],summary: "Move a project to another workspace",description:- "Move a project and its tasks. Requires update and delete permission in the source and create permission in the destination. Remove cross-project task relationships before moving.",+ "Move a project and its tasks. Requires update and delete permission in the source, plus project creation and workspace settings management permission in the destination. Remove cross-project task relationships before moving.",middleware: [workspaceAccess.fromProject(),requireWorkspacePermission({ project: ["update", "delete"] }),@@ -413,7 +413,7 @@ const project = apiRouter<BaseVariables & { workspaceId: string }>()if (!(await hasWorkspacePermission(c,- { project: ["create"] },+ { project: ["create"], workspace: ["manage_settings"] },targetWorkspaceId,)))diff --git a/apps/docs/openapi.json b/apps/docs/openapi.jsonindex 80fbe9c7e..b2b0d2878 100644--- a/apps/docs/openapi.json+++ b/apps/docs/openapi.json@@ -6807,7 +6807,7 @@"Projects"],"summary": "Move a project to another workspace",- "description": "Move a project and its tasks. Requires update and delete permission in the source and create permission in the destination. Remove cross-project task relationships before moving.",+ "description": "Move a project and its tasks. Requires update and delete permission in the source, plus project creation and workspace settings management permission in the destination. Remove cross-project task relationships before moving.","parameters": [{"schema": {diff --git a/apps/web/src/routes/_layout/_authenticated/dashboard/settings/projects/$projectId/general.tsx b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/projects/$projectId/general.tsxindex cfc4c42ec..f95f4d7b5 100644--- a/apps/web/src/routes/_layout/_authenticated/dashboard/settings/projects/$projectId/general.tsx+++ b/apps/web/src/routes/_layout/_authenticated/dashboard/settings/projects/$projectId/general.tsx@@ -74,7 +74,10 @@ export const Route = createFileRoute(});// Module-level so their identity stays stable across renders.-const PROJECT_CREATE = { project: ["create"] };+const PROJECT_MOVE_TARGET = {+ project: ["create"],+ workspace: ["manage_settings"],+};// Asked as one check: the endpoint requires both in the source workspace.const PROJECT_UPDATE_AND_DELETE = { project: ["update", "delete"] };@@ -176,17 +179,17 @@ function RouteComponent() {() => (workspaces ?? []).filter((item) => item.id !== project?.workspaceId),[workspaces, project?.workspaceId],);- // The endpoint also requires `project:create` in the target, so a workspace- // the user can't create in would only fail server-side after they picked it.+ // Moving retains project integrations, so the endpoint requires both project+ // creation and settings management in the target workspace.const moveCandidateIds = useMemo(() => moveCandidates.map((item) => item.id),[moveCandidates],);- const { allowed: canCreateIn, isError: moveTargetsFailed } =- useWorkspacesWithPermission(moveCandidateIds, PROJECT_CREATE);+ const { allowed: canMoveInto, isError: moveTargetsFailed } =+ useWorkspacesWithPermission(moveCandidateIds, PROJECT_MOVE_TARGET);const moveTargets = useMemo(- () => moveCandidates.filter((item) => canCreateIn.has(item.id)),- [moveCandidates, canCreateIn],+ () => moveCandidates.filter((item) => canMoveInto.has(item.id)),+ [moveCandidates, canMoveInto],);// The API authorizes the move against the project's own workspace, which// isn't necessarily the active one `useWorkspacePermission` answers for. Itdiff --git a/tests/api-integration/project-move.test.ts b/tests/api-integration/project-move.test.tsindex a902bd422..32f65f576 100644--- a/tests/api-integration/project-move.test.ts+++ b/tests/api-integration/project-move.test.ts@@ -111,6 +111,33 @@ describe("API integration: moving a project between workspaces", () => {expect(response.status).toBe(403);});+ it("rejects a move when the caller can't manage target workspace settings", async () => {+ const owner = await createWorkspaceMember({ role: "owner" });+ const target = await createTargetWorkspace();+ // Members can create projects, but cannot bring retained integrations into+ // a workspace because they lack workspace:manage_settings.+ await addMember(target.id, owner.user.id, "member");+ const { project } = await createProjectFixture({+ workspaceId: owner.workspace.id,+ });++ mockAuthenticatedSession(owner.user);+ const { app } = createApp();++ const response = await app.request(+ `/api/project/${project.id}/move`,+ moveRequest(target.id),+ );++ expect(response.status).toBe(403);++ const [unchanged] = await db+ .select()+ .from(schema.projectTable)+ .where(eq(schema.projectTable.id, project.id));+ expect(unchanged.workspaceId).toBe(owner.workspace.id);+ });+it("rejects a move when the target workspace already uses the project's key", async () => {const owner = await createWorkspaceMember({ role: "owner" });const target = await createTargetWorkspace();