Cross-Site Scripting
Injecting attacker-controlled script into a page that a victim's browser then executes with the victim's own privileges.
Cross-Site Scripting is a vulnerability class where an attacker gets their own script to run inside a page in a victim's browser, under that page's own origin — meaning the script can read cookies, make authenticated requests, and manipulate the Document Object Model exactly as the site's legitimate code could. The attacker never touches the victim's session directly; they trick the victim's own browser into running code on their behalf.
The three variants differ in where the malicious payload lives. Stored XSS persists the payload server-side — a comment field, a profile bio — so it executes for every visitor who views that content, which is why it's the most dangerous variant: one injection, many victims, no interaction required beyond viewing a page. Reflected XSS bounces the payload off the server in a single response, typically via a URL parameter echoed back unescaped, requiring the victim to click a crafted link. DOM-based XSS never touches the server at all — client-side script reads something attacker-controlled, like location.hash, and writes it into the page unsafely, so the vulnerability lives entirely in front-end code a server-side scanner won't see.
The root cause across all three is the same: untrusted input rendered into a context — HTML, a script tag, an attribute — without escaping appropriate to that context. The fix is equally uniform: escape on output, at the point data crosses into HTML, not on input, since data legitimately used in multiple contexts needs different escaping for each. Modern frameworks that auto-escape interpolated values by default (React's JSX, Vue's templates) close most of the surface automatically; dangerouslySetInnerHTML and its equivalents exist precisely to name the escape hatch, so a reviewer can spot it.
Content Security Policy is the layer that limits damage after an injection succeeds anyway — it's a mitigation, not a substitute for escaping.
See also4
Content Security Policy
An HTTP header that tells the browser which sources of script, style, and other content a page is allowed to load.
Web Platform6 connections
Document Object Model
The live tree of objects a browser builds from a document, and the surface every UI framework writes to.
Web Platform18 connections
Same-Origin Policy
The browser rule isolating documents by scheme, host, and port, and the mechanisms for relaxing it.
Web Platform15 connections
Cross-Origin Resource Sharing
The mechanism by which a server opts in to letting scripts on other origins read its responses.
Web Platform5 connections
Related1
Nearby in the graph rather than deliberately chosen. Looser, sometimes surprising.
Linked from4
- Content Security PolicyWeb Platform
An HTTP header that tells the browser which sources of script, style, and other content a page is allowed to load.
- Cross-Origin Resource SharingWeb Platform
The mechanism by which a server opts in to letting scripts on other origins read its responses.
- JSON Web TokenWeb Platform
A signed, self-contained token that carries claims a server can verify without a database lookup.
- OAuthWeb Platform
A protocol for granting one application limited access to a user's data on another, without handing over the user's password.