Skip to content

Commit 28a05a2

Browse files
authored
Merge pull request #1232 from nextcloud/backport-1224-do-not-allow-linebreak-in-paths-9
[stable9] Do not allow linebreaks and null bytes in paths
2 parents a98e66d + 1352365 commit 28a05a2

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ nbproject
104104
/build/lib/
105105
/build/jsdocs/
106106
/npm-debug.log
107+
/PhantomJS_*
107108

108109
# puphpet
109110
puphpet

apps/files/js/filelist.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1327,14 +1327,20 @@
13271327
return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/');
13281328
},
13291329

1330+
/**
1331+
* @param {string} path
1332+
* @returns {boolean}
1333+
*/
13301334
_isValidPath: function(path) {
13311335
var sections = path.split('/');
13321336
for (var i = 0; i < sections.length; i++) {
13331337
if (sections[i] === '..') {
13341338
return false;
13351339
}
13361340
}
1337-
return true;
1341+
1342+
return path.toLowerCase().indexOf(decodeURI('%0a')) === -1 &&
1343+
path.toLowerCase().indexOf(decodeURI('%00')) === -1;
13381344
},
13391345

13401346
/**

apps/files/tests/js/filelistSpec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,9 +1333,11 @@ describe('OCA.Files.FileList tests', function() {
13331333
'/abc/..',
13341334
'/abc/../',
13351335
'/../abc/',
1336+
'/foo%0Abar/',
1337+
'/foo%00bar/',
13361338
'/another\\subdir/../foo\\../bar\\..\\file/..\\folder/../'
13371339
], function(path) {
1338-
fileList.changeDirectory(path);
1340+
fileList.changeDirectory(decodeURI(path));
13391341
expect(fileList.getCurrentDirectory()).toEqual('/');
13401342
});
13411343
});

0 commit comments

Comments
 (0)