Restrict where scripts can load from on nginx
Why it matters
The policy sets neither script-src nor default-src, so it does nothing against injected scripts, the main thing a CSP is for. Add a script-src that lists only your own origin and the services you use, or that uses nonces.
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
- Stage 1: add the line below next to your existing CSP, run sudo nginx -t and reload; check the developer console.
- Stage 2: merge the directives into the enforced Content-Security-Policy and remove the report-only line.
nginx
add_header Content-Security-Policy-Report-Only "script-src 'self'; object-src 'none'; base-uri 'self'" always; Related
- Reported by the Content-Security-Policy check
- Add a Content-Security-Policy
- Enforce the report-only Content-Security-Policy
- Send the Content-Security-Policy as an HTTP header
- Replace 'unsafe-inline' scripts with nonces or hashes
- Remove 'unsafe-eval' from script-src
- Remove wildcard sources from script-src
- Set object-src to 'none'
- Add base-uri to the Content-Security-Policy
- Reduce reliance on inline styles
- Fix the Content-Security-Policy syntax
Scan your domain to see whether this applies to you.