when NFT position is transferred, approvals are not cleared #74
Labels
3 (High Risk)
Assets can be stolen/lost/compromised directly
bug
Something isn't working
duplicate-160
🤖_22_group
AI based duplicate group recommendation
satisfactory
satisfies C4 submission criteria; eligible for awards
sufficient quality report
This report is of sufficient quality
Lines of code
https://github.com/code-423n4/2024-08-superposition/blob/main/pkg/seawater/src/lib.rs#L554-L569
https://github.com/code-423n4/2024-08-superposition/blob/main/pkg/sol/OwnershipNFTs.sol#L109-L116
Vulnerability details
Impact
Approvals are not being cleared when
OwnershipNFT
is being transferred by owner. NFT can be sold and later on can be stolen back along with all the deposited tokens.Proof of Concept
Looking at the OZ ERC721 implementation we will see the following function being called in
transferFrom
andtransfer
:ERC721.sol
As we can see approve with
address(0)
is called each time, which clears theper token
andoperator approvals
of the previous owner, exactly to prevent the old approvers to steal back the NFT.However, in
OwnershipNFT
approvals are not being cleared and will remain even after the position is transferred:OwnershipNFT.sol
Note that the
Rust
code,lib::transfer_position_E_E_C7_A3_C_D
in particular, doesn’t manage the approvals, it cares only about adding/removing the position owner:lib.rs
So approvals are managed only in OwnershipNFT, which is also the
nft_manager
inlib.rs
, and everyone approved by the old owner can do anything with the new owner’s position- to increase, decrease, burn or even transfer it back to himself.For example, when malicious owner wants to steal from other users he can do the following:
token_owed_0
andtoken_owed_0
.OwnershipNFT::transferFrom
from the approved address._requireAuthorised
passes becausemsg.sender == getApproved[_tokenId]
lib::transfer_position_E_E_C7_A3_C_D
wipes the buyer as position owner and grants the ownership back to the old owner, who can choose whether to continue using the stolen position or collect it and close it stealing all the liquidity from it.Tools Used
Manual Review
Recommended Mitigation Steps
In
_transfer
make sure to clear the approvals for the given token:Assessed type
ERC721
The text was updated successfully, but these errors were encountered: