Skip to main content
Legia

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.

Related Legia service Penetration Testing Manual testing that proves how far a vulnerability can be exploited, with the evidence to back it up.