Prevent webauthn type check out-of-gas#6429
Prevent webauthn type check out-of-gas#6429james-toussaint wants to merge 9 commits intoOpenZeppelin:masterfrom
Conversation
|
WalkthroughThis PR modifies the WebAuthn signature verification logic in Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
contracts/utils/cryptography/WebAuthn.sol (1)
136-136: Potential integer overflow whentypeIndexis extremely large.If
typeIndex > type(uint256).max - 21, the additiontypeIndex + 21will overflow and revert in Solidity 0.8+. This causes a revert instead of gracefully returningfalse. For consistency with_validateChallenge(which usesMath.saturatingAdd), consider using saturating arithmetic here.♻️ Suggested fix using saturating arithmetic
- if (bytes(clientDataJSON).length < typeIndex + 21) return false; + if (bytes(clientDataJSON).length < Math.saturatingAdd(typeIndex, 21)) return false;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@contracts/utils/cryptography/WebAuthn.sol` at line 136, The length check using "if (bytes(clientDataJSON).length < typeIndex + 21) return false;" can overflow when typeIndex is near uint256 max; update this to use saturating addition (the same approach as _validateChallenge) so the comparison cannot overflow—e.g., compute a saturating sum of typeIndex and 21 via Math.saturatingAdd (or equivalent helper) and compare bytes(clientDataJSON).length against that saturating sum; ensure you reference typeIndex, clientDataJSON, and Math.saturatingAdd/_validateChallenge when making the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@contracts/utils/cryptography/WebAuthn.sol`:
- Line 136: The length check using "if (bytes(clientDataJSON).length < typeIndex
+ 21) return false;" can overflow when typeIndex is near uint256 max; update
this to use saturating addition (the same approach as _validateChallenge) so the
comparison cannot overflow—e.g., compute a saturating sum of typeIndex and 21
via Math.saturatingAdd (or equivalent helper) and compare
bytes(clientDataJSON).length against that saturating sum; ensure you reference
typeIndex, clientDataJSON, and Math.saturatingAdd/_validateChallenge when making
the change.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: d1193455-8237-469c-b968-7a96179a92aa
📒 Files selected for processing (2)
contracts/utils/cryptography/WebAuthn.soltest/utils/cryptography/WebAuthn.t.sol
|
The test that is added here doesn't trigger the out of gas when running with the old version of the library. So its not properly validating the behavior we want to fix because it doesn't trigger it. Note: we already have tests with high challengeIndex in testVerifyIndexOutOfBounds. |
…b.com/james-toussaint/openzeppelin-contracts into chore/prevent-webauthn-type-check-oog
Fixes L-08.
PR Checklist
npx changeset add)