chore: add prototype pollution guards to setState and SnapController#3719
Open
odaysec wants to merge 1 commit intoMetaMask:mainfrom
Open
chore: add prototype pollution guards to setState and SnapController#3719odaysec wants to merge 1 commit intoMetaMask:mainfrom
odaysec wants to merge 1 commit intoMetaMask:mainfrom
Conversation
poratoes
approved these changes
Nov 5, 2025
Author
|
/cc @FrederikBolding |
| if (FORBIDDEN_KEYS.includes(currentKey)) { | ||
| // Explicitly block prototype pollution keys | ||
| if ( | ||
| FORBIDDEN_KEYS.includes(currentKey) || |
Member
There was a problem hiding this comment.
FORBIDDEN_KEYS already include __proto__ etc.
| if (rate) { | ||
| accumulator[conversion.from] ??= {}; | ||
| accumulator[conversion.from][conversion.to] = rate; | ||
| if (!accumulator.has(conversion.from)) { |
Member
There was a problem hiding this comment.
The results processed in this function come from BaseSnapExecutor, where the result is passed through getSafeJson:
This function eliminates any disallowed properties like __proto__
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
request strengthens security across multiple components of the MetaMask Snaps codebase by addressing potential prototype pollution vulnerabilities in recursive state assignment and object accumulation logic.
these fixes prevent malicious user input from mutating JavaScript object prototypes or altering inherited behavior, thereby improving the overall safety and robustness of Snaps runtime operations.
Issue: #3718
Mitigate Prototype Pollution in
setState(packages/snaps-rpc-methods/src/permitted/setState.ts)The recursive assignment function used in
setStatecould inadvertently allow prototype pollution if untrusted keys such as__proto__,constructor, orprototypewere used as property names during state updates.This issue could enable malicious payloads to modify global object prototypes, leading to unpredictable behavior or security compromises.
Secure Object Construction in
SnapControllerConversion Logic (packages/snaps-controllers/src/snaps/SnapController.ts#L3946)Within the logic that constructs
filteredConversionRatesfromrequestedConversions, plain JavaScript objects were being used to store user-derived keys (conversion.fromandconversion.to).Since object property keys can interact with the prototype chain, this pattern risked prototype pollution if untrusted input was introduced.
Prevent Pollution in Market Data Transformation (
#transformOnAssetsMarketDataResult)In the private method
#transformOnAssetsMarketDataResult, user-derivedassetandunitstrings were used as keys during reduction to constructfilteredMarketData.As with the previous issue, this pattern risked prototype pollution via implicit property inheritance.
Note
Adds explicit prototype pollution guards in setState and switches SnapController asset transform reducers to safe accumulators, preserving output shape.
packages/snaps-rpc-methods/src/permitted/setState.ts:set(...): Rejects keys__proto__,constructor,prototype(in addition to existing forbidden keys); updates error message.packages/snaps-controllers/src/snaps/SnapController.ts:#transformOnAssetsConversionResult(...): UsesMap→Mapaccumulator during reduction; converts nestedMaps back to plain objects for return.#transformOnAssetsMarketDataResult(...): UsesObject.create(null)for nested objects to avoid prototype inheritance.Written by Cursor Bugbot for commit 700c6b6. This will update automatically on new commits. Configure here.