Weak Content Security Policies Leave XSS Protections Vulnerable to Bypass
Vulnerability Disclosure · 3 sources · Updated 3mo ago · First seen Sep 3, 2026

Content Security Policy (CSP) can limit the impact of cross-site scripting, clickjacking, mixed content, and untrusted resource loading, but it is a defense-in-depth control rather than a replacement for input validation and output sanitization. Effective policies use per-response cryptographically random nonces or script hashes, narrowly define resource sources, set object-src, base-uri, form-action, and frame-ancestors explicitly, and can use Trusted Types to restrict dangerous DOM injection sinks such as innerHTML, document.write(), and eval().
Misconfigured policies can provide a false sense of security: unsafe-inline, unsafe-eval, data:, broad schemes, wildcards, and permissive third-party script allowlists can enable XSS bypasses. In HackMD/CodiMD 1.2.1, a stored XSS flaw in Markdown comment filtering allowed attackers to inject HTML; the platform's CSP still permitted exploitation because it trusted cdnjs.cloudflare.com, enabling an AngularJS client-side template-injection bypass. Organizations should deploy CSP first in Content-Security-Policy-Report-Only mode, collect violations through Reporting endpoints, and continuously test policies for regressions and risky third-party dependencies.


