Cybersecurity
What is XSS (Cross-Site Scripting)?
Also called cross-site scripting, XSS.
Short definition
XSS (cross-site scripting) is a flaw that lets an attacker inject scripts into a website's pages, so the scripts run in other visitors' browsers and can steal login sessions or change how the page looks.
The three known types
Stored XSS happens when a malicious script is saved in the database, for example through a comment field or profile name, and then shown to everyone who opens that page. Reflected XSS bounces a script back from a page address sent to the victim as a link. DOM-based XSS happens entirely in the browser, when the page's JavaScript inserts unsafe data into the display.
The impact
A script running in your site's name can read data shown to users, perform actions on behalf of a logged-in user, display a fake login form, or redirect visitors to another site. If the victim is an admin, the attacker can take over the website's management panel. Because the script runs from the real domain, visitors have no easy way to tell it apart from legitimate site content.
How to prevent it
All user data is encoded for the place where it is displayed: in HTML, attributes, or JavaScript. Modern frontend frameworks do this by default, unless a developer deliberately turns it off. A Content Security Policy (CSP) limits which scripts may run on a page. Session cookies are given the HttpOnly attribute so scripts cannot read them. Outdated CMS plugins and themes are a frequent source of XSS.
Resources
- OWASP: Cross Site Scripting (XSS) (owasp.org)
- MDN Web Docs: Cross-site scripting (XSS) (developer.mozilla.org)