From 866740f717d9c54dd415bb0d61fa460171d284ba Mon Sep 17 00:00:00 2001 From: Sumit Panwar Date: Wed, 4 Oct 2023 18:52:18 +0530 Subject: [PATCH] Fixed: Security Vulnerability: XSS for back and email_create parameters while registration --- controllers/front/AuthController.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/controllers/front/AuthController.php b/controllers/front/AuthController.php index 320da13dd..8898433cc 100644 --- a/controllers/front/AuthController.php +++ b/controllers/front/AuthController.php @@ -112,6 +112,9 @@ class AuthControllerCore extends FrontController $back .= (strpos($back, '?') !== false ? '&' : '?').'key='.$key; } + // sanitize backurl for XSS protection + $back = filter_var($back, FILTER_SANITIZE_URL); + if ($back == Tools::secureReferrer(Tools::getValue('back'))) { $this->context->smarty->assign('back', html_entity_decode($back)); } else { @@ -173,9 +176,15 @@ class AuthControllerCore extends FrontController 'errors' => $this->errors, 'hasAjaxExtraData' => !empty($this->ajaxExtraData), 'ajaxExtraData' => $this->ajaxExtraData, - 'page' => $this->context->smarty->fetch($this->template), 'token' => Tools::getToken(false) ); + + // send page html only if no errors in the form and we have to open registration form + // It also prevents opening html in the response in case of an error for XSS protection + if (empty($this->errors)) { + $return['page'] = $this->context->smarty->fetch($this->template); + } + $this->ajaxDie(json_encode($return)); } } @@ -736,6 +745,8 @@ class AuthControllerCore extends FrontController unset($_POST['email_create']); } elseif ($id_customer = Customer::customerExists($email, true, false)) { $this->informations[] = Tools::displayError('You are already registered as a guest with this email address.').' '.Tools::displayError('').' to generate a password for your account.'; + } elseif (Tools::getValue('back') && !Validate::isUrl(Tools::getValue('back'))) { + $this->errors[] = Tools::displayError('back url is invalid.'); } else { $this->create_account = true; $this->context->smarty->assign('email_create', Tools::safeOutput($email)); @@ -794,4 +805,4 @@ class AuthControllerCore extends FrontController $customer->firstname.' '.$customer->lastname ); } -} \ No newline at end of file +}