Adding CSP support to the inline google consent mode script, while ke…#32
Merged
sprankhub merged 1 commit intocustomgento:masterfrom Mar 3, 2025
Merged
Conversation
…eping in mind compatibility with Magento 2.3.x and 2.4.x
Member
|
Thanks a lot for your contribution! Honestly, I'd also be fine with ditching Magento 2.3 support. So if you don't need it and would be willing to, feel free to update the dependencies and the code. If you don't want to, I can also take over :) |
Contributor
Author
|
Hi Simon I'll leave it up to you to deal with removing Magento 2.3 support. Thanks! |
sprankhub
approved these changes
Mar 3, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…eping in mind compatibility with Magento 2.3.x and 2.4.x
I noticed while installing this module in a Magento 2.4.7-p4 shop that we got an error on the checkout in the browser console that this inline google consent mode script is being blocked by the Content-Security-Policy checks in the browser.
We need to add a
nonceto the script to allow CSP checks to not block this script.I've created this PR to fix that.
Good to know:
SecureHtmlRendererclass doesn't exist in Magento 2.3.x, and yourcomposer.jsonindicates that this module can still be installed on Magento 2.3.x shops, so I'm first checking if that class exists before trying to use it. Otherwise I'm just outputting the script as-is. Read more about it hereI also cleaned up some code styling/formatting, let me know if this doesn't follow the standards used in this module and if it should be reworked in some way.