fix(webauthn): Enhance JSON key search to prevent pattern injection, and fix Barz.getDiamondCutCode#4747
Open
sergei-boiko-trustwallet wants to merge 3 commits intomasterfrom
Open
fix(webauthn): Enhance JSON key search to prevent pattern injection, and fix Barz.getDiamondCutCode#4747sergei-boiko-trustwallet wants to merge 3 commits intomasterfrom
Barz.getDiamondCutCode#4747sergei-boiko-trustwallet wants to merge 3 commits intomasterfrom
Conversation
Binary size comparison➡️ aarch64-apple-ios: 14.36 MB ➡️ aarch64-apple-ios-sim: - 14.37 MB
+ 14.37 MB +1 KB➡️ aarch64-linux-android: 18.81 MB ➡️ armv7-linux-androideabi: 16.23 MB ➡️ wasm32-unknown-emscripten: - 13.72 MB
+ 13.72 MB +1 KB |
Barz.getDiamondCutCode
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens WebAuthn clientDataJSON key-index discovery to avoid ambiguous/malicious matches and fixes DiamondCut calldata padding to prevent underflow on unaligned init data, adding regression tests for both areas.
Changes:
- Update
find_json_key_indexto validate keys via JSON parsing and reject ambiguous raw matches. - Fix DiamondCut init-data padding calculation to correctly pad to 32-byte boundaries without underflow.
- Add unit tests covering the DiamondCut padding edge case and WebAuthn key-search ambiguity.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
rust/tw_evm/tests/barz.rs |
Adds a regression test for unaligned init_data to ensure padding logic doesn’t underflow. |
rust/tw_evm/src/modules/webauthn.rs |
Adds JSON parsing + stricter matching for key-index lookup; introduces unit tests for ambiguity/injection scenarios. |
rust/tw_evm/src/modules/barz/core.rs |
Corrects padding-length computation to standard modulo-based padding for 32-byte alignment. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
This pull request introduces important bug fixes and security improvements to the
barzandwebauthnmodules, with a focus on correct data padding and robust JSON key detection. It also adds new tests to ensure these behaviors are properly validated.Bug fixes and correctness improvements:
get_diamond_cut_codeto prevent potential overflow or incorrect padding wheninit_datais not aligned to the encoding chunk size.Security and robustness improvements:
find_json_key_indexfunction inwebauthn.rsto accurately locate a key in a JSON string by parsing the JSON and ensuring the key occurs exactly once, preventing false positives from injected or repeated keys.find_json_key_indexcorrectly rejects injected or multiple key occurrences, increasing security against malicious input.Testing and validation:
get_diamond_cut_codeto ensure correct behavior wheninit_datais not aligned to 32 bytes, confirming that no subtraction overflow occurs and the output is as expected.Code quality:
serde_json::ValueasJsonto support the improved JSON parsing logic.