To prevent prototype pollution, filter out merge functions and specifically remove underscore, underscore, proto, underscore, underscore. Lodash has fixed all instances of prototype pollution. When using as-owned property, ensure it exists on the object and not its prototype chain. Building defensive objects using Object.create or Object.createNull can prevent prototype pollution. Sanitization and data validation are crucial for preventing outside attacks. Consider using libraries like joy for data sanitization when building a Node.js web server. Node.js has an option to disable proto, underscore, underscore, proto, underscore, underscore, but be cautious as it may break some code.
How to prevent prototype pollution because I'm a responsible person, I don't want you to feel scared and say, you know, let's use a language without prototypes like Python. How to prevent? Well, let's filter out, you know, merge functions. You see, for instance online nine here, line nine, nine, three, or online four here, that we filter out, underscore, underscore, proto, underscore, underscore. And that's what we've been fixing a lot of libraries. Lodash has been adding more prototype pollution than any other library I know, and they've been all fixed one by one. If you find a new one, feel free to responsibly disclose it to their maintainer, whatever libraries it is.
Sometimes, you will know that your code path is critical and you want to make sure that you're using as-owned property. Well, well, as-owned property can be tampered with with third-party attacks, but that's something else. So make sure that if you expect a property to exist on an object, you make sure that it exists on the object and not on its prototype chain. Also, this one I like. It's what I call building defensive object. I don't know if that's the academic term, but you can use Object.create and that will create a new object with its arguments as prototype. Well, null is an object. So you can do Object.createNull. These objects won't have all the methods you expect them to have as-owned property, as-owned symbols, get-owned-property descriptors, but this object will be safe from prototype pollutions because it doesn't have any prototype.
Sanitization, make sure that stuff that gets in your process from the outside are safe. Do data validation. I love the joy library because I'm a happy, happy thin fat boy, but there are a lot of amazing libraries to do data sanitization. Use them. They are very cool. And anyway, you should use them if you're building a web server with Node.js. As mentioned that will also probably remove your surface of attack to no secret injection. So go for it.
Conclusions. Oh my god, I'm on time. What's now? Monitor incoming objects Node.js has an option to disable proto, underscore, underscore, proto, underscore, underscore. It might break some code. So be warned that it might break some code because the Internet but you can use it. And for sanitization and prototype less object. Oh, you remember why I told you should use Python? That was a joke in January.
Comments