integer-net / magento2-sansec-watch
Sansec Watch integration for Magento 2
IntegerNet_SansecWatch Module
This module allows the integration CSP rules from Sansec Watch (https://sansec.watch/) into Magento without the need for file manipulations and a re-deployment
Setup
composer require integer-net/magento2-sansec-watch
bin/magento module:enable IntegerNet_SansecWatch
bin/magento setup:upgrade
Configuration
The configuration can be found under Stores > Configuration > IntegerNet > Sansec Watch.
Enable Sansec Watch and enter its project ID. You can find the ID in the project URL after navigating to https://sansec.watch/d/account/list and selecting a project (for example, 685769a2-38a4-4d06-a19a-67a528197f51).
Enablement and the project ID can be configured at the Default or Store View scope. A store view inherits the Default configuration unless it has its own values. These settings are not configurable at Website scope. Policies and update status are saved per store view; if a store view has no policies yet, it uses the Default policy set.
Scheduled policy updates are disabled by default. To enable them, set Enable cron job at Default scope. This global setting controls the cron job that updates policies for all enabled store views.
How it works
The policies are fetched from the Sansec Watch API and saved into a database table (integernet_sansecwatch_policies)
When Magento collects the CSP rules, it uses the Magento\Csp\Model\CompositePolicyCollector class and this module adds
a collector to this class, which will read the policies from the database table and add them to the existing policies.
Once policies are fetched from Sansec Watch, the result will be hashed and further updates are only executed, if the
newly fetched policies differ from the existing ones. (This is handled via the entry integernet_sansecwatch in the flag table)
Full Page Cache (FPC)
After policies are updated (either by an updated list from sansec watch or by force), the FPC will be, depending on the configuration either cleared, invalidated or ignored.
Usage
Backend
Directly below the configuration is a button, Update Policies Now, which will fetch and update the policies on demand.
This will do a forced update, where rules are updated, even if the hashes of the old and new policies match.
Command Line
An update can be triggered via bin/magento integer-net:sansec-watch:update
This updates policies for every enabled store view and by default only saves changes if the hashes of the old and new policies differ.
To update only one store view, pass its ID or code with --store-id:
bin/magento integer-net:sansec-watch:update --store-id=default
A dry-run is possible by adding the --dry-run flag, which fetches and outputs the policies without updating the database.
If an update should be force (regardless of the hashes), the --force flag can be added.
Cronjob
The policies are also fetched via the cron job integernet_sansecwatch_update, which runs daily at 01:05 (cron expression: 5 1 * * *) when Enable cron job is enabled at Default scope.
This will also only update the database, if the hashes of the old and new policies do not match.
Changelog
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog,
and this project adheres to Semantic Versioning.
[Unreleased]
Added
- Added a global-only configuration option to enable scheduled policy updates, disabled by default.
Changed
- Moved Sansec Watch enablement, project IDs, policy storage, and update status to store-view scope.
[2.1.0]
Added
- Added backend configuration for CSP fetch-policy flags per supported directive, including inherited fallback settings.
- Added website/store-scoped configuration for Sansec Watch and CSP policy settings.
- Added a link to MDN’s Content Security Policy directive documentation in the backend configuration.
- Added an injectable API URL provider interface for Sansec Watch-compatible services.
Changed
- Generated CSP fetch policies using the configured flags for each directive instead of one global set of flags.
- Updated the admin templates to render inline styles through Magento’s secure HTML renderer.
2.0.1 - 2026-07-17
Changed
- Replace deprecated ConvertKeysToCamelCase with MapKeysToCamelCase in SansecWatchFlagMapper
Fixed
- Updated the changelog with the missing entry for 2.0.0
- Fix bitbucket pipeline
2.0.0 - 2026-07-17
Changed
- Raised the minimum supported PHP version to 8.3.
- Added compatibility with Symfony 8 components.
- Updated Valinor to 2.4 and adapted Sansec Watch flag mapping accordingly.
- Updated the development and CI toolchain for PHP 8.5, including PHPUnit 12 and PHPStan 2.
Fixed
- Ensured policies loaded from the database are returned as a sequential list.
1.1.1 - 2026-05-11
Fixed
- Use heredoc instead of nowdoc to render scripts with the SecureHtmlRenderer (prevent problems with processed templates)
1.1.0 - 2026-04-03
Added
- Added policy search in the admin configuration.
- Added sorting for the displayed policy list.
- Added a German (
de_DE) translation for admin texts.
Changed
- Collapsed long policy lists by default in the admin UI.
- Hid labels for informational fields that are not editable configuration values.
- Made admin UI strings translatable.
Fixed
- Added an explicit empty-state message when no policies are available.
1.0.12 - 2025-09-23
Changed
- Memoized policy fetches to avoid repeated requests during a single update flow.
- Disabled inline policies by default.
1.0.10 - 2025-02-20
Fixed
- Sorted policies before calculating the change hash so identical policy sets no longer trigger incorrect update detection.
1.0.9 - 2025-02-14
Added
- Added a status indicator for the report URI configuration.
Changed
- Added compatibility with
symfony/http-client5.x.
Fixed
- Prevented policies from being loaded when the module is disabled.
1.0.7 - 2024-12-02
Added
- Added an admin action that links directly to the Sansec dashboard.
- Added default button styling for the dashboard shortcut.
1.0.6 - 2024-11-30
Changed
- Made the default Sansec policy fetch parameters configurable.
- Stopped enabling
strict-dynamicby default.
1.0.4 - 2024-11-17
Fixed
- Resolved policy table names through Magento's
ResourceConnectionto improve compatibility with customized database table names.
1.0.3 - 2024-11-17
Changed
- Added compatibility with
symfony/http-client7.
1.0.2 - 2024-11-05
Fixed
- Added support for Magento installations that use database table prefixes.
1.0.1 - 2024-10-29
Changed
- Changed the package license to MIT.
1.0.0 - 2024-10-18
Added
- Initial release of the Magento integration for importing CSP policies from Sansec Watch.
- Added scheduled and manual policy updates, including CLI support.
- Added an admin policy list and backend timestamps for the last checks and updates.
- Added full page cache handling after policy updates.
- Added extension points for customizations.
| Version | Stability | QA Status | Compatibility | Released |
|---|---|---|---|---|
| 2.1.0-beta3 | beta | Not tested | Not yet tested Details | 2026-10-05 13:19:11 |
| 2.1.0-beta2 | beta | Not tested | Not yet tested Details | 2026-08-12 10:14:31 |
| 2.1.0-beta | beta | Not tested | Not yet tested Details | 2026-07-17 20:05:36 |
| 2.0.1 | stable | Fail | Magento 2.4.8-2.4.9 Details | 2026-07-17 17:22:52 |
| 2.0.0 | stable | Not tested | Not yet tested Details | 2026-07-17 16:59:31 |
| 2.0.0-beta | beta | Not tested | Not yet tested Details | 2026-06-16 09:17:59 |
| 1.1.1 | stable | Fail | Not yet tested Details | 2026-05-11 09:52:01 |
| 1.1.0 | stable | Not tested | Not yet tested Details | 2026-04-03 17:43:06 |
| 1.0.12 | stable | Not tested | Not yet tested Details | 2025-09-23 10:44:09 |
| 1.0.11 | stable | Not tested | Not yet tested Details | 2025-03-12 15:32:10 |
| 1.0.10 | stable | Not tested | Not yet tested Details | 2025-02-20 10:34:09 |
| 1.0.9 | stable | Not tested | Not yet tested Details | 2025-02-14 14:46:59 |
| 1.0.8 | stable | Not tested | Not yet tested Details | 2024-12-09 09:07:35 |
| 1.0.7 | stable | Not tested | Not yet tested Details | 2024-12-02 11:02:18 |
| 1.0.6 | stable | Not tested | Not yet tested Details | 2024-11-30 12:42:45 |
| 1.0.5 | stable | Not tested | Not yet tested Details | 2024-11-18 12:49:30 |
| 1.0.4 | stable | Not tested | Not yet tested Details | 2024-11-17 18:44:00 |
| 1.0.3 | stable | Not tested | Not yet tested Details | 2024-11-17 18:16:44 |
| 1.0.2 | stable | Not tested | Not yet tested Details | 2024-11-05 12:02:23 |
| 1.0.1 | stable | Not tested | Not yet tested Details | 2024-10-29 08:43:40 |
| 1.0.0 | stable | Not tested | Not yet tested Details | 2024-10-04 11:40:38 |
Requires 8
| Package | Constraint |
|---|---|
| beberlei/assert | ^3.3 |
| cuyz/valinor | ^2.4.0 |
| magento/framework | >=100.0.0 |
| magento/module-csp | * |
| php | >=8.3.0 |
| symfony/clock | ^6.4 || ^7.0 || ^8.0 |
| symfony/http-client | ^5.0 || ^6.0 || ^7.0 || ^8.0 |
| symfony/uid | ^6.2 || ^7.0 || ^8.0 |
Requires-dev 13
| Package | Constraint |
|---|---|
| bitexpert/phpstan-magento | ^0.42.0 |
| ergebnis/composer-normalize | ^2.52 |
| php-parallel-lint/php-console-highlighter | ^1.0 |
| php-parallel-lint/php-parallel-lint | ^1.4 |
| phpstan/extension-installer | ^1.4 |
| phpstan/phpstan | ^2.2 |
| phpstan/phpstan-deprecation-rules | ^2.0 |
| phpstan/phpstan-phpunit | ^2.0 |
| phpstan/phpstan-strict-rules | ^2.0 |
| phpunit/phpunit | ^12.5 |
| rector/rector | ^2.4 |
| roave/security-advisories | dev-latest |
| symplify/easy-coding-standard | ^13.2 |
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.
| Tool | Status | Findings | Summary |
|---|---|---|---|
| PHPCS | Fail | 46 | 6 errors, 40 warnings (ruleset: Magento2), 12 auto-fixable with phpcbf |
| PHPMD | Warning | 6 | 6 rule violations (UnusedFormalParameter:4, MissingImport:2) |
| Cpd | Pass | 0 | |
| Composer validate | Info | 2 | valid; 2 advisory notes (composer validate --strict) |
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.
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 integer-net
View vendorGenerate RewriteMap files for Apache from Magento URL rewrites
Magento 2 Health Check
Create an "is_sale" product attribute and update it automatically from the "price" and "special_price" attributes
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.