How Content Security Policy Headers Shield Browsers from XSS Attacks
Content Security Policy (CSP) is a W3C standard implemented as an HTTP response header that instructs browsers to load scripts, styles, and other resources only from explicitly permitted origins. It serves as a critical second layer of defense against cross-site scripting (XSS) attacks, where malicious code injected into a trusted page can steal cookies or capture passwords. Without CSP, any script embedded in a page's HTML runs with the same privileges as legitimate site code, but an active policy blocks unauthorized scripts before they execute. CSP supports directives like script-src, style-src, and default-src, and offers nonces or hashes to safely allow specific inline scripts. Developers can also deploy it in report-only mode to monitor policy violations without breaking site functionality during rollout.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in