From 4b430243c7d73f9016c97e1ccf3de44690055152 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 26 Nov 2026 19:28:29 -0500 Subject: [PATCH] fix: Scope events.list results by collection visibility --- server/routes/api/events/events.test.ts | 30 +++++++++++++++++++++++++ server/routes/api/events/events.ts | 19 +++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/server/routes/api/events/events.test.ts b/server/routes/api/events/events.test.ts index 04485b3cca..1e86201b0c 100644 --- a/server/routes/api/events/events.test.ts +++ b/server/routes/api/events/events.test.ts @@ -8,6 +8,7 @@ import { buildCollection, buildDocument, buildEvent, + buildPersonalCollection, buildUser, buildUserPasskey, buildWebhookSubscription, @@ -484,6 +485,35 @@ describe("#events.list", () => { expect(eventIds).toContain(draftEvent.id); }); + it("should not return events in other users' personal collections to admins", async () => { + const user = await buildUser(); + const admin = await buildAdmin({ teamId: user.teamId }); + const collection = await buildPersonalCollection(user); + const ownEvent = await buildEvent({ + name: "collections.create", + collectionId: (await buildPersonalCollection(admin)).id, + teamId: user.teamId, + actorId: admin.id, + }); + const otherEvent = await buildEvent({ + name: "documents.delete", + collectionId: collection.id, + teamId: user.teamId, + actorId: user.id, + }); + + for (const auditLog of [false, true]) { + const res = await server.post("/api/events.list", admin, { + body: { auditLog }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + const eventIds = body.data.map((e: { id: string }) => e.id); + expect(eventIds).toContain(ownEvent.id); + expect(eventIds).not.toContain(otherEvent.id); + } + }); + it("should allow non-admins to list events when collectionId is specified", async () => { const user = await buildUser(); const collection = await buildCollection({ diff --git a/server/routes/api/events/events.ts b/server/routes/api/events/events.ts index d8cc1e45af..885faaef3f 100644 --- a/server/routes/api/events/events.ts +++ b/server/routes/api/events/events.ts @@ -81,7 +81,18 @@ router.post( } const loadedEvents = await Event.findAll({ - where, + where: { + [Op.and]: [ + where, + // Exclude events in the personal collections of other users. + { + [Op.or]: [ + { "$collection.ownerId$": null }, + { "$collection.ownerId$": user.id }, + ], + }, + ], + }, order: [[sort, direction]], include: [ { @@ -89,6 +100,12 @@ router.post( as: "actor", paranoid: false, }, + { + model: Collection.unscoped(), + as: "collection", + attributes: [], + paranoid: false, + }, ], offset: ctx.state.pagination.offset, limit: ctx.state.pagination.limit,