Skip to content

fix: prevent prototype pollution in Chart.defaults path APIs#12268

Open
csworm-rudraksha wants to merge 1 commit into
chartjs:masterfrom
csworm-rudraksha:fix/prototype-pollution-12265
Open

fix: prevent prototype pollution in Chart.defaults path APIs#12268
csworm-rudraksha wants to merge 1 commit into
chartjs:masterfrom
csworm-rudraksha:fix/prototype-pollution-12265

Conversation

@csworm-rudraksha

Copy link
Copy Markdown

Description

This PR fixes a prototype pollution vulnerability in Chart.defaults path-based APIs reported in #12265.

Changes

  • Added isValidScopePath() function to validate path segments before walking them
  • Modified getScope() to reject dangerous path segments (__proto__, prototype, constructor)
  • Throws descriptive error messages when invalid scope paths are detected

Affected APIs

All path-based defaults APIs are now protected:

  • Chart.defaults.set(scope, values)
  • Chart.defaults.get(scope)
  • Chart.defaults.describe(scope, values)
  • Chart.defaults.override(scope, values)
  • Chart.defaults.route(scope, name, targetScope, targetName)

Security Impact

Before: Attackers could pollute Defaults.prototype via paths like __proto__ or constructor.prototype, affecting all charts in the same realm.

After: Dangerous path segments are rejected early with clear error messages, preventing prototype pollution.

Testing

Verified using the reproduction case from the security report. All attack vectors now throw Invalid defaults scope errors:

Chart.defaults.set('__proto__', {xPolluted: 'test'});
// Error: Invalid defaults scope: __proto__

Chart.defaults.set('constructor.prototype', {evilColor: '#bad'});
// Error: Invalid defaults scope: constructor.prototype

Chart.defaults.route('__proto__', 'routePolluted', '', 'color');
// Error: Invalid defaults scope: __proto__

Closes #12265

- Add isValidScopePath() to validate path segments
- Reject '__proto__', 'prototype', and 'constructor' in scope paths
- Fixes chartjs#12265 - prototype pollution gadget vulnerability

This prevents prototype pollution via Chart.defaults.set(), get(),
describe(), override(), and route() methods by validating path
segments before walking them.
Copilot AI review requested due to automatic review settings June 26, 2026 18:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens Chart.js’ path-based Chart.defaults APIs against prototype pollution by validating dotted scope strings before walking them in getScope().

Changes:

  • Added scope-path segment validation to reject __proto__, prototype, and constructor
  • Updated getScope() to throw a descriptive error when an invalid scope is provided

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/core/core.defaults.js
Comment on lines +25 to +27
if (!isValidScopePath(key)) {
throw new Error(`Invalid defaults scope: ${key}`);
}
Comment thread src/core/core.defaults.js
Comment on lines +11 to +15
function isValidScopePath(key) {
return !key.split('.').some((part) => (
part === '__proto__' || part === 'prototype' || part === 'constructor'
));
}
Comment thread src/core/core.defaults.js
Comment on lines +25 to +27
if (!isValidScopePath(key)) {
throw new Error(`Invalid defaults scope: ${key}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Security: Prototype pollution gadget in Chart.defaults path APIs

2 participants