I'm working on handling file uploads using express.js and node, and have the basic functionality working. What I need is to implement some security measures -- namely, to limit uploads to certain formats (PNG, JPEG). Is there an easy way to only allow certain formats? Would it go in the body-parser?
app.use(express.bodyParser({
uploadDir: __dirname + '/public/uploads',
keepExtensions: true }));
app.use(express.limit('4mb'));
Are there any other security measures that I should take into account? Is it generally a good idea to wipe EXIF data from the image?
Thanks,
Ben
According to the documentation for connect's
bodyParser
, any options are also passed to formidable, which does the actual form parsing.According to formidable docs, you can pass your own
onPart
handler:Taken together, you should be able to do something like this:
Warning: I haven't tested any of this.
I found a potential solution:
In your middleware,
update: This doesn't actually stop the file from uploading, though.