This is an old version, saved 5 Dec 2026, 05:27 by TechWritereditor. See the current version.

Cross-site scripting

Cross-site scripting (XSS) is a type of security flaw in websites that lets an attacker slip malicious code, usually JavaScript, into pages that other people then view. The victim's Web browser has no way to know that the script should not be trusted, so it runs it as if the site itself had sent it.[1]

Contents
  1. How it works
  2. History
  3. Defences
  4. See also
  5. References

How it works

XSS is a form of injection. It happens when a web application includes input from users in the pages it sends out without first checking or encoding that input.[1] Browsers normally follow the same-origin policy, under which code from one site cannot reach the data of another. In an XSS attack the attacker gets round this by tricking the target site into running the code within its own context.[2]

There are three main kinds. In reflected XSS the script bounces straight back from the server in a single response, such as an error message or search result. In stored XSS the script is saved on the server, for example in a forum post or comment, and is served to everyone who views that content. DOM-based XSS, identified by Amit Klein in 2005, is a kind of XSS that takes place in code running in the browser. The effects range from annoyance to full takeover of an account, most seriously by stealing the session HTTP cookie that keeps a user logged in.[1]

History

The name was settled by a small group of Microsoft security engineers in January 2000: several names were discussed on 16 January, and the group agreed on "cross site scripting" the next day. A coordinated advisory with the CERT security centre followed in early February 2000.[3]

Defences

MITRE's Common Weakness Enumeration lists XSS as weakness CWE-79 and describes proper output encoding, escaping and quoting as the most effective way to prevent it. Marking session cookies as HttpOnly helps keep them away from scripts.[4] Mozilla's developer documentation also recommends sanitising HTML and, as a backup, using a strict Content Security Policy that stops the browser running injected code.[2]

The problem remains common. Between July 2024 and July 2025, XSS made up 15% of the important or critical cases handled by the Microsoft Security Response Center, which paid $912,300 in bounty awards for XSS reports.[5]

See also

References

  1. ^ Cross Site Scripting (XSS). OWASP Foundation. community.owasp.org
  2. ^ Cross-site scripting (XSS). Mozilla (MDN Web Docs). developer.mozilla.org
  3. ^ Happy 10th birthday Cross-Site Scripting!. Microsoft. 2009-12-15. learn.microsoft.com
  4. ^ CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'). MITRE. cwe.mitre.org
  5. ^ Why XSS still matters: MSRC's perspective on a 25-year-old threat. Microsoft Security Response Center. 2025-09-04. microsoft.com