CSP (Content Security Policy) is an HTTP security header that tells browsers which scripts, styles, images, and other resources are allowed to load on your page. It prevents XSS attacks by blocking inline scripts and unauthorized third-party resources. If an attacker injects malicious JavaScript, CSP blocks it from executing.
Add CSP to all web apps to prevent XSS attacks. Start with a strict policy (only allow your own domain), then add exceptions for trusted third parties (CDNs, analytics, payment providers). Use nonces or hashes for inline scripts. Test CSP in "report-only" mode first to catch issues before enforcing. Use tools like Google CSP Evaluator to validate your policy.
Cybersecurity
Control which resources can load on your page