Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Magento 2.4.7] Refused to execute inline script because it violates the following Content Security Policy directive: "script-src #3270

Closed
hostep opened this issue May 3, 2024 · 2 comments · Fixed by #3277
Assignees

Comments

@hostep
Copy link
Contributor

hostep commented May 3, 2024

Preconditions

Magento Version : CE 2.4.7

ElasticSuite Version : 2.11.6.1

Environment : Developer

Third party modules : many

Steps to reproduce

  1. Open the frontend of the shop, put a product in your cart
  2. Open the javascript console
  3. Go to checkout

Expected result

  1. No errors that have to do with Content Security Policy (CSP)

Actual result

  1. Seeing 2 errors:
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src ...

One comes from this script: https://github.com/Smile-SA/elasticsuite/blob/2.11.6.1/src/module-elasticsuite-tracker/view/frontend/templates/config.phtml
The other from this script: https://github.com/Smile-SA/elasticsuite/blob/2.11.6.1/src/module-elasticsuite-tracker/view/frontend/templates/variables/page.phtml

Maybe other scripts are also affected, I haven't checked everything.

More details

Explanation (quoted from Adobe documentation):

In Adobe Commerce and Magento Open Source version 2.4.7 and later, CSP is configured in restrict-mode by default for payment pages in the storefront and admin areas, and in report-only mode for all other pages. The corresponding CSP header does not contain the unsafe-inline keyword inside the script-src directive for payment pages. Also, only whitelisted inline scripts are allowed.

Adobe recommends to fix this using the SecureHtmlRenderer View Helper so a nonce is set to the script tag: https://developer.adobe.com/commerce/php/development/security/content-security-policies/#whitelist-an-inline-script-or-style

@romainruaud
Copy link
Collaborator

@vahonc can you quickly check this ?

@vahonc
Copy link
Collaborator

vahonc commented May 3, 2024

@romainruaud I'll take care of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants