In a nutshell
XSS: a hijacking trap, planted in your site before you know it. Just like Zeke’s wine.
What else?
It can be planted through an ordinary input box, with no break-in to the server. But the fix is simple.
What Is Cross-Site Scripting (XSS)?
Cross-site scripting runs a script, a set of commands for the browser, across sites. The short form would be CSS, which already names the language for styling web pages, so it is written XSS.
The way in: an ordinary input box
The attacker’s way in is any box anyone can write in: comments, reviews, profiles, contact forms, search boxes.
There is no need to break into the server. As with Sitomo: What Is SQL Injection?, the attacker walks in the front door.
The target is different. SQL injection goes after the site’s database. XSS goes after the people who come to see the page.
Mecha-UjiroEvery site has input boxes, though.
ProfessorThat’s why they’re targeted. Not through the locked back door. In through the front, in disguise.
Planting: commands dressed up as text
The attacker mixes browser commands (a script) into an ordinary review and submits it. The site saves it as one more review.
Ordinary review: It was delicious
Planted review: It was delicious<script>(send the key out)</script>
└─ nothing from <script> on shows on screen
the admin sees only “It was delicious”
Because the command part never shows on screen, it looks like an ordinary review even on the admin’s screen. Before anyone knows it, a trap has been planted in the site.
Mecha-UjiroEven the admin can’t tell? Creepy.
ProfessorZeke’s wine looked like ordinary wine too. Neither the brass it was served to nor the soldiers who drank it knew what was inside.
Serving: the site hands it out itself
When someone opens the page, the site takes the saved content and embeds it in the page it sends back.
It is only supposed to be displayed. But the browser recognizes the planted command and runs it, so the malicious content is executed.
The one handing it out is not the attacker. It is the site.
Infection: the visitor’s browser runs it
To the browser, it looks like a command from this very site, so it trusts it and runs it.
Mecha-UjiroBut the wine doesn’t do anything until the signal is given, right?
ProfessorThat’s the difference. XSS waits for no signal. It runs the moment the page opens.
IPA (Japan’s Information-technology Promotion Agency) and OWASP, an international nonprofit that works on web security, list damage like this (IPA (Japanese), OWASP).
- Impersonation: the key that keeps you logged in (a cookie) is stolen, and the attacker gets in as you.
- Fake screens: a fake login form appears on top of the real site and steals the password you type (Sitomo: What Is Phishing?).
- Acting as you: posts and settings changes are made with the visitor’s own rights.
- Being taken elsewhere: the visitor is sent to a site the attacker prepared.
If the command says “copy this same command into the visitor’s profile too,” every visitor becomes the next server of the wine (see the Samy worm below).
Admins drink it too
Visitors are not the only targets. A command planted in a contact form runs in the browser of the admin who opens it in the admin panel.
Other ways to plant it
OWASP sorts XSS into three types by how it is planted (OWASP). The review example so far is the first.
- Stored: the command is saved in the site’s database and served to everyone who opens the page.
- Reflected: nothing is saved. A URL containing the command is sent by email or social media, and the site bounces the command back only to the person who clicks. Not a cask left out, but a glass handed over one at a time.
- DOM-based: the page sent by the site does not change. A script running in the browser writes a value such as part of the URL straight into the page, and the command runs there (OWASP).
How to keep it from being planted
Closing the hole is the job of the people who build and run the site.
- Escape everything you output: replace symbols such as “<” and “>” with plain characters before putting them on the page. IPA calls this the fundamental fix (IPA (Japanese)).
- Keep the key away from scripts: a cookie marked HttpOnly cannot be read by scripts (MDN).
- Tell the browser which commands may run: with CSP (Content Security Policy), the site specifies where scripts may be loaded from (IPA (Japanese)).
- Allow only http:// and https:// links: do not let commands shaped like URLs through as links (IPA (Japanese)).
How to tell it has been planted
- Check the original source: look at the original source and check for text you never meant to put there.
- Let browsers tell you: if CSP (the rules a site gives the browser about which scripts may run) names a reporting endpoint, the browser sends the site a report when a script breaks the policy (MDN).
- Get a vulnerability assessment: missing escapes can be found by testing. IPA publishes the items to check as its “Web Health Check Specification” (IPA (Japanese)).
- Listen to users: “I was logged out by itself,” “there is a post I never wrote,” “I got sent to a strange page.” Each is a sign of the damage listed above.
Mecha-UjiroIt’s a pain, but if I patrol the pages every day, I’ll find it!
ProfessorPatrolling shows you nothing. What matters is a system that finds it fast.
What to do once it has been planted
When you find it, act in this order.
- Remove the command: delete the planted post or take it offline. Stop it being served.
- Close the entrance: fix the missing escape. Deleting alone lets it be planted again in the same place.
- Make new keys: invalidate on the server any login sessions that may have been stolen, and have users log in again (OWASP). If an administrator opened it, change the administrator’s password too.
- Investigate and report: check the logs for who the attacker acted as and what they did. In Japan, if personal data may have leaked through an act with a wrongful purpose, reporting to the Personal Information Protection Commission is mandatory, whatever the number of people (PPC (Japanese)).
Takeaways
One of the classic injection attacks.
If SQL injection steals information from a site’s database, this one is planted everywhere and takes keys and information from each visitor, one by one. The more visitors, the bigger the damage.
The more influential the site, the more likely it is to be targeted. From here on, smaller sites will be hit hard too. Scary stuff...
Trivia
- Script: a small piece of writing the browser reads and runs as commands. Usually written in JavaScript.
- Cookie: a small note a site leaves with your browser. Also used to remember that you are logged in.
- Escaping: making symbols with special meanings be treated as plain characters.
- CSP: Content Security Policy. A way for a site to tell the browser where scripts may come from.
- Samy Kamkar: the person who planted a self-copying XSS on MySpace in 2005.
- OWASP: an international nonprofit focused on web application security. It publishes the risk ranking “Top 10.”
- IPA: Information-technology Promotion Agency, Japan. A government agency supporting Japan’s IT policy.
History
Beginnings: the day it got a name
From mid-December 1999, Microsoft engineers had been studying a weakness that let scripts be run from another site.
On January 16, 2000, they traded candidate names, and the next day settled on “Cross Site Scripting.” In early February, they issued a warning together with the US CERT (Microsoft).
The weakness was being studied before it even had a name.
Walls and turning points: every viewer becomes the next server
On October 4, 2005, Samy Kamkar planted XSS in his own profile on the social network MySpace.
Anyone who viewed it unknowingly added him as a friend and had the same command copied into their own profile. By his own account, it passed one million users in under 20 hours (Samy Kamkar).
In November 2012, the W3C published the CSP specification, which lets a site specify which scripts may run on a page, as a Candidate Recommendation (W3C). Even if escaping is missed somewhere, the browser now had a way to stop it.
One post can reach a million people in a day. So a defense was added on the browser side too.
Recent moves
Timeline
| Period | Key events | Key people and organizations | Country or region | Notes |
|---|---|---|---|---|
| January 2000 | Microsoft engineers name it “Cross Site Scripting” | Microsoft engineers | United States | Candidates traded on January 16, settled the next day. Warning issued with CERT in early February. [Microsoft](https://learn.microsoft.com/en-us/archive/blogs/dross/happy-10th-birthday-cross-site-scripting) |
| October 2005 | The Samy worm spreads on MySpace | Samy Kamkar | United States | Copied itself into each viewer’s profile; over one million users in under 20 hours (his own account). [Samy Kamkar](https://sa.my/myspace/) |
| November 2012 | CSP becomes a W3C Candidate Recommendation | W3C | Worldwide | Lets a site tell the browser where scripts may come from. [W3C](https://www.w3.org/TR/2012/CR-CSP-20121115/) |
| 2021 | Injection, now including XSS, ranks third in the OWASP Top 10 | OWASP | Worldwide | XSS was folded into the injection category. [OWASP](https://owasp.org/Top10/2021/A03_2021-Injection/) |
| 2025 | Injection ranks fifth in the OWASP Top 10 | OWASP | Worldwide | The 2025 ranking. [OWASP](https://owasp.org/Top10/2025/A05_2025-Injection/) |
| 2025 | XSS ranks first in MITRE’s CWE Top 25 for the second year running | MITRE | United States | Ranked from about 39,000 CVE records published June 2024 to June 2025. [MITRE](https://cwe.mitre.org/top25/archive/2025/2025_cwe_top25.html) |