integer-net / magento2-sansec-watch
Sansec Watch integration for Magento 2
Package info
github.com/integer-net/magento2-sansec-watch
Type:magento2-module
pkg:composer/integer-net/magento2-sansec-watch
Requires
- php: >=8.3.0
- beberlei/assert: ^3.3
- cuyz/valinor: ^2.4.0
- magento/framework: >=100.0.0
- magento/module-csp: *
- 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)
- bitexpert/phpstan-magento: ^0.42
- 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.4
- phpstan/phpstan-phpunit: ^2.0.18
- phpstan/phpstan-strict-rules: ^2.0.11
- phpunit/phpunit: ^12.5
- rector/rector: ^2.5
- roave/security-advisories: dev-latest
- symplify/easy-coding-standard: ^13.2.9
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-11 10:21:43 UTC
README
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.