From 41df7e42fd457369321e9874762d972440ab07fb Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Thu, 3 Aug 2023 11:26:15 +0530 Subject: [PATCH 1/2] Fix PHP warning due to occupancy query parameter in URL --- classes/controller/FrontController.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/classes/controller/FrontController.php b/classes/controller/FrontController.php index 2f19b9f61..f9e4338ef 100644 --- a/classes/controller/FrontController.php +++ b/classes/controller/FrontController.php @@ -917,11 +917,19 @@ class FrontControllerCore extends Controller } $excluded_key = array('isolang', 'id_lang', 'controller', 'fc', 'id_product', 'id_category', 'id_manufacturer', 'id_supplier', 'id_cms'); foreach ($_GET as $key => $value) { - if (!in_array($key, $excluded_key) && Validate::isUrl($key) && Validate::isUrl($value)) { - $params[Tools::safeOutput($key)] = Tools::safeOutput($value); + if (!in_array($key, $excluded_key)) { + if (is_string($value)) { + if (Validate::isUrl($key) && Validate::isUrl($value)) { + $params[Tools::safeOutput($key)] = Tools::safeOutput($value); + } + } else { + $tempValue = http_build_query($value); + if (Validate::isUrl($key) && Validate::isUrl($tempValue)) { + $params[Tools::safeOutput($key)] = $value; + } + } } } - $str_params = http_build_query($params, '', '&'); if (!empty($str_params)) { $final_url = preg_replace('/^([^?]*)?.*$/', '$1', $canonical_url).'?'.$str_params; From 400580838288e217153ff5ca0decd4849248e16b Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 26 Sep 2023 10:19:41 +0530 Subject: [PATCH 2/2] ALlow array in URL param --- classes/controller/FrontController.php | 30 ++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/classes/controller/FrontController.php b/classes/controller/FrontController.php index f9e4338ef..80e33e72e 100644 --- a/classes/controller/FrontController.php +++ b/classes/controller/FrontController.php @@ -918,18 +918,18 @@ class FrontControllerCore extends Controller $excluded_key = array('isolang', 'id_lang', 'controller', 'fc', 'id_product', 'id_category', 'id_manufacturer', 'id_supplier', 'id_cms'); foreach ($_GET as $key => $value) { if (!in_array($key, $excluded_key)) { - if (is_string($value)) { - if (Validate::isUrl($key) && Validate::isUrl($value)) { - $params[Tools::safeOutput($key)] = Tools::safeOutput($value); + if (is_array($value)) { + if (Validate::isUrl($key)) { + $params[Tools::safeOutput($key)] = $this->sanitizeQueryOutput($value); } } else { - $tempValue = http_build_query($value); - if (Validate::isUrl($key) && Validate::isUrl($tempValue)) { - $params[Tools::safeOutput($key)] = $value; + if (Validate::isUrl($key) && Validate::isUrl($value)) { + $params[Tools::safeOutput($key)] = Tools::safeOutput($value); } } } } + $str_params = http_build_query($params, '', '&'); if (!empty($str_params)) { $final_url = preg_replace('/^([^?]*)?.*$/', '$1', $canonical_url).'?'.$str_params; @@ -951,6 +951,24 @@ class FrontControllerCore extends Controller } } + protected function sanitizeQueryOutput($query) + { + $params = array(); + foreach ($query as $key => $value) { + if (Validate::isUrl($key)) { + if (is_array($value)) { + $params[Tools::safeOutput($key)] = $this->sanitizeQueryOutput($value); + } else { + if (Validate::isUrl($value)) { + $params[Tools::safeOutput($key)] = Tools::safeOutput($value); + } + } + } + } + + return $params; + } + /** * Geolocation management *