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): prioritize project workspace lookup (#1383)

Tin Sever7a8320a783fa
diff --git a/apps/api/src/utils/workspace-access-middleware.ts b/apps/api/src/utils/workspace-access-middleware.ts
index e32a9210b..b7c6e719a 100644
--- a/apps/api/src/utils/workspace-access-middleware.ts
+++ b/apps/api/src/utils/workspace-access-middleware.ts
@@ -245,10 +245,7 @@ export const workspaceAccess = {
fromProject: (idKey = "id") =>
workspaceAccessMiddleware({
- sources: [
- { type: "query", key: "workspaceId" },
- { type: "lookup", resource: "project", idKey },
- ],
+ sources: [{ type: "lookup", resource: "project", idKey }],
}),
fromTask: (idKey = "id") =>
diff --git a/tests/api-integration/workspace-rbac.test.ts b/tests/api-integration/workspace-rbac.test.ts
index 4b104fc6d..898110ed8 100644
--- a/tests/api-integration/workspace-rbac.test.ts
+++ b/tests/api-integration/workspace-rbac.test.ts
@@ -188,6 +188,33 @@ describe("API integration: workspace RBAC enforcement", () => {
// workspaceAccess.fromProject runs first and rejects with its own message
expect(response.status).toBe(403);
});
+
+ it("does not authorize a project through a conflicting workspaceId query", async () => {
+ const attacker = await createWorkspaceMember({ role: "admin" });
+ const victim = await createWorkspaceMember({ role: "admin" });
+ const { project } = await createProjectFixture({
+ workspaceId: victim.workspace.id,
+ });
+
+ mockAuthenticatedSession(attacker.user);
+ const { app } = createApp();
+
+ const response = await app.request(
+ `/api/task/${project.id}?workspaceId=${attacker.workspace.id}`,
+ {
+ method: "POST",
+ headers: { "content-type": "application/json" },
+ body: JSON.stringify({
+ title: "Cross-workspace probe",
+ description: "",
+ priority: "low",
+ status: "to-do",
+ }),
+ },
+ );
+
+ expect(response.status).toBe(403);
+ });
});
describe("custom workspace roles", () => {