How XSS (Cross-Site Scripting) Works in Practice
Whether Stored (saved in a database comment/profile), Reflected (bounced off a URL parameter), or DOM-based (written via unsafe innerHTML sinks in client JS), XSS executes inside the victim origin. That gives the attacker script full access to the DOM, CSRF tokens, non-HttpOnly cookies, and authenticated API endpoints.
Defensive Mitigation & Hardening Checklist
Use modern auto-escaping UI templates, never pass untrusted strings to innerHTML or document.write without sanitization, mark session cookies HttpOnly, and deploy a strict Content-Security-Policy (CSP).