-
Notifications
You must be signed in to change notification settings - Fork 10
Fix critical security vulnerabilities in VouchMe contract #23
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
base: main
Are you sure you want to change the base?
Fix critical security vulnerabilities in VouchMe contract #23
Conversation
📝 WalkthroughWalkthroughThe VouchMe contract now extends ReentrancyGuard and applies the nonReentrant modifier to Changes
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@contracts/src/VouchMe.sol`:
- Around line 278-281: The delete in _removeTestimonialFromList only clears the
_testimonials[tokenId] struct but leaves ERC721 ownership and tokenURI data
(ERC721._owners and ERC721URIStorage._tokenURIs) intact; change
_removeTestimonialFromList to burn the NFT (call _burn(tokenId)) after deleting
testimonial data so ownership and tokenURI storage are cleared, and update the
_update function (or transfer blocker) to permit burns while still preventing
transfers by allowing _burn to bypass the transfer-blocking check; ensure you
reference and use the existing _burn method from ERC721/ERC721URIStorage and
adjust any transfer guard that previously blocked burns so burns succeed but
normal transfers remain blocked.
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
contracts/src/VouchMe.sol
🔇 Additional comments (1)
contracts/src/VouchMe.sol (1)
8-10: The import path@openzeppelin/contracts/utils/ReentrancyGuard.solis correct for OpenZeppelin v5. OpenZeppelin v4 usessecurity/while v5 usesutils/. Since the code uses the v5 path, the import will compile correctly with OpenZeppelin v5.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
| function _removeTestimonialFromList(uint256 tokenId, address sender, address receiver) internal { | ||
| // Delete testimonial data to fix memory leak | ||
| delete _testimonials[tokenId]; | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
find . -type f -name "VouchMe.sol" | head -5Repository: StabilityNexus/VouchMe
Length of output: 93
🏁 Script executed:
cat -n contracts/src/VouchMe.sol | head -100Repository: StabilityNexus/VouchMe
Length of output: 4659
🏁 Script executed:
cat -n contracts/src/VouchMe.sol | sed -n '270,330p'Repository: StabilityNexus/VouchMe
Length of output: 2354
🏁 Script executed:
# Check the full _removeTestimonialFromList and surrounding context
cat -n contracts/src/VouchMe.sol | sed -n '275,320p'Repository: StabilityNexus/VouchMe
Length of output: 2170
🏁 Script executed:
# Check _update method
rg -n "_update" contracts/src/VouchMe.sol -A 5Repository: StabilityNexus/VouchMe
Length of output: 420
🏁 Script executed:
# Check the imports to understand ERC721 inheritance
head -50 contracts/src/VouchMe.solRepository: StabilityNexus/VouchMe
Length of output: 1893
Deletion leaves ERC721 ownership and tokenURI queryable after removal.
delete _testimonials[tokenId] only clears the testimonial struct. ERC721URIStorage's _tokenURIs mapping and ERC721's _owners mapping remain intact, so the token still exists as an NFT, its URI is still queryable, and storage isn't fully reclaimed. To achieve complete cleanup, burn the token and modify _update to allow burns while blocking transfers.
🧹 Suggested fix (burn + allow burns while blocking transfers)
function _removeTestimonialFromList(uint256 tokenId, address sender, address receiver) internal {
// Delete testimonial data to fix memory leak
delete _testimonials[tokenId];
+ // Burn to clear ownership + URI storage (gas refund)
+ _burn(tokenId);
@@
function _update(address to, uint256 tokenId, address auth) internal override returns (address) {
- require(_ownerOf(tokenId) == address(0), "Tokens are non-transferrable");
+ address from = _ownerOf(tokenId);
+ // Allow mint (from == 0) and burn (to == 0); block transfers
+ require(from == address(0) || to == address(0), "Tokens are non-transferrable");
return super._update(to, tokenId, auth);
}Also applies to: 308-318
🤖 Prompt for AI Agents
In `@contracts/src/VouchMe.sol` around lines 278 - 281, The delete in
_removeTestimonialFromList only clears the _testimonials[tokenId] struct but
leaves ERC721 ownership and tokenURI data (ERC721._owners and
ERC721URIStorage._tokenURIs) intact; change _removeTestimonialFromList to burn
the NFT (call _burn(tokenId)) after deleting testimonial data so ownership and
tokenURI storage are cleared, and update the _update function (or transfer
blocker) to permit burns while still preventing transfers by allowing _burn to
bypass the transfer-blocking check; ensure you reference and use the existing
_burn method from ERC721/ERC721URIStorage and adjust any transfer guard that
previously blocked burns so burns succeed but normal transfers remain blocked.
Summary
This PR addresses critical security vulnerabilities discovered in the VouchMe smart contract.
-Added Reentrancyguard in createTestimonial and deleteTestimonial
-Added
delete _testimonials[tokenId]Impact
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.