diff --git a/admin/themes/default/template/helpers/list/list_header.tpl b/admin/themes/default/template/helpers/list/list_header.tpl
index 77922dae1..13983743f 100644
--- a/admin/themes/default/template/helpers/list/list_header.tpl
+++ b/admin/themes/default/template/helpers/list/list_header.tpl
@@ -300,8 +300,8 @@
{if $params.type == 'range'}
{$field_name="`$list_id`Filter_{if isset($params.filter_key)}`$params.filter_key`{else}`$key`{/if}"}
-
-
+
+
{elseif $params.type == 'bool'}
{$field_name="`$list_id`Filter_{if isset($params.filter_key)}`$params.filter_key`{else}`$key`{/if}"}
@@ -314,14 +314,14 @@
diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php
index 25bf22c7d..d62aa672f 100644
--- a/controllers/admin/AdminOrdersController.php
+++ b/controllers/admin/AdminOrdersController.php
@@ -4059,10 +4059,11 @@ class AdminOrdersControllerCore extends AdminController
$this->errors[] = $this->l('Please select a file to upload.');
} elseif ($objHotelBookingDocument->fileInfo['size'] > Tools::getMaxUploadSize()) {
$this->errors[] = $this->l('Uploaded file size is too large.');
- } elseif(!(ImageManager::isRealImage($objHotelBookingDocument->fileInfo['tmp_name'])
- || $objHotelBookingDocument->fileInfo['mime'] == 'application/pdf')
- ) {
- $this->errors[] = $this->l('Please upload an image or a PDF file only. Allowed image formats: .gif, .jpg, .jpeg and .png');
+ } else {
+ $objHotelBookingDocument->setFileType();
+ if (!$objHotelBookingDocument->file_type) {
+ $this->errors[] = $this->l('Please upload an image or a PDF file only. Allowed image formats: .gif, .jpg, .jpeg and .png');
+ }
}
} else {
$this->errors[] = Tools::displayError('You do not have permission to edit this order.');
diff --git a/modules/hotelreservationsystem/classes/HotelBookingDocument.php b/modules/hotelreservationsystem/classes/HotelBookingDocument.php
index 6c223106f..3567440e7 100644
--- a/modules/hotelreservationsystem/classes/HotelBookingDocument.php
+++ b/modules/hotelreservationsystem/classes/HotelBookingDocument.php
@@ -133,16 +133,19 @@ class HotelBookingDocument extends ObjectModel
public function getDestinationFilePath()
{
- $fileExtension = pathinfo($this->fileInfo['rename'], PATHINFO_EXTENSION);
-
- return $this->documentFolder.$this->id.'.'.$fileExtension;
+ return $this->documentFolder.$this->id.'.'.$this->getFileExtension();
}
public function setFileType()
{
- if (ImageManager::isRealImage($this->fileInfo['tmp_name'])) {
+ $content = @file_get_contents($this->fileInfo['tmp_name']);
+ $activeContentPattern = '/\/(JavaScript|JS|OpenAction|AA|Launch|SubmitForm|ImportData)\b/i';
+
+ $this->imageInfo = @getimagesize($this->fileInfo['tmp_name']);
+
+ if ($this->imageInfo && ImageManager::isRealImage($this->fileInfo['tmp_name'])) {
$this->file_type = self::FILE_TYPE_IMAGE;
- } elseif ($this->fileInfo['mime'] == 'application/pdf') {
+ } elseif ($content !== false && substr($content, 0, 5) === '%PDF-' && !preg_match($activeContentPattern, $content)) {
$this->file_type = self::FILE_TYPE_PDF;
} else {
$this->file_type = 0;
@@ -151,8 +154,22 @@ class HotelBookingDocument extends ObjectModel
public function setFileName()
{
- $fileExtension = pathinfo($this->fileInfo['rename'], PATHINFO_EXTENSION);
- $this->file_name = $this->id.'.'.$fileExtension;
+ $this->file_name = $this->id.'.'.$this->getFileExtension();
+ }
+
+ /**
+ * Extension is derived from the file's real, validated content
+ * (getimagesize()/PDF signature), captured once in setFileType(),
+ * never from the uploaded filename or mime header (both are
+ * attacker-controlled).
+ */
+ public function getFileExtension()
+ {
+ if ($this->file_type == self::FILE_TYPE_PDF) {
+ return 'pdf';
+ }
+
+ return image_type_to_extension($this->imageInfo[2], false);
}
public function getContentType()
diff --git a/modules/hotelreservationsystem/controllers/admin/AdminBookingDocumentController.php b/modules/hotelreservationsystem/controllers/admin/AdminBookingDocumentController.php
index c3d92c748..b161a2a27 100644
--- a/modules/hotelreservationsystem/controllers/admin/AdminBookingDocumentController.php
+++ b/modules/hotelreservationsystem/controllers/admin/AdminBookingDocumentController.php
@@ -34,7 +34,11 @@ class AdminBookingDocumentController extends ModuleAdminController
$contentLength = $objHotelBookingDocument->getContentLength();
$filePath = $objHotelBookingDocument->getPhysicalPath();
$downloadFileName = $objHotelBookingDocument->getDownloadFileName();
- $contentDisposition = Tools::getValue('is_preview') ? 'inline' : 'attachment';
+ // Only images are safe to render inline; PDFs can carry embedded JavaScript
+ // that executes when opened inline, so they always force a download instead.
+ $contentDisposition = (Tools::getValue('is_preview')
+ && $objHotelBookingDocument->file_type == HotelBookingDocument::FILE_TYPE_IMAGE)
+ ? 'inline' : 'attachment';
if (Tools::file_exists_cache($filePath)) {
if (ob_get_level() && ob_get_length() > 0) {