summaryrefslogtreecommitdiff
path: root/lib/web/imageRouter/filesystem.js
diff options
context:
space:
mode:
authorDavid Mehren2020-12-27 19:52:42 +0100
committerGitHub2020-12-27 19:52:42 +0100
commite9306991cdb5ff2752c1eeba3fedba42aec3c2d8 (patch)
tree50eea3b294f40287a8eded1938593d0a2c4f206a /lib/web/imageRouter/filesystem.js
parent58276ebbf4504a682454a3686dcaff88bc1069d4 (diff)
parent6932cc4df7e0c2826e47b2d9ca2f0031f75b1b58 (diff)
Merge pull request from GHSA-wcr3-xhv7-8gxc
Fix arbitrary file upload
Diffstat (limited to '')
-rw-r--r--lib/web/imageRouter/filesystem.js11
1 files changed, 10 insertions, 1 deletions
diff --git a/lib/web/imageRouter/filesystem.js b/lib/web/imageRouter/filesystem.js
index 3ba09e88..f8fd7e16 100644
--- a/lib/web/imageRouter/filesystem.js
+++ b/lib/web/imageRouter/filesystem.js
@@ -1,6 +1,7 @@
'use strict'
const URL = require('url').URL
const path = require('path')
+const fs = require('fs')
const config = require('../../config')
const logger = require('../../logger')
@@ -16,5 +17,13 @@ exports.uploadImage = function (imagePath, callback) {
return
}
- callback(null, (new URL(path.basename(imagePath), config.serverURL + '/uploads/')).href)
+ const fileName = path.basename(imagePath)
+ // move image from temporary path to upload directory
+ try {
+ fs.copyFileSync(imagePath, path.join(config.uploadsPath, fileName))
+ } catch (e) {
+ callback(new Error('Error while moving file'), null)
+ return
+ }
+ callback(null, (new URL(fileName, config.serverURL + '/uploads/')).href)
}