Skip to content

Commit

Permalink
remove images only from dedicated folder and forbid non image extensi…
Browse files Browse the repository at this point in the history
…ons in image path
  • Loading branch information
matthieu-rolland authored and Matthieu Rolland committed Nov 8, 2023
1 parent 0a74bf1 commit 6327811
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions controllers/admin/AdminBlockListingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function displayAjaxDeleteBlock()
$result = true;
// Remove Custom icon
if (!empty($blockPSR['custom_icon'])) {
$filePath = _PS_ROOT_DIR_ . $blockPSR['custom_icon'];
$filePath = _PS_ROOT_DIR_ . $this->module->img_path_perso . '/' . basename($blockPSR['custom_icon']);
if (file_exists($filePath)) {
$result = unlink($filePath);
}
Expand Down Expand Up @@ -143,6 +143,14 @@ public function displayAjaxSaveBlockContent()
$type_link = (int) Tools::getValue('typelink');
$id_cms = Tools::getValue('id_cms');
$psr_languages = (array) json_decode(Tools::getValue('lang_values'));
$authExtensions = ['gif', 'jpg', 'jpeg', 'jpe', 'png', 'svg'];
$authMimeType = ['image/gif', 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/svg', 'image/svg+xml'];

if (!empty($picto) && !in_array(pathinfo($picto, PATHINFO_EXTENSION), $authExtensions)) {
$errors[] = Context::getContext()->getTranslator()->trans('Image format not recognized, allowed formats are: .gif, .jpg, .png', [], 'Admin.Notifications.Error');

return $this->ajaxRenderJson(empty($errors) ? 'success' : 'error');
}

$blockPsr = new ReassuranceActivity($id_block);
if (!$id_block) {
Expand All @@ -168,8 +176,6 @@ public function displayAjaxSaveBlockContent()
$filename = $customImage['name'];

// validateUpload return false if no error (false -> OK)
$authExtensions = ['gif', 'jpg', 'jpeg', 'jpe', 'png', 'svg'];
$authMimeType = ['image/gif', 'image/jpg', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/svg', 'image/svg+xml'];
if (version_compare(_PS_VERSION_, '1.7.7.0', '>=')) {
// PrestaShop 1.7.7.0+
$validUpload = ImageManager::validateUpload(
Expand Down Expand Up @@ -246,24 +252,26 @@ public function displayAjaxUpdatePosition()
}

/**
* @param $hook
* @param string $hook
*
* @return bool
*/
private function isAuthorizedHookConfigurationKey($hook)
{
return (
return
!empty($hook) &&
in_array($hook, [
blockreassurance::PSR_HOOK_HEADER,
blockreassurance::PSR_HOOK_FOOTER,
blockreassurance::PSR_HOOK_PRODUCT,
blockreassurance::PSR_HOOK_CHECKOUT,
], true)
);
;
}

/**
* @param $value
* @param string $value
*
* @return bool
*/
private function isAuthorizedPositionValue($value)
Expand Down

0 comments on commit 6327811

Please sign in to comment.