Dev.Lib
arrow_backBack to Blogs
LEVEL_066.1June 27, 20261 min read

Content Security Policy (CSP)

Web Security

Whitelist script/style/connect sources — blocks inline script unless nonce/hash.

Summary

Whitelist script/style/connect sources — blocks inline script unless nonce/hash. Start report-only, tighten gradually. 'unsafe-inline' defeats most XSS protection. strict-dynamic for modern bundlers. Breakage symptoms: blocked analytics, fonts, WebSocket — check console CSP reports.

Code example

<meta http-equiv="Content-Security-Policy"
      content="default-src 'self'; script-src 'self' 'nonce-R4nd0m'; connect-src 'self' https://api.example.com" />

Key points

  • Whitelist script/style/connect sources — blocks inline script unless nonce/hash.
  • Start report-only, tighten gradually.
  • 'unsafe-inline' defeats most XSS protection.
  • strict-dynamic for modern bundlers.
  • Breakage symptoms: blocked analytics, fonts, WebSocket — check console CSP reports.

Further reading

Related concepts