Understand Where XSS Usually Starts
The danger appears when untrusted content is executed instead of treated as data.
Cross-site scripting becomes possible when user-controlled content is inserted into the page as HTML or script-capable markup.
The practical frontend rule is simple: if something is plain text, render it as plain text. Do not upgrade it to HTML unless you have a strong reason and a sanitization strategy.
- Do not trust input just because it comes from your own backend
- Treat comments, names, descriptions, and query strings as untrusted data
- Prefer safe DOM APIs over string-based HTML insertion