loki-checkout / magento2-csp
Provides highly recommended CSP, thus PCI DSS 4 compliance
Package info
github.com/LokiCheckout/LokiCheckout_Csp
Type:magento2-module
pkg:composer/loki-checkout/magento2-csp
Requires
- php: >=8.2 <8.6
- loki-checkout/magento2-core: ^2.3
- loki/magento2-base: ^1.2
- loki/magento2-components: ^2.7
- magento/framework: ^103.0
- magento/module-csp: ^100.4
- magento/module-store: ^101.1
- yireo/magento2-csp-utilities: ^1.0
Requires (Dev)
- loki-checkout/magento2-functional-tests: @dev
- loki/magento2-functional-tests: @dev
- phpunit/phpunit: ^10.5
- yireo/magento2-integration-test-helper: ~0.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
This Magento 2 module is an add-on package for enforcing the CSP Restrictive Mode in the checkout, including the Alpine CSP Build and removing the unsafe-inline and unsafe-eval policies. This is required to be fully compliant with PCI DSS v4.
Note that we develop our core with this module enabled at all times, which ensures that the Loki Checkout is CSP compliant at all times.
Installation
Install this package via composer:
composer require loki-checkout/magento2-csp
Next, enable this module:
bin/magento module:enable LokiCheckout_Csp
Usage notes
Note that this module only covers CSP rules for the LokiCheckout extensions. Your theme still requires work as well to work together with the no-unsafe-inline and no-unsafe-eval policies.
When the Loki Checkout is enabled, this module enforces the CSP (no report-only mode) on the checkout page and removes unsafe-inline and unsafe-eval from script-src. This applies to every theme. Because of this, the following is required:
- Hyvä: Use the CSP theme
Hyva/default-csp(or a child theme of it). The regularHyva/defaulttheme loads an Alpine.js build that requiresunsafe-evaland stops working in the checkout. - Luma: This module replaces Alpine.js with the Alpine CSP build in Luma-based themes (themes inheriting from
Magento/blank). Knockout UI components are parsed withevalby Knockout andmage/utils/template.js, and break with errors likeEvalError: Unable to parse bindings. Therefore, this module removes the Knockout blocks of the Luma page from the checkout (header,customer,catalog.compare.link,compare-link-wrapper,messages,frontend-storage-managerandcustomer.data.invalidation.rules). The checkout messages are still shown by the Loki messages component. If your theme adds other Knockout UI components to the checkout page, remove them from the checkout layout of your theme. - Other themes (Breeze, themes not inheriting from
Magento/blank) and MageOS_AlpineLoader: The Alpine CSP build of this module is not loaded there, so make sure that your theme loads an Alpine CSP build itself.
Magento 2.4.6 does not support CSP settings per page. With 2.4.6, this module therefore overrides the global storefront CSP settings, but only for the checkout page.