Can access cards of other markets
The functions `ownerOf` and `onlyTokenOwner` in `RCMarket.sol` do not check that the card ID is less than the total number of cards, allowing a user to supply a larger ID and access cards belonging to other markets. This can be exploited in `upgradeCard` to circumvent the market approval check and potentially steal NFTs.
Submitted by gpersoon
Within RCMarket.sol the functions ownerOf and onlyTokenOwner do not check if the _cardId/_token is smaller than numberOfCards. So it’s possible to supply a larger number and access cards of other markets. The most problematic seems to be upgradeCard. Here the check for isMarketApproved can be circumvented by trying to move the card via another market.
You can still only move cards you own.
function ownerOf(uint256 _cardId) public view override returns (address) {
uint256 _tokenId = _cardId + totalNftMintCount; // doesn't check if _cardId < numberOfCards
return nfthub.ownerOf(_tokenId);
}
https:
modifier onlyTokenOwner(uint256 _token) {
require(msgSender() == ownerOf(_token), "Not owner"); // _token could be higher than numberOfCards,
_;
}
function upgradeCard(uint256 _card) external onlyTokenOwner(_card) { // _card could be higher than numberOfCards,
_checkState(States.WITHDRAW);
require(
!factory.trapIfUnapproved() ||
factory.isMarketApproved(address(this)), // this can be circumvented by calling the function via another market
"Upgrade blocked"
);
uint256 _tokenId = _card + totalNftMintCount; // _card could be higher than numberOfCards, thus accessing a card in another market
_transferCard(ownerOf(_card), address(this), _card); // contract becomes final resting place
nfthub.withdrawWithMetadata(_tokenId);
emit LogNftUpgraded(_card, _tokenId);
}
Recommend adding the following to ownerOf: require(_card < numberOfCards, "Card does not exist");
Splidge (Reality Cards) confirmed but recommended higher severity:
I would assign this a higher severity level, I think it should be 3(High Risk) as this can be used to steal assets. An NFT being an asset as defined in the warden judging criteria found here.
It is planned that eventually market creation will be opened up to anyone. There are several steps along this path towards opening up market creation:
- only the Factory
ownercan create markets- Governors will be assigned who also have the ability to create markets
- Anybody can be allowed to create markets by calling
changeMarketCreationGovernorsOnly- NFTs allowed to be created (or more accurately not burned on market completion) by anyone by calling
changeTrapCardsIfUnapprovedThe key here is that even in step 3 where anybody can create a market, the market will still require Governor approval for it to be displayed in the UI and for the NFT to be allowed to be upgraded. It is here in step 3 that
upgradeCardcould be called on an approved market in order to move a card from an unapproved market.
mcplums (Reality Cards) confirmed:
Agreed, this indeed should have a higher severity- fantastic catch @gpersoon!!
Splidge (Reality Cards) resolved:
Fixed here Impressed also with the simplicity of the solution.
Agree with the higher severity
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely, the functions `ownerOf` and `onlyTokenOwner` lack a bounds check to ensure the provided card ID is less than `numberOfCards`, allowing IDs from other markets to be used.
Impact
An attacker could steal NFTs by moving cards from an unapproved market to an approved one, bypassing the market approval check.
What the attacker needed
Own a card in another market; market creation open to anyone (future step)
The fix
The fix was to add a require statement in `ownerOf` to check that the card ID is less than `numberOfCards`.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
In this smart contract, each market has a set of cards, and the code is supposed to ensure you only interact with cards in your market. However, it forgets to check that the card number you provide is actually within the range of cards for that market. By giving a number that is too large, you can reach into another market's cards, and if you own that card, you might be able to move it in ways that bypass restrictions.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.