code-423n4 / 2022-05-bunker-findings

1 stars 0 forks source link

Usage of `transferFrom` leads to irreversible loss of user funds. #84

Open code423n4 opened 2 years ago

code423n4 commented 2 years ago

Lines of code

https://github.com/bunkerfinance/bunker-protocol/blob/752126094691e7457d08fc62a6a5006df59bd2fe/contracts/CNft.sol#L213

Vulnerability details

[H] : Usage of transferFrom leads to irreversible loss of user ERC721 funds.

Assessed risk: 8/10

Urgency: 10/10

Codebase frequency: 1

[H - Impact]:

The validReceive modifier that checks whether the transaction of ERC721 or ERC1155 tokens has been executed according to the rules(msg.sender == underlying and operator == address(this)) is used on functions that would handle the callback on safeTransferFrom but it can be bypassed by a user that transfers on their own, via transferFrom .

The onERC721Received is only triggered via its subsequent safeTransferFrom function. Should a user transfer their tokens via transferFrom or any other transfer function facilitated by usual ERC721 contracts, the ERC721 token that they’ve just transferred would be lost, since the onERC721Received would not trigger to deny the improper(according to the implemented modifier) ERC721 transfer. The user would basically “forcibly” transfer their token, unknowingly that this is not the correct procedure of how the protocol should work.

[H - Mitigation]:

Although there’s not much that can be done to refuse the transferFrom transaction, I would suggest considering the following mitigation, for the sake of the users:

function retrieveLostERC721(address _token, address _sender, uint256 _id) external onlyOwner {
    // making sure that the _token is not the underlying, so that no owner could
    // withdraw at will
    require(_token != underlying, "cannot withdraw underlying");

    ERC721(_token).safeTransferFrom(address(this), _sender, _id);
}
bunkerfinance-dev commented 2 years ago

This isn't a priority for us because we can add a sweep function to the contract in the future.

gzeoneth commented 2 years ago

Downgrading to Low / QA.

gzeoneth commented 2 years ago

Treating as warden's QA report.