Other meanings of Cross-site scripting
Cybersecurity
Cross-site scripting (XSS) is a web security vulnerability that allows an attacker to inject malicious scripts into content served to other users, bypassing the same-origin policy that normally isolates websites from one another.1 When a victim visits a vulnerable page, the injected script executes in their browser with the privileges of the trusted site, enabling data theft, session hijacking, and defacement. XSS is among the most prevalent web vulnerabilities, consistently ranking in the OWASP Top 10.2 It arises when applications fail to properly validate or encode user-supplied input before reflecting it in HTML, JavaScript, or other contexts. The impact ranges from minor annoyance to full account compromise, making XSS a critical concern for developers and security professionals alike.
XSS is commonly classified into three main types based on how the malicious script is delivered. Reflected XSS occurs when the injected script is part of a request (e.g., a URL parameter) and is immediately reflected in the response without sanitization; the victim must click a crafted link. Stored XSS persists on the server (e.g., in a database) and executes whenever any user views the affected page, making it more severe. DOM-based XSS arises entirely in client-side JavaScript, where untrusted data modifies the Document Object Model (DOM) without ever being sent to the server. Each type exploits the trust a browser places in a legitimate origin, often bypassing security measures like Content Security Policy if misconfigured.
The consequences of XSS range from data theft to full account takeover. Attackers can steal cookies, session tokens, or credentials, impersonate users, and perform actions on their behalf. In 2005, the Samy worm exploited a stored XSS vulnerability in MySpace, spreading to over one million users within hours.3 More recently, XSS has been used to deliver ransomware, deface government sites, and mine cryptocurrencies in visitors' browsers. The 2020 Twitter Bitcoin scam, though not purely XSS, highlighted how social engineering combined with script injection can cause widespread financial damage. Even low-severity XSS can be chained with other vulnerabilities, such as CSRF, to escalate privileges.
Defense against XSS requires a multi-layered approach. The primary countermeasure is output encoding—escaping user-controlled data according to the context (HTML, attribute, JavaScript, CSS, or URL) before rendering.4 Input validation, using allowlists for expected formats, reduces attack surface. Content Security Policy (CSP) acts as a secondary defense, restricting script sources and blocking inline scripts. Modern frameworks like React and Angular auto-escape by default, but developers must still avoid dangerous APIs like innerHTML. Regular security testing, including automated scanners and manual penetration testing, helps identify gaps. The OWASP Cheat Sheet Series provides detailed guidance on each mitigation technique.
Beyond the basics, XSS has subtle and surprising dimensions. Mutation XSS (mXSS) exploits browser parser quirks to bypass sanitizers, as demonstrated in 2013 by researchers who found that HTML5 parsing could mutate supposedly safe markup into executable scripts. Universal XSS (UXSS) occurs when a browser vulnerability allows script injection across all origins, often via flawed extension APIs. XSS has also been used as a vector for client-side denial of service, where scripts consume excessive resources. In 2019, a stored XSS in the popular MathJax library was used to steal credentials from academic sites. Additionally, XSS can be leveraged for port scanning and keylogging without the victim's knowledge, turning a simple injection into a full surveillance tool.
This article focuses on the web security vulnerability sense of cross-site scripting, not the unrelated programming technique of the same name.
Help improve the encyclopedia. Reports go straight to the site manager.