mirror of
https://github.com/outline/outline.git
synced 2026-11-28 08:14:58 +03:00
fix: Validate attachment in documents.import (#14711)
This commit is contained in:
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({
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user