Skip to content

Charts fail to render when Object prototype is frozen #11528

@AugustasIgneris

Description

@AugustasIgneris

Expected behavior

Chart.js should be able to cope with Object prototype frozen. Object prototype constructor should not be reassigned.

Current behavior

The library attempts to reassign Object prototype constructor and thus breaks if Object prototype is frozen.

Reproducible sample

https://codepen.io/AugustIgner/pen/XWoxROZ?editors=1111

Optional extra steps/info to reproduce

Freeze the Object prototype before rendering a chart: Object.freeze(Object.prototype)
Updating the chart then causes errors such as:

Uncaught TypeError: Cannot assign to read only property 'constructor' of object '#<Object>'
    at qe (chart.umd.js:13:22633)
    at Object.get (chart.umd.js:13:20541)
    at Xe (chart.umd.js:13:22512)
    at chart.umd.js:13:21853
    at chart.umd.js:13:21893
    at qe (chart.umd.js:13:22618)
    at Object.get (chart.umd.js:13:21187)
    at an (chart.umd.js:13:84298)
    at An.buildOrUpdateControllers (chart.umd.js:13:93384)
    at An.update (chart.umd.js:13:94319)

Possible solution

No response

Context

To prevent prototype pollution we freeze Object prototype. Chart.js is the only library we use that has an issues with that.

chart.js version

4.4.0

Browser name and version

No response

Link to your project

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions