QuickDevGuide

Home › OWASP Top 10

Cross-Site Scripting (XSS) — OWASP Top 10

XSS is injection into HTML/JavaScript: an attacker's script runs in a victim's browser with their session. Type Where the payload lives Stored saved in the DB (comments, profiles) and shown to others Reflected echoed from the URL/request into the response DOM-based client-side JS writes untrusted data into the DOM (innerHTML, eval) Defences (layered) Contextual output encoding — templating engines (Jinja2, Razor, React JSX, Angular) escape by default. Avoid escape hatches: safe, @Html.Raw, dangerouslySetInnerHTML, v-html, innerHTML. Sanitise rich HTML with an allow-list library (DOMPurify, bleach/nh3) when users must submit HTML. Content-Security-Policy blocks inline scripts and unknown origins even if a payload slips through. HttpOnly cookies keep session tokens away from JavaScript. In…

Key Takeaways