Skip to content

Instantly share code, notes, and snippets.

@pocotan001
Last active April 29, 2023 15:03
Show Gist options
  • 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