Skip to content

fix: prototype pollution vulnerability in extend (CVE-2024-45435)#1433

Merged
dangreen merged 3 commits intochartist-js:mainfrom
andersk:proto
Apr 7, 2025
Merged

fix: prototype pollution vulnerability in extend (CVE-2024-45435)#1433
dangreen merged 3 commits intochartist-js:mainfrom
andersk:proto

Conversation

@andersk
Copy link
Contributor

@andersk andersk commented Oct 2, 2024

@tariqhawis
Copy link

Hi @andersk ,

Thank you for your feedback regarding the report. I would like to highlight an additional prototype accessor: constructor.prototype. A potential injection could look like this:

extend ({}, JSON.parse('{"constructor":{"prototype":{"polluted":yes}}}'))"

Checking for the presence of constructor in the input should be sufficient.

Best,
Tariq

@andersk andersk force-pushed the proto branch 2 times, most recently from 4801823 to 17cffef Compare October 2, 2024 20:41
@andersk
Copy link
Contributor Author

andersk commented Oct 2, 2024

Checking for the presence of constructor in the input should be sufficient.

Nope, it’s not.

extend({}, {"hasOwnProperty": {"polluted": "yes"}});
console.log(Object.prototype.hasOwnProperty.polluted); // → yes

I’ve pushed a more complete fix.

@andersk andersk force-pushed the proto branch 4 times, most recently from 6745108 to 12b84bd Compare October 2, 2024 21:10
rockerBOO added a commit to rockerBOO/chartist that referenced this pull request Nov 8, 2024
@praveen-zensar
Copy link

praveen-zensar commented Jan 20, 2025

Please merge this fix as it's a severity score is high.

const source = sources[i];
const targetProto = Object.getPrototypeOf(target);
for (const prop in source) {
if (targetProto !== null && prop in targetProto) {
Copy link

@danielpalme danielpalme Feb 9, 2025

Choose a reason for hiding this comment

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

I propose the following change for this line:
if (prop === "__proto__" || prop === "constructor" || (targetProto !== null && prop in targetProto)) {

See: https://codeql.github.com/codeql-query-help/javascript/js-prototype-pollution-utility/

Copy link
Contributor Author

@andersk andersk Apr 7, 2025

Choose a reason for hiding this comment

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

Your change isn’t necessary because both __proto__ and constructor are already skipped by targetProto !== null && prop in targetProto.

@@ -11,7 +11,11 @@ export function extend<T, A, B>(target: T, a: A, b: B): T & A & B;
export function extend(target: any = {}, ...sources: any[]) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

All usage cases are where first argument is empty object. We can rename extend to merge, remove first argument, and as target use Object.create(null).

I can fix it by myself later on next week

Copy link

Choose a reason for hiding this comment

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

seems that @andersk might not be able to help here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No I agree in principle, but here’s the problem: Chartist.extend is part of the public API of this package, and if we bump the semver major version to remove it, that’s going to take years to propagate through the ecosystem…

@dangreen
Copy link
Collaborator

dangreen commented Apr 7, 2025

@andersk You should run "update storyshots" action manually in your fork. Then download artifacts and update screenshots in your branch.

@andersk

This comment was marked as resolved.

@andersk

This comment was marked as resolved.

@dangreen dangreen merged commit 5a24b93 into chartist-js:main Apr 7, 2025
5 of 6 checks passed
@andersk andersk deleted the proto branch April 7, 2025 18:45
@dangreen
Copy link
Collaborator

dangreen commented Apr 7, 2025

https://github.com/chartist-js/chartist/releases/tag/v1.3.1

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.

[Bug]: Prototype Pollution Vulnerability Affecting chartist module, versions >=1.0.0 <=1.3.0

6 participants