arrow_backAll termssecurity

Content Security Policy (CSP)

A Content Security Policy (CSP) is an HTTP header that whitelists trusted content sources, mitigating cross-site scripting (XSS) and other injection attacks.

Also available: Auf Deutsch

A Content Security Policy (CSP) is an HTTP response header that allows web application developers to control which resources the user agent is allowed to load for a given page. It's a crucial security mechanism designed to prevent a wide range of attacks, most notably Cross-Site Scripting (XSS) and data injection attacks.

By defining a CSP, you can whitelist specific domains from which your application is allowed to load scripts, stylesheets, images, fonts, and other assets. For example, a CSP might specify: Content-Security-Policy: script-src 'self' cdn.example.com; img-src 'self' data:;. This policy would only allow scripts from your own domain and cdn.example.com, and images from your domain or embedded as data URIs.

Implementing a strong CSP significantly enhances the security posture of your web application. It acts as a robust defense layer, even if vulnerabilities exist elsewhere in your code, by preventing browsers from executing malicious code injected by an attacker. While powerful, configuring CSPs can be complex and requires careful testing to avoid blocking legitimate resources.

Related terms

Audit your site on all of these?

Pantra scans you in 8 seconds. Free, no signup.

Scan my sitearrow_forward