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
Fix: issues with v4 tempering and obfuscation #277
Merged
Merged
Conversation
This file contains 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
phanshiyu
changed the title
wip: draft of changes to address issues raised
Fix: issues with v4 tempering and obfuscation
May 1, 2024
HJunyuan
reviewed
May 2, 2024
HJunyuan
approved these changes
May 2, 2024
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.
Why
We have the following problems:
1. Document can be tempered with by inserting empty
[]
or{}
while passing verificationLeaf node
We define leaf node as a value in an object that does not have any children:
string | number | boolean | null | empty objects | empty arrays
The way we compute our hash (>v3) has always been over leaf nodes, but did not include
empty objects | empty arrays
. This allow[]
or{}
to be inserted into the document while still passing validation.2. Document can be tempered with by changing the values from one type to the other provided they are string coerced to the same value. ie,
true
can be changed to"true"
This is how we hash each leaf node, as you can see, no type info is being accounted
3. Obfuscation does not error when it leaves behind new leaf nodes
How we perform obfuscation and allow the document to still verify as valid hinges on the fact that the obfuscation does not create a new leaf node; but you can imagine taking out all keys in an object would essentially have that effect, ie
y: { x: 1 }
is not leaf node, since it has a child, but now if we obfuscatex
, we y now becomes a leaf node (see above on definition of leaf node).The case with removing an item from an array can be illustrated below:
in js land
removing the first item from
[0,1]
will yieldall good, empty items are not considered leaf node, so it does not affect the verification.. RIGHT!?
in JSON land
becomes
wait...
null
is a new leaf node; verification failsWhat
traverseAndFlatten
our method to find leaf nodes will not include empty arrays and objects