Skip to content

Commit 15996a7

Browse files
AC-10685: [PCI] CSP enforced on payment pages
1 parent b0ffe1e commit 15996a7

File tree

5 files changed

+29
-22
lines changed

5 files changed

+29
-22
lines changed

app/code/Magento/Checkout/etc/csp_whitelist.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/code/Magento/Paypal/Block/PayLater/Banner.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public function getJsLayout()
9797
$config['displayAmount'] = !$displayAmount || $this->payLaterConfig->isPPBillingAgreementEnabled()
9898
? false : true;
9999
$config['dataAttributes'] = [
100-
'data-partner-attribution-id' => $this->paypalConfig->getBuildNotationCode()
100+
'data-partner-attribution-id' => $this->paypalConfig->getBuildNotationCode(),
101+
'data-csp-nonce' => $this->paypalConfig->getCspNonce(),
101102
];
102103

103104
//Extend block component attributes with defaults

app/code/Magento/Paypal/Block/PayLater/LayoutProcessor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public function process($jsLayout)
8888
$config['displayAmount'] = !$displayAmount || $this->payLaterConfig->isPPBillingAgreementEnabled()
8989
? false : true;
9090
$config['dataAttributes'] = [
91-
'data-partner-attribution-id' => $this->paypalConfig->getBuildNotationCode()
91+
'data-partner-attribution-id' => $this->paypalConfig->getBuildNotationCode(),
92+
'data-csp-nonce' => $this->paypalConfig->getCspNonce(),
9293
];
9394

9495
$attributes = $this->payLaterConfig->getSectionConfig(

app/code/Magento/Paypal/Model/Config.php

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace Magento\Paypal\Model;
88

9+
use Magento\Csp\Helper\CspNonceProvider;
10+
use Magento\Framework\App\ObjectManager;
911
use Magento\Payment\Helper\Formatter;
1012

1113
/**
@@ -599,21 +601,28 @@ class Config extends AbstractConfig
599601
*/
600602
protected $_certFactory;
601603

604+
/**
605+
* @var CspNonceProvider
606+
*/
607+
protected $cspNonceProvider;
608+
602609
/**
603610
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
604611
* @param \Magento\Directory\Helper\Data $directoryHelper
605612
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
606613
* @param \Magento\Payment\Model\Source\CctypeFactory $cctypeFactory
607614
* @param CertFactory $certFactory
608615
* @param array $params
616+
* @param CspNonceProvider|null $cspNonceProvider
609617
*/
610618
public function __construct(
611619
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
612620
\Magento\Directory\Helper\Data $directoryHelper,
613621
\Magento\Store\Model\StoreManagerInterface $storeManager,
614622
\Magento\Payment\Model\Source\CctypeFactory $cctypeFactory,
615623
\Magento\Paypal\Model\CertFactory $certFactory,
616-
$params = []
624+
$params = [],
625+
CspNonceProvider $cspNonceProvider = null
617626
) {
618627
parent::__construct($scopeConfig);
619628
$this->directoryHelper = $directoryHelper;
@@ -628,6 +637,8 @@ public function __construct(
628637
$this->setStoreId($storeId);
629638
}
630639
}
640+
641+
$this->cspNonceProvider = $cspNonceProvider ?: ObjectManager::getInstance()->get(CspNonceProvider::class);
631642
}
632643

633644
/**
@@ -1845,4 +1856,15 @@ public function getPayLaterConfigValue($fieldName)
18451856
$this->_storeId
18461857
);
18471858
}
1859+
1860+
/**
1861+
* Get a cps nonce for the current request
1862+
*
1863+
* @return string
1864+
* @throws \Magento\Framework\Exception\LocalizedException
1865+
*/
1866+
public function getCspNonce(): string
1867+
{
1868+
return $this->cspNonceProvider->generateNonce();
1869+
}
18481870
}

app/code/Magento/Paypal/Model/SmartButtonConfig.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use Magento\Framework\App\Config\ScopeConfigInterface;
1212
use Magento\Framework\Locale\ResolverInterface;
1313
use Magento\Store\Model\ScopeInterface;
14-
use Magento\Store\Model\StoreManagerInterface;
1514
use Magento\Paypal\Model\Config as PaypalConfig;
1615

1716
/**
@@ -92,7 +91,8 @@ public function getConfig(string $page): array
9291
'isGuestCheckoutAllowed' => $isGuestCheckoutAllowed,
9392
'sdkUrl' => $this->sdkUrl->getUrl(),
9493
'dataAttributes' => [
95-
'data-partner-attribution-id' => $this->paypalConfig->getBuildNotationCode()
94+
'data-partner-attribution-id' => $this->paypalConfig->getBuildNotationCode(),
95+
'data-csp-nonce' => $this->paypalConfig->getCspNonce(),
9696
]
9797
];
9898
}

0 commit comments

Comments
 (0)