Is possible to disable Javascript/Jquery from the browser inspector console?

ぐ巨炮叔叔 提交于 2019-12-12 09:18:25

问题


Hi i was thinking about if there could be any way of disable the ability to change the javascript/jquery from the inspector console?

Just in case you want to avoid that a user interacts and change things from the DOM using the console, or maybe send forms avoiding some checks from javascript.

Or is impossible to do that and you just have to do all the security or this kind of things on the serverside?

Thanks!


回答1:


Yes to disable the console just run this on the client

Object.defineProperty(console, '_commandLineAPI', {
    get : function() {
        throw "Console is disabled";
    }
});

This won't leave then to use the console.

Note: There isn't a 100% secure option to get around this, but at least doing this won't allow console usage. Add security to your server to see which request are legit.

Also this will only work in Chrome this is because Chrome wraps all the console code in:

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

Firefox has a different way to wrap the code from the console. This is why this is not a 100% secure protection from console commands




回答2:


Anything on the client side is never going to be fully secure. This is because it can be manipulated not only by the browser's developer tools, but by any number of other 3rd party tools.

The server itself must be fully secured, because there is no way of guaranteeing that a request is even being made from the web site itself, let alone that the javascript validation was not tampered with.



来源:https://stackoverflow.com/questions/22204658/is-possible-to-disable-javascript-jquery-from-the-browser-inspector-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!