New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: make validateObject less affected by prototype tampering
#42929
lib: make validateObject less affected by prototype tampering
#42929
Conversation
|
Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1133/ No significant perf decrease or improvments |
|
@nodejs/tsc can this get some reviews please? |
lib/internal/validators.js
Outdated
| @@ -140,6 +141,10 @@ function validateBoolean(value, name) { | |||
| throw new ERR_INVALID_ARG_TYPE(name, 'boolean', value); | |||
| } | |||
|
|
|||
| function getOwnPropertyValueOrDefault(options, key, defaultValue) { | |||
| return options == null || !ObjectPrototypeHasOwnProperty(options, key) ? defaultValue : options[key]; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we use Object.hasOwn in node core now? https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s not available in primordials because it can be disabled with a runtime flag
node/deps/v8/src/flags/flag-definitions.h
Line 339 in d96a2ea
| V(harmony_object_has_own, "harmony Object.hasOwn") \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the info.
a05b2c6
to
5ddd351
Compare
Is the rule of thumb going to be that we pass objects with a null prototype to V8 built-ins, but that we don't use null prototypes and instead only check own properties for our own utility functions?
|
I think for internals, it's probably simpler to only check own properties because we never use inheritance on |
LGTM as long as we don't start passing objects with null prototypes to such functions.
|
Landed in b4a7d9f |
PR-URL: #42929 Reviewed-By: Tobias Nießen <tniessen@tnie.de>


No description provided.