A content security policy tells the browser which scripts, stylesheets, images and connections a page may use. A strict policy, such as script-src 'self' without 'unsafe-inline', means that a script injected into a page through a stored or reflected value does not run, even where a template forgets to escape it. Exponential sends a policy from site.ini [ContentSecurityPolicy], beside the security headers of [HTTPHeaderSettings] SecurityHeaders[].
Modes
- disabled: no policy.
- report-only: the browser reports what the policy would block, in its developer console and to ReportURI when set, and blocks nothing.
- enforce: the browser blocks what the policy does not allow.
- auto (the default): report-only on administration siteaccesses (those whose design begins with admin) and disabled on all others.
The shipped directives
[ContentSecurityPolicy] Mode=auto Directives[] Directives[default-src]='self' Directives[script-src]='self' Directives[style-src]='self' Directives[img-src]='self' data: blob: Directives[font-src]='self' data: Directives[media-src]='self' blob: Directives[connect-src]='self' Directives[frame-src]='self' Directives[object-src]='none' Directives[base-uri]='self' Directives[form-action]='self' Directives[frame-ancestors]='self' ReportURI=
Set an entry empty in an override to leave that directive out; an override that starts with Directives[] alone replaces the whole list. An entry whose value holds ; or , is ignored, so a setting cannot split the header. Browsers ignore frame-ancestors and sandbox in a report-only policy, so they are sent only when the policy is enforced. Browsers post their reports to the csp/report view, which takes them on every siteaccess without sign-in.
Moving to enforce
- Audit the templates. The test AdminContentSecurityPolicyTest checks the core designs and shipped extensions; run it with every extension of your installation. Each failure names a template with inline code that an enforced policy would break.
- Collect reports of real use: set ReportURI to a collector of your own, or watch the developer console, and use the administration for a few days. Open the menus and dialogs too.
- Enforce one siteaccess first, best a second administration siteaccess only you use, with the same designs and extensions.
- Loosen only what you must, per siteaccess and per directive.
# settings/siteaccess/<admin siteaccess>/site.ini.append.php [ContentSecurityPolicy] Mode=enforce
Pages answered from the kernel's HTTP cache carry the same headers. Per path, [HTTPHeaderSettings] HeaderList still overrides any header, the policy included. More on hardening: Security.