Skip to content

fix(utils): prevent prototype pollution in deepExtend - #3287

Open
lahirumaramba wants to merge 2 commits into
mainfrom
lm-fix-deep-extend
Open

lahirumaramba wants to merge 2 commits into
mainfrom
lm-fix-deep-extend

Conversation

@lahirumaramba

Copy link
Copy Markdown
Member

Prevent prototype pollution in deepExtend

@lahirumaramba lahirumaramba added the release:stage Stage a release candidate label Oct 14, 2026
@lahirumaramba
lahirumaramba requested a review from a team October 14, 2026 21:21

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request adds a security check to the deepExtend function in src/utils/deep-copy.ts to prevent prototype pollution by skipping __proto__, constructor, and prototype properties. The feedback suggests adding unit tests to verify that these prototype pollution vectors are successfully blocked and to prevent future regressions.

Comment thread src/utils/deep-copy.ts
Comment on lines +76 to +78
if (prop === '__proto__' || prop === 'constructor' || prop === 'prototype') {
continue;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

security-medium medium

While the prototype pollution check is correct, there are no unit tests included in this pull request to verify that deepExtend successfully blocks prototype pollution attempts (e.g., using __proto__, constructor, or prototype). Adding unit tests for these edge cases is highly recommended to prevent future regressions. For example, you can add tests like:\n\ndescribe('deepExtend prototype pollution', () => {\n it('should not pollute prototype via proto', () => {\n const payload = JSON.parse('{"proto": {"polluted": true}}');\n deepExtend({}, payload);\n expect((Object.prototype as any).polluted).to.be.undefined;\n });\n\n it('should not pollute prototype via constructor', () => {\n const payload = JSON.parse('{"constructor": {"prototype": {"polluted": true}}}');\n deepExtend({}, payload);\n expect((Object.prototype as any).polluted).to.be.undefined;\n });\n});

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release:stage Stage a release candidate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant