<!-- canonical: https://0xsimao.com/findings/clip-finance-i-callbacks-malicious-attackers-steal -->

# Tokens with callbacks may allow malicious attackers to steal the protocol

Crit/High · Three Sigma · DeFi infrastructure · 10th November, 2023

Finding 3S-Clip Finance-M08 of the Clip Finance Strategies security review.

- Protocol: https://www.clip.finance/
- Report: /reports/clip-finance-i
- Source: https://cdn.sanity.io/files/qoqld077/production/c23d04c8223879d2443221caf3ccb55ac118441a.pdf

---

### Description

In Batch.sol, function withdraw() [burns](https://github.com/ClipFinance/strategy-router/blob/master/contracts/Batch.sol#L217-L218) the receiptId after transferring the tokens to
the user. This means that if the token has a callback, the user may use it to sell the nft
somewhere else, getting some extra value for it, and then the execution continues in
withdraw(), burning the nft of the other new owner.
In BatchOut.sol, withdrawFulfill(), the withdrawStatus is set to [true](https://github.com/ClipFinance/strategy-router/blob/master/contracts/BatchOut.sol#L379-L381) only after the
tokens are transferred to the user. An attacker could use a callback to reenter the function
and withdraw the shares until the contract is drained.

### Recommendation

Follow the checks-effects-interactions pattern.
In Batch.sol, burn the receipt and only then transfer the tokens to the receiptOwner.
In BatchOut.sol, set the withdrawStatus to true before transferring tokens.

### Status

Addressed in [#972526f](https://github.com/ClipFinance/StrategyRouter-private/commit/972526f894796b2388f79393cf5d169f7aed3ef8)

---

Related findings:

- [Wrong tokensToCheck logic in BaseRouter enables attackers to steal funds](https://0xsimao.com/findings/fuji-finance-logic-enables-attackers-steal): Fuji Finance
- [ERC20AssetPool and ERC721AssetPool should have the nonReentrant modifier as ERC721 and some tokens have callbacks](https://0xsimao.com/findings/singularity-erc20-erc721-reentrant-callbacks): Singularity
- [Attackers will steal the reserve from the `Vault` by receiving `ra` in `FlashSwapRouter::__swapDsforRa()`](https://0xsimao.com/findings/cork-protocol-steal-receiving-flash-dsfor): Cork Protocol
- [Signatures missing some parameters being vulnerable to attackers using them coupled with malicious parameters](https://0xsimao.com/findings/crestal-network-signatures-parameters-them-coupled): Crestal Network
