Add ignore_files to config,

test files against ignore_files list on upload

fix typo and indentation

Move blacklist declaration to lib/public/Files/FileInfo.php,

Rename *ignored to *blacklisted

Mocked blacklist_files for testing

Mocked blacklist_files for testing

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Felix Heidecke 2017-02-13 16:51:23 +01:00 committed by Morris Jobke
parent 528a903a7b
commit 11f838f9e4
No known key found for this signature in database
GPG Key ID: 9CE5ED29E7FCD38A
6 changed files with 23 additions and 2 deletions

View File

@ -101,7 +101,10 @@
throw t('files', '"{name}" is an invalid file name.', {name: name}); throw t('files', '"{name}" is an invalid file name.', {name: name});
} else if (trimmedName.length === 0) { } else if (trimmedName.length === 0) {
throw t('files', 'File name cannot be empty.'); throw t('files', 'File name cannot be empty.');
} else if (OC.fileIsBlacklisted(trimmedName)) {
throw t('files', '"{name}" is not an allow filetype', {name: name});
} }
return true; return true;
}, },
displayStorageWarnings: function() { displayStorageWarnings: function() {

View File

@ -58,7 +58,9 @@ describe('OCA.Files.Files tests', function() {
' ..', ' ..',
'.. ', '.. ',
'. ', '. ',
' .' ' .',
'foo.part',
'bar.filepart'
]; ];
for ( var i = 0; i < fileNames.length; i++ ) { for ( var i = 0; i < fileNames.length; i++ ) {
var threwException = false; var threwException = false;

View File

@ -224,6 +224,14 @@ var OCP = {},
return link; return link;
}, },
/**
* Check if a user file is allowed to be handled.
* @param {string} file to check
*/
fileIsBlacklisted: function(file) {
return !!(file.match(oc_config.blacklist_files_regex));
},
/** /**
* Redirect to the target URL, can also be used for downloads. * Redirect to the target URL, can also be used for downloads.
* @param {string} targetURL URL to redirect to * @param {string} targetURL URL to redirect to

View File

@ -94,7 +94,8 @@ window.oc_appswebroots = {
}; };
window.oc_config = { window.oc_config = {
session_lifetime: 600 * 1000, session_lifetime: 600 * 1000,
session_keepalive: false session_keepalive: false,
blacklist_files_regex: '\.(part|filepart)$',
}; };
window.oc_appconfig = { window.oc_appconfig = {
core: {} core: {}

View File

@ -209,6 +209,7 @@ class JSConfigHelper {
'modRewriteWorking' => ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'), 'modRewriteWorking' => ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true'),
'sharing.maxAutocompleteResults' => intval($this->config->getSystemValue('sharing.maxAutocompleteResults', 0)), 'sharing.maxAutocompleteResults' => intval($this->config->getSystemValue('sharing.maxAutocompleteResults', 0)),
'sharing.minSearchStringLength' => intval($this->config->getSystemValue('sharing.minSearchStringLength', 0)), 'sharing.minSearchStringLength' => intval($this->config->getSystemValue('sharing.minSearchStringLength', 0)),
'blacklist_files_regex' => \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX,
]), ]),
"oc_appconfig" => json_encode([ "oc_appconfig" => json_encode([
'core' => [ 'core' => [

View File

@ -63,6 +63,12 @@ interface FileInfo {
*/ */
const MIMETYPE_FOLDER = 'httpd/unix-directory'; const MIMETYPE_FOLDER = 'httpd/unix-directory';
/**
* @const \OCP\Files\FileInfo::BLACKLIST_FILES_REGEX Return regular expression to test filenames against (blacklisting)
* @since 12.0.0
*/
const BLACKLIST_FILES_REGEX = '\.(part|filepart)$';
/** /**
* Get the Etag of the file or folder * Get the Etag of the file or folder
* *