Skip to content

Commit e43100a

Browse files
author
Sebastian.Just
committed
Avoid path traversal with "../"-filenames
1 parent 8dbf590 commit e43100a

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

lib/uploadhandler.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,20 @@ module.exports = function (options) {
174174
var self = this,
175175
fileName = path.basename(decodeURIComponent(this.req.url));
176176

177-
fs.unlink(options.uploadDir() + '/' + fileName, function (ex) {
177+
var filepath = path.join(options.uploadDir(), fileName);
178+
if (filepath.indexOf(options.uploadDir()) !== 0) {
179+
self.emit('delete', fileName);
180+
self.callback({success: false});
181+
return;
182+
}
183+
fs.unlink(filepath, function (ex) {
178184
_.each(options.imageVersions, function (value, version) {
185+
var versionfilepath = path.join(options.uploadDir(), version, fileName);
186+
if (versionfilepath.indexOf(options.uploadDir()) !== 0) {
187+
self.emit('delete', fileName);
188+
self.callback({success: false});
189+
return;
190+
}
179191
fs.unlink(options.uploadDir() + '/' + version + '/' + fileName);
180192
});
181193
self.emit('delete', fileName);

0 commit comments

Comments
 (0)