From b28cdc030501fcc25bc9ceb36fb11586fe17adfe Mon Sep 17 00:00:00 2001 From: khushboos Date: Fri, 1 Nov 2024 13:24:24 +0100 Subject: [PATCH 01/11] Adobe Commerce solving Security Errors --- Controller/Webhook/Index.php | 58 +++++++++---------- Helper/Requests.php | 19 ++++-- .../web/template/payment/pos-cloud-form.html | 2 +- 3 files changed, 42 insertions(+), 37 deletions(-) diff --git a/Controller/Webhook/Index.php b/Controller/Webhook/Index.php index 8dc758f0d..edfe97282 100755 --- a/Controller/Webhook/Index.php +++ b/Controller/Webhook/Index.php @@ -89,6 +89,8 @@ class Index extends Action */ private $remoteAddress; + private $request; + /** * Json constructor. * @@ -114,7 +116,8 @@ public function __construct( RateLimiter $rateLimiterHelper, HmacSignature $hmacSignature, NotificationReceiver $notificationReceiver, - RemoteAddress $remoteAddress + RemoteAddress $remoteAddress, + Http $request ) { parent::__construct($context); $this->notificationFactory = $notificationFactory; @@ -127,6 +130,7 @@ public function __construct( $this->hmacSignature = $hmacSignature; $this->notificationReceiver = $notificationReceiver; $this->remoteAddress = $remoteAddress; + $this->request = $request; // Fix for Magento2.3 adding isAjax to the request params if (interface_exists(CsrfAwareActionInterface::class)) { @@ -376,36 +380,30 @@ private function isDuplicate(array $response) */ private function fixCgiHttpAuthentication() { - // do nothing if values are already there - if (!empty($_SERVER['PHP_AUTH_USER']) && !empty($_SERVER['PHP_AUTH_PW'])) { + if ($this->request->getServer('PHP_AUTH_USER') && $this->request->getServer('PHP_AUTH_PW')) { return; - } elseif (isset($_SERVER['REDIRECT_REMOTE_AUTHORIZATION']) && - $_SERVER['REDIRECT_REMOTE_AUTHORIZATION'] != '' - ) { - list( - $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] - ) = - explode(':', base64_decode((string) $_SERVER['REDIRECT_REMOTE_AUTHORIZATION']), 2); - } elseif (!empty($_SERVER['REDIRECT_HTTP_AUTHORIZATION'])) { - list( - $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] - ) = - explode(':', base64_decode(substr((string) $_SERVER['REDIRECT_HTTP_AUTHORIZATION'], 6)), 2); - } elseif (!empty($_SERVER['HTTP_AUTHORIZATION'])) { - list( - $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] - ) = - explode(':', base64_decode(substr((string) $_SERVER['HTTP_AUTHORIZATION'], 6)), 2); - } elseif (!empty($_SERVER['REMOTE_USER'])) { - list( - $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] - ) = - explode(':', base64_decode(substr((string) $_SERVER['REMOTE_USER'], 6)), 2); - } elseif (!empty($_SERVER['REDIRECT_REMOTE_USER'])) { - list( - $_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'] - ) = - explode(':', base64_decode(substr((string) $_SERVER['REDIRECT_REMOTE_USER'], 6)), 2); + } + + $authorizationHeaders = [ + 'REDIRECT_REMOTE_AUTHORIZATION', + 'REDIRECT_HTTP_AUTHORIZATION', + 'HTTP_AUTHORIZATION', + 'REMOTE_USER', + 'REDIRECT_REMOTE_USER' + ]; + + foreach ($authorizationHeaders as $header) { + $authHeader = $this->request->getServer($header); + + if ($authHeader) { + list( + $phpAuthUser, $phpAuthPw + ) = explode(':', base64_decode(substr($authHeader, 6)), 2); + + $this->request->setServer('PHP_AUTH_USER', $phpAuthUser); + $this->request->setServer('PHP_AUTH_PW', $phpAuthPw); + return; + } } } diff --git a/Helper/Requests.php b/Helper/Requests.php index 9d7aa7c21..b2b038795 100644 --- a/Helper/Requests.php +++ b/Helper/Requests.php @@ -16,6 +16,7 @@ use Adyen\Payment\Model\Ui\AdyenPayByLinkConfigProvider; use Adyen\Util\Uuid; use Magento\Framework\App\Helper\AbstractHelper; +use Magento\Framework\App\RequestInterface; class Requests extends AbstractHelper { @@ -36,19 +37,22 @@ class Requests extends AbstractHelper private Address $addressHelper; private StateData $stateData; private Vault $vaultHelper; + private RequestInterface $request; public function __construct( Data $adyenHelper, Config $adyenConfig, Address $addressHelper, StateData $stateData, - Vault $vaultHelper + Vault $vaultHelper, + RequestInterface $request ) { $this->adyenHelper = $adyenHelper; $this->adyenConfig = $adyenConfig; $this->addressHelper = $addressHelper; $this->stateData = $stateData; $this->vaultHelper = $vaultHelper; + $this->request = $request; } /** @@ -294,14 +298,17 @@ public function buildPaymentData($amount, $currencyCode, $reference, array $requ * @param array $request * @return array */ - public function buildBrowserData($request = []) + public function buildBrowserData(array $request = []): array { - if (!empty($_SERVER['HTTP_USER_AGENT'])) { - $request['browserInfo']['userAgent'] = $_SERVER['HTTP_USER_AGENT']; + $userAgent = $this->request->getServer('HTTP_USER_AGENT'); + $acceptHeader = $this->request->getServer('HTTP_ACCEPT'); + + if (!empty($userAgent)) { + $request['browserInfo']['userAgent'] = $userAgent; } - if (!empty($_SERVER['HTTP_ACCEPT'])) { - $request['browserInfo']['acceptHeader'] = $_SERVER['HTTP_ACCEPT']; + if (!empty($acceptHeader)) { + $request['browserInfo']['acceptHeader'] = $acceptHeader; } return $request; diff --git a/view/frontend/web/template/payment/pos-cloud-form.html b/view/frontend/web/template/payment/pos-cloud-form.html index 29bc691d4..683cffa9d 100644 --- a/view/frontend/web/template/payment/pos-cloud-form.html +++ b/view/frontend/web/template/payment/pos-cloud-form.html @@ -15,7 +15,7 @@ + data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()" /> From a14676e7a90356e15da15a4dc4b6b6f4ab66e99a Mon Sep 17 00:00:00 2001 From: khushboos Date: Fri, 1 Nov 2024 16:21:17 +0100 Subject: [PATCH 02/11] Adobe Commerce solving Security Errors --- view/frontend/web/template/payment/boleto-form.html | 5 +---- .../frontend/web/template/payment/card-vault-form.html | 10 +++------- view/frontend/web/template/payment/cc-form.html | 2 +- view/frontend/web/template/payment/giftcard-form.html | 2 +- .../template/payment/payment-method-vault-form.html | 2 +- .../web/template/payment/payment-method-vault.html | 2 +- view/frontend/web/template/payment/pm-form.html | 2 +- view/frontend/web/template/payment/pos-cloud-form.html | 2 +- 8 files changed, 10 insertions(+), 17 deletions(-) diff --git a/view/frontend/web/template/payment/boleto-form.html b/view/frontend/web/template/payment/boleto-form.html index c6b3d670f..fc061331c 100755 --- a/view/frontend/web/template/payment/boleto-form.html +++ b/view/frontend/web/template/payment/boleto-form.html @@ -16,7 +16,7 @@ + data-bind="attr: {'id': getCode()}, value: getCode(), checked: isChecked, click: selectPaymentMethod, visible: isRadioButtonVisible()">