webzod
account

Send the Content-Security-Policy as an HTTP header on nginx

headers.csp.meta_only · effort: about an hour

Why it matters

A policy in a meta tag cannot use frame-ancestors, reporting or sandbox, and it only protects what comes after the tag in the page. The same policy sent as a response header covers the whole document.

Staged change. Do this in stages and check each one before the next, so a mistake does not break your site or your mail.

The fix

  1. Stage 1: add the policy as a report-only header with add_header ... always in every server block (and every location with its own add_header lines), optionally followed by ; frame-ancestors 'self'. Run sudo nginx -t and reload.
  2. Stage 2: rename it to Content-Security-Policy and remove the meta tag.
nginx
add_header Content-Security-Policy-Report-Only "<content value of the meta tag>" always;

Read the documentation (opens in a new tab)

Scan your domain to see whether this applies to you.