Skip to main content
Module 3 · Lesson 3 of 410/42 in the course~15 min
Module lessons (3/4)

Content Security Policy (CSP) & Trusted Nonces

Lesson preview6 hands-on exercises readyApplication & Web Security · Module 3 — XSS, CSP & Client-Side Security

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', wildcard https:) 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

  1. 11. How Attackers Bypass Weak CSP Headers
  2. 22. Interactive Explorer: Defense-in-Depth HTTP Headers
  3. 33. Progressive Labs: Warm-Up → Attack → Defend → Harden
  4. 44. Checkpoints & Code Review
Pro Lesson · Module 3 — XSS, CSP & Client-Side Security

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.