Skip to content
Access control Audit finding Intermediate

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.

gpersoon Follow

Originally disclosed on Code4rena

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:

  1. only the Factory owner can create markets
  2. Governors will be assigned who also have the ability to create markets
  3. Anybody can be allowed to create markets by calling changeMarketCreationGovernorsOnly
  4. NFTs allowed to be created (or more accurately not burned on market completion) by anyone by calling changeTrapCardsIfUnapproved

The 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 upgradeCard could 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.

dmvt (Judge) commented:

Agree with the higher severity

The original report as published on Code4rena, by gpersoon. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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.

More by gpersoon

View all

47 more disclosed reports, best first.

More from Reality Cards (round 2)

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.