Magento 2 – Disabling CSP in 2.4.6-p6+

As of version 2.4.6-p6+ Magento 2 now puts pages that contain payment information into enforced CSP mode, before it was in Report-Only mode. Now the change is good but it does break things, here is how you can temporarily put them back into reporting mode and allowing inline scripts.

Add this into the env.php file

'system' => [
            'default' => [
                'csp' => [
                   'mode' => [
                      'storefront_checkout_index_index' => [
                         'report_only' => '1'
                      ],
                      'admin_sales_order_create_index' => [
                        'report_only' => '1'
                      ]
                   ],
                   'policies' => [
                      'storefront_checkout_index_index' => [
                        'scripts' => [
                            'inline' => '1'
                        ]
                      ],
                      'admin_sales_order_create_index' => [
                        'scripts' => [
                            'inline' => '1'
                        ]
                      ]
                   ]
                ]
            ]
        ]

Then in terminal run this:

bin/magento app:config:import

And voila! – Everything will now be working again.

    Leave a Reply

    Your email address will not be published. Required fields are marked *