# Cancelling bid doesn't clear token approval of bidder allows malicious bidder to steal any tokens listing for sale with auto-approve enabled

Cancelling a bid in Coded Estate leaves the bidder's token approval intact, letting them call transfer_nft and steal an auto-approved listing without paying.

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

**Target:** CosmWasm marketplace contract (setbidtobuy/transfer_nft)
**Root cause:** setbidtobuy's cancellation branch removes the bid and refunds funds but never revokes the spender approval granted when auto_approve is enabled.
**Steps:**
1. Seller lists token via `SetListForSell{islisted:true, auto_approve:true, price:1000}`.
2. Attacker calls `SetBidToBuy{token_id}` with 1000 USDC, gaining approval.
3. Attacker calls `SetBidToBuy{token_id}` again with no funds to cancel; bid removed and 1000 USDC refunded, approval persists.
4. Attacker calls `TransferNft{recipient:attacker, token_id}`; contract clears approvals, transfers token, pays seller from (now empty) bid state.
5. Attacker owns token, balance unchanged at 1000 USDC.
**How found:** Code review of setbidtobuy's cancellation branch: noticed bids are retained-filtered and funds refunded but no approval revocation, then traced transfer_nft's reliance on the approval list.
**Exploitation:** Attacker needs only the listing price as temporary capital: bid at price to obtain approval, immediately cancel to reclaim funds, then invoke transfer_nft as approved spender to take the token while paying the seller nothing.
**Insight:** When a contract grants an approval as a side effect of a state-changing action, audit every path that reverses that action (cancel, refund, expiry) for a matching approval revocation; refunds and bid removal are not equivalent to clearing spender allowances.

