XSS injects malicious scripts into pages viewed by other users:
Stored XSS: Attacker saves script in database (comment field). Every viewer executes it.
Reflected XSS: Script in URL parameter gets rendered in response.
Prevention:
Output encoding: Escape HTML entities before rendering
< becomes <
> becomes >
Content Security Policy: HTTP header restricts script sources
Content-Security-Policy: script-src 'self'
HttpOnly cookies: JavaScript can't access auth tokens
Framework auto-escaping: React, Vue escape by default