Added configurable dangerous file upload extensions

This commit is contained in:
Andy Miller
2018-10-06 16:35:15 -06:00
parent 8dd352c5c4
commit 6b46c288a6
3 changed files with 30 additions and 3 deletions

View File

@@ -4,7 +4,7 @@ form:
validation: loose
fields:
security_section:
xss_section:
type: section
title: PLUGIN_ADMIN.XSS_SECURITY
underline: true
@@ -82,3 +82,18 @@ form:
validate:
type: commalist
uploads_section:
type: section
title: PLUGIN_ADMIN.UPLOADS_SECURITY
underline: true
uploads_dangerous_extensions:
type: selectize
size: large
label: PLUGIN_ADMIN.UPLOADS_DANGEROUS_EXTENSIONS
help: PLUGIN_ADMIN.UPLOADS_DANGEROUS_EXTENSIONS_HELP
classes: fancy
validate:
type: commalist

View File

@@ -23,4 +23,9 @@ xss_dangerous_tags:
- bgsound
- title
- base
uploads_dangerous_extensions:
- php
- html
- htm
- js
- exe

View File

@@ -573,6 +573,13 @@ abstract class Utils
*/
public static function checkFilename($filename)
{
$dangerous_extensions = Grav::instance()['config']->get('security.uploads_dangerous_extensions', []);
array_walk($dangerous_extensions, function(&$val) {
$val = '.' . $val;
});
$extension = '.' . pathinfo($filename, PATHINFO_EXTENSION);
return !(
// Empty filenames are not allowed.
!$filename
@@ -581,7 +588,7 @@ abstract class Utils
// Filename should not start or end with dot or space.
|| trim($filename, '. ') !== $filename
// Filename should not contain .php in it.
|| strpos($filename, '.php') !== false
|| static::contains($extension, $dangerous_extensions)
);
}