Skip to content

Commit a2711cf

Browse files
committed
verify that the uploaded modified file is temporary
1 parent 84feec2 commit a2711cf

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/routes/api/files.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,16 @@ function saveAttachmentToTmpDir(req) {
154154
return saveToTmpDir(fileName, content, 'attachments', attachment.attachmentId);
155155
}
156156

157+
const createdTemporaryFiles = new Set();
158+
157159
function saveToTmpDir(fileName, content, entityType, entityId) {
158160
const tmpObj = tmp.fileSync({ postfix: fileName });
159161

160162
fs.writeSync(tmpObj.fd, content);
161163
fs.closeSync(tmpObj.fd);
162164

165+
createdTemporaryFiles.add(tmpObj.name);
166+
163167
log.info(`Saved temporary file ${tmpObj.name}`);
164168

165169
if (utils.isElectron()) {
@@ -183,6 +187,10 @@ function uploadModifiedFileToNote(req) {
183187
const noteId = req.params.noteId;
184188
const {filePath} = req.body;
185189

190+
if (!createdTemporaryFiles.has(filePath)) {
191+
throw new ValidationError(`File '${filePath}' is not a temporary file.`);
192+
}
193+
186194
const note = becca.getNoteOrThrow(noteId);
187195

188196
log.info(`Updating note '${noteId}' with content from '${filePath}'`);

0 commit comments

Comments
 (0)