Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Facebook disable the browser's integrated Developer Tools?

So apparently because of the recent scams, the developer tools is exploited by people to post spam and even used to "hack" accounts. Facebook has blocked the developer tools, and I can't even use the console.

Enter image description here

How did they do that?? One Stack Overflow post claimed that it is not possible, but Facebook has proven them wrong.

Just go to Facebook and open up the developer tools, type one character into the console, and this warning pops up. No matter what you put in, it will not get executed.

How is this possible?

They even blocked auto-complete in the console:

Enter image description here

like image 328
Derek 朕會功夫 Avatar asked Feb 11 '14 03:02

Derek 朕會功夫


People also ask

How does Facebook disable integrated Developer Tools?

Just go to Facebook and open up the developer tools, type one character into the console, and this warning pops up. No matter what you put in, it will not get executed.

Can a website disable Developer Tools?

You can't prevent users from opening the developer's tools in the browser, that's for sure. At the end of all, they will be able always to open it through the settings of the browser and selecting Developer Tools.

How do I disable the console on my website?

To disable Javascript console, we need to throw an exception in the get accessor by checking if the property attached by chrome developer tool exists. With this script above, user won't be allowed to enter Javascript in the console. It also blocks auto-complete in console too.


2 Answers

I'm a security engineer at Facebook and this is my fault. We're testing this for some users to see if it can slow down some attacks where users are tricked into pasting (malicious) JavaScript code into the browser console.

Just to be clear: trying to block hackers client-side is a bad idea in general; this is to protect against a specific social engineering attack.

If you ended up in the test group and are annoyed by this, sorry. I tried to make the old opt-out page (now help page) as simple as possible while still being scary enough to stop at least some of the victims.

The actual code is pretty similar to @joeldixon66's link; ours is a little more complicated for no good reason.

Chrome wraps all console code in

with ((console && console._commandLineAPI) || {}) {   <code goes here> } 

... so the site redefines console._commandLineAPI to throw:

Object.defineProperty(console, '_commandLineAPI',    { get : function() { throw 'Nooo!' } }) 

This is not quite enough (try it!), but that's the main trick.


Epilogue: The Chrome team decided that defeating the console from user-side JS was a bug and fixed the issue, rendering this technique invalid. Afterwards, additional protection was added to protect users from self-xss.

like image 61
Alf Avatar answered Sep 26 '22 15:09

Alf


I located the Facebook's console buster script using Chrome developer tools. Here is the script with minor changes for readability. I have removed the bits that I could not understand:

Object.defineProperty(window, "console", {     value: console,     writable: false,     configurable: false });  var i = 0; function showWarningAndThrow() {     if (!i) {         setTimeout(function () {             console.log("%cWarning message", "font: 2em sans-serif; color: yellow; background-color: red;");         }, 1);         i = 1;     }     throw "Console is disabled"; }  var l, n = {         set: function (o) {             l = o;         },         get: function () {             showWarningAndThrow();             return l;         }     }; Object.defineProperty(console, "_commandLineAPI", n); Object.defineProperty(console, "__commandLineAPI", n); 

With this, the console auto-complete fails silently while statements typed in console will fail to execute (the exception will be logged).

References:

  • Object.defineProperty
  • Object.getOwnPropertyDescriptor
  • Chrome's console.log function (for tips on formatting output)
like image 40
Salman A Avatar answered Sep 24 '22 15:09

Salman A