Sunday, April 18, 2021
Home E-commerce Magento 2.3.5 Content Security Warnings | How to Fix

Magento 2.3.5 Content Security Warnings | How to Fix

Magento 2.3.5 Content Security Warnings | How to Fix – You are working on a Magento 2.3.5 project and you have a console full of red lines?

Content Security Policies (CSP) are a powerful tool to mitigate against Cross Site Scripting (XSS) and related attacks, including card skimmers, session hijacking, clickjacking, and more. Web servers send CSPs in response HTTP headers (namely Content-Security-Policy and Content-Security-Policy-Report-Only) to browsers that whitelist the origins of scripts, styles, and other resources. Together, CSPs and built-in browser features help prevent:

  • Loading a malicious script from an attacker’s website
  • A malicious inline script from sending credit card info to an attacker’s website
  • Loading a malicious style that will make users click on an element that wasn’t supposed to be on a page

See Content Security Policy (CSP) and Content-Security-Policy to learn more about CSP and each individual policy.

Magento and CSP

As of version 2.3.5, Magento supports CSP headers and provides ways to configure them. (This functionality is defined in the Magento_Csp module.) Magento also provides default configurations at the application level and for individual core modules that require extra configuration. Policies can be configured for adminhtml and storefront areas separately to accommodate different use cases. Magento also permits configuring unique CSPs for specific pages.

CSP can work in two modes:

  • report-only – In this mode, Magento reports policy violations but does not interfere. This mode is useful for debugging. By default, CSP violations are written to the browser console, but they can be configured to be reported to an endpoint as an HTTP request to collect logs. There are a number of services that will collect, store, and sort your store’s CSP violations reports for you.
  • restrict mode – In this mode, Magento acts on any policy violations.

How to add CSP whitelist using Magento 2 extension?

You can eliminate CSP warning using whitelist file, below is a simple extension to work with Magento 2

How to install Extension

Step 01

Download the Extension

Step 02

Upload file to the app/code directory & unzip using below command

$  unzip

Step 03

Go to the Magento 2.3.5 root folder & Install extension using below commands

$  php bin/magento setup:upgrade
$  php bin/magento setup:static-content:deploy -f

Step 04

How to Whitelist domains?

Go to Sagistri > CspWhitelist > etc and edit csp_whitelist.xml

<?xml version="1.0"?>
<csp_whitelist xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp/etc/csp_whitelist.xsd">
        <policy id="script-src">
                <value id="cloudflare" type="host">*</value>
                <value id="" type="host">*</value>
                <value id="google-analytics" type="host">*</value>
                <value id="twimg" type="host">*</value>
                <value id="gstatic" type="host">*</value>
                <value id="trustedshops" type="host">*</value>
                <value id="usercentrics" type="host">*</value>
                <value id="fontawesome" type="host">*</value>
                <value id="google-recaptcha" type="host">*</value>
                <value id="googleapis" type="host">*</value>
                <value id="googleadservices" type="host">*</value>
                <value id="google-analytics" type="host">*</value>
                <value id="vimeo" type="host">*</value>
                <value id="paypal-project" type="host">*</value>
                <value id="paypal" type="host">*</value>
                <value id="google-tagmanager" type="host">*</value>
                <value id="cloudflareinsights" type="host">*</value>
        <policy id="style-src">

How to identify policy ID?

Go to your browser developer console > go to errors > you can see CSP errors.


[Report Only] Refused to connect to ‘……..’ because it violates the following Content Security Policy directive: “connect-src

Note : connect-src is the policy id and is a domain to whitelist.

        <policy id="connect-src">
                <value id="cloudflare" type="host">*</value>
                <value id="" type="host">*</value>
                <value id="paypal" type="host">*</value>
                <value id="twimg" type="host">*</value>
                <value id="doubleclick" type="host">*</value>
                <value id="cardinalcommerce" type="host">*</value>

Once you added new domain to the whitelist please make sure to follow Step 03

Hope this is helpful to resolve the issue


Please enter your comment!
Please enter your name here

Most Popular

Free Website Uptime & Blacklist Monitoring

Free Website Uptime & Blacklist Monitoring - It is very important to monitor your Shared Hosting, VPS, dedicated server or other services...

What’s New in PHP 8 (Features & Improvements)

What’s New in PHP 8 (Features & Improvements) - it is a major update of the PHP language. It contains many new...

How to add Facebook Customer Chat with GTM

How to add Facebook Customer Chat with GTM | The Plugin allows you to integrate your Messenger experience directly into your website....

Implement Facebook pixel with Google Tag Manager-GTM

What is Facebook Pixel How to Implement Facebook pixel with Google Tag Manager-GTM - The Facebook pixel is...

Recent Comments