Skip to content

Commit 213f169

Browse files
Alexander MakeevYaroslav Voronoy
authored andcommitted
MAGETWO-45594: XSS code still can be saved into database
- Removed html tags - Added check to returnUrl action
1 parent a0ed5ec commit 213f169

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

app/code/Magento/Paypal/Controller/Payflow.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public function __construct(
7373
*/
7474
protected function _cancelPayment($errorMsg = '')
7575
{
76+
$errorMsg = trim(strip_tags($errorMsg));
77+
7678
$gotoSection = false;
7779
$this->_checkoutHelper->cancelCurrentOrder($errorMsg);
7880
if ($this->_checkoutSession->restoreQuote()) {

app/code/Magento/Paypal/Controller/Payflow/ReturnUrl.php

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
namespace Magento\Paypal\Controller\Payflow;
88

99
use Magento\Paypal\Controller\Payflow;
10+
use Magento\Paypal\Model\Config;
1011
use Magento\Sales\Model\Order;
1112

1213
class ReturnUrl extends Payflow
@@ -19,6 +20,15 @@ class ReturnUrl extends Payflow
1920
Order::STATE_COMPLETE,
2021
];
2122

23+
/**
24+
* Payment method code
25+
* @var string
26+
*/
27+
protected $allowedPaymentMethodCodes = [
28+
Config::METHOD_PAYFLOWPRO,
29+
Config::METHOD_PAYFLOWLINK
30+
];
31+
2232
/**
2333
* When a customer return to website from payflow gateway.
2434
*
@@ -35,16 +45,44 @@ public function execute()
3545
$order = $this->_orderFactory->create()->loadByIncrementId($this->_checkoutSession->getLastRealOrderId());
3646

3747
if ($order->getIncrementId()) {
38-
if (in_array($order->getState(), $this->allowedOrderStates)) {
48+
if ($this->checkOrderState($order)) {
3949
$redirectBlock->setData('goto_success_page', true);
4050
} else {
41-
$gotoSection = $this->_cancelPayment(strval($this->getRequest()->getParam('RESPMSG')));
42-
$redirectBlock->setData('goto_section', $gotoSection);
43-
$redirectBlock->setData('error_msg', __('Your payment has been declined. Please try again.'));
51+
if ($this->checkPaymentMethod($order)) {
52+
$gotoSection = $this->_cancelPayment(strval($this->getRequest()->getParam('RESPMSG')));
53+
$redirectBlock->setData('goto_section', $gotoSection);
54+
$redirectBlock->setData('error_msg', __('Your payment has been declined. Please try again.'));
55+
} else {
56+
$redirectBlock->setData('goto_section', false);
57+
$redirectBlock->setData('error_msg', __('Requested payment method does not match with order.'));
58+
}
4459
}
4560
}
4661
}
4762

4863
$this->_view->renderLayout();
4964
}
65+
66+
/**
67+
* Check order state
68+
*
69+
* @param Order $order
70+
* @return bool
71+
*/
72+
protected function checkOrderState(Order $order)
73+
{
74+
return in_array($order->getState(), $this->allowedOrderStates);
75+
}
76+
77+
/**
78+
* Check requested payment method
79+
*
80+
* @param Order $order
81+
* @return bool
82+
*/
83+
protected function checkPaymentMethod(Order $order)
84+
{
85+
$payment = $order->getPayment();
86+
return in_array($payment->getMethod(), $this->allowedPaymentMethodCodes);
87+
}
5088
}

app/code/Magento/Paypal/Controller/Payflowadvanced/ReturnUrl.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,21 @@
66
*/
77
namespace Magento\Paypal\Controller\Payflowadvanced;
88

9+
use Magento\Paypal\Model\Config;
10+
911
class ReturnUrl extends \Magento\Paypal\Controller\Payflow\ReturnUrl
1012
{
1113
/**
1214
* Redirect block name
1315
* @var string
1416
*/
1517
protected $_redirectBlockName = 'payflow.advanced.iframe';
18+
19+
/**
20+
* Payment method code
21+
* @var string
22+
*/
23+
protected $allowedPaymentMethodCodes = [
24+
Config::METHOD_PAYFLOWADVANCED
25+
];
1626
}

app/code/Magento/Paypal/i18n/en_US.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,3 +693,4 @@ unverified,unverified
693693
Eligible,Eligible
694694
Ineligible,Inligible
695695
"PayPal Express Checkout","PayPal Express Checkout"
696+
"Requested payment method does not match with order.","Requested payment method does not match with order."

0 commit comments

Comments
 (0)