Skip to content

Commit 40eae7b

Browse files
Merge pull request #69 from BlueFinchCommerce/feature/csp-update
Fixed CSP issue with Braintree PayPal Express button
2 parents 3d019c1 + bddfe30 commit 40eae7b

5 files changed

Lines changed: 84 additions & 77 deletions

File tree

view/frontend/templates/bluefinch-checkout.phtml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
* @var \BlueFinch\Checkout\ViewModel\Assets $assetViewModel
66
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
77
*/
8+
use BlueFinch\Checkout\Helper\CspHelper;
9+
10+
$cspHelper = $this->helper(CspHelper::class);
11+
$cspNonce = $cspHelper->getCspNonce();
812
$assetViewModel = $block->getAssetViewModel();
913
$jsAssets = $assetViewModel->getAssetsByType('js');
1014
$cssAssets = $assetViewModel->getAssetsByType('css');
@@ -18,7 +22,7 @@ $fontFamily = $assetViewModel->getFontFamily();
1822
?>
1923

2024
<?php $scriptString = <<<script
21-
25+
window.cspNonce = '$cspNonce';
2226
window.bluefinchCheckout = window.bluefinchCheckout || {};
2327
window.bluefinchCheckout.magentoEdition = "{$escaper->escapeJs($assetViewModel->getMagentoEdition())}";
2428

view/frontend/templates/gtag_ga.phtml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ switch ($accountType) {
2424
?>
2525
<!-- GOOGLE TAG MANAGER -->
2626
<script defer nonce="<?= $cspNonce ?>" src="<?= $escaper->escapeHtmlAttr($block->getViewFileUrl('BlueFinch_Checkout::js/google-tag-manager.js')) ?>"></script>
27-
27+
2828
<?php $scriptString = <<<SCRIPT
2929
/**
3030
* @param {Object} config
3131
*/
32-
window.cspNonce = '$cspNonce';
33-
32+
3433
(function (config) {
3534
// If the init is available call it otherwise wait until it's available.
3635
window.bluefinchInitGtm
@@ -44,7 +43,7 @@ switch ($accountType) {
4443
window.bluefinchInitGtm(config);
4544
});
4645
})($jsonConfig)
47-
46+
4847
SCRIPT;
4948

5049
?>
@@ -76,7 +75,7 @@ switch ($accountType) {
7675
window.bluefinchInitGtm(config);
7776
});
7877
})($analyticsData)
79-
78+
8079
SCRIPT;
8180

8281
?>

view/frontend/web/js/checkout/dist/main.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

view/frontend/web/js/checkout/dist/main.min.js

Lines changed: 70 additions & 70 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

view/frontend/web/js/checkout/src/components/Steps/PaymentPage/Braintree/PayPal/PayPal.vue

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@ export default {
138138
sdkConfig['buyer-country'] = this.paypal.merchantCountry;
139139
}
140140
141+
if (window.cspNonce) {
142+
sdkConfig.dataAttributes['csp-nonce'] = window.cspNonce;
143+
}
144+
141145
paypalInstance.loadPayPalSDK(sdkConfig, () => {
142146
const renderData = {
143147
env: this.environment,

0 commit comments

Comments
 (0)