Skip to content

First part of a solution for fixing JSON validation security issue#103

Merged
david0xd merged 9 commits intomainfrom
dd/fix-json-validation-security
May 30, 2023
Merged

First part of a solution for fixing JSON validation security issue#103
david0xd merged 9 commits intomainfrom
dd/fix-json-validation-security

Conversation

@david0xd
Copy link
Copy Markdown
Contributor

@david0xd david0xd commented May 15, 2023

First part to fix an issue around JSON validation.

Second part (PR): MetaMask/snaps#1405

Explanation

This PR resolves the security issue with JSON validation and usage of the validated objects.

JsonStruct is updated to use coerce instead of define and it does sanitization now by having JSON.parse(JSON.stringify(value)) as the return value.
From now it is supposed that validation is done using create function from Superstruct which will return validated and sanitized JSON. New function getValidatedAndSanitizedJson which handles this is added.

isValidJson function is updated in order to use new JsonStruct and keep its return values the same.

On the places (e.g. snaps-monorepo) where JSON structure is validated and used later in the process, getValidatedAndSanitizedJson should always be used.

@david0xd david0xd requested a review from a team as a code owner May 15, 2023 15:55
@david0xd david0xd self-assigned this May 15, 2023
@ritave
Copy link
Copy Markdown
Contributor

ritave commented May 15, 2023

We should merge all parts of this task at the same time so as not to have a release with unsafe JSON.

@david0xd david0xd marked this pull request as ready for review May 18, 2023 16:34
hmalik88
hmalik88 previously approved these changes May 18, 2023
Copy link
Copy Markdown
Contributor

@hmalik88 hmalik88 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@ritave ritave left a comment

Choose a reason for hiding this comment

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

minor stylistical

@david0xd david0xd merged commit 68ef1a9 into main May 30, 2023
@david0xd david0xd deleted the dd/fix-json-validation-security branch May 30, 2023 16:51
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