From 9d39e07a7d5fbf4b90d27cf5f8330e37fec22a90 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 26 Nov 2026 19:01:36 -0500 Subject: [PATCH] fix: documents.duplicate returns 403 for an unknown collectionId (#14750) --- server/routes/api/documents/documents.test.ts | 18 ++++++++++++++++++ server/routes/api/documents/documents.ts | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/server/routes/api/documents/documents.test.ts b/server/routes/api/documents/documents.test.ts index a157fb8441..7d4aa9bbb0 100644 --- a/server/routes/api/documents/documents.test.ts +++ b/server/routes/api/documents/documents.test.ts @@ -9768,6 +9768,24 @@ describe("#documents.duplicate", () => { expect(res.status).toEqual(401); }); + it("should fail with status 403 for an unknown collectionId", async () => { + const user = await buildUser(); + const document = await buildDocument({ + userId: user.id, + teamId: user.teamId, + }); + + const res = await server.post("/api/documents.duplicate", user, { + body: { + id: document.id, + collectionId: faker.string.uuid(), + publish: true, + }, + }); + + expect(res.status).toEqual(403); + }); + it("should duplicate a document with fullWidth property", async () => { const user = await buildUser(); const document = await buildDocument({ diff --git a/server/routes/api/documents/documents.ts b/server/routes/api/documents/documents.ts index 314407487a..631f62e0d9 100644 --- a/server/routes/api/documents/documents.ts +++ b/server/routes/api/documents/documents.ts @@ -1580,7 +1580,7 @@ router.post( // The copy is created in the destination collection, so create permission // is required there rather than on the source. - if (collection) { + if (collectionId || collection) { authorize(user, "createDocument", collection); } }