From e88faa7fd42975cb5e1ba1fbe1bcca2784cb1ca2 Mon Sep 17 00:00:00 2001 From: azhar bhat Date: Wed, 21 Jan 2026 19:19:11 +0530 Subject: [PATCH 1/3] Vulnerability issue while uploading code updated --- modules/qlohotelreview/classes/QhrHotelReview.php | 4 ++++ modules/qlohotelreview/controllers/front/default.php | 2 +- modules/qlohotelreview/views/js/hook/review.js | 8 ++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/modules/qlohotelreview/classes/QhrHotelReview.php b/modules/qlohotelreview/classes/QhrHotelReview.php index 8768061d2..70ef425ed 100644 --- a/modules/qlohotelreview/classes/QhrHotelReview.php +++ b/modules/qlohotelreview/classes/QhrHotelReview.php @@ -290,9 +290,13 @@ class QhrHotelReview extends ObjectModel public function saveReviewImages() { $files = QhrHotelReviewHelper::fileAttachmentMultiple('images'); + $allowedExtensions = array('jpg', 'png', 'jpeg',); if (is_array($files) && count($files)) { foreach ($files as $key => $file) { $ext = pathinfo($file['rename'], PATHINFO_EXTENSION); + if (!in_array($ext, $allowedExtensions, true)) { + continue; + } $dir = _PS_MODULE_DIR_.'qlohotelreview/views/img/review/'.Image::getImgFolderStatic($this->id); QhrHotelReviewHelper::createDirectory($dir); $useSameExt = false; diff --git a/modules/qlohotelreview/controllers/front/default.php b/modules/qlohotelreview/controllers/front/default.php index c380cd5f7..899428526 100644 --- a/modules/qlohotelreview/controllers/front/default.php +++ b/modules/qlohotelreview/controllers/front/default.php @@ -86,7 +86,7 @@ class QloHotelReviewDefaultModuleFrontController extends ModuleFrontController } if (is_array($_FILES) && array_key_exists('images', $_FILES) ) { - $allowedExtensions = array('jpg', 'png'); + $allowedExtensions = array('jpg', 'png', 'jpeg',); foreach ($_FILES['images']['name'] as $key => $imageName) { $extension = Tools::strtolower(pathinfo($imageName, PATHINFO_EXTENSION)); if (!in_array($extension, $allowedExtensions)) { diff --git a/modules/qlohotelreview/views/js/hook/review.js b/modules/qlohotelreview/views/js/hook/review.js index 2a30ce2ef..b34571456 100644 --- a/modules/qlohotelreview/views/js/hook/review.js +++ b/modules/qlohotelreview/views/js/hook/review.js @@ -147,7 +147,7 @@ var QhrReviewImages = { reader.readAsDataURL(file); }, removeFile: function(iInput, iFile) { - var input = $('.images-field input.input-images').eq(iInput); + var input = $('.images-field input.input-images').get(iInput); var files = $(input).get(0).files; var dataTransfer = new DataTransfer(); $(files).each(function(iiFile, file) { @@ -155,9 +155,9 @@ var QhrReviewImages = { dataTransfer.items.add(file); } }); - input.get(0).files = dataTransfer.files; - if (input.get(0).files.length === 0) { - input.remove(); + input.files = dataTransfer.files; + if (input.files.length === 0) { + $(input).remove(); } }, resetPreviews: function() { From 96df477887b1f9fd599a33a1a9a8218c83101bef Mon Sep 17 00:00:00 2001 From: azhar bhat Date: Fri, 23 Jan 2026 12:26:00 +0530 Subject: [PATCH 2/3] Prevent invalid formats before upload --- .../controllers/front/default.php | 2 +- modules/qlohotelreview/qlohotelreview.php | 1 + .../qlohotelreview/views/css/front/review.css | 4 +++ .../qlohotelreview/views/js/hook/review.js | 26 ++++++++++++++++++- .../views/templates/hook/add-review-popup.tpl | 1 + 5 files changed, 32 insertions(+), 2 deletions(-) diff --git a/modules/qlohotelreview/controllers/front/default.php b/modules/qlohotelreview/controllers/front/default.php index 899428526..66e1b0a4f 100644 --- a/modules/qlohotelreview/controllers/front/default.php +++ b/modules/qlohotelreview/controllers/front/default.php @@ -90,7 +90,7 @@ class QloHotelReviewDefaultModuleFrontController extends ModuleFrontController foreach ($_FILES['images']['name'] as $key => $imageName) { $extension = Tools::strtolower(pathinfo($imageName, PATHINFO_EXTENSION)); if (!in_array($extension, $allowedExtensions)) { - $errors['general'][] = $imageName . ' ' . $objModule->l('is not a supported image format.','default'); + $errors['general'][] = $objModule->l('Only images with the following extensions are allowed: jpg, jpeg, png','default'); } } } diff --git a/modules/qlohotelreview/qlohotelreview.php b/modules/qlohotelreview/qlohotelreview.php index 405f12ff4..086265f15 100644 --- a/modules/qlohotelreview/qlohotelreview.php +++ b/modules/qlohotelreview/qlohotelreview.php @@ -182,6 +182,7 @@ class QloHotelReview extends Module $this->l('You can upload a maximum of %d images.', false, true), (int) Configuration::get('QHR_MAX_IMAGES_PER_REVIEW') ), + 'allowed_extensions' => $this->l('Only images with the following extensions are allowed: jpg, jpeg, png', false, true), ), ))); diff --git a/modules/qlohotelreview/views/css/front/review.css b/modules/qlohotelreview/views/css/front/review.css index 0c7346dce..539d10199 100644 --- a/modules/qlohotelreview/views/css/front/review.css +++ b/modules/qlohotelreview/views/css/front/review.css @@ -52,6 +52,10 @@ margin-bottom: 14px; } +#add-review-popup .hint { + margin-top: 6px; +} + #add-review-popup .review-error { margin-top: 2px; color: #E85757; diff --git a/modules/qlohotelreview/views/js/hook/review.js b/modules/qlohotelreview/views/js/hook/review.js index b34571456..2db6b37b9 100644 --- a/modules/qlohotelreview/views/js/hook/review.js +++ b/modules/qlohotelreview/views/js/hook/review.js @@ -132,6 +132,29 @@ var QhrReviewImages = { init: function() { QhrReviewImages.inputHtml = ''; }, + validateFiles: function () { + $('#review-general-errors').hide(); + let isValid = true; + $('.images-field input.input-images').each(function (iInput, input) { + let files = input.files; + let dataTransfer = new DataTransfer(); + $.each(files, function (iFile, file) { + if (file.type.startsWith('image/')) { + dataTransfer.items.add(file); + } else { + isValid = false; + } + }); + input.files = dataTransfer.files; + if (!input.files.length) { + $(input).remove(); + } + }); + if (!isValid) { + QhrReviewForm.showGeneralErrors(qlo_hotel_review_js_vars.texts.allowed_extensions); + } + return isValid; + }, getFilesCount: function() { var count = 0; $('.images-field input.input-images').each(function(i, input) { @@ -244,8 +267,9 @@ $(document).on('change', 'input.input-images', function(e) { var filesCount = QhrReviewImages.getFilesCount(); if (filesCount > qlo_hotel_review_js_vars.num_images_max) { QhrReviewImages.removeLastInput(); - alert(qlo_hotel_review_js_vars.texts.num_files); + QhrReviewForm.showGeneralErrors(qlo_hotel_review_js_vars.texts.num_files); } else { + QhrReviewImages.validateFiles(); QhrReviewImages.updatePreviews(); if (filesCount == qlo_hotel_review_js_vars.num_images_max) { diff --git a/modules/qlohotelreview/views/templates/hook/add-review-popup.tpl b/modules/qlohotelreview/views/templates/hook/add-review-popup.tpl index a838127d8..1ba6f6936 100644 --- a/modules/qlohotelreview/views/templates/hook/add-review-popup.tpl +++ b/modules/qlohotelreview/views/templates/hook/add-review-popup.tpl @@ -40,6 +40,7 @@
+

{l s='Allowed formats are: .jpg, .jpeg, .png' mod='qlohotelreview'}