Skip to content

Security: sanitize sensitive keys in merge functions#26756

Closed
themilessky01 wants to merge 1 commit intoemscripten-core:mainfrom
themilessky01:main
Closed

Security: sanitize sensitive keys in merge functions#26756
themilessky01 wants to merge 1 commit intoemscripten-core:mainfrom
themilessky01:main

Conversation

@themilessky01
Copy link
Copy Markdown

This change prevents Prototype Pollution vulnerabilities by filtering out sensitive keys like proto, constructor, and prototype during object merging in utility.mjs

This change prevents Prototype Pollution vulnerabilities by filtering out sensitive keys like __proto__, constructor, and prototype during object merging in utility.mjs
Comment thread src/utility.mjs
// Sanitize 'other' object before Object.assign to prevent prototype pollution
const keys = Object.keys(other);
for (const key of keys) {
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Object.keys already doesn't include any of these.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Hi @sbc100,
I understand your point about Object.keys, but the concern is when other comes from a source where these properties are enumerable (for example, when using JSON.parse on a specially crafted string).
Here is a simple PoC that shows how the pollution can happen if we don't have these checks:

const payload = JSON.parse('{"proto": {"polluted": "yes"}}');
const target = {};
// If mergeInto uses Object.assign or a loop on enumerable keys:
Object.assign(target, payload);
console.log({}.polluted); // In some environments/scenarios, this could lead to pollution

My goal is to ensure Emscripten's core utilities are robust against such untrusted inputs. If you feel Object.keys is sufficient for the current implementation, I'd appreciate your guidance on the preferred way to strictly enforce this safety for all contributors.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Emscripten is compiler. We already trust the inputs so its not an issue for us.

The JS library files passed to the compiler already have full access to all node API, so there is no limit to their power and we trust them fully.

@themilessky01
Copy link
Copy Markdown
Author

themilessky01 commented Apr 23, 2026 via email

@sbc100
Copy link
Copy Markdown
Collaborator

sbc100 commented Apr 23, 2026

Closing for now. Feel free to re-open.

@sbc100 sbc100 closed this Apr 23, 2026
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.

2 participants