Fix path joining/expanding

This commit is contained in:
Loay 2017-02-07 22:21:18 -05:00
parent 080f18a985
commit c6978261c7
3 changed files with 39 additions and 2 deletions

View File

@ -40,9 +40,11 @@ function FileSystemProvider(options) {
} }
var namePattern = new RegExp('[^' + path.sep + '/]+'); var namePattern = new RegExp('[^' + path.sep + '/]+');
// To detect any file/directory containing dotdot paths
var containsDotDotPaths = /(^|[\\\/])\.\.([\\\/]|$)/;
function validateName(name, cb) { function validateName(name, cb) {
if (!name) { if (!name || containsDotDotPaths.test(name)) {
cb && process.nextTick(cb.bind(null, new Error(g.f('Invalid name: %s', name)))); cb && process.nextTick(cb.bind(null, new Error(g.f('Invalid name: %s', name))));
if (!cb) { if (!cb) {
console.error(g.f('{{FileSystemProvider}}: Invalid name: %s', name)); console.error(g.f('{{FileSystemProvider}}: Invalid name: %s', name));

View File

@ -161,4 +161,3 @@ describe('FileSystem based storage provider', function() {
}); });
}); });
}); });

View File

@ -173,6 +173,42 @@ describe('storage service', function() {
}); });
}); });
it('fails to upload using dotdot file path', function(done) {
request('http://localhost:' + app.get('port'))
.post('/containers/%2e%2e/upload')
.expect(200, function(err, res) {
assert(err);
done();
});
});
it('fails to upload using dotdot file path', function(done) {
request('http://localhost:' + app.get('port'))
.post('%2e%2e/containers/upload')
.expect(200, function(err, res) {
assert(err);
done();
});
});
it('fails to upload using dotdot file path', function(done) {
request('http://localhost:' + app.get('port'))
.post('%2e%2e')
.expect(200, function(err, res) {
assert(err);
done();
});
});
it('fails to upload using dotdot file path', function(done) {
request('http://localhost:' + app.get('port'))
.post('/containers/upload/%2e%2e')
.expect(200, function(err, res) {
assert(err);
done();
});
});
it('uploads files with renamer', function(done) { it('uploads files with renamer', function(done) {
request('http://localhost:' + app.get('port')) request('http://localhost:' + app.get('port'))
.post('/imageContainers/album1/upload') .post('/imageContainers/album1/upload')