Skip to content

Set up a policy

The first time you open Security > CSP on a project, the page shows five steps: Scan, Review sources, Generate, Validate and Deploy. Nothing changes on the site until you deploy in step 5.

Deploy in report-only mode first. Change to enforcing mode only after the violation reports of real visitors show no source that the site needs.

  1. In Base URL, select the address of the site. The list holds the domains of the project, with https. Select Save.
  2. Optional: select the strict flags.
    • Strict scripts: use hashes for inline scripts. The policy allows each inline script by its hash, and does not use 'unsafe-inline' for scripts.
    • Strict styles: use hashes for inline styles. The same for inline styles.
  3. In Pages to scan, add the path of each type of page, for example /, /about, a search page, a form page and a page with embedded media. A path starts with /.
  4. Select Start scan. A headless browser loads each page and records every script, style, font, image, frame and connection. The list shows the status of each page.

Scan each type of page. A source that only one template loads is not in the policy if no scanned page uses that template.

If the site already sends a CSP, step 1 shows the notice This site already serves a CSP. The notice gives the mode, the policy text, and the source: the project headers or the origin.

  • Select Import as version 1 to start from that policy.
  • Select Skip to build a new policy from a scan.

Quant replaces the report directives in an imported policy with its own when you deploy. If the site sends more than one header of the same name, only the first is imported.

After an import, you can select Deploy version 1 as it is, which goes to step 5. Or you can scan to build a new policy.

The page lists each domain and each inline hash that the scan found.

  1. For each source, select Approve domain (or Approve hash) or Deny. The policy allows only approved sources.
  2. Read the Supply chain risk warning, if it shows. A public CDN that serves any package is not limited to code you chose. Prefer a hash or a copy that you host.
  3. Select Skip the rest if you do not want to decide the other sources now. A skipped source is not in the policy.
  4. Select Continue.
  1. Check the strict flags.
  2. Select Generate policy. Quant builds the policy from the approved sources and shows it as Version 1. Each later change makes a new version.
  3. Read the warnings. Examples: 'unsafe-inline' is on, or a script source is a third-party origin or a public CDN.
  4. Select Continue.
  1. Select Validate. The scanner loads each enabled page with the draft policy and lists what the policy blocks, for each page.
  2. For each finding, use the fix button on its row:
    • Approve domain or Approve hash adds the source.
    • Allow ‘unsafe-eval’ (or another keyword) opens the dialog Weaken script protection?. Read it before you select Allow. See Validation finds eval.
  3. Select Validate again. An approval can show new violations, because a script that now runs can load more sources. Repeat until none remain.
  4. Select Continue. Deploy anyway continues with findings that are not fixed. Use it only for a report-only deploy.
  1. In Mode, select one option:
    • Report-only: browsers report violations and block nothing.
    • Enforcing: browsers block what the policy does not allow.
  2. Read Headers to write. It shows the exact headers: Content-Security-Policy-Report-Only or Content-Security-Policy, and Reporting-Endpoints.
  3. Select Deploy, then confirm in the dialog.

Quant writes the headers to the project and clears the cache of the project. The dashboard says a deploy can take up to 30 seconds. A page can show the old header for about a minute.

If the origin sends its own enforcing policy, the page tells you. See The origin sends its own policy.

  1. Leave the policy in report-only mode during normal traffic. Allow 24 to 48 hours as a minimum.
  2. Read the Violations tab. Approve each source that the site needs. Dismiss or ignore the reports that the site does not cause.
  3. Generate and deploy the new version, still in report-only mode.
  4. When no new report shows a source that the site needs, go to the Policy tab and select Switch to enforcing mode. Then deploy. See Manage the policy.