Every website faces security risks from malicious scripts, data theft, and unauthorized access. A Content Security Policy (CSP) provides an important layer of protection by controlling which sources browsers may trust, helping reduce attacks such as cross-site scripting.
When properly configured, Content Security Policy strengthens website security without relying solely on firewalls or antivirus software. It also supports digital privacy by limiting how web content loads and communicates with external services.
Content Security Policy is a browser-based security standard that helps website operators control which resources a page may load. It can restrict scripts, stylesheets, images, frames, fonts, and other content sources.
A website delivers its Content Security Policy through an HTTP response header, such as Content-Security-Policy. The policy contains directives, including script-src, style-src, img-src, and connect-src, which specify permitted origins or approved resource types.
A carefully configured policy can reduce the impact of cross-site scripting and certain code-injection attacks by blocking unauthorised scripts. Policies using nonces or hashes can permit specific inline scripts without allowing all inline code.
Administrators can test a policy with Content-Security-Policy-Report-Only before enforcement. This mode reports violations without blocking resources, helping identify compatibility problems. CSP does not replace secure coding, input validation, access controls, or other website security measures.