Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 9 commits into from
May 30, 2023

Conversation

david0xd
Copy link
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
Member

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

@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

src/json.ts Outdated Show resolved Hide resolved
Copy link
Member

@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

src/json.ts Outdated Show resolved Hide resolved
src/json.ts Outdated Show resolved Hide resolved
src/json.ts Outdated Show resolved Hide resolved
src/json.ts Outdated Show resolved Hide resolved
src/json.test.ts Outdated Show resolved Hide resolved
src/json.ts Outdated Show resolved Hide resolved
@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