From bba2c8393db7a3f6e055ae72d692ec5065795031 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 26 Nov 2026 19:38:17 -0500 Subject: [PATCH] fix: Scope admin share fields to the owning team (#14770) --- server/routes/api/shares/shares.test.ts | 30 +++++++++++++++++++++++++ server/routes/api/shares/shares.ts | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/server/routes/api/shares/shares.test.ts b/server/routes/api/shares/shares.test.ts index 6b6051bbea..e57419d3c6 100644 --- a/server/routes/api/shares/shares.test.ts +++ b/server/routes/api/shares/shares.test.ts @@ -852,6 +852,36 @@ describe("#shares.info", () => { expect(body.data.shares[0].id).toEqual(share.id); }); + it("should only return lastAccessedAt to admins of the owning team", async () => { + const admin = await buildAdmin(); + const otherAdmin = await buildAdmin(); + const document = await buildDocument({ + createdById: admin.id, + teamId: admin.teamId, + }); + const share = await buildShare({ + documentId: document.id, + teamId: admin.teamId, + userId: admin.id, + published: true, + lastAccessedAt: new Date(), + }); + + const res = await server.post("/api/shares.info", admin, { + body: { id: share.id }, + }); + const body = await res.json(); + expect(res.status).toEqual(200); + expect(body.data.shares[0].lastAccessedAt).toBeTruthy(); + + const otherRes = await server.post("/api/shares.info", otherAdmin, { + body: { id: share.id }, + }); + const otherBody = await otherRes.json(); + expect(otherRes.status).toEqual(200); + expect(otherBody.data.shares[0].lastAccessedAt).toBeUndefined(); + }); + it("should not return the sharer for an unauthenticated viewer", async () => { const user = await buildUser(); const document = await buildDocument({ diff --git a/server/routes/api/shares/shares.ts b/server/routes/api/shares/shares.ts index 036c80cb50..460f6207a7 100644 --- a/server/routes/api/shares/shares.ts +++ b/server/routes/api/shares/shares.ts @@ -105,7 +105,7 @@ router.post( data: { shares: [ presentShare(share, { - isAdmin: user?.isAdmin ?? false, + isAdmin: !!user?.isAdmin && user.teamId === share.teamId, isPublic: cannot(user, "read", share), }), ],