Ignore invalid paths in the JS file list (#25368)

This commit is contained in:
Vincent Petry 2016-07-06 11:55:02 +02:00 committed by Thomas Müller
parent a2e0573987
commit c92c234059
No known key found for this signature in database
GPG Key ID: A943788A3BBEC44C
2 changed files with 39 additions and 0 deletions

View File

@ -1327,6 +1327,16 @@
return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/'); return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/');
}, },
_isValidPath: function(path) {
var sections = path.split('/');
for (var i = 0; i < sections.length; i++) {
if (sections[i] === '..') {
return false;
}
}
return true;
},
/** /**
* Sets the current directory name and updates the breadcrumb. * Sets the current directory name and updates the breadcrumb.
* @param targetDir directory to display * @param targetDir directory to display
@ -1334,6 +1344,10 @@
*/ */
_setCurrentDir: function(targetDir, changeUrl) { _setCurrentDir: function(targetDir, changeUrl) {
targetDir = targetDir.replace(/\\/g, '/'); targetDir = targetDir.replace(/\\/g, '/');
if (!this._isValidPath(targetDir)) {
targetDir = '/';
changeUrl = true;
}
var previousDir = this.getCurrentDirectory(), var previousDir = this.getCurrentDirectory(),
baseDir = OC.basename(targetDir); baseDir = OC.basename(targetDir);

View File

@ -1323,6 +1323,31 @@ describe('OCA.Files.FileList tests', function() {
fileList.changeDirectory('/another\\subdir'); fileList.changeDirectory('/another\\subdir');
expect(fileList.getCurrentDirectory()).toEqual('/another/subdir'); expect(fileList.getCurrentDirectory()).toEqual('/another/subdir');
}); });
it('switches to root dir when current directory is invalid', function() {
_.each([
'..',
'/..',
'../',
'/../',
'/../abc',
'/abc/..',
'/abc/../',
'/../abc/'
], function(path) {
fileList.changeDirectory(path);
expect(fileList.getCurrentDirectory()).toEqual('/');
});
});
it('allows paths with dotdot at the beginning or end', function() {
_.each([
'..abc',
'def..',
'...'
], function(path) {
fileList.changeDirectory(path);
expect(fileList.getCurrentDirectory()).toEqual(path);
});
});
it('switches to root dir when current directory does not exist', function() { it('switches to root dir when current directory does not exist', function() {
fileList.changeDirectory('/unexist'); fileList.changeDirectory('/unexist');
deferredList.reject(404); deferredList.reject(404);