Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Invalid

Unauthorized Access for NFT Owners

Summary

The current implementation of the tokenURI function in the smart contract disallows NFT owners from viewing their NFTs. This is due to the conditional check on whether the owner of the token with the given tokenId is the zero address. If it is, the transaction reverts with the error message MondrainWallet__InvalidTokenId. This check effectively prevents legitimate NFT owners from accessing the URI associated with their tokens.

Vulnerability Details

Steps to Reproduce:

  • Deploy the smart contract implementing the ERC721 standard for NFTs.

  • Mint one or more NFTs to different addresses.

  • Attempt to retrieve the URI associated with any of the minted NFTs using the tokenURI function while being the owner of the NFT.

Expected Behavior:

  • NFT owners should be able to view the URI associated with their NFTs using the tokenURI function without encountering any errors.

Actual Behavior:

  • NFT owners are unable to view the URI associated with their NFTs due to the conditional check in the tokenURI function. The transaction reverts with the error message MondrainWallet__InvalidTokenId, indicating an invalid token ID.

Impact

This issue prevents NFT owners from accessing important metadata associated with their NFTs, such as name, image, and other attributes. It also disrupts the intended functionality of the ERC721 standard, which is to provide a standardized interface for non-fungible tokens, including the ability for owners to access metadata via the tokenURI function.

Tools Used

Manual

Recommendations

Modify the tokenURI function to remove the conditional check that prevents access for NFT owners. Instead of reverting the transaction when the owner of the token is the zero address, consider implementing a different error handling mechanism that allows legitimate NFT owners to access the URI associated with their tokens. This could involve returning an empty string or emitting an event to notify the caller of the invalid token ID without reverting the transaction.

Code Snippet
function tokenURI(uint256 tokenId) public view override returns (string memory) {
// Remove the conditional check to allow NFT owners to view their NFTs or tweak the conditional to allow owners only view their
- if (ownerOf(tokenId) == address(0)) { revert MondrainWallet__InvalidTokenId(); }
+ if (ownerOf(tokenId) != address(0)) { revert MondrianWallet__NotFromEntryPointOrOwner; }
uint256 modNumber = tokenId % 10;
if (modNumber == 0) {
return ART_ONE;
} else if (modNumber == 1) {
return ART_TWO;
} else if (modNumber == 2) {
return ART_THREE;
} else {
return ART_FOUR;
}
}
Updates

Lead Judging Commences

inallhonesty Lead Judge
about 1 year ago
inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Too generic
emiridbest Submitter
about 1 year ago
inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Invalidated
Reason: Too generic

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.