This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
@@ -0,0 +1,41 @@
<?php
declare(strict_types=1);
namespace Esun\FileManager\Model\Config\Backend;
use Magento\Framework\App\Config\Value;
use Magento\Framework\Exception\LocalizedException;
use Esun\FileManager\Model\Security\FilePolicy;
class AllowedExtensions extends Value
{
/**
* @throws LocalizedException
*/
public function beforeSave(): self
{
$value = strtolower((string) $this->getValue());
$extensions = preg_split('/[\s,]+/', $value, -1, PREG_SPLIT_NO_EMPTY) ?: [];
if (!$extensions) {
throw new LocalizedException(__('At least one allowed extension is required.'));
}
foreach ($extensions as $extension) {
if (!preg_match('/^[a-z0-9]+$/', $extension)) {
throw new LocalizedException(__('Invalid extension: %1', $extension));
}
if (in_array($extension, FilePolicy::BLOCKED_EXTENSIONS, true)) {
throw new LocalizedException(__('The extension %1 is always forbidden.', $extension));
}
if (!in_array($extension, FilePolicy::getSupportedExtensions(), true)) {
throw new LocalizedException(
__('The extension %1 does not have a secure MIME policy.', $extension)
);
}
}
$this->setValue(implode(',', array_values(array_unique($extensions))));
return parent::beforeSave();
}
}