Anatomy of the Twitter worm

The worm which made trouble on twitter today is a textbook example of XSS which happens when user input is not properly escaped before being displayed.

Here’s how it worked:

The worm is a tweet which contains the following string:"onmouseover=";$('textarea:first').val(this.innerHTML);

Twitter is converting every string that looks like a link to a clickable link. So is being converted to the following HTML code:

<a href="">

Now twitter has a flaw which improperly handles quotes and at-signs in URLs. E.g it transforms" style="color:red" to

<a href="" style="color:red">" style="color:red"

In the worm’s case, twitter considers the whole tweet as long URL and transforms it into the following code (breaks added for legibility):

     <!-- regular tweet text starts here -->"onmouseover=";$('textarea:first').val(this.innerHTML);
    <!-- regular tweet text ends here -->

So when you hover over the tweet, the following JS is being called:


This tweet adds the worm’s content into the status update field and submits the data. Neat.

What twitter did to fix it, was to fix their conversion engine to escape the quote after the @ so that the the what follows after @” is not considered anymore as attribute of the a tag.

This shows how important sanitization is when handling user input.

This entry was posted in Uncategorized, Web Development. Bookmark the permalink.

Comments are closed.