- WWDC 2009
- Protocol Inheritance in Objective-C
- The Problem of Trust
- nil
- App Store
- Pandora for iPhone version 2.0
- Awards
- Podcast Interview on Mobile Orchard
- Mobile Orchard
- Harmony
- The Ajax Experience
- Overwhelmed
- Programming Language in a Web Page: The Conundrum
- Chess and Politics
- Winter Daze
- Your Facebook Profile Doesn’t *Really* Matter, Does It?
- Projects
- Beyond DOM
- About Me
- Disphoria
- Generators and Erlang Processes
- The Auto-Update Problem
- You Want Me To Do What?
- The Case for ES4
- The Story Behind ES4
Facebook Security Hole #1
Wednesday, August 8, 2007This is the first post in a series detailing the security holes I find in FBJS. Hopefully others will find this info useful, if for no other reason than to learn some neat JavaScript pony tricks.
Securing Facebook (and JS in the browser generally) boils down to 3 over-arching tenets:
- prevent execution of arbitrary JavaScript
- prevent access to the window/global object
- prevent direct access to DOM elements
Bypassing any of these three access controls gives, at the very least, the ability for a hacker to violate someone’s privacy. At worst, an exploit can cause downtime the Facebook service.
The first security hole was the easiest and least interesting hack. It bypasses access control #1 by making use of an old, arcane behavior of the setTimeout method, namely that you can pass a string as the code to execute:
setTimeout("alert('arbitrary JavaScript')", 1);
Facebook (or more specifically Marcel Laverdet) fixed this by checking the datatype of the first argument to setTimeout:
fbjs_sandbox.set_timeout = function(js,timeout) {
if(typeof js!='function') {
fbjs_console.error(...);
} else {
return setTimeout(js, timeout);
}
}
Simple enough. As I said, the hacks get more interesting as we progress.
Thus far I’ve found six security holes in FBJS. I’m sure there are many more, it’s just a matter of finding time to find the holes. To Facebook and Marcel’s credit, they are aggressive about fixing the holes that I find. So while I might complain that the approach of sandboxing-plus-code-generation isn’t an acceptably secure strategy, I’m reassured that they take the issue of security seriously.
Please note that I’m posting these “exploits” publicly only after they’ve been fixed. Facebook is doing all the right things to responsibly handle these security exploits. It would be irresponsible and downright mean to publish early.
...Original article from http://www.neilmix.com/2007/08/07/facebook-security-hole-1/