Chart.js: Prototype is missing

Created on 20 Oct 2020  ·  4Comments  ·  Source: chartjs/Chart.js

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?

support

All 4 comments

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')

@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 !!!

@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!

Glad it worked @stockiNail 😄

Was this page helpful?
0 / 5 - 0 ratings

Related issues

HeinPauwelyn picture HeinPauwelyn  ·  3Comments

frlinw picture frlinw  ·  3Comments

lizbanach picture lizbanach  ·  3Comments

JAIOMP picture JAIOMP  ·  3Comments

longboy picture longboy  ·  3Comments