-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
This is not an issue with multer directly, but more an issue with applications using multer.
There is little to no mention of any security issues with file uploads handled by multer leading to a lot of example code around the web based off the simple examples in the readme that completely ignore any security issues, notably things like:
var express = require('express')
var multer = require('multer')
var app = express()
app.use(multer({ dest: './uploads/'}))
app.post('/api/uploads', ...handles maby one expected file...)
The first major issue here is that multer will be executed on any post request, even for post requests that are not expected to handle files, meaning that you could potentially upload files to the server bypassing the upload url if there exists another post url.
This is a major concern as if people are using these examples directly in their code they will be vulnerable to to file upload exploits if they do not already know about them.
The example should probably be changed to app.use('/api/upload', multer({ dest: './uploads/'})) so that multer only handles files to locations that are known to handle uploads.
It also might be worth adding a filter on what files are expected so that the user does not have to worry about unexpected files being uploaded. Something long the lines of:
app.use('/api/uploads', multer({ dest: './uploads', filter: ['someFile']})
so that multer only handles files found in the POST requests someFile variable and rejects/errors for any other files found. This could be partly done by limits.files, but this does not ensure that the expected file ends up in the right variable, and people generally only check for what they are expecting.