Last active
April 29, 2023 15:03
-
-
Save pocotan001/6305714 to your computer and use it in GitHub Desktop.
Finding improper JavaScript globals.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// globals.js | |
// https://gist.github.com/pocotan001/6305714 | |
// Finding improper JavaScript globals | |
(function() { | |
var prop, cleanWindow, | |
globals = new function globals() {}, | |
body = document.body, | |
iframe = document.createElement('iframe'), | |
ignore = { | |
console: true, | |
Components: true, | |
XPCNativeWrapper: true, | |
XPCSafeJSObjectWrapper: true, | |
getInterface: true, | |
GetWeakReference: true | |
}; | |
globals.__proto__ = null; | |
iframe.src = 'about:blank'; | |
body.appendChild(iframe); | |
cleanWindow = iframe.contentWindow; | |
for (prop in window) { | |
if (!(prop in cleanWindow) && !ignore[prop] && !/^\d/.test(prop)) { | |
globals[prop] = window[prop]; | |
} | |
} | |
console.group('Found %c' + Object.keys(globals).length + '%c JavaScript globals.', 'color: red', ''); | |
console.dir(globals); | |
console.groupEnd(); | |
body.removeChild(iframe); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment