CyberGlossary

Attacks & Threats

Cross-Site Scripting (XSS)

Also known as: XSS

Definition

A web vulnerability that allows attackers to inject malicious scripts into pages viewed by other users, executing in the victim's browser under the site's origin.

Cross-Site Scripting (XSS) occurs when a web application includes untrusted input in its responses without proper escaping or sanitization, allowing attacker-controlled JavaScript to run in the victim's browser. The three main classes are reflected XSS (payload sent in a request and echoed back), stored XSS (payload persisted server-side, e.g. in comments), and DOM-based XSS (vulnerability lives in client-side code). Successful XSS can hijack sessions, steal tokens, deface pages, deliver malware, or pivot through SSRF and CSRF. Defences include context-aware output encoding, strict Content-Security-Policy, framework templating, HTTPOnly and SameSite cookies, and input validation.

Examples

  • A stored XSS payload in a forum post steals session cookies from every reader that views the thread.
  • A reflected XSS in a search parameter executes JavaScript supplied by an attacker via a crafted link.

Related terms