VibeSecurity

Web attacks

What is XSS (Cross-Site Scripting)?

XSS is an attack where an attacker gets your site to run their JavaScript in other visitors' browsers, usually by slipping untrusted input into a page without escaping it. The script then acts with the victim's access.

If your app shows text that a user typed, such as a comment or a profile name, and puts it into the page as raw HTML, a visitor can type a script instead. Every person who views that content then runs the script. It can read what the page can read, send requests as the user and change what they see.

Modern frameworks such as React escape values by default, so the risk comes from the escape hatches: setting inner HTML directly, rendering user-supplied Markdown without cleaning it, or building HTML strings by hand. AI tools reach for these when asked to render rich text.

Keep default escaping on, run any HTML you must render through a maintained sanitizer, and add a Content Security Policy as a second layer. Set session cookies as HttpOnly so a successful script cannot read them.

Sanitize before rendering rich text
import DOMPurify from "dompurify";

const clean = DOMPurify.sanitize(userHtml);

Related terms

Sources

  1. 1.MDN: Cross-site scripting