Skip to content
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

Prototype is missing #7935

Closed
stockiNail opened this issue Oct 20, 2020 · 4 comments
Closed

Prototype is missing #7935

stockiNail opened this issue Oct 20, 2020 · 4 comments

Comments

@stockiNail
Copy link
Contributor

Using the CHART.JS from master and probably related to PR #7920, I got the following exception:

hasOwnProperty is not a function

I got this issue because I'm using prototypes methods to interact with/on the object.
Going more in details, I discovered I was using only hasOwnProperty, as prototype method.

As workaround I changed the calls that method to the static one Object.getOwnPropertyDescriptor, checking the result equals to null.
Now I'm testing it but I have another workaround if I see other issues, to use Object.keys and indexOf of the array to check the the key is part of the object or not (I think it's less performances).

What do you think about the workarounds? Do you think there is anything better?

@etimberg
Copy link
Member

We made that change due to a reported security issue. During the config merge process, it the user supplied a specific object, they could overwrite Object.prototype in insecure ways. By preventing the prototype from being added to the options objects, we can prevent that (along with a filter to #7919 to block the bad key).

I believe there is a workaround through

const obj = Object.create(null);
obj.a = true;

// Causes an error
obj.hasOwnProperty('a')

// Works and returns the correct response
Object.prototype.hasOwnProperty.call(obj, 'a')

@stockiNail
Copy link
Contributor Author

@etimberg Unfortunately that is easy in javascript... But I'm not using it, I'm using java...

Nevertheless I can do it as you described, even if a bit more complex that what I have done. I'm gonna test it and give you a feedback.

Thank you very much !!!

@stockiNail
Copy link
Contributor Author

@etimberg I have implemented your code and it works perfectly (I did't have any doubt about that!).

The good thing sounds it's better (in terms of performance) than my workarounds!

THANK A LOT!

@etimberg
Copy link
Member

Glad it worked @stockiNail 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants