Content-Security-Policy: CSP — controls what resources (scripts, styles, images) the browser is allowed to load. Strongest XSS defence in depth. Content Security Policy, or CSP, is a response header that tells the browser which sources of scripts, styles, images and other resources a page may load. Anything not on the list is blocked.
Frequently asked questions about Content-Security-Policy
How is Content-Security-Policy used in practice?
It is a strong second line of defence against cross-site scripting. Even if an attacker manages to inject a <script> tag into your page, the browser refuses to run it when the policy does not allow it.
What should you keep in mind with Content-Security-Policy?
Start with a strict base, such as default-src 'self', and add only what the site needs. Inline scripts are the usual obstacle; nonces or hashes let you allow specific ones safely. Roll a new policy out with Content-Security-Policy-Report-Only first, so violations are reported without breaking the site. Third-party widgets and analytics tags are often what makes a policy grow.
What does an example of Content-Security-Policy look like?
Use when reviewing or setting HTTP response headers for a web app or API - security headers (Content-Security-Policy, Strict-Transport-Security, X-Frame-Options, X-Content-Type-Options, Referrer-Policy, Permissions-Policy), CORS headers, caching headers (Cache-Control, ETag, Last-Modified, Vary) and cookies (Set-Cookie flags). Also use when a security scan reports missing headers.
OWASP Top 10 security audit and secure coding guidelines for Laravel + React/Inertia.js applications. Use when auditing for vulnerabilities ("run OWASP audit", "security review", "check my app security") or writing secure Laravel code involving auth, payments, file uploads, or API design. Triggers on security-related tasks, payment handling, authentication, or any request to audit a Laravel codeba
Configure Static Application Security Testing (SAST) tools for automated vulnerability detection in application code. Use when setting up security scanning, implementing DevSecOps practices, or automating code vulnerability detection.