sendCollateralTo is unchecked in closeLoan() , which can cause user’s collateral NFT to be frozen
The closeLoan function transfers a collateral NFT to an arbitrary address using transferFrom, which does not check if the recipient can handle ERC721 tokens. If the recipient is a contract that cannot receive NFTs, the token becomes permanently stuck.
Submitted by WatchPug, also found by berndartmueller, Dravee, hake, jah, and minhquanym
NFTLoanFacilitator.sol#L116-L126
function closeLoan(uint256 loanId, address sendCollateralTo) external override notClosed(loanId) {
require(IERC721(borrowTicketContract).ownerOf(loanId) == msg.sender,
"NFTLoanFacilitator: borrow ticket holder only");
Loan storage loan = loanInfo[loanId];
require(loan.lastAccumulatedTimestamp == 0, "NFTLoanFacilitator: has lender, use repayAndCloseLoan");
loan.closed = true;
IERC721(loan.collateralContractAddress).transferFrom(address(this), sendCollateralTo, loan.collateralTokenId);
emit Close(loanId);
}
The sendCollateralTo will receive the collateral NFT when closeLoan() is called. However, if sendCollateralTo is a contract address that does not support ERC721, the collateral NFT can be frozen in the contract.
As per the documentation of EIP-721:
A wallet/broker/auction application MUST implement the wallet interface if it will accept safe transfers.
Ref: EIP-721
Recommended Mitigation Steps
Change to:
function closeLoan(uint256 loanId, address sendCollateralTo) external override notClosed(loanId) {
require(IERC721(borrowTicketContract).ownerOf(loanId) == msg.sender,
"NFTLoanFacilitator: borrow ticket holder only");
Loan storage loan = loanInfo[loanId];
require(loan.lastAccumulatedTimestamp == 0, "NFTLoanFacilitator: has lender, use repayAndCloseLoan");
loan.closed = true;
IERC721(loan.collateralContractAddress).safeTransferFrom(address(this), sendCollateralTo, loan.collateralTokenId);
emit Close(loanId);
}
wilsoncusack (Backed Protocol) acknowledged, but disagreed with Medium severity and commented:
We use transferFrom and _mint instead of the safe versions to save gas. We think it is a reasonable expectation that users calling this should know what they are doing. We feel this is OK especially because other major protocols like Uniswap do this (Uniswap/NonfungiblePositionManager.sol#L156).
I believe Med Risk is a fair assessment given the mixed/inconsistent usage of
safeTransferFromandtransferFromin the contract.
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
The function uses transferFrom instead of safeTransferFrom, so it does not verify that the recipient contract implements the ERC721 receiver interface.
Impact
A user's collateral NFT could become permanently frozen if sent to a contract that cannot handle ERC721 tokens.
What the attacker needed
User calls closeLoan with a contract address; contract does not support ERC721
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.
When you close a loan, the contract sends your collateral NFT to an address you specify. The code uses a basic transfer method that does not check if the receiving address is able to handle NFTs. If you accidentally send it to a contract that cannot accept NFTs, the token gets stuck there forever.
What is Business logic?
The application works as coded but not as intended: a negative price, a skipped payment step, a limit that can be crossed.