From d98b3e5bff4838c7fb14fefb2b4b93e4d1648ba3 Mon Sep 17 00:00:00 2001 From: le king fu Date: Mon, 2 Nov 2026 21:19:43 -0500 Subject: [PATCH] fix(web): check the task owner in loadTaskTags too A link joins two owned rows: REVIEW.md asks for the ownership check on both sides, so loadTaskTags also joins sl_tasks on the account (still one query). Refs #179 Co-Authored-By: Claude Opus 5.5 --- web/src/lib/taskQueries.test.ts | 5 +++-- web/src/lib/taskQueries.ts | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/web/src/lib/taskQueries.test.ts b/web/src/lib/taskQueries.test.ts index fc85fc0..342091e 100644 --- a/web/src/lib/taskQueries.test.ts +++ b/web/src/lib/taskQueries.test.ts @@ -111,8 +111,9 @@ describe('loadTaskTags', () => { const other = await foreignTagOn(a.t2); const map = await loadTaskTags(a.userId, [a.t1, a.t2]); expect(map[a.t2].map((t) => t.id)).toEqual([a.blue]); - // Nor are the tags of `a` returned to the other account. - expect(await loadTaskTags(other.userId, [a.t1, a.t2])).toEqual({ [a.t2]: [{ id: other.tag, name: 'foreign', color: '#4A90A4' }] }); + // The task side is checked too: the other account gets nothing for tasks + // of `a`, its own tag included. + expect(await loadTaskTags(other.userId, [a.t1, a.t2])).toEqual({}); }); }); diff --git a/web/src/lib/taskQueries.ts b/web/src/lib/taskQueries.ts index a6d9bd6..3021535 100644 --- a/web/src/lib/taskQueries.ts +++ b/web/src/lib/taskQueries.ts @@ -92,8 +92,9 @@ export async function loadSubtasks(userId: string, parentIds: string[]) { return map; } -// Tags of the given tasks, grouped by task id, in one query. Deleted tags and -// tags of another account never appear. +// Tags of the given tasks, grouped by task id, in one query. Ownership is +// checked on both sides of the link: deleted tags, tags of another account and +// tasks of another account never appear. export async function loadTaskTags(userId: string, taskIds: string[]) { const map: Record = {}; if (taskIds.length === 0) return map; @@ -101,8 +102,10 @@ export async function loadTaskTags(userId: string, taskIds: string[]) { .select({ taskId: slTaskTags.taskId, id: slTags.id, name: slTags.name, color: slTags.color }) .from(slTaskTags) .innerJoin(slTags, eq(slTags.id, slTaskTags.tagId)) + .innerJoin(slTasks, eq(slTasks.id, slTaskTags.taskId)) .where(and( inArray(slTaskTags.taskId, taskIds), + eq(slTasks.userId, userId), eq(slTags.userId, userId), isNull(slTags.deletedAt), ))