Skip to content

Instantly share code, notes, and snippets.

@pocotan001
Last active April 29, 2023 15:03
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pocotan001/6305714 to your computer and use it in GitHub Desktop.
Save pocotan001/6305714 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