Closed shadowspawn closed 2 years ago
Yes, but I am not assuming which lands first.
I'm on the fence about this one, do we want to take away object helper methods from users, for the benefit of having less confusing behavior around edge-cases like a key called "toString"? If someone has a need for this key name, couldn't they use hasOwnProperty to handle the edge case themselves?
Nobody uses object helper methods, precisely because of the risk of collision.
Nobody uses object helper methods, precisely because of the risk of collision.
Argument lands for me, if we want to go this route 👍
Nobody uses object helper methods, precisely because of the risk of collision.
This is a generalisation which is not true in my experience. I see lots of use of object helper methods. I can't know whether because of carefully reasoned balance of the convenience vs the theoretical risk, or dismissal of the risk, or ignorance.
To check my impression, I tried searched for "javascript hasownproperty" and opened the top four links. All were showing how to use the helper method. Some of the pages did also mention or demonstrate the possibility of hasownproperty
being missing (e.g. null prototype) or overwritten and explain alternatives. (And this seems like the helper function mostly likely to go into the issues, given its purpose!)
Only one of the pages actually pointed away from using the helper function with a note at the top of the page:
Note: Object.hasOwn() is recommended over hasOwnProperty(), in browsers where it is supported.
One of the pages introduced an alternative in a small trailing section with :
It's highly unlikely that you will encounter such cases but it's good to be aware of the possibility.
Let's say you're right, and users will be confused by this.
So? The result is hopefully that they'll be educated on how the language works, and their code will be better as a result.
The alternative is that code using parseArgs has a CVE, or worse, is exploited without a CVE. Some amount of confusion from people who misunderstand the language seems far preferable to the likely potential for security exploits ("prototype pollution" CVEs are one of the most popular flavors of the last few years in the npm ecosystem, in my experience).
The alternative is that code using parseArgs has a CVE
I tend to agree, let's err on the side of caution. I really want to avoid having to cut a patch Node.js release for a sporius prototype pollution vulnerability.
The alternative
(That was a pretty loaded comparison, but the concerns are real.)
From an earlier discussion (https://github.com/pkgjs/parseargs/issues/32#issuecomment-1013914178)
@bcoe said:
I think we should create all our objects with null prototypes, Object.create(null).
and @ljharb replied:
That’s good, but isn’t sufficient to protect against prototype pollution because of the dunder proto setter on Object.prototype.
What's the issue here? Is { __proto__: null }
different? Or was this that (Safe)Map is even safer, which was the other thing being discussed?
Yes, it's different. Using it syntactically in an object literal is grammar, and has nothing to do with the setter, which comes into play if someone does foo.__proto__ = bar
(and not foo['__proto__'] = bar
, i believe)
and not
foo['__proto__'] = bar
, i believe
The setter does also apply there. It's just a normal accessor on Object.prototype; it works like every other accessor.
Updated original comment with notes and crack at documentation. I didn't soak up the rest of the utils page for style.
Both the reviews were from when there was just one line of code, so bumped for re-review as much to make sure you were not misrepresented as to give you the opportunity!
Simple code change, with repercussions for tests and documentation.
Closes: #108
Removed the recently added protections when storing option values in
values
.First cut at documentation follows. I gave two shallow examples, just pick one? I went further than the existing reference which didn't unblock my problems. (The caveats and work-arounds could go on a canonical page, if there is somewhere appropriate. I didn't go looking for that, out of scope for my current efforts!)
Reference documentation: https://nodejs.org/api/querystring.html#querystringparsestr-sep-eq-options