0

I have searched alot on the internet and I want to hide this error (magento 2.4) enter image description here

content security policy error , we don't have authority to disable magento_csp module and we can not create module, we just have theme, what are the best options to figure out this issue

2 Answers 2

2

Solution for Magento 2.4.6 or above

You can bypass the Magento_CSP by using the around plugin:

Create your di.xml in any custom module

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <type name="Magento\Csp\Observer\Render">
        <plugin name="ByPassCSPValidation" type="Vendor_Module\Plugin\ByPassCSPValidation" />
    </type>
</config>

Create a Plugin Vendor\Module\Plugin\ByPassCSPValidation

<?php

namespace Vendor\Module\Plugin;

use Magento\Csp\Observer\Render;

class ByPassCSPValidation
{
    public function aroundExecute(Render $subject, callable $proceed)
    {
       // Do nothing
    }
}

Thanks

1
  • this certainly helps by removing the ERRORS in console. Thanks
    – ItsJhonny
    Commented Oct 9 at 13:52
-1

Please disable Magento_Csp module

php bin/magento module:disable Magento_Csp

php bin/magento s:up

php bin/magento c:c

OR

Into Magento_root/app/etc/config.php find Magento_Csp and put 1 to 0 like this then save the file and run php bin/magento s:up command.

'Magento_Csp' => 0,

I Hope This Helps You.

7
  • bro disabling module is not an option i have explained that in the question , you can read again
    – samair ali
    Commented Jun 22, 2021 at 15:36
  • Ok then you have to whitelist all files which are coming from 3rd party site or url. Commented Jun 22, 2021 at 16:06
  • You can google it how to whitelist in csp magento 2.4 Commented Jun 22, 2021 at 16:06
  • i know how to whitelist it bro but disabling it with theme only is what i dont know , for that i have pasted the question
    – samair ali
    Commented Jun 22, 2021 at 22:53
  • disable with theme what u by this?? its not possible man. you have to disable module or you have to whitelist file. no any other option :) Commented Jun 23, 2021 at 3:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.