🔐Content Security Policy (CSP)
Also known as CSP, CSP Header, Content-Security-Policy
A header that tells the browser where scripts may load from.
Think of it like
Think of it like a guest list at the door. Scripts that are not on the list do not get in.
Example
Lucy's site sends script-src 'self'. A script injected from a stranger's server is blocked, and the browser logs a warning.
Why it matters
It limits the damage of cross-site scripting. One slip in your code no longer means a stranger's script runs.
Definition
Example code
http
Content-Security-Policy: default-src 'self'; script-src 'self'Common mistake
Key takeaways
- 1An allow list. Only listed places may load.
- 2The browser enforces it. It blocks everything else.
- 3A second layer. Use it with output encoding.