fix: Validate that shares contain only a documentId or collectionId (#12098)

* fix: Validate that shares contain only a documentId or collectionId

* Restore test
This commit is contained in:
Tom Moor authored and GitHub committed 2026-04-18 03:29:20 +00:00
1 parent 04debcb607
commit 4dd24b59ad
2 files changed
+63 -14

No files matched your search

+7 -1
View File
@@ -87,7 +87,13 @@ export const SharesCreateSchema = BaseSchema.extend({
})
.refine((obj) => !(isEmpty(obj.collectionId) && isEmpty(obj.documentId)), {
error: "one of collectionId or documentId is required",
}),
})
.refine(
(obj) => !(!isEmpty(obj.collectionId) && !isEmpty(obj.documentId)),
{
error: "only one of collectionId or documentId may be provided",
}
),
});
export type SharesCreateReq = z.infer<typeof SharesCreateSchema>;
+56 -13
View File
@@ -573,18 +573,11 @@ describe("#shares.create", () => {
it("should not allow creating a share for a document in another team", async () => {
const user = await buildUser();
const collection = await buildCollection({
userId: user.id,
teamId: user.teamId,
});
// document belongs to a completely different team
const otherDocument = await buildDocument();
const res = await server.post("/api/shares.create", {
body: {
token: user.getJwtToken(),
collectionId: collection.id,
documentId: otherDocument.id,
},
});
@@ -593,23 +586,73 @@ describe("#shares.create", () => {
it("should not allow creating a published share for a document in another team", async () => {
const user = await buildUser();
const collection = await buildCollection({
userId: user.id,
teamId: user.teamId,
});
const otherDocument = await buildDocument();
const res = await server.post("/api/shares.create", {
body: {
token: user.getJwtToken(),
collectionId: collection.id,
documentId: otherDocument.id,
published: true,
},
});
expect(res.status).toEqual(403);
});
it("should not allow creating a share for a collection in another team", async () => {
const user = await buildUser();
const otherCollection = await buildCollection();
const res = await server.post("/api/shares.create", {
body: {
token: user.getJwtToken(),
collectionId: otherCollection.id,
},
});
expect(res.status).toEqual(403);
});
it("should not allow creating a share with both a collectionId and documentId", async () => {
const user = await buildUser();
const collection = await buildCollection({
userId: user.id,
teamId: user.teamId,
});
const document = await buildDocument({
userId: user.id,
teamId: user.teamId,
});
const res = await server.post("/api/shares.create", {
body: {
token: user.getJwtToken(),
collectionId: collection.id,
documentId: document.id,
},
});
expect(res.status).toEqual(400);
});
it("should not allow creating a published share with both a collectionId and documentId", async () => {
const user = await buildUser();
const collection = await buildCollection({
userId: user.id,
teamId: user.teamId,
});
const document = await buildDocument({
userId: user.id,
teamId: user.teamId,
});
const res = await server.post("/api/shares.create", {
body: {
token: user.getJwtToken(),
collectionId: collection.id,
documentId: document.id,
published: true,
},
});
expect(res.status).toEqual(400);
});
});
describe("#shares.info", () => {