Skip to content
Access control Audit finding Advanced

Imprecise management of users’ allowance allows the admin of the upgradeable proxy contract to rug users

The FeeFollowModule contract allows the Hub to transfer funds from any address specified as the follower, and because the Hub is an upgradeable proxy, a malicious admin could upgrade it to a contract that calls processFollow with an arbitrary follower, draining that user's approved allowance. An attacker with admin access could steal up to the allowance limit from any user who has approved the module.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

In the current implementation, when there is a fee on follow or collect, users need to approve to the follow modules or collect module contract, and then the Hub contract can call processFollow() and transfer funds from an arbitrary address (as the follower parameter).

FeeFollowModule.sol#L75-L91

function processFollow(
    address follower,
    uint256 profileId,
    bytes calldata data
) external override onlyHub {
    uint256 amount = _dataByProfile[profileId].amount;
    address currency = _dataByProfile[profileId].currency;
    _validateDataIsExpected(data, currency, amount);

    (address treasury, uint16 treasuryFee) = _treasuryData();
    address recipient = _dataByProfile[profileId].recipient;
    uint256 treasuryAmount = (amount * treasuryFee) / BPS_MAX;
    uint256 adjustedAmount = amount - treasuryAmount;

    IERC20(currency).safeTransferFrom(follower, recipient, adjustedAmount);
    IERC20(currency).safeTransferFrom(follower, treasury, treasuryAmount);
}

A common practice is asking users to approve an unlimited amount to the contracts. Normally, the allowance can only be used by the user who initiated the transaction.

It’s not a problem as long as transferFrom will always only transfer funds from msg.sender and the contract is non-upgradable.

However, the LensHub contract is upgradeable, and FeeFollowModule will transferFrom an address decided by an input parameter follower, use of upgradeable proxy contract structure allows the logic of the contract to be arbitrarily changed.

This allows the proxy admin to perform many malicious actions, including taking funds from users’ wallets up to the allowance limit.

This action can be performed by the malicious/compromised proxy admin without any restriction.

Proof of Concept

Given:

  • profileId 1 uses FeeCollectModule with currency = WETH and amount = 1e18
  • Alice is rich (with 1,000,000 WETH in wallet balance)
  • Alice approve() type(uint256).max to FeeCollectModule and follow() profileId 1 with 1e18 WETH;
  • A malicious/compromised proxy admin can call upgradeToAndCall() on the proxy contract and set a malicious contract as newImplementation, adding a new functions:
function rugFollow(address follower, address followModule, uint256 profileId, bytes calldata data)
    external
{
    IFollowModule(followModule).processFollow(
        follower,
        profileIds,
        data
    );
}
  1. The attacker creates a new profile with FeeCollectModule and set currency = WETH and amount = 1,000,000, got profileId = 2
  2. The attacker rugFollow() with follower = Alice, profileId = 2, stolen 1,000,000 WETH from Alice’s wallet

Recommended Mitigation Steps

Improper management of users’ allowance is the root cause of some of the biggest attacks in the history of DeFi security. We believe there are 2 rules that should be followed:

  1. the from of transferFrom should always be msg.sender;
  2. the contracts that hold users’ allowance should always be non-upgradable.

We suggest adding a non-upgradeable contract for processing user payments:

function followWithFee(uint256 profileId, bytes calldata data)
    external
{
    (address currency, uint256 amount) = abi.decode(data, (address, uint256));
    IERC20(currency).transferFrom(msg.sender, HUB, amount);

    uint256[] memory profileIds = new uint256[](1);
    profileIds[0] = profileId;

    bytes[] memory datas = new bytes[](1);
    datas[0] = data;

    IHUB(HUB).follow(profileIds, datas);
}

This comes with an additional benefit: users only need to approve one contract instead of approving multiple follow or collect module contracts.

Zer0dot (Aave Lens) acknowledged, but disagreed with High severity and commented:

This is true, but is within the acceptable risk model.

0xleastwood (judge) decreased severity to Medium and commented:

While I agree with the warden, this assumes that the admin acts maliciously. As such, I think medium risk is more in line with a faulty governance.

Zer0dot (Aave Lens) commented:

I still relatively disagree with severity, as with M-03 (Issue #26) faulty governance is an acceptable risk parameter. Though we should have been more clear that this is the case!

0xleastwood (judge) commented:

I agree with you fully here, but again it comes down to the judging guidelines which might change in the future. The stated attack vector has stated assumptions which leads to a loss of funds.

2 — Med (M): vulns have a risk of 2 and are considered “Medium” severity when assets are not at direct risk, but the function of the protocol or its availability could be impacted, or leak value with a hypothetical attack path with stated assumptions, but external requirements.


The original report as published on Code4rena, by WatchPug. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 FeeFollowModule's processFollow function uses a user-supplied follower address in transferFrom, and the Hub contract is upgradeable, so a malicious admin can change the logic to call processFollow with any follower address.

Impact

A malicious or compromised proxy admin could steal funds from users up to their approved allowance limit; the report notes this requires the admin to act maliciously, and the judge rated it Medium severity.

What the attacker needed

User has approved the module contract; Attacker has admin access to the proxy; User has sufficient token balance

The fix

The report recommends that transferFrom should always use msg.sender as the from address and that contracts holding user allowances should be non-upgradeable, suggesting a separate non-upgradeable payment contract.

How it was found

  1. Alice approves the FeeCollectModule to spend her WETH and follows a profile, paying the fee.
  2. A malicious proxy admin upgrades the Hub to a malicious implementation that adds a function to call processFollow with an arbitrary follower.
  3. The attacker creates a new profile with a high fee amount.
  4. The attacker calls the malicious function with Alice as the follower, causing the module to transfer Alice's WETH to the attacker.

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 approve a contract to spend your tokens, you usually trust that only you can trigger that spending. Here, the contract allowed the caller to specify whose tokens to take, and because the main contract could be upgraded by an admin, that admin could change the rules and take tokens from anyone who had approved the module. This is like giving a friend permission to withdraw from your bank account, but the bank manager can change the rules to let anyone withdraw.

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.

More by WatchPug

View all

197 more disclosed reports, best first.

More from Aave Lens contest

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.