diff --git a/protected/humhub/docs/CHANGELOG.md b/protected/humhub/docs/CHANGELOG.md index f39ac19fa3..73e0e43b52 100644 --- a/protected/humhub/docs/CHANGELOG.md +++ b/protected/humhub/docs/CHANGELOG.md @@ -7,6 +7,7 @@ HumHub Change Log - Fix: #2536 Incorrect log of "Attempt to steal file" due to faulty File::isAssignedTo() check - Fix: Wrong help block position in admin basic settings - Chng: Removed yiisoft/yii2-apidoc dependency +- Enh: Double file extension check is now optional and disabled by default 1.3.12 (March 26, 2019) diff --git a/protected/humhub/modules/file/Module.php b/protected/humhub/modules/file/Module.php index 38c279daac..c15dee42a3 100644 --- a/protected/humhub/modules/file/Module.php +++ b/protected/humhub/modules/file/Module.php @@ -43,6 +43,11 @@ class Module extends \humhub\components\Module 'image/jpeg' ]; + /** + * @var bool Prohibit uploads of files with double file extension. + */ + public $denyDoubleFileExtensions = false; + /** * @var array of converter options */ diff --git a/protected/humhub/modules/file/validators/FileValidator.php b/protected/humhub/modules/file/validators/FileValidator.php index 13c3e8e480..1854a8637d 100644 --- a/protected/humhub/modules/file/validators/FileValidator.php +++ b/protected/humhub/modules/file/validators/FileValidator.php @@ -8,6 +8,7 @@ namespace humhub\modules\file\validators; +use humhub\modules\file\Module; use Yii; use humhub\modules\file\models\File; use humhub\modules\file\libs\ImageConverter; @@ -27,17 +28,29 @@ class FileValidator extends \yii\validators\FileValidator */ public $useDefaultExtensionRestriction = true; + /** + * @var boolean deny double file extensions + */ + public $denyDoubleFileExtensions; + /** * @inheritdoc */ public function init() { + /** @var Module $module */ + $module = Yii::$app->getModule('file'); + if ($this->extensions === null && $this->useDefaultExtensionRestriction) { - $this->extensions = Yii::$app->getModule('file')->settings->get('allowedExtensions'); + $this->extensions = $module->settings->get('allowedExtensions'); } if ($this->maxSize === null) { - $this->maxSize = Yii::$app->getModule('file')->settings->get('maxFileSize'); + $this->maxSize = $module->settings->get('maxFileSize'); + } + + if ($this->denyDoubleFileExtensions === null) { + $this->denyDoubleFileExtensions = $module->denyDoubleFileExtensions; } parent::init(); @@ -81,7 +94,7 @@ class FileValidator extends \yii\validators\FileValidator $this->addError($model, $attribute, Yii::t('FileModule.models_File', 'Invalid file name detected!')); } - if(preg_match('/\.\w{2,3}\.\w{2,3}$/', $model->file_name)) { + if($this->denyDoubleFileExtensions && preg_match('/\.\w{2,3}\.\w{2,3}$/', $model->file_name)) { $this->addError($model, $attribute, Yii::t('FileModule.models_File', 'Double file extensions are not allowed!')); } }