topic
Verified 2026-09-18Cross-Site Scripting (XSS) Prevention
XSS occurs when attacker-controlled data becomes executable markup or script in another user’s browser.
Prefer framework auto-escaping, context-aware output encoding, safe DOM APIs such as textContent, and strict CSP. Treat innerHTML, template interpolation in raw HTML, URL sinks, and script construction as explicit security boundaries.
httpsecurityxssbrowser
Reference (http)
<div>{escapeHtml(userProvidedText)}</div>
node.textContent = userProvidedText;Prefer framework auto-escaping, context-aware output encoding, safe DOM APIs such as textContent, and strict CSP. Treat innerHTML, template interpolation in raw HTML, URL sinks, and script construction as explicit security boundaries.
Common mistakes
- Using regex or HTML stripping as a sanitizer, inserting untrusted data into JavaScript or CSS contexts, or treating CSP as permission to keep unsafe sinks.