Pcornel
Security · Web Security

Content Security Policy

Cheat sheet · https://pcornel.dk/topic.php?topic=4762

Back to the Topic

Answer

Content Security Policy (CSP) is a response header that restricts where scripts, styles, images and frames may load from, such as script-src 'self', which greatly limits the impact of XSS.

Remember

  • script-src 'self' blocks inline scripts.
  • Use nonces or hashes when inline scripts are needed.
  • Report-only mode lets you test safely.

First checks

  • curl -sI https://<site> | grep -i content-security-policy — CSP
  • CSP report-uri/report-to — violation reports
  • Nonces/hashes instead of 'unsafe-inline' — strict CSP

Verify in this order

response CSP → browser blocks disallowed sources

Where it usually breaks

First mismatch in asset/subject identity → trust/authentication → authorization/policy → enforcement/control → telemetry/detection → protected outcome/response; preserve identity/policy/pre-state before mutation.

Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=4762

Confirmation

Confirm action

Continue?