From e65d337c6416130c18348577f186b6e43d4f8ca6 Mon Sep 17 00:00:00 2001 From: Pieter Hoste Date: Fri, 4 Jul 2025 15:50:32 +0200 Subject: [PATCH] Added csp support for inline scripts. --- view/frontend/templates/head/head.phtml | 54 ++++++++++++++------- view/frontend/templates/order/success.phtml | 26 ++++++++-- view/frontend/templates/trustbox.phtml | 28 ++++++++--- 3 files changed, 79 insertions(+), 29 deletions(-) diff --git a/view/frontend/templates/head/head.phtml b/view/frontend/templates/head/head.phtml index 67a276c..d05bb1f 100755 --- a/view/frontend/templates/head/head.phtml +++ b/view/frontend/templates/head/head.phtml @@ -1,18 +1,27 @@ - - - - \ No newline at end of file +'; + +// checking on if SecureHtmlRenderer exists first, because this module is still compatible with Magento 2.3.x which doesn't include this class +if (class_exists(SecureHtmlRenderer::class)) { + echo $secureRenderer->renderTag('script', ['async' => 'async'], $scriptStringPartOne, false); + echo $secureRenderer->renderTag('script', [], $scriptStringPartTwo, false); +} else { + echo ''; + echo ''; +} diff --git a/view/frontend/templates/order/success.phtml b/view/frontend/templates/order/success.phtml index 27abf42..59512b5 100755 --- a/view/frontend/templates/order/success.phtml +++ b/view/frontend/templates/order/success.phtml @@ -1,6 +1,22 @@ - - \ No newline at end of file +'; + +// checking on if SecureHtmlRenderer exists first, because this module is still compatible with Magento 2.3.x which doesn't include this class +if (class_exists(SecureHtmlRenderer::class)) { + echo $secureRenderer->renderTag('script', [], $scriptString, false); +} else { + echo ''; +} diff --git a/view/frontend/templates/trustbox.phtml b/view/frontend/templates/trustbox.phtml index 55660d3..4984a49 100755 --- a/view/frontend/templates/trustbox.phtml +++ b/view/frontend/templates/trustbox.phtml @@ -1,9 +1,25 @@ - - \ No newline at end of file +'; + +// checking on if SecureHtmlRenderer exists first, because this module is still compatible with Magento 2.3.x which doesn't include this class +if (class_exists(SecureHtmlRenderer::class)) { + echo $secureRenderer->renderTag('script', ['async' => 'async'], $scriptString, false); +} else { + echo ''; +}