Home
← All questions

Content Security Policy (CSP) | Web Fundamentals

HardPremiumWeb Fundamentals

Asked at Google · Stripe · Meta

Web Fundamentals interview practice: Mitigate XSS with CSP directives, nonces, and report-only mode.

Answer

CSP is an HTTP header (or <meta>) that whitelists where content can load from, reducing XSS blast radius even if attacker injects HTML.

Common directives:

  • default-src 'self' — fallback for other directives
  • script-src 'self' 'nonce-abc123' — only trusted scripts
  • style-src, img-src, connect-src (XHR/fetch), frame-ancestors (clickjacking)
  • report-uri / report-to — violation telemetry

Modes:

  • Enforce — blocks violations
  • Report-Only — logs without blocking (rollout)
Premium question

Unlock the full model answer with Mentoxis Premium.

Unlock with Premium