-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
chore: replace __proto__ by getPrototypeOf #17386
Conversation
Should we add the |
Let's see how it goes |
The CI is failing: |
Oh ! fixed and rebased. |
@@ -184,5 +184,6 @@ function isURL(obj: any): obj is URL { | |||
} | |||
|
|||
function isError(obj: any): obj is Error { | |||
return obj instanceof Error || obj?.__proto__?.name === 'Error' || (obj?.__proto__ && isError(obj.__proto__)); | |||
const proto = obj ? Object.getPrototypeOf(obj) : null; |
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.
This will fail if there is a user code like Object.getPrototypeOf = () => {};
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.
Oh, this is a server side code, we don't run random js here so it should be ok.
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.
Indeed, and obj.__proto__
was an order of magnitude less safe than Object.getPrototypeOf :)
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 you add a test for this?
@@ -184,5 +184,6 @@ function isURL(obj: any): obj is URL { | |||
} | |||
|
|||
function isError(obj: any): obj is Error { | |||
return obj instanceof Error || obj?.__proto__?.name === 'Error' || (obj?.__proto__ && isError(obj.__proto__)); | |||
const proto = obj ? Object.getPrototypeOf(obj) : null; |
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.
Oh, this is a server side code, we don't run random js here so it should be ok.
What do you mean ? this is already tested. The behavior didn't change at all ? |
For the record, the more modules are going to fix this, the more node is likely to get rid of proto ! nodejs/node#31951 |
I mean a test that would fail before your change and pass after, this way we can ensure that this is documented and will not break in the future during refactoring of the code. |
Not a test, but the |
Maybe |
I'm fine with the change, but I don't get the idea behind the option above. We can't guarantee Playwright operation in the mode above, because we use third party modules and |
|
Some users might want to run
--disable-proto=throw|delete
option for a hardened Node.It's easy to fix and doesn't prevent
{ __proto__: null }
pattern.