lib: make Error objects instantiation less vulnerable to prototype pollution#46065
lib: make Error objects instantiation less vulnerable to prototype pollution#46065aduh95 wants to merge 2 commits intonodejs:mainfrom
Error objects instantiation less vulnerable to prototype pollution#46065Conversation
|
Review requested:
|
|
|
||
| const messages = new SafeMap(); | ||
| const codes = {}; | ||
| const codes = ObjectCreate(null); |
There was a problem hiding this comment.
| const codes = ObjectCreate(null); | |
| const codes = { __proto__: null }; |
this is equally robust and avoids a function call.
There was a problem hiding this comment.
I do prefer this, but I know Antoine prefers the other, and the diff is pretty "6 of one".
There was a problem hiding this comment.
Why the preference?
Even setting aside that Object.create is a regretted addition to the JS language, it's still got the potential overhead of a function call, as compared to the very straightforward syntax that node already uses with objects initialized with more than one property. Why is "no properties" a special case that requires a function call?
There was a problem hiding this comment.
it's still got the potential overhead of a function call
I don't think that should be a concern here because lib/internal/errors.js is already a part of the snapshot, so this code won't get executed at startup, rather the context would get deserialized from the snapshot.
There was a problem hiding this comment.
ok, fair - it’s still indirection, and it’s using an API call for something that’s available with syntax.
There was a problem hiding this comment.
This is a style question that’s out of scope for this PR. If someone feels strongly about this, they should open a new PR that updates our eslint to enforce a particular style.
There was a problem hiding this comment.
yes thanks, i'm sure that won't get bogged down in blocks, i'll get right on that
There was a problem hiding this comment.
(that was landed, so this can be resolved)
| * @returns {T} | ||
| */ | ||
| function assignOwnProperties(obj, ...sources) { | ||
| const descriptors = ObjectCreate(null); |
There was a problem hiding this comment.
| const descriptors = ObjectCreate(null); | |
| const descriptors = { __proto__: null }; |
|
Benchmak CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1287/ Results |
BridgeAR
left a comment
There was a problem hiding this comment.
I do not think we should do this. It increases the implementation complexity signficantly and reduces the performance of a critical part of the application.
mcollina
left a comment
There was a problem hiding this comment.
The slowdown is not acceptable in this specific case.
Errors are already a slow path for us given all the modifications we do to them, and we should not slow them down further.
Having a more robust
Errorinstantiation makes sure the user would get the actual error rather than an unrelated one if the prototype was altered somewhere else.Before this change:
After this change: