fix: Validate attachment in documents.import (#14711)

This commit is contained in:
Tom Moor authored and GitHub committed 2026-11-25 20:20:58 -05:00
1 parent bb0f59f562
commit 4f25f3854e
2 files changed
+31

No files matched your search

@@ -6363,6 +6363,32 @@ describe("#documents.import", () => {
);
});
it("should reject an attachment that is not an import upload", async () => {
const user = await buildUser();
const collection = await buildCollection({
userId: user.id,
teamId: user.teamId,
});
const attachment = await buildAttachment({
teamId: user.teamId,
userId: user.id,
});
const deleteFile = vi.spyOn(FileStorage, "deleteFile");
const res = await server.post("/api/documents.import", user, {
body: {
collectionId: collection.id,
attachmentId: attachment.id,
},
});
const body = await res.json();
expect(res.status).toEqual(400);
expect(body.message).toEqual("Attachment is not an import upload");
expect(deleteFile).not.toHaveBeenCalled();
vi.restoreAllMocks();
});
it("should error if no file or attachmentId is passed", async () => {
const user = await buildUser();
const collection = await buildCollection({
+5
View File
@@ -1794,6 +1794,11 @@ router.post(
const attachment = await Attachment.findByPk(attachmentId);
authorize(user, "read", attachment);
// The import task deletes the file, so only accept temporary import uploads.
if (!attachment.expiresAt) {
throw ValidationError("Attachment is not an import upload");
}
key = attachment.key;
fileName = attachment.name;
mimeType = attachment.contentType;