Created
September 9, 2019 16:58
-
-
Save MikeRalphson/8e2813b0f762d43e3968805dd11cb43f to your computer and use it in GitHub Desktop.
Clean Array.prototype pollution in Javascript/Node.js
This file contains hidden or 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
Array.prototype.foo = function() { return 'Still callable'; }; | |
function test() { | |
let count = 0; | |
for (const e in []) { | |
console.log('Found '+e); | |
count++; | |
Object.defineProperty(Array.prototype, e, { | |
value: Array.prototype[e], | |
enumerable: false | |
}); | |
} | |
if (!count) console.log('All clean'); | |
} | |
test(); | |
test(); | |
console.log([].foo()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment