Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

fix(api): require task:read on the project relations endpoint

Juanbb07653f5777
diff --git a/apps/api/src/task-relation/index.ts b/apps/api/src/task-relation/index.ts
index 91873a6dd..76e008f03 100644
--- a/apps/api/src/task-relation/index.ts
+++ b/apps/api/src/task-relation/index.ts
@@ -124,7 +124,10 @@ const getProjectTaskRelationsRoute = createRoute({
summary: "Get a project's task relations",
description:
"Get every relation joining two tasks in the project, without the task summaries the per-task endpoint returns. Intended for views that render many tasks at once and already hold them. Relations reaching outside the project are omitted.",
- middleware: [workspaceAccess.fromProject("projectId")] as const,
+ middleware: [
+ workspaceAccess.fromProject("projectId"),
+ requireWorkspacePermission({ task: ["read"] }),
+ ] as const,
request: { params: projectIdParam },
responses: {
200: jsonResponse(
@@ -134,7 +137,7 @@ const getProjectTaskRelationsRoute = createRoute({
400: errorResponse(
"Unknown project, or its workspace could not be determined",
),
- 403: errorResponse("No access to the project's workspace"),
+ 403: errorResponse("No workspace access, or missing task:read permission"),
},
});
diff --git a/apps/docs/openapi.json b/apps/docs/openapi.json
index 796922646..b7fe63de9 100644
--- a/apps/docs/openapi.json
+++ b/apps/docs/openapi.json
@@ -13038,7 +13038,7 @@
"description": "Missing or invalid credentials"
},
"403": {
- "description": "No access to the project's workspace",
+ "description": "No workspace access, or missing task:read permission",
"content": {
"text/plain": {
"schema": {
diff --git a/tests/api-integration/task-relation-project.test.ts b/tests/api-integration/task-relation-project.test.ts
index 789e9a27a..cca2a4331 100644
--- a/tests/api-integration/task-relation-project.test.ts
+++ b/tests/api-integration/task-relation-project.test.ts
@@ -126,6 +126,45 @@ describe("API integration: project task relations", () => {
await expect(response.json()).resolves.toEqual([]);
});
+ it("refuses a member whose role does not grant task:read", async () => {
+ const member = await createWorkspaceMember({ role: "viewer" });
+ const { project } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ await seedTask(member.user.id, project.id, "Parent");
+
+ // A workspace can redefine its roles, and the stored definition wins over
+ // the compiled-in one. This is the shape an API key restricted below
+ // task:read also takes.
+ await db.insert(schema.workspaceRoleTable).values({
+ workspaceId: member.workspace.id,
+ role: "viewer",
+ permission: JSON.stringify({ project: ["read"], workspace: ["read"] }),
+ });
+
+ mockAuthenticatedSession(member.user);
+ const response = await fetchProjectRelations(project.id);
+
+ expect(response.status).toBe(403);
+ });
+
+ it("allows a viewer, whose built-in role grants task:read", async () => {
+ const member = await createWorkspaceMember({ role: "viewer" });
+ mockAuthenticatedSession(member.user);
+ const { project } = await createProjectFixture({
+ workspaceId: member.workspace.id,
+ });
+ const parent = await seedTask(member.user.id, project.id, "Parent");
+ const child = await seedTask(member.user.id, project.id, "Child");
+ const relation = await relate(parent.id, child.id);
+
+ const response = await fetchProjectRelations(project.id);
+
+ expect(response.status).toBe(200);
+ const payload = (await response.json()) as RelationRow[];
+ expect(payload.map((row) => row.id)).toEqual([relation.id]);
+ });
+
it("refuses a caller outside the project's workspace", async () => {
const owner = await createWorkspaceMember({ role: "owner" });
const { project } = await createProjectFixture({