Skip to content

Conversation

@zjs81
Copy link

@zjs81 zjs81 commented Jan 20, 2026

Added constructor and prototype to the not allowed keys

@zjs81
Copy link
Author

zjs81 commented Jan 20, 2026

This fixes a potental security issue.

@codecov-commenter
Copy link

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.36%. Comparing base (69295b3) to head (72c8490).
⚠️ Report is 39 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #288   +/-   ##
=======================================
  Coverage   97.36%   97.36%           
=======================================
  Files          16       16           
  Lines        1138     1138           
  Branches      252      252           
=======================================
  Hits         1108     1108           
  Misses         30       30           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gfx gfx merged commit dd2190b into msgpack:main Jan 20, 2026
14 checks passed
@gfx
Copy link
Member

gfx commented Jan 20, 2026

Thanks. Will release a new version immediatly.

@zjs81 zjs81 deleted the fix/complete-prototype-pollution-protection branch January 20, 2026 23:02
@zjs81
Copy link
Author

zjs81 commented Jan 20, 2026

Awesome thank you for your attention on this.

@michaelficarra
Copy link

michaelficarra commented Jan 30, 2026

A better fix would be to just make state.map a null-prototype object in

state.map = {};

state.map = { __proto__: null };

Then you don't have to reject any key names.

Comment on lines +25 to +32
const o = {
foo: "bar",
};
// override constructor as an enumerable property
Object.defineProperty(o, "constructor", {
value: new Date(0),
enumerable: true,
});

Choose a reason for hiding this comment

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

This is the same thing as

Suggested change
const o = {
foo: "bar",
};
// override constructor as an enumerable property
Object.defineProperty(o, "constructor", {
value: new Date(0),
enumerable: true,
});
const o = {
foo: "bar",
constructor: new Date(0),
};

Comment on lines +35 to +37
throws(() => {
decode(encoded);
}, DecodeError);

Choose a reason for hiding this comment

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

Instead of just testing that it fails to decode, you should've instead tested that, even in the hostile environment where you've imagined a current security issue, the library does not trigger it.

@michaelficarra
Copy link

Alternatively, on

state.map[state.key!] = object;

you can just use Object.defineProperty instead of assignment. Either way, there's no need to forbid any key names.

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.

4 participants