XSS
How it works
1) The attacker identifies an entry point where user-controlled data (URL parameter, form field, header, database content) is placed into a response without neutralization. 2) They craft a payload containing script markup or code (e.g., <script>, an onerror event attribute, a javascript: URI). 3) The payload is delivered: in Reflected XSS via a crafted link or request whose script is immediately reflected in the response; in Stored XSS by persisting the payload on the server (comment, forum post, log) so it is served to subsequent visitors; in DOM-based XSS via client-side JavaScript that writes untrusted data into a dangerous sink (e.g., innerHTML) without the data ever leaving the browser. 4) The victim's browser executes the script in the trusted site's origin, gaining access to cookies, session tokens, and the DOM, enabling session hijacking, data theft, keylogging, or further requests on the victim's behalf.
Problem solved
Names and organizes the class of vulnerabilities in which untrusted input reaches an executable browser context (HTML, attributes, JavaScript, CSS, URL) without proper encoding or sanitization. Understanding XSS enables defenses—context-aware output encoding, HTML sanitization, and Content Security Policy—that keep data as data rather than code.
Components
The injected script is immediately reflected off the server in a response (e.g., an error message or search result) and executes when the victim opens a crafted link or request. Also called non-persistent or Type-I XSS.
The malicious script is permanently stored on the target server (database, forum, visitor log, comment field) and served to subsequent users. Also called persistent or Type-II XSS. Blind XSS is a stored form whose payload executes later, when a back-end administrator views the content.
A client-side vulnerability, identified in 2005, occurring when JavaScript manipulates the DOM using untrusted data, writing it into a dangerous sink (e.g., innerHTML, document.write, eval) without server involvement.
Implementation
Using innerHTML, document.write, eval, or framework escape hatches (React dangerouslySetInnerHTML, Angular bypassSecurityTrustAs*, Lit unsafeHTML) to insert user-controlled data bypasses built-in protections and leads to DOM-based XSS.
Placing data without encoding appropriate to its context (HTML, attribute, JavaScript, CSS, URL) allows breaking out of the data context. HTML encoding does not protect inside <script>, HTML comments, <style> blocks, or event-handler attributes.
Attempting to block XSS with blacklists of words/characters is easy to bypass (encoding, alternative vectors, new HTML elements) and creates a false sense of security.
Content Security Policy is sometimes mistaken for a primary defense; misconfigured or overly permissive policies (e.g., unsafe-inline) will not stop XSS, and uniform enterprise-wide policies can break legacy systems.
Evolution
Microsoft security engineers coined the term 'cross-site scripting'; CERT/CC published advisory CA-2000-02 describing injection of malicious HTML tags in web requests.
DOM-based XSS was described as a distinct client-side variant in which the payload never leaves the browser.
In the OWASP Top 10 (2013), Cross-Site Scripting was ranked as its own risk category, A3.
In the OWASP Top 10 (2021), Cross-Site Scripting was folded into the broader A03:2021 – Injection category.