From report-only to an enforced CSP
This page is for administrators and developers who turn the Content Security Policy from a reporting tool into a protection. Enforcing is a decision per siteaccess, made after an audit; the project's step-by-step procedure is in Switching to enforce, step by step. This page turns it into a plan with milestones that fits a public body's change process.
Contents
- Phase 1: Audit the templates
- Phase 2: Collect real reports
- Phase 3: Enforce one siteaccess
- Phase 4: Enforce the administration
- Phase 5: Public siteaccesses
- Rollback
- Related pages
Phase 1: Audit the templates
Run the project's test with every extension of the installation, as the administration renders them:
CSP_ALL_EXTENSIONS=1 php vendor/bin/phpunit tests/tests/design/AdminContentSecurityPolicyTest.phpEach failure line is a template with inline code that an enforced policy would break. Fix extensions in their own
repositories: scripts into files loaded with ezscript, values into data-* attributes, handlers into listeners,
menu items into data-menu-*.
Milestone: the list of remaining findings, each with an owner.
Phase 2: Collect real reports
Point reports at the site's own collector, in the administration siteaccess's site.ini.append.php:
[ContentSecurityPolicy]
ReportEndpoint=enabledClear the INI cache (php bin/php/ezcache.php --clear-tag=ini) and reload PHP (restart Velocity). Use the
administration for a few days: every extension's pages, the editors, dialogs and context menus (handler attributes are
reported only when they run). Read Setup > Log files > "Content Security Policy reports" (csp.log).
Milestone: no report for the pages your staff use, or a decision for each source.
Phase 3: Enforce one siteaccess
Enforce a second administration siteaccess that only the web team uses, with the same designs and extensions:
# settings/siteaccess/<test admin siteaccess>/site.ini.append.php
[ContentSecurityPolicy]
Mode=enforce
ReportEndpoint=enabledWork in it for a week. Where something must stay, loosen only that directive for that siteaccess, for example with
AdditionalSources[]=script-src https://maps.example.org or, for TinyMCE 3, 'unsafe-inline' in script-src and
style-src.
Milestone: a week of normal work without breakage.
Phase 4: Enforce the administration
Set Mode=enforce on the main administration siteaccess, clear the INI cache, reload PHP-FPM and restart Velocity
(./console exp:velocity deploy --allow-root-user does all of it). Classic designs (ReportOnlyDesigns[]) stay
report-only for users who pick them. Keep ReportEndpoint=enabled and read the reports weekly.
Phase 5: Public siteaccesses
Public designs and rich text output (styles from content, embedded players) are not checked by the project's test.
Start each public siteaccess with Mode=report-only and ReportEndpoint=enabled, fix your design, add the hosts of
embeds you keep, and enforce when the reports are quiet. A stricter companion can measure the next step:
ReportOnlyDirectives[style-src]='self' beside an enforced policy that still allows inline styles.
Rollback
Set Mode=report-only in the siteaccess, clear the INI cache, reload PHP-FPM and restart Velocity. Nothing else
changes (Enforcing: rollback).
Write the rollback into your change request before you enforce.
Related pages
- Content Security Policy
- Content Security Policy for public sites
- Log review routine (the CSP log is part of it)
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.