BeefyAdapter() malicious vault owner can use malicious \_beefyBooster to steal the adapter’s token
The BeefyAdapter contract did not verify that the _beefyBooster address was legitimate before approving it to spend the adapter's _beefyVault tokens. A malicious vault owner could supply a malicious _beefyBooster that would transfer all tokens held by the adapter.
bin2chen Follow with Ch_301, rvierdiiev and 1 other
Originally disclosed on Code4rena
Submitted by bin2chen, also found by Ch_301, rvierdiiev, and 0xTraub
Malicious vault owner can use Malicious \_beefyBooster to steal the adapter’s token.
Proof of Concept
When creating a BeefyAdapter, the vault owner can specify the \_beefyBooster.
The current implementation does not check if the \_beefyBooster is legitimate or not, and worse, it \_beefyVault.approve to the \_beefyBooster during initialization.
The code is as follows:
contract BeefyAdapter is AdapterBase, WithRewards {
...
function initialize(
bytes memory adapterInitData,
address registry,
bytes memory beefyInitData
) external initializer {
(address _beefyVault, address _beefyBooster) = abi.decode(
beefyInitData, //@audit <--------- beefyInitData comes from the owner's input: adapterData.data
(address, address)
);
//@audit <-------- not check _beefyBooster is legal
if (
_beefyBooster != address(0) &&
IBeefyBooster(_beefyBooster).stakedToken() != _beefyVault
) revert InvalidBeefyBooster(_beefyBooster);
...
if (_beefyBooster != address(0))
IERC20(_beefyVault).approve(_beefyBooster, type(uint256).max); //@audit <--------- _beefyVault approve _beefyBooster
}
function _protocolDeposit(uint256 amount, uint256)
internal
virtual
override
{
beefyVault.deposit(amount);
if (address(beefyBooster) != address(0))
beefyBooster.stake(beefyVault.balanceOf(address(this))); //@audit <--------- A malicious beefyBooster can transfer the token
}
As a result, a malicious user can pass a malicious \_beefyBooster contract, and when the user deposits to the vault, the vault is saved to the \_beefyVault.
This malicious \_beefyBooster can execute \_beefyVault.transferFrom(BeefyAdapter), and take all the tokens stored by the adapter to \_beefyVault.
Recommended Mitigation Steps
Check \_beefyBooster just like you check \_beefyVault:
function initialize(
bytes memory adapterInitData,
address registry,
bytes memory beefyInitData
) external initializer {
...
if (!IPermissionRegistry(registry).endorsed(_beefyVault))
revert NotEndorsed(_beefyVault);
...
+ if (!IPermissionRegistry(registry).endorsed(_beefyBooster))
+ revert NotEndorsed(_beefyBooster);
if (
_beefyBooster != address(0) &&
IBeefyBooster(_beefyBooster).stakedToken() != _beefyVault
) revert InvalidBeefyBooster(_beefyBooster);
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 initialize function approved the _beefyBooster to spend the adapter's _beefyVault tokens without checking that _beefyBooster was endorsed or otherwise legitimate.
Impact
A malicious vault owner could steal all _beefyVault tokens held by the adapter.
What the attacker needed
Attacker is the vault owner; attacker can deploy a malicious contract; victim deposits into the vault
The fix
The _beefyBooster should be checked against the permission registry's endorsed list, just like _beefyVault.
How it was found
- The vault owner creates a BeefyAdapter and supplies a malicious _beefyBooster address.
- The adapter approves the malicious _beefyBooster to spend its _beefyVault tokens.
- A user deposits into the vault, and the adapter calls stake on the malicious _beefyBooster.
- The malicious _beefyBooster calls transferFrom on the adapter to take all its _beefyVault tokens.
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.
When you deposit money into a vault, the vault uses a helper contract to manage your funds. This report shows that the vault owner could plug in a fake helper that was allowed to move the vault's tokens, letting the owner steal them. The fix is to check that the helper is on an approved list before trusting it.
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.