Content Security Policy
An HTTP response header that tells the browser which sources of scripts and other content a page may load, limiting what injected markup can do.
In more detail
CSP stands for Content Security Policy. A strict policy using nonces or hashes stops injected inline scripts from running, making XSS far harder to exploit. Test a new policy in Report-Only mode first.
Examples
Content-Security-Policy: script-src 'nonce-r4nd0m' 'strict-dynamic'; object-src 'none'; base-uri 'none'The course's dynamic scan checks that the header is present.Related terms
- CSP directive — One rule inside a Content Security Policy, such as script-src, that lists the allowed sources for one kind of resource.
- nonce — A value meant to be used only once, such as a unique number given to a cipher or a random token that marks trusted scripts in a web page.
- 'unsafe-inline' — A CSP keyword that allows all inline scripts or styles, which removes most of the protection CSP offers against XSS.
- Trusted Types — A browser security feature that makes dangerous DOM sinks such as innerHTML reject plain strings and accept only values produced by a policy you define.
- cross-site scripting — An attack in which someone gets their own script to run inside your page, where it can read data, act as the user or steal tokens.
- Content-Security-Policy-Report-Only — A header that applies a Content Security Policy in test mode: violations are reported but nothing is blocked.
- security headers — HTTP response headers that switch on browser protections, such as HSTS for HTTPS-only access and X-Frame-Options against framing.
Taught in
- Content Security Policy (CSP), Trusted Types And XSS Defenses — Frontend Architecture & Web Platform
- Dynamic Scanning — Application Security & Threat Modeling for Engineers