Module lessons (3/4)
Content Security Policy (CSP) & Trusted Nonces
Audit unsafe CSP directives like unsafe-inline, simulate inline script blocking, and generate strict nonce-based policies.
What you'll learn in this lesson
- Explain how Content Security Policy (CSP) blocks injected inline scripts and restricts script loading as defense-in-depth.
- Audit CSP headers for dangerous directives (
'unsafe-inline','unsafe-eval', wildcardhttps:) and missing locks (object-src 'none',base-uri 'none'). - Construct strict cryptographic nonce policies (
'strict-dynamic') and harden nonced<script>tag emitters against header/nonce/URL injection.
Overview
Context-safe encoding prevents HTML/JS injection at the source, while Content Security Policy (CSP) acts as the browser-enforced seat belt if an encoding bug ever reaches production. A weak CSP header, however, gives a false sense of security.
Compare four CSP header configurations from weakest to strongest:
Sections covered in this lesson
- 11. How Attackers Bypass Weak CSP Headers
- 22. Interactive Explorer: Defense-in-Depth HTTP Headers
- 33. Progressive Labs: Warm-Up → Attack → Defend → Harden
- 44. Checkpoints & Code Review
Unlock "Content Security Policy (CSP) & Trusted Nonces" and the full Application & Web Security curriculum
Audit unsafe CSP directives like unsafe-inline, simulate inline script blocking, and generate strict nonce-based policies.
Unlock all 6 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.
- Instant access to all advanced modules in Application & Web Security plus 17 more courses
- Hands-on browser exercises with automated test suites and solutions
- 14-day money-back guarantee processed via Paddle.com
14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.