experius / module-csp
experius/module-csp
Provide a basic Content Security Policy Allowed List and report blocked resources.
Mage2 Module Experius Csp
experius/module-csp
- Installation
- Main Functionalities
- Basic allowed list
- Content Security Policy Reporting & whitelisting
- Add a resource to the allowed list permanently
Installation
In production please use the --keep-generated option
- Install the module composer by running
composer require experius/module-csp - enable the module by running
php bin/magento module:enable Experius_Csp - apply database updates by running
php bin/magento setup:upgrade - Flush the cache by running
php bin/magento cache:flush
Main Functionalities
Provide a basic Content Security Policy allowed-list (whitelist) and when the Resource should be blocked it will automatically be reported within the Experius CSP Report Table (experius_csp_report).
When there is a report of a blocked directive is found, an error message will be show in the admin to notify the developer/client.
These reports can be whitelisted for directive which allow this.
See "Content Security Policy Reporting & whitelisting" below for an example and more details.
IMPORTANT: Content Security Policy Report Only Mode
In the upcoming Magento 2.4 Release then the Content Security Policy Report Only Mode then will be disabled and it will validate strict.
The report-to has been disabled in this version because it is not working properly.
See: \Experius\Csp\Plugin\Magento\Framework\App\Response\HttpInterface::beforeSetHeader
Basic allowed list
Currently this module contains a basic whitelist of considerd "safe" sources.
A few examples:
- Google Fonts
- Google Maps
- Dotdigital / Dotmailer Chat
- Buckaroo
- etc.
For a full list for each directive, please check the following file:
etc/csp_whitelist.xml
Content Security Policy Reporting & whitelisting
In the Magento Admin you can view the reports which are created.
System > Tools > CSP reporting & whitelist
[image: Scheme]
To avoid clutter a counter is introduced, which prevents the table from growing in size excessively with many pageviews.
This is grouped by "violated_directive", "blocked_uri" and "document_uri".
@TODO: [Nice to have] consider letting louse "document_uri", since whitelist is applied across the entire Magento installation (globally).
Add a resource to the allowed list permanently
Based on the reports you can easily add a csp_whitelist.xml file within your own modules and when you are done just delete the record because it no longer is relevant.
More information about how this xml file works you can find here:
https://devdocs.magento.com/guides/v2.3/extension-dev-guide/security/content-security-policies.html
For example Report:
- document_uri: https://example.com/
- referer:https://example.com/
- violated_directive: img-src
- original_policy: font-src fonts.googleapis.com fonts.gstatic.com https://www.gstatic.com https://fonts.gstatic.com 'self' 'unsafe-inline'; form-action 'self' 'unsafe-inline'; frame-ancestors 'self' 'unsafe-inline'; frame-src cdn.dnky.co youtube.com www.youtube.com https:/
- blocked_uri: https://maps.gstatic.com/mapfiles/openhand_8_8.cur
- date: 2020-06-25 16:42:23
Fix:
# app/code/Custom/Csp/etc/csp_whitelist
<?xml version="1.0"?>
<csp_whitelist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Csp:etc/csp_whitelist.xsd">
<policies>
<policy id="img-src">
<values>
<value id="gstatic" type="host">*.gstatic.com</value>
</values>
</policy>
</policies>
</csp_whitelist>
2.0.3 (2022-04-15)
- [FEATURE][DONS-65] added paypal to whitelisting (Dylan Maurits)
2.0.2 (2022-01-25)
- [BUGFIX][SUBI-320] fixed bug where FallbackDirective was not being used properly (Dylan Maurits)
2.0.1 (2021-12-21)
- [FEATURE][SPC-3021] Fixed issue where count wasn't working properly. (René Schep)
2.0.0 (2021-12-21)
- [FEATURE][SPC-3021] Imported more classes. Rewrote Collectors (René Schep)
1.8.3 (2021-10-13)
- [FEATURE][EMGA-374] Add logic to (de-)whitelist all identical reports upon (de-)whitelist of report (Martijn van den Kerkhof)
- [FEATURE][EMGA-374] Efficiency improvements (Martijn van den Kerkhof)
- [FEATURE][EMGA-374] Remove unneccesary import (Martijn van den Kerkhof)
- [FEATURE][EMGA-374] Make method public (Martijn van den Kerkhof)
1.8.2 (2021-10-04)
- [BUGFIX][SBN-216] Correct img-src 'data' policy in amasty base (Matthijs Breed)
1.8.1 (2021-09-16)
- [BUGFIX] Changed in_array to array_key_exists (René Schep)
1.8.0 (2021-09-16)
- [BUGFIX] Remove type-o (Martijn van den Kerkhof)
- [FEATURE] Implement fallback directives for non-magento-standard directives (Martijn van den Kerkhof)
- [FEATURE] Minor reformats (Martijn van den Kerkhof)
- [FEATURE] When checking for existing entries, disregard query strings. (Martijn van den Kerkhof)
- [BUGFIX] Removed commented code (Hexmage)
1.7.2 (2021-09-09)
- [BUGFIX] Moved policies node to proper location in csp node (René Schep)
1.7.1 (2021-09-09)
- [FEATURE] Fixed 'frame-ancestors' does not support 'unsafe-inline' (René Schep)
1.7.0 (2021-09-09)
- [FEATURE][SBAS-1452] Readded Media and Static urls and changed how urls get stripped (René Schep)
1.6.1 (2021-09-08)
- [FEATURE][EMGA-374] Added styling to prevent listing overflow (Martijn van den Kerkhof)
1.6.0 (2021-08-26)
- [FEATURE][SFIN-60] Started custom whitelist add via admin grid (martijn.vanhaagen)
- [FEATURE][SFIN-60] Added functionality to whitelist scripts via admin grid + colors in enable/disable + refactored some code (martijn.vanhaagen)
- [REFACTOR][BUGFIX][DLTM2-617] Store url directive addition doesn't really work properly. Refactored DynamicCollector to properly use scoperesolver supplied by Magento (instead of hard-coded sql). Improved configuration to properly reflect global scope of this setting. (Boris van Katwijk)
- [REFACTOR][DLTM2-617] Rename policy from "dynamic" to "all-store-urls" to better reflect it's workings. (Boris van Katwijk)
- [BUGFIX][DLTM2-617] "Add all store urls" to whitelist policy is a "text" configuration whilst it is ment to be a "select" with Yes/No source model. (Boris van Katwijk)
- [BUGFIX][DLTM2-617] *.[base_url] wildcard system does not work. Reverted it to pure base url logic for adding all store urls. (Boris van Katwijk)
- [REFACTOR][SFIN-60] Refactor of whitelist addition; it should be full domain to work; "*".[url] wildcard syntax does not seem to work for these. Clarified type of collector by renaming it to "ConfiguredWhitelistCollector". (Boris van Katwijk)
- [FEATURE][SFIN-60] Made "current policy" hidden for default CSP report view; since it is often very large. (Boris van Katwijk)
- [FEATURE][SFIN-60] Right trim the slash off all store urls. Correctly extract "host source" from whitelisted urls to add them to the whitelist for the Content Security Policy. (Boris van Katwijk)
- [FEATURE][ARCI-151] Put collector for all store urls after the configured whitelist collector to also add store urls to custom directives. (Boris van Katwijk)
- [BUGFIX][ARCI-151] Styling (red and green) doesn't work if "Enabled" or "Disabled" are translated, since it's value is required to be exactly these values for the knockout styling to work. (Boris van Katwijk)
- [BUGFIX][ARCI-151] Not allowed policies can be reported such as "script-src-elem". Whitelisting these results in breaking all of the CSP whitelist workings. To prevent this only allowed policies can be whitelisted with configuration. (Boris van Katwijk)
- [REFACTOR][ARCI-151] Move message inside allowed directives for "whitelist action" in csp report listing. Add "De-whitelist" label to whitelist toggle action and make labels translatable strings. (Boris van Katwijk)
- [REFACTOR][ARCI-151] Refactor name of menu item and reporting page from "Csp Report" to "CSP reporting & whitelist". (Boris van Katwijk)
- [BUGFIX][SFIN-60][ARCI-151] Existing original policy isn't updated when adding to the hitcount. Update this on upping the hitcount to accurately display the most recent policy. (Boris van Katwijk)
- [DOCS][ARCI-151] Update copyright to include "B.V." in company name. (Boris van Katwijk)
- [FEATURE][SFIN-60][ARCI-151] Include "Not allowed" as type of whitelist to clearly display the "violated directives" which aren't allowed to be whitelisted. (Boris van Katwijk)
- [DOCS][ARCI-151] Updated README.md with new whitelist feature; general update of README.md. (Boris van Katwijk)
1.5.0 (2021-08-25)
- [FEATURE][SBAS-1452] Refactored database queries and added support for alternative media, static or link domains (René Schep)
1.4.0 (2021-08-12)
- [FEATURE][AOM2-172] Started using count in reports (martijn.vanhaagen)
- [FEATURE][DONS-156] Added delay + fixed filters (martijn.vanhaagen)
- [BUGFIX][AOM2-172] Fatal error: Uncaught Error: Undefined class constant 'COUNT' in ReportInterface instances. (Boris van Katwijk)
- [BUGFIX][AOM2-172] Refactor report existance in save() function to properly function without any reports being active. Small simplification/cleanup for ease of reading the code. (Boris van Katwijk)
- [REFACTOR][AOM2-172] Sleep for a random millisecond instead of microsecond to avoid the difference being smaller than the save time, which would result in duplicate CSP reports. (Boris van Katwijk)
1.3.7 (2021-07-19)
- [FEATURE][SBN-184] Add google ad services to whitelist (Matthijs Breed)
1.3.6 (2021-06-30)
- Update csp_whitelist.xml (Hexmage)
1.3.5 (2021-06-30)
- Added mouseflow (Hexmage)
1.3.4 (2021-06-28)
- [BUGFIX][DOBO-262] - Remove the config change that disables report_only in the backend on module installation (cassatter)
1.3.3 (2021-06-18)
- [BUGFIX][DONS-148] ACL nesting is broken since the introduction of the settings; restored this. (Boris van Katwijk)
1.3.2 (2021-06-16)
- [FEATURE][ARCI-143] Made notice/error bar less red. (Boris van Katwijk)
- [BUGFIX][DLTM2-617][ARCI-143] Configuration did not have a "tab". ACL is missing for configuration. (Boris van Katwijk)
- [FEATURE][ARCI-143] Add "on/off" switch (configuration setting) to toggle reporting on and off by NOT returning the reporting url csp_reporting.php when the reporting setting is disabled. Default is enabled. (Boris van Katwijk)
1.3.1 (2021-06-11)
- [BUGFIX] Blank screen due to erro (florisschreuder)
1.3.0 (2021-06-09)
- [FEATURE][DLTSM2-617] dynamically add base urls of all stores to csp list (Derrick Heesbeen)
- [FEATURE][DLTM2-617] Added config setting to add store urls dynamically (Derrick Heesbeen)
1.2.30 (2021-05-10)
- [FEATURE][SXLMP-327] - Expand CSP Whitelist (cassatter)
1.2.29 (2021-05-05)
- [FEATURE] Added support for local fonts. (Hexmage)
1.2.28 (2021-04-15)
- [FEATURE][NAU-712] Added new whitelisted hosts (JobStoker)
- [DOCS] Updated the CHANGELOG.md (JobStoker)
1.2.27 (2021-03-22)
- [FEATURE][SMSE-216] Add jsdelivr CDN, used by snowdog/frontools (Matthijs Breed)
1.2.16 (2021-03-15)
- [BUGFIX] Increased size of database fields because they were to small. (Hexmage)
1.2.15 (2021-03-15)
- [FEATURE] Added nr-data.net to whitelist (Hexmage)
1.2.14 (2021-02-02)
- [FEATURE][DDIJK-229] Added zendesk and newrelic to whitelist to resolve reports for dijkstra (Quinn Stadens)
- [DOCS] Updated the CHANGELOG.md (Quinn Stadens)
- CHANGELOG.md changed (Quinn Stadens)
1.2.13 (2020-10-30)
- [FEATURE][PSTR-151] Trustpilot added to style-src in whitelist (Quinn Stadens)
1.2.12 (2020-10-30)
- [FEATURE][PSTR-151] Trustpilot added to whitelist (Quinn Stadens)
1.2.11 (2020-10-28)
- [DOCS] Modified the COPYING.txt (Lewis Voncken)
1.2.10 (2020-10-15)
- [REFACTOR] [BACI-123] solved errors based on php code sniffer (Lewis Voncken)
1.2.9 (2020-10-15)
- [REFACTOR] Removed unused code or added suppression when unused code is allowed and applied phpcs fixes (Lewis Voncken)
1.2.8 (2020-09-23)
- Update csp_whitelist.xml (Derrick Heesbeen)
- [TASK] added amcglobal to connect-src (Derrick Heesbeen)
1.2.7 (2020-08-28)
- [FEATURE] Added facebook, feedbackcompany and zendesk chat to csp whitelist (Matthijs Breed)
- Update csp_whitelist.xml (Matthijs Breed)
1.2.6 (2020-08-11)
- [FEATURE][SUBI-145] - Whitelisted reported scripts based on patch 2.3.5-p2 (Ton Matton)
1.2.5 (2020-08-03)
1.1.1 (2020-08-03)
- [TASK] Additional defaults proposal (Derrick Heesbeen)
- Update csp_whitelist.xml (Derrick Heesbeen)
- [TASK] added demdex and everesttech amcglobal (admin notices) (Derrick Heesbeen)
1.2.4 (2020-07-16)
- [FEATURE] added gallery.mailchimp.com to the allowed list for img-src (Lewis Voncken)
1.2.3 (2020-07-02)
- [TASK] Added google tagmanager to the img-src in the csp_whitelist.xml (Lewis Voncken)
1.2.2 (2020-06-30)
- [FEATURE] Added addtional hosts to the csp_whitelist.xml (Lewis Voncken)
1.2.1 (2020-06-26)
- [DOCS] Updated Screenshot csp-admin-notification.png (Lewis Voncken)
1.2.0 (2020-06-26)
- [FEATURE] Allow images from google api (Lewis Voncken)
- [FEATURE] Removed disable report only mode and added admin error notifications (Lewis Voncken)
1.1.0 (2020-06-22)
- Update csp_whitelist.xml (Dulshad)
1.0.1 (2020-06-18)
- [BUGFIX] Solved composer mapping invalid path for csp_reporter.php (Lewis Voncken)
1.0.0 (2020-06-15)
- [FEATURE] Initial Commit (Lewis Voncken)
| Version | Stability | QA Status | Compatibility | Released |
|---|---|---|---|---|
| 2.0.3 | stable | Fail | Magento 2.4.7-2.4.9 Details | 2022-04-15 09:20:16 |
| 2.0.2 | stable | Not tested | Not yet tested Details | 2022-01-25 10:16:33 |
| 2.0.1 | stable | Not tested | Not yet tested Details | 2021-12-21 14:10:09 |
| 2.0.0 | stable | Not tested | Not yet tested Details | 2021-12-21 12:47:18 |
| 1.8.3 | stable | Not tested | Not yet tested Details | 2021-10-13 09:04:48 |
| 1.8.2 | stable | Not tested | Not yet tested Details | 2021-10-04 11:51:29 |
| 1.8.1 | stable | Not tested | Not yet tested Details | 2021-09-16 14:35:05 |
| 1.8.0 | stable | Not tested | Not yet tested Details | 2021-09-16 13:23:20 |
| 1.7.2 | stable | Not tested | Not yet tested Details | 2021-09-09 11:31:43 |
| 1.7.1 | stable | Not tested | Not yet tested Details | 2021-09-09 10:44:30 |
| 1.7.0 | stable | Not tested | Not yet tested Details | 2021-09-09 08:21:13 |
| 1.6.1 | stable | Not tested | Not yet tested Details | 2021-09-08 13:11:56 |
| 1.6.0 | stable | Not tested | Not yet tested Details | 2021-08-26 09:03:49 |
| 1.5.0 | stable | Not tested | Not yet tested Details | 2021-08-25 11:22:44 |
| 1.4.0 | stable | Not tested | Not yet tested Details | 2021-08-12 10:01:23 |
| 1.3.7 | stable | Not tested | Not yet tested Details | 2021-07-19 12:43:55 |
| 1.3.6 | stable | Not tested | Not yet tested Details | 2021-06-30 14:38:12 |
| 1.3.5 | stable | Not tested | Not yet tested Details | 2021-06-30 14:18:51 |
| 1.3.4 | stable | Not tested | Not yet tested Details | 2021-06-29 15:18:08 |
| 1.3.3 | stable | Not tested | Not yet tested Details | 2021-06-18 15:14:01 |
| 1.3.2 | stable | Not tested | Not yet tested Details | 2021-06-16 09:22:51 |
| 1.3.1 | stable | Not tested | Not yet tested Details | 2021-06-11 15:03:55 |
| 1.3.0 | stable | Not tested | Not yet tested Details | 2021-06-09 08:58:25 |
| 1.2.30 | stable | Not tested | Not yet tested Details | 2021-05-10 07:59:29 |
| 1.2.29 | stable | Not tested | Not yet tested Details | 2021-05-05 08:58:41 |
| 1.2.28 | stable | Not tested | Not yet tested Details | 2021-04-15 14:32:21 |
| 1.2.27 | stable | Not tested | Not yet tested Details | 2021-03-22 13:34:40 |
| 1.2.16 | stable | Not tested | Not yet tested Details | 2021-03-15 13:26:35 |
| 1.2.15 | stable | Not tested | Not yet tested Details | 2021-03-15 10:54:39 |
| 1.2.14 | stable | Not tested | Not yet tested Details | 2021-02-02 09:49:51 |
| 1.2.13 | stable | Not tested | Not yet tested Details | 2020-10-30 14:15:03 |
| 1.2.12 | stable | Not tested | Not yet tested Details | 2020-10-30 13:52:13 |
| 1.2.11 | stable | Not tested | Not yet tested Details | 2020-10-28 15:10:00 |
| 1.2.10 | stable | Not tested | Not yet tested Details | 2020-10-15 21:53:56 |
| 1.2.9 | stable | Not tested | Not yet tested Details | 2020-10-15 21:34:07 |
| 1.2.8 | stable | Not tested | Not yet tested Details | 2020-09-23 10:30:32 |
| 1.2.7 | stable | Not tested | Not yet tested Details | 2020-08-28 13:04:45 |
| 1.2.6 | stable | Not tested | Not yet tested Details | 2020-08-11 11:17:44 |
| 1.2.5 | stable | Not tested | Not yet tested Details | 2020-08-03 09:03:46 |
| 1.1.1 | stable | Not tested | Not yet tested Details | 2020-08-03 09:02:30 |
| 1.2.4 | stable | Not tested | Not yet tested Details | 2020-07-16 14:45:50 |
| 1.2.3 | stable | Not tested | Not yet tested Details | 2020-07-02 08:42:17 |
| 1.2.2 | stable | Not tested | Not yet tested Details | 2020-06-30 11:41:39 |
| 1.2.1 | stable | Not tested | Not yet tested Details | 2020-06-26 11:14:40 |
| 1.2.0 | stable | Not tested | Not yet tested Details | 2020-06-26 11:12:27 |
| 1.1.0 | stable | Not tested | Not yet tested Details | 2020-06-22 19:51:53 |
| 1.0.1 | stable | Not tested | Not yet tested Details | 2020-06-18 10:00:30 |
| 1.0.0 | stable | Not tested | Not yet tested Details | 2020-06-15 09:53:13 |
No dependencies declared
This package's composer.json doesn't declare any required, suggested, replaced, or conflicting packages.
Compatibility
Each Magento release line is installed on its supported PHP versions, then the module is built (DI compilation + static-content deploy) and its unit and integration suites are run. The matrix shows the lines and PHP versions the module is confirmed to install and run on. Code-quality results further down (phpstan, phpcs, …) are reported separately and never affect compatibility.
Code Quality
Advisory checks against the module's source. Static analysis runs once across the whole module; PHPStan re-runs per Magento + PHP version because resolvable symbols differ between releases. These NEVER affect the Compatibility badge — a phpcs finding can't make a module incompatible.
Static analysis
Coding standards (phpcs), mess detection (phpmd), copy-pasted code (cpd), PHP cross-version compatibility, composer.json validity. Each runs once for the whole module.
PHPStan
Type-checks the module's PHP against a real Magento install at the configured gate level. Re-runs per Magento and PHP version because resolvable symbols differ between releases. Cell → details modal.
Tests
Unit and integration suites, run for each applicable Magento and PHP version. A test failure speaks to the module's behaviour, not its compatibility with a Magento line, so it is reported here separately and never reddens the compatibility matrix.
Unit tests
| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | ||
| 2.4.8 | N/A | N/A | ||
| 2.4.9 | N/A | N/A |
Integration tests
| Magento | PHP 8.2 | PHP 8.3 | PHP 8.4 | PHP 8.5 |
|---|---|---|---|---|
| 2.4.7 | N/A | N/A | ||
| 2.4.8 | N/A | N/A | ||
| 2.4.9 | N/A | N/A |
Security
Security checks run directly against the module: an audit of its declared dependencies for known vulnerabilities (composer audit) and a scan of its source for malware and web-shell signatures. Each runs once. A malware detection fails the version outright.
More from experius
View vendorCollect missing translations in specified folder or the entire Magento 2 Root. Adds database editing and management of translations.
Magento 2 store config override hints module
Add labels to address lines and configuration for each address line.
This module makes it possible to upload different filetypes inside the WYSIWYG-editor (Media Gallery). Extra filetypes are Word (doc, docm, docx, odt), Excel (csv, xml, xls, xlsx, ods), PDF (pdf), Compressed Folder (zip, tar)
Turn an existing module into recurring revenue.
If you already maintain a Magento 2 module on GitHub or GitLab, listing it on Packagento takes about five minutes. We mirror your tags, handle distribution signing, and route paid licenses through Stripe Connect, so you can keep shipping the way you already do.