Explore our new Cybersecurity Terms Glossary, explained by our experts.
Cybersecurity Terms Glossary
Cross-site scripting (XSS) is a web vulnerability that lets an attacker inject JavaScript into a trusted page, so it runs in visitors’ browsers with the site’s own permissions.

What Is Cross-Site Scripting (XSS)?
Cross-site scripting (XSS) is a vulnerability in which an application includes untrusted input in a web page without handling it safely, so the browser treats that input as code. The attacker’s JavaScript then runs in the victim’s browser under the vulnerable site’s origin, with access to everything the page can see and do. Unlike server-side injection, XSS targets the people using the application rather than the server itself.
Browsers trust any script delivered by a site as if the site wrote it. If a search page prints You searched for: <script>…</script> without encoding the angle brackets, the browser cannot tell that part of the page came from an attacker. Once running, the injected script can read page content, call internal APIs as the logged-in user, capture keystrokes, rewrite forms, or steal session tokens that are not protected by the HttpOnly flag.
The Samy worm of October 2005 showed the scale this can reach. A stored XSS payload on a MySpace profile added its author as a friend and copied itself to every visitor’s profile, spreading to more than a million accounts in under a day.
The payload travels in the request, usually a URL parameter, and the server echoes it straight back in the response. The victim has to be lured into opening a crafted link, which is why reflected XSS often pairs with phishing. Each attack typically hits one user at a time.
The payload is saved by the application—in a comment, a profile field, a support ticket, a product review—and served to everyone who views it. No link is needed, and a single injection can affect every user, including administrators. A variant known as blind XSS fires in a back-office tool that the attacker never sees, such as a helpdesk console or log viewer.
The flaw sits entirely in client-side JavaScript. Code reads attacker-controlled data from a source such as location.hash or postMessage and passes it to a dangerous sink such as innerHTML, eval(), or document.write(). The server response may be identical for every visitor, so server-side scanners often miss it.
XSS is CWE-79 and falls under A03 Injection in the OWASP Top 10 2021; it remains within the Injection category in the 2025 edition. It is still one of the most frequently reported issues on bug bounty platforms because modern applications have so many places where data and markup meet.
A close relative is client-side script tampering of the Magecart kind. In the 2018 British Airways breach, attackers modified a script on the airline’s payment pages to skim card details, and the ICO fined the company £20 million in 2020. That was not classic XSS, but it shows the same point: whoever controls the JavaScript on your page controls what your customers type into it.
No single control is enough, but the following combination stops the vast majority of attacks:
dangerouslySetInnerHTML or bypassSecurityTrustHtml.unsafe-inline, blocks injected scripts even when encoding fails. Trusted Types adds similar protection for DOM sinks in Chromium-based browsers.HttpOnly and Secure so scripts cannot read them, while remembering that XSS can still act as the user without the cookie.Automated scanners such as Burp Suite and ZAP find many reflected cases, but stored, blind, and DOM-based flaws usually need a human who understands the application’s data flows and front-end code. Our web application security services combine both approaches, and developers who want to fix the root cause can build the skills through our web application security training.
Often, yes. An injected script can read session tokens that lack the HttpOnly flag, change the account’s email address or password through the application’s own forms, or quietly add a new API key. Even with well-protected cookies, the script acts with the victim’s full permissions while the page is open. Stored XSS that reaches an administrator is especially dangerous because it can compromise the whole application.
A strict, nonce-based Content Security Policy blocks most injected scripts, but it is a safety net rather than a fix. Weak policies that allow unsafe-inline, broad CDN domains, or JSONP endpoints can be bypassed. CSP also does not prevent HTML injection used for phishing or data exfiltration through other channels. Treat it as a second layer behind correct output encoding.
No, although they help a great deal. React, Angular, and Vue escape output by default, which removes many classic mistakes. XSS still appears when developers use raw HTML features, build URLs from user input without checking the scheme, render server-side templates unsafely, or rely on third-party components with their own flaws. Code review and testing remain essential.
You May Be Interested In These
Cybersecurity Terms
17 November 2026
What Is the Information and Communication Security Guide?
Read MoreWe use a few cookies that are needed to make this website work, and they are always on. We would also like to set analytics cookies, to see which pages are useful; functional cookies, so that our live chat works; and advertising cookies, to measure our campaigns. We will not set any of those until you say yes, and you can change your mind at any time from the Cookie Settings link in the footer.
Choose the cookies you are happy for us to use. Strictly necessary cookies are always on; everything else is off until you turn it on.
These cookies keep the website working: they hold your security checks, your form submissions and the choice you make here. The site cannot run without them, so they are always on.
These let our live chat open and remember your conversation, and let the newsletter sign-up work. Switch them off and the chat window will not appear.
These tell us which pages are read and how people find us, so that we can improve the site. The reports are about groups of visitors, never about you personally.
These let us measure our advertising and show you our adverts on other websites, such as LinkedIn, Google and Meta. Switch them off and you will still see adverts, but they will be less relevant.