Skip to content

Instantly share code, notes, and snippets.

@spiralx
Forked from pocotan001/globals.snippets.js
Created August 12, 2016 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spiralx/3b0c64b6e7d7547b4732cffbc0fdc0ec to your computer and use it in GitHub Desktop.
Save spiralx/3b0c64b6e7d7547b4732cffbc0fdc0ec to your computer and use it in GitHub Desktop.
Finding improper JavaScript globals.
// 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