
Cross-site scripting (XSS) is a web application vulnerability that lets an attacker inject malicious script into pages that other users view. Because the script runs in the context of the trusted site, it can read data, act as the user or change what the page shows. OWASP describes XSS as a type of injection, and it is catalogued as CWE-79.
In each case, the root cause is user input that reaches the page without proper encoding or validation.
XSS can be used to steal session data, enabling session hijacking, or to show fake login forms on a real domain. Defenses include context-aware output encoding, input validation, frameworks that escape output by default, a Content Security Policy and cookies marked HttpOnly. Regular testing of public web applications, as part of managing the external attack surface, helps find these flaws before attackers do.
Sources: OWASP: Cross Site Scripting (XSS), CWE-79: Improper Neutralization of Input During Web Page Generation (‘Cross-site Scripting’)