verify that the uploaded modified file is temporary

(cherry picked from commit a2711cfb7b5b454182393aa160e45ccbf52c949d)
This commit is contained in:
zadam 2024-05-18 05:50:46 +02:00
parent 3035473751
commit a88bf68eb6
2 changed files with 5845 additions and 0 deletions

5837
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -154,12 +154,16 @@ function saveAttachmentToTmpDir(req) {
return saveToTmpDir(fileName, content, 'attachments', attachment.attachmentId);
}
const createdTemporaryFiles = new Set();
function saveToTmpDir(fileName, content, entityType, entityId) {
const tmpObj = tmp.fileSync({ postfix: fileName });
fs.writeSync(tmpObj.fd, content);
fs.closeSync(tmpObj.fd);
createdTemporaryFiles.add(tmpObj.name);
log.info(`Saved temporary file ${tmpObj.name}`);
if (utils.isElectron()) {
@ -183,6 +187,10 @@ function uploadModifiedFileToNote(req) {
const noteId = req.params.noteId;
const {filePath} = req.body;
if (!createdTemporaryFiles.has(filePath)) {
throw new ValidationError(`File '${filePath}' is not a temporary file.`);
}
const note = becca.getNoteOrThrow(noteId);
log.info(`Updating note '${noteId}' with content from '${filePath}'`);