Detect if function is native to browser

前端 未结 5 1054
借酒劲吻你
借酒劲吻你 2020-11-30 07:38

I am trying to iterate over all the globals defined in a website, but in doing so I am also getting the native browser functions.

var numf=0; var nump=0; v         


        
5条回答
  •  春和景丽
    2020-11-30 08:15

    Function.prototype.toString can be spoofed, something kinda like this:

    Function.prototype.toString = (function(_toString){
      return function() {
        if (shouldSpoof) return 'function() { [native code] }'
        return _toString.apply(this, arguments)
      }
    })(Function.prototype.toString)
    

    You can detect if Function.prototype.toString is vandalized by trapping .apply(), .call(), .bind() (and others).

    And if it was, you can grab a "clean" version of Function.prototype.toString from a newly injected IFRAME.

提交回复
热议问题