Content Security Policy
Content Security Policy is a security standard that tells web browsers which resources a web page is allowed to load and execute. It is primarily used to reduce the risk of attacks like cross-site scripting and clickjacking by blocking unauthorized scripts, images, and other content. It is typically enforced by the browser through an HTTP response header sent by the web server.
Content Security Policy is a browser-enforced security standard delivered via the Content-Security-Policy HTTP response header (or a meta tag equivalent) that allows server operators to define allowlists of trusted sources for resource types such as scripts, stylesheets, images, fonts, and frames. The browser uses these directives to restrict resource loading and script execution at runtime, mitigating code injection attacks including cross-site scripting (XSS) and clickjacking. CSP operates exclusively as a runtime browser control and cannot detect or prevent vulnerabilities at the code or static analysis level. Its effectiveness is bounded by policy completeness and correctness, as misconfigured or overly permissive policies may provide limited protection, and certain attack vectors such as server-side injection or vulnerabilities in explicitly trusted origins remain outside its scope.
Why it matters
Cross-site scripting remains one of the most prevalent vulnerability classes in web applications, and CSP provides a browser-enforced mitigation layer that operates independently of whether the underlying code vulnerability has been remediated. Even when a developer introduces an XSS flaw, a well-configured CSP can prevent injected scripts from executing by blocking resources not included in the approved source allowlist. This makes it a meaningful defense-in-depth control, particularly for applications that process user-supplied content or integrate third-party scripts.
Who it's relevant to
Inside CSP
Common questions
Answers to the questions practitioners most commonly ask about CSP.