If you run a modern Vite SPA without a strict Content Security Policy (CSP), you’re one XSS away from a full account takeover.
This guide walks you through hardening your Vite + React + TypeScript SPA with a strong CSP using Subresource Integrity (SRI) and per-request nonces, while avoiding common pitfalls that silently weaken security.
A Content Security Policy is a powerful defense-in-depth control that mitigates XSS, data exfiltration, and injection attacks by explicitly allowing only trusted sources for scripts, styles, images, fonts, and network calls.
With the right CSP, you can: