Submitted by 0xpiken, also found by MrPotatoMagic
https://github.com/code-423n4/2024-12-bakerfi/blob/main/contracts/core/VaultRouter.sol#L120
https://github.com/code-423n4/2024-12-bakerfi/blob/main/contracts/core/VaultRouter.sol#L122
Once a user approves VaultRouter to spend their ERC4626 shares, anyone could call VaultRouter#execute() to drain the users ERC4626 shares.
The VaultRouter#execute() function allows users to perform multiple commands within a single transaction. A user can redeem their ERC4626 shares for underlying assets through VaultRouter using the ERC4626_VAULT_REDEEM command. Subsequently, the redeemed underlying assets can be further processed within the same transaction through other commands, such as V3_UNISWAP_SWAP for token swaps or PUSH_TOKEN for token transferrings.
Redeem ERC4626 shares for underlying assets:
Withdraw underlying assets by burning shares:
To allow VaultRouter to redeem ERC4626 shares on behalf of a user, the user must approve VaultRouter to spend their shares in advance.  However, the caller can be anyone when handling ERC4626 shares redeeming / underlying asset withdrawing, a malicious actor can exploit this approval to drain the users ERC4626 shares.
Copy below codes to VaultRouter.ts and run npm run test:
As we can see, all owners vault shares were drained.
Both ERC4626_VAULT_REDEEM and ERC4626_VAULT_WITHDRAW commands should only handle the callers ERC4626 shares:
chefkenji (BakerFi) confirmed
BakerFi mitigated:
Status: Mitigation confirmed. Full details in reports from 0xlemon and shaflow2.
