From f20c9ad1ef9582a854496c7fd052eecc3cd26c46 Mon Sep 17 00:00:00 2001 From: nivcoo <36514752+nivcoo@users.noreply.github.com> Date: Mon, 6 Dec 2021 20:12:12 +0100 Subject: [PATCH 1/7] improv. add auto excluded request to prevent issue --- app/Controller/AppController.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index 6aae8f8c..44c56b00 100755 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -48,7 +48,7 @@ public function beforeFilter() { // find any xss vulnability on request data $datas = $this->request->data; - $this->request->data = $this->xssProtection($datas); + $this->request->data = $this->xssProtection($datas, ['command', 'order', 'broadcast']); $this->request->data["xss"] = $datas; // lowercase to avoid errors when the controller is called with uppercase $this->params['controller'] = strtolower($this->params['controller']); @@ -113,10 +113,13 @@ public function beforeFilter() } - public function xssProtection($array) + public function xssProtection($array, $excluded = []) { foreach ($array as $key => $value) { - $array[$key] = is_array($value) ? $this->xssProtection($value) : $this->EySecurity->xssProtection($value); + if (strlen(str_replace($excluded, '', $key)) !== strlen($key)) + $array[$key] = $value; + else + $array[$key] = is_array($value) ? $this->xssProtection($value) : $this->EySecurity->xssProtection($value); } return $array; From 675a6ab29cf3ce7aeec7a668831bda375be6eea9 Mon Sep 17 00:00:00 2001 From: nivcoo Date: Mon, 6 Dec 2021 20:17:59 +0100 Subject: [PATCH 2/7] improv. convert navbar request to new method --- app/Controller/NavbarController.php | 2 +- app/View/Navbar/admin_index.ctp | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/Controller/NavbarController.php b/app/Controller/NavbarController.php index 8617f6a9..12262cd8 100755 --- a/app/Controller/NavbarController.php +++ b/app/Controller/NavbarController.php @@ -54,7 +54,7 @@ public function admin_save_ajax() if ($this->isConnected and $this->Permissions->can('MANAGE_NAV')) { if ($this->request->is('post')) { if (!empty($this->request->data)) { - $data = $this->request->data['xss']['nav']; + $data = $this->request->data['navbar_order']; $data = explode('&', $data); $i = 1; foreach ($data as $key => $value) { diff --git a/app/View/Navbar/admin_index.ctp b/app/View/Navbar/admin_index.ctp index 051deefb..42122fc3 100755 --- a/app/View/Navbar/admin_index.ctp +++ b/app/View/Navbar/admin_index.ctp @@ -73,10 +73,8 @@ axis: 'y', stop: function (event, ui) { $('#save').empty().html('get('NAVBAR__SAVE_IN_PROGRESS') ?>'); - var inputs = {}; - var nav = $(this).sortable('serialize'); - inputs['nav'] = nav; - $('#yolo').text(nav); + let inputs = {}; + inputs['navbar_order'] = $(this).sortable('serialize'); inputs['data[_Token][key]'] = ''; $.post("Html->url(['controller' => 'navbar', 'action' => 'save_ajax', 'admin' => true]) ?>", inputs, function (data) { if (data.statut) { From 49a491ed8232d1877635c08df8aff7c725ca27ec Mon Sep 17 00:00:00 2001 From: nivcoo Date: Mon, 6 Dec 2021 20:26:46 +0100 Subject: [PATCH 3/7] improv. remove warnings messages --- app/Controller/AppController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index 44c56b00..88170055 100755 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -48,7 +48,7 @@ public function beforeFilter() { // find any xss vulnability on request data $datas = $this->request->data; - $this->request->data = $this->xssProtection($datas, ['command', 'order', 'broadcast']); + $this->request->data = $this->xssProtection($datas, ['command', 'cmd', 'order', 'broadcast']); $this->request->data["xss"] = $datas; // lowercase to avoid errors when the controller is called with uppercase $this->params['controller'] = strtolower($this->params['controller']); @@ -553,9 +553,11 @@ public function __initSeoConfiguration() $default = $this->Seo->find('first', ["conditions" => ['page' => null]])['Seo']; $current_url = $this->here; $get_page = []; - $check = max($this->Seo->find('all', ['conditions' => ["'" . $current_url . "' LIKE CONCAT(page, '%')"]])); - if ($check && ($check['Seo']["page"] == $current_url || $current_url != "/")) + $check = $this->Seo->find('all', ['conditions' => ["'" . $current_url . "' LIKE CONCAT(page, '%')"]]); + + if ($check && ($check = max($check)) && ($check['Seo']["page"] == $current_url || $current_url != "/")) $get_page = $check['Seo']; + $seo_config['title'] = (!empty($default['title']) ? $default['title'] : "{TITLE} - {WEBSITE_NAME}"); $seo_config['title'] = (!empty($get_page['title']) ? $get_page['title'] : $seo_config['title']); $seo_config['description'] = (!empty($get_page['description']) ? $get_page['description'] : (!empty($default['description']) ? $default['description'] : "")); From c8c06121ebaf1d3cc3063d7f126a225443fb8c91 Mon Sep 17 00:00:00 2001 From: nivcoo Date: Mon, 6 Dec 2021 21:44:25 +0100 Subject: [PATCH 4/7] improv. fix issue with sqlite3 + remove useless code --- app/Controller/AppController.php | 10 ++++- app/Controller/Component/UtilComponent.php | 5 +++ app/Controller/ConfigurationController.php | 44 +--------------------- app/Model/Maintenance.php | 11 +++++- 4 files changed, 23 insertions(+), 47 deletions(-) diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index 88170055..c9e39dc8 100755 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -57,7 +57,7 @@ public function beforeFilter() $LoginCondition = $this->here != "/login" || !$this->EyPlugin->isInstalled('phpierre.signinup'); $this->loadModel("Maintenance"); - if ($this->params['controller'] != "user" and $this->params['controller'] != "maintenance" and !$this->Permissions->can("BYPASS_MAINTENANCE") and $maintenance = $this->Maintenance->checkMaintenance($this->here) and $LoginCondition) { + if ($this->params['controller'] != "user" and $this->params['controller'] != "maintenance" and !$this->Permissions->can("BYPASS_MAINTENANCE") and $maintenance = $this->Maintenance->checkMaintenance($this->here, $this->Util) and $LoginCondition) { $this->redirect([ 'controller' => 'maintenance', 'action' => $maintenance['url'], @@ -553,7 +553,13 @@ public function __initSeoConfiguration() $default = $this->Seo->find('first', ["conditions" => ['page' => null]])['Seo']; $current_url = $this->here; $get_page = []; - $check = $this->Seo->find('all', ['conditions' => ["'" . $current_url . "' LIKE CONCAT(page, '%')"]]); + $condition = ["'" . $current_url . "' LIKE CONCAT(page, '%')"]; + + $db_type = $this->Util->getDBType(); + + if (strpos(strtolower($db_type), "sqlite")) + $condition = ["'" . $current_url . "' LIKE 'page' || '%' "]; + $check = $this->Seo->find('all', ['conditions' => $condition]); if ($check && ($check = max($check)) && ($check['Seo']["page"] == $current_url || $current_url != "/")) $get_page = $check['Seo']; diff --git a/app/Controller/Component/UtilComponent.php b/app/Controller/Component/UtilComponent.php index 27aba45d..e95b4f9f 100755 --- a/app/Controller/Component/UtilComponent.php +++ b/app/Controller/Component/UtilComponent.php @@ -1,5 +1,6 @@ controller->Configuration === null) { $this->controller->Configuration = ClassRegistry::init('Configuration'); } + + $db_type = ConnectionManager::$config->default['datasource']; } function startup($controller) diff --git a/app/Controller/ConfigurationController.php b/app/Controller/ConfigurationController.php index 0ce3f542..fc7bdb0b 100755 --- a/app/Controller/ConfigurationController.php +++ b/app/Controller/ConfigurationController.php @@ -14,51 +14,11 @@ public function admin_index() if ($this->request->is('post')) { foreach ($this->request->data as $key => $value) { - if ($key != "version" && $key != "social_btn" && $key != "social_btn_edited" && $key != "social_btn_added") { + if ($key != "version") { if ($key == "banner_server") { $value = serialize($value); } $data[$key] = $value; - } else if ($key == "social_btn") { // si c'est pour les boutons sociaux personnalisés - - $this->loadModel('SocialButton'); - foreach ($value as $k => $v) { // on enregistre le tout - if (!empty($v['color']) && !empty($v['url']) && (!empty($v['title']) || !empty($v['img']))) { - $this->SocialButton->create(); - $this->SocialButton->set([ - 'title' => $v['title'], - 'img' => $v['img'], - 'color' => $v['color'], - 'url' => $v['url'] - ]); - $this->SocialButton->save(); - } - } - - } else if ($key == "social_btn_edited") { // si c'est pour les boutons sociaux personnalisés - - $this->loadModel('SocialButton'); - foreach ($value as $k => $v) { // on enregistre le tout - if (!empty($v['color']) && !empty($v['url']) && (!empty($v['title']) || !empty($v['img']))) { - $this->SocialButton->read(null, $v['id']); - $this->SocialButton->set([ - 'title' => $v['title'], - 'img' => $v['img'], - 'color' => $v['color'], - 'url' => $v['url'] - ]); - $this->SocialButton->save(); - } - } - - } else if ($key == "social_btn_added") { - $this->loadModel('SocialButton'); - foreach ($value['deleted'] as $k => $v) { // on enregistre le tout - $find = $this->SocialButton->findById($v); - if (!empty($find)) { - $this->SocialButton->delete($v); - } - } } } @@ -98,8 +58,6 @@ public function admin_index() $this->set('shopIsInstalled', $this->EyPlugin->isInstalled('eywek.shop')); - $this->loadModel('SocialButton'); - $this->set('social_buttons', $this->SocialButton->find('all', ['order' => 'id desc'])); } else { $this->redirect('/'); } diff --git a/app/Model/Maintenance.php b/app/Model/Maintenance.php index b7a83842..2bc0a732 100644 --- a/app/Model/Maintenance.php +++ b/app/Model/Maintenance.php @@ -2,9 +2,16 @@ class Maintenance extends AppModel { - function checkMaintenance($url = "") + function checkMaintenance($url, $utilComponent) { - $check = $this->find("first", ["conditions" => ["'" . $url . "' LIKE CONCAT(Maintenance.url, '%')", "active" => 1]]); + $db_type = $utilComponent->getDBType(); + + $condition = ["'" . $url . "' LIKE CONCAT(Maintenance.url, '%')", "active" => 1]; + + if (strpos(strtolower($db_type), "sqlite")) + $condition = ["'" . $url . "' LIKE 'Maintenance.url' || '%')", "active" => 1]; + + $check = $this->find("first", ["conditions" => $condition]); if (isset($check["Maintenance"])) $check = $check["Maintenance"]; if ($check && (($check["url"] == $url) || ($check["sub_url"] && $url != "/"))) From a77ee83ea529296921cd3a2dd08ee9203f156883 Mon Sep 17 00:00:00 2001 From: nivcoo Date: Mon, 6 Dec 2021 21:47:30 +0100 Subject: [PATCH 5/7] improv. add function to get db type --- app/Controller/Component/UtilComponent.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Controller/Component/UtilComponent.php b/app/Controller/Component/UtilComponent.php index e95b4f9f..70ae950b 100755 --- a/app/Controller/Component/UtilComponent.php +++ b/app/Controller/Component/UtilComponent.php @@ -37,7 +37,7 @@ function initialize($controller) $this->controller->Configuration = ClassRegistry::init('Configuration'); } - $db_type = ConnectionManager::$config->default['datasource']; + $this->db_type = ConnectionManager::$config->default['datasource']; } function startup($controller) @@ -351,5 +351,10 @@ public function random($list, $probabilityTotal) return $item; } + public function getDBType() + { + return $this->db_type; + } + } From 79207481f09bafb3aea30b890f5de122d632b024 Mon Sep 17 00:00:00 2001 From: nivcoo Date: Mon, 6 Dec 2021 21:50:33 +0100 Subject: [PATCH 6/7] improv. add function to get db type --- app/Controller/AppController.php | 4 ++-- app/Controller/Component/UtilComponent.php | 6 ++++++ app/Model/Maintenance.php | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/app/Controller/AppController.php b/app/Controller/AppController.php index c9e39dc8..2c3f8a35 100755 --- a/app/Controller/AppController.php +++ b/app/Controller/AppController.php @@ -555,9 +555,9 @@ public function __initSeoConfiguration() $get_page = []; $condition = ["'" . $current_url . "' LIKE CONCAT(page, '%')"]; - $db_type = $this->Util->getDBType(); + $use_sqlite = $this->Util->useSqlite(); - if (strpos(strtolower($db_type), "sqlite")) + if ($use_sqlite) $condition = ["'" . $current_url . "' LIKE 'page' || '%' "]; $check = $this->Seo->find('all', ['conditions' => $condition]); diff --git a/app/Controller/Component/UtilComponent.php b/app/Controller/Component/UtilComponent.php index 70ae950b..55c64946 100755 --- a/app/Controller/Component/UtilComponent.php +++ b/app/Controller/Component/UtilComponent.php @@ -356,5 +356,11 @@ public function getDBType() return $this->db_type; } + public function useSqlite() { + if (strpos(strtolower($this->getDBType()), "sqlite")) + return true; + return false; + } + } diff --git a/app/Model/Maintenance.php b/app/Model/Maintenance.php index 2bc0a732..e711b868 100644 --- a/app/Model/Maintenance.php +++ b/app/Model/Maintenance.php @@ -4,11 +4,11 @@ class Maintenance extends AppModel { function checkMaintenance($url, $utilComponent) { - $db_type = $utilComponent->getDBType(); + $use_sqlite = $utilComponent->useSqlite(); $condition = ["'" . $url . "' LIKE CONCAT(Maintenance.url, '%')", "active" => 1]; - if (strpos(strtolower($db_type), "sqlite")) + if ($use_sqlite) $condition = ["'" . $url . "' LIKE 'Maintenance.url' || '%')", "active" => 1]; $check = $this->find("first", ["conditions" => $condition]); From eb5786a191acc4052dfed83cf77d297580792fd4 Mon Sep 17 00:00:00 2001 From: nivcoo Date: Mon, 6 Dec 2021 21:57:20 +0100 Subject: [PATCH 7/7] improv. fix weird issue with initialize function --- app/Controller/Component/UtilComponent.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Controller/Component/UtilComponent.php b/app/Controller/Component/UtilComponent.php index 55c64946..5c6cf39d 100755 --- a/app/Controller/Component/UtilComponent.php +++ b/app/Controller/Component/UtilComponent.php @@ -15,7 +15,7 @@ class UtilComponent extends CakeObject private $smtpOptions = []; - private $db_type; + private $db_type = "mysql"; function shutdown($controller) { @@ -37,11 +37,11 @@ function initialize($controller) $this->controller->Configuration = ClassRegistry::init('Configuration'); } - $this->db_type = ConnectionManager::$config->default['datasource']; } function startup($controller) { + $this->db_type = ConnectionManager::$config->default['datasource']; } // Get ip (support cloudfare)