Please enable JavaScript to use CodeHS

Cyber Attack Stories · Case 03

The MySpace Worm: “but most of all, samy is my hero”

In October 2005, a 19-year-old hid a few lines of code in his MySpace profile. Everyone who simply viewed his page added him as a friend — and became the next carrier. Twenty hours later: one million profiles.

Web worm · 2005 ~11 min Grades 6–9
The True Story

One million friends, overnight

In 2005, the biggest social network on Earth was MySpace. Your profile was your identity: you picked the songs, the glittery background, and your "Top 8" friends list — a ranking that could start real drama at school.

Samy Kamkar was a 19-year-old from Los Angeles who taught himself to code. He wanted more MySpace friends, and he noticed the site let you customize your profile with HTML — the same language web pages are written in. Just after midnight on October 4, 2005, he hid some JavaScript code inside his own profile page.

The code did three quiet things whenever anyone viewed his profile: it added Samy to the viewer's friends list, wrote "but most of all, samy is my hero" at the bottom of their profile, and — here's the worm part — copied itself into the viewer's profile too. Anyone who later viewed that profile got infected the same way. No clicks, no downloads, no warning. Just looking at a page was enough.

Samy went to bed thinking it might earn him a few hundred friends. He woke up to thousands of new friend requests per hour. Within about 20 hours, more than a million profiles displayed "samy is my hero" — making it, at the time, the fastest-spreading computer virus ever. MySpace had to take the whole site offline to scrape the code out of a million pages.

XSS WORM
What happened
The Samy worm (JS.Spacehero) spread through MySpace profiles by self-copying code. Over a million profiles were infected in about 20 hours — the fastest spread ever recorded at that point.
When
October 4, 2005. MySpace briefly shut down to clean it up.
Who
Samy Kamkar, a self-taught 19-year-old programmer from Los Angeles.
The catch
It didn't need anyone to download or click anything. Visiting a profile page ran the code automatically.

How It Worked

When the website runs your words

A web page is made of two kinds of text: words meant to be read (like your bio) and code meant to be run (like the scripts that make buttons work). Your browser can't tell the difference on its own — it's the website's job to draw the line.

MySpace let members decorate profiles with HTML. Samy realized MySpace's filters were incomplete: they blocked obvious ways of smuggling in scripts, but missed others. He found the gaps one by one — hiding the word "javascript" inside a style rule, splitting it with a line break, and using a browser quirk that ran script inside image properties. It took cleverness, but in the end MySpace was treating his typed-in words as runnable code.

That's cross-site scripting, or XSS: an attacker slips code into a page by typing it into a field the site then displays to other people — a comment, a bio, a username. The victim's browser runs the attacker's code as if the website itself wrote it, because in a way, it did.

Simple definition: cross-site scripting (XSS) is when a website displays user-submitted text as if it were part of the site's own code. If a comment box accepts <script> and the page runs it, every visitor to that page is in trouble. The defense is called escaping — turning special characters like < into harmless text before showing them.

Because the code lived inside the profiles themselves, each view copied it forward — a "stored" worm that never needed email or downloads. It's the same family of trick used in XSS attacks today, and cousins of it show up wherever a site displays what users type.


The Fallout

What happened after

For Samy, the fallout was personal. He later wrote that as the friend requests piled up past anything he imagined, he got scared: he deleted the profile, thinking maybe that would erase the whole thing. It didn't — by then the copies lived on a million other profiles. Within days, law enforcement was involved. Months later, the Secret Service raided his home.

In 2007, Kamkar took a plea deal on a felony computer-hacking charge: three years of probation, 90 days of community service, about $15,000–$20,000 in restitution, a suspended prison sentence hanging over him — and, originally, a lifetime ban on using the internet. A judge later lifted the internet ban; the rest stood.

For the rest of us, the fallout was architectural. MySpace rebuilt its filters. Web developers everywhere learned to escape user input by default, and modern browsers added defenses like Content Security Policy that make stored XSS much harder. Kamkar himself became a well-known security researcher — the kind companies pay to find holes before the internet's villains do.

RoundNew profiles infectedRunning total (est.)
Hour 01 profile (Samy's)1
Hour 8~200 friend requests an hourhundreds
Hour 13~2,500 friends added, thousands of requeststhousands
Hour 20hundreds of thousands more1,000,000+

Exact counts are estimates reported by Kamkar and news coverage at the time; the shape is what matters — each viewer became a carrier, so the spread went exponential.


Interactive

Escape or not?

Below is a pretend "profile text" box, like the one Samy typed into. Type anything — try <b>cool</b> or <script>samy</script> — and see the difference between a site that escapes your text (shows it as words) and one that doesn't (runs it as code).

PROFILE TEXT → WHAT VISITORS SEE
escaped — shown as text
not escaped — run as code

Try typing HTML like <b>, <i>, <marquee>, or a fake <script> tag. On the left it stays words; on the right, the page treats it as code and the markup renders — that's the XSS door Samy walked through. (Scripts are sandboxed in this demo, but on the real 2005 MySpace they ran for real.)


The Habit

Viewing a page should never be dangerous

Samy's worm didn't steal passwords or delete files — but it could have. The same trick can carry much worse cargo. The habits that matter:

1

Stick to sites that take input seriously

Modern sites escape user text automatically. A sketchy site that renders whatever people type is a riskier place to hang out.

2

Your posts are code-adjacent

When a site lets you add HTML or scripts to a profile or comment, what you publish runs in other people's browsers. Never embed code you don't understand — copying a "cool trick" can make you the worm author.

3

Weird profile text? Report it

"samy is my hero" showed up because profiles could carry hidden code. Strange text appearing on your own page means the site — or your account — needs a cleanup.

4

Experiment in sandboxes

Samy's bug-testing belonged on a test page, not on a million strangers. Curiosity is a superpower — aim it at systems you own or have permission to poke.

Remember: the web feels passive, but pages are programs. If a site doesn't escape what users type, simply reading a page can run someone else's code.


Talk About It

Try it with your family or class

Pick one of these to talk about at dinner, in the car, or with a classmate.

  • Samy wanted popularity and got a million fake "friends" overnight. What do follower counts and friend lists actually measure? Did his plan even work?
  • He got probation, community service, and a suspended prison sentence — for a prank that mostly wrote a joke line on profiles. Too harsh, too soft, or just right?
  • Where else does a website display what users type — comments, reviews, display names, bios? What could hidden code in each of those places do?

Your Turn

Check your understanding

In your own words: what is cross-site scripting, and why did it let the Samy worm spread to a million profiles without anyone downloading or clicking anything?

Your answer:

Sample answer: Cross-site scripting is when a website shows text a user typed in as if it were part of the site's own code, so the visitor's browser runs it. Samy hid JavaScript in his MySpace profile, so everyone who viewed his page automatically ran code that added him as a friend, wrote "samy is my hero," and copied the same code into their own profile — spreading it to the next viewer. The site forgot to escape user input, so just viewing a profile was enough to get infected.


Check Yourself

Quick quiz

1. How did the Samy worm infect new profiles?

2. What is cross-site scripting (XSS)?

3. Which defense would have stopped the Samy worm?

Next: the worm that locked up hospitals

Samy's worm was a prank. In 2017, a worm with a ransom note attached swept through 150 countries in a single day — until a researcher found its accidental off switch.

Part of the Cyber Attack Stories tutorial series.