# Attakers can steal the funds from long-term reservation

Auto-approved bidder on a rented NFT gains approval, withdraws landlord rental funds via withdrawtolandlord, then cancels bid to recover deposit.

- Payout: Audit contest
- Severity: high
- Program: Coded Estate
- Found by: Ch\_301
- Disclosed: 2024-12-04
- Write-up quality: 7/10
- Original: https://github.com/code-423n4/2024-10-coded-estate-findings/issues/41
- Library page: https://bugbountylibrary.com/r/c4%3A2024-10-coded-estate%3AH-01
- Tags: area:web3 domain:web3 impact:funds-loss kind:contest platform:code4rena sev:high tech:solidity technique:source-review vuln:access-control vuln:accounting-error vuln:business-logic

**Target:** CosmWasm NFT rental marketplace contract (execute.rs)
**Root cause:** withdrawtolandlord uses check_can_send (send permission) instead of check_can_approve, so an address merely approved via auto_approve bid can withdraw rental funds; setbidtobuy refunds the bid deposit with no fee.
**Steps:**
1. Find NFT with token.sell.auto_approve == true and active long-term rental
2. Call `setbidtobuy()` with required funds to gain approval on the NFT
3. Call `withdrawtolandlord()` with max amount to send rental deposit to attacker address
4. Call `setbidtobuy()` again to cancel bid and reclaim deposited funds
**How found:** Code review of approval semantics: noticed setbidtobuy grants approval when auto_approve is set, and that withdrawtolandlord only checks send permission rather than approve permission, allowing an approved-but-not-owner address to withdraw.
**Exploitation:** Attacker bids on an auto-approve listed NFT to become an approved spender, uses that approval to invoke withdrawtolandlord and route the long-term rental deposit to themselves, then cancels the bid to recover the bid funds, netting the stolen rental deposit.
**Insight:** When a contract has separate send vs approve permission checks, audit every fund-moving function for which check it uses; an approval granted for one purpose (bidding) can be abused to move funds if the withdraw path only validates send rights.

## Proof of concept (copied exactly from the original report)

**setbidtobuy auto-approve code granting attacker approval**

```
if token.sell.auto_approve {
676:                 // update the approval list (remove any for the same spender before adding)
677:                 let expires = Expiration::Never {  };
678:                 token.approvals.retain(|apr| apr.spender != info.sender);
679:                 let approval = Approval {
680:                     spender: info.sender.clone(),
681:                     expires,
682:                 };
683:                 token.approvals.push(approval);
```

**withdrawtolandlord sends funds to arbitrary address**

```
pub fn withdrawtolandlord(
/**CODE**/
1796:         address:String
1797:     ) -> Result<Response<C>, ContractError> {
/**CODE**/
1848:             .add_message(BankMsg::Send {
1849:                 to_address: address,
1850:                 amount: vec![Coin {
1851:                     denom: token.longterm_rental.denom,
1852:                     amount: Uint128::from(amount) - Uint128::new((u128::from(amount) * u128::from(fee_percentage)) / 10000),
```

**withdrawtolandlord deposit amount check**

```
if item.deposit_amount - Uint128::from(token.longterm_rental.price_per_month) < Uint128::from(amount)  {
1833:                     return Err(ContractError::UnavailableAmount {  });
```

