Slide 24 of 27
Part 4 · PreventionSlide 24
Slide 24 · Mitigation 6 of 7
A browser-side safety net for when output encoding isn’t enough.
📄 OWASP LLM Top 10:2025 · LLM05 Prevention — Browser Controls
M6 — Content Security Policy
Deploy CSP Headers to Limit What a Browser Will Execute

“Implement Content Security Policy (CSP) in web applications that render LLM output. CSP provides a browser-enforced defense against XSS by restricting which scripts can execute, complementing server-side output encoding.” OWASP treats CSP as a critical defense-in-depth layer for any web app that displays LLM-generated content.

The ChatGPT plugin XSS (Imperva research) and similar LLM output XSS demonstrations all required the browser to execute inline scripts. A strict CSP — script-src 'self' with no 'unsafe-inline' — would have blocked script execution even if a payload slipped through the output encoding layer. CSP is the last line of defense when encoding fails.

→ Minimum effective CSP for LLM output pages:
Content-Security-Policy: default-src 'self'; script-src 'self'; object-src 'none';→ Use nonce-based CSP for any legitimate inline scripts
→ Add X-Content-Type-Options: nosniff to prevent MIME-type sniffing attacks
→ Use frame-ancestors 'none' to prevent clickjacking
→ Test with Google’s CSP Evaluator tool

Open browser DevTools → Network tab → Check your app’s response headers for Content-Security-Policy. If absent, CSP is not deployed. If present, paste the value into csp-evaluator.withgoogle.com to identify weaknesses.

← BackNext → M7: Least privilege & monitoring