Skip to content

Commit 12e9b94

Browse files
committed
fix(api): restore atomic ownership check on activity comment writes
Re-add the userId predicate to the UPDATE/DELETE WHERE clauses in the activity comment controllers so the write itself enforces ownership, matching the comment controllers. The preceding SELECT was already checking ownership, but the write was open on id alone — a TOCTOU gap.
1 parent 84fd6bd commit 12e9b94

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

apps/api/src/activity/controllers/delete-comment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async function deleteComment(userId: string, id: string) {
2424

2525
const [deletedComment] = await db
2626
.delete(activityTable)
27-
.where(eq(activityTable.id, id))
27+
.where(and(eq(activityTable.id, id), eq(activityTable.userId, userId)))
2828
.returning();
2929

3030
if (!deletedComment) {

apps/api/src/activity/controllers/update-comment.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ async function updateComment(userId: string, id: string, content: string) {
2525
const [updated] = await db
2626
.update(activityTable)
2727
.set({ content })
28-
.where(eq(activityTable.id, id))
28+
.where(and(eq(activityTable.id, id), eq(activityTable.userId, userId)))
2929
.returning();
3030

3131
if (!updated) {

0 commit comments

Comments
 (0)