Submitted by popular00, also found by gzeon
CidNFT.sol#L147
CidNFT.sol#L165
CidNFT.sol#L237
High - an attacker can steal deposited NFTs from victims using the mint() + add() functionality in CidNFT.sol
One of the core features of CID Protocol is the ability for users to attach Subprotocol NFTs to their CidNFT. The CidNFT contract custodies these attached NFTs, and they are regarded as traits of the user.
The protocol currently includes functionality for a user to mint a CidNFT as their identity and then optionally add a subprotocol NFT to that CidNFT in the same transaction. This occurs in the mint() function of CidNFT.sol, which takes a byte array of add() parameters and includes a loop where add() can be repeatedly called with these parameters to attach subprotocol NFTs to the CidNFT.
One of the arguments for add() is the _cidNFTID to which the user would like to attach their outside NFT. However, _cidNFTID is specified in calldata to mint(), and there is no guarantee that the user is actually add()ing to the CidNFT that they just minted. There is only a check in add() that the user is either the owner or approved for that CidNFT.
This opens up the following attack:
Below is a forge test executing this attack. This should run if dropped into CidNFT.t.sol.
OpenCoreCH (Canto Identity) confirmed and commented:
