⚡ 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: enforce user ownership in notification endpoints (#1089)
Ivan Bobchenkov16c28a92551a
diff --git a/apps/api/src/notification/controllers/mark-notification-as-read.ts b/apps/api/src/notification/controllers/mark-notification-as-read.tsindex 1cc59f974..bb1c9c9b5 100644--- a/apps/api/src/notification/controllers/mark-notification-as-read.ts+++ b/apps/api/src/notification/controllers/mark-notification-as-read.ts@@ -1,13 +1,15 @@-import { eq } from "drizzle-orm";+import { and, eq } from "drizzle-orm";import { HTTPException } from "hono/http-exception";import db from "../../database";import { notificationTable } from "../../database/schema";-async function markNotificationAsRead(id: string) {+async function markNotificationAsRead(id: string, userId: string) {const [notification] = await db.update(notificationTable).set({ isRead: true })- .where(eq(notificationTable.id, id))+ .where(+ and(eq(notificationTable.id, id), eq(notificationTable.userId, userId)),+ ).returning();if (!notification) {diff --git a/apps/api/src/notification/index.ts b/apps/api/src/notification/index.tsindex 3491b363d..b54073470 100644--- a/apps/api/src/notification/index.ts+++ b/apps/api/src/notification/index.ts@@ -60,7 +60,6 @@ const notification = new Hono<{validator("json",v.object({- userId: v.string(),title: v.string(),message: v.string(),type: v.string(),@@ -69,14 +68,9 @@ const notification = new Hono<{}),),async (c) => {- const {- userId,- title,- message,- type,- relatedEntityId,- relatedEntityType,- } = c.req.valid("json");+ const { title, message, type, relatedEntityId, relatedEntityType } =+ c.req.valid("json");+ const userId = c.get("userId");const notification = await createNotification({userId,title,@@ -106,7 +100,8 @@ const notification = new Hono<{validator("param", v.object({ id: v.string() })),async (c) => {const { id } = c.req.valid("param");- const notification = await markAsRead(id);+ const userId = c.get("userId");+ const notification = await markAsRead(id, userId);return c.json(notification);},)