Script integrity and schedules
A CSP controls where scripts come from. It does not tell you when an approved script changes. The Script integrity tab of Security > CSP records the scripts that the site runs and reports each change.
The first check: the baseline
Section titled “The first check: the baseline”- Open Security > CSP > Script integrity.
- Select Run the first check. You can leave the page while the check runs.
The check loads the Base URL of the site and records:
- Script inventory: every script the page loads, with its hash and its execution order.
- Network tracking: the requests that scripts send to other domains.
The first completed check is the baseline. Later checks are compared with it.
Later checks: drift
Section titled “Later checks: drift”Each later check reports the scripts that were Added, Removed or Changed against the baseline, with a Severity: high, medium, low or none.
A change is not always a problem. A release of your site changes its scripts. Examine each change:
- If you expect the change, select Set as baseline on the check. Later checks are then compared with this check.
- If you do not expect the change, find where the script comes from before you do anything else. A changed third-party script is a supply chain risk.
Scripts that change on purpose
Section titled “Scripts that change on purpose”Some scripts change often, for example a tag manager. Add the host to Dynamic domains, with an optional path pattern and a reason. A change to a script from a dynamic domain does not raise the severity of a check.
Requests to other domains
Section titled “Requests to other domains”Suspicious activity detected lists the scripts that send data to other domains, with the target domain and the script that started the request. Approve an activity that you expect. It then shows in Approved activity and is not reported as suspicious again. Remove the approval to get the report back.
Other results
Section titled “Other results”- Subresource integrity gives an integrity value for each external script. Use the value in the
integrityattribute of a<script>tag for a script whose content does not change. - Security sinks lists calls that run text as code, such as
eval()andnew Function().
Schedules
Section titled “Schedules”The Schedules tab runs scans on their own. Results show in the History tab.
- Select Create schedule.
- Enter a Name (optional).
- Select the Scan type:
- CSP validation checks the pages against the deployed policy.
- Script integrity compares the scripts with the baseline.
- Select the Frequency: Daily, Weekly, Monthly or Custom (cron). Daily, weekly and monthly runs start at 02:00 in the timezone of the schedule. A cron expression has five fields, and the runs must be at least one hour apart.
- Select the Timezone.
- Save the schedule.
Use the actions of a schedule to run it now, edit it or delete it. Turn off Enabled to keep a schedule without runs.
Quant disables a schedule after 5 failures one after the other, and shows Stopped after 5 failures. Find the cause in History, correct it, then enable the schedule again.
A good start is one daily Script integrity schedule and one weekly CSP validation schedule. Set up an alert channel so that someone sees the results.
