Skip to content
Access control Audit finding Advanced

Can register a non-allowed collateral as collateral

The protocol did not check whether tokens returned from external interactions were allowed before registering them as collateral. An attacker could use an arbitrary token with an active oracle as collateral, manipulate its price, and drain funds.

Lambda Follow with Bahurum, kirk-baird and 3 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2022-08-sentiment-judging/tree/main/029-M

Found by

Lambda, Bahurum, kirk-baird, bin2chen, xiaoming90, GalloDaSballo

Summary

Some external interactions send tokens to the account, and the token address is not checked before being registered as a collateral for the account. This allows using an arbitrary token as a collateral as long as there is a corresponding oracle.

Vulnerability Detail

In the following controllers, at the line referenced

UniV2Controller.sol #L189
AaveV2Controller.sol #L91
AaveV3Controller.sol #L79
BalancerController.sol#L137

There is an operation with a return value that can be an arbitrary token. No check is made to verify that the tokens in tokensIn are activated in controllerFacade.isTokenAllowed. No check is made either in AccountManager.exec() when calling _updateTokensIn() (AccountManager.sol#L305), so the tokens are added as a collateral as long as the oracle for the token in OracleFacade is active.

This can be clarified with an example using UniV2Controller.sol:

  1. Admin sets the oracle for token XYZ, but does not activate yet the token in controllerFacade.isTokenAllowed or in AccountManager.isCollateralAllowed waiting to clear some security concerns with the token (vulnerabilities, high volatility, low liquidity, ...)
  2. Attacker opens an account
  3. Attacker provides liquidity to XYZ / ETH pool on UniswapV2
  4. Attacker transfers the LP to the account
  5. Attacker removes liquidity from the UniswapV2 pool through the account by calling AccountManager.exec. Note that there is no check to control whether tokens exiting the account are allowed (UniV2Controller.sol#L175-L190). No checks are performed on tokens sent from the pool to the account, so account receives WETH + XYZ and also XYZ is registered as an account collateral (AccountManager.sol#L305). An oracle was set for XYZ so the call to riskEngine.isAccountHealthy(account)(AccountManager.sol#L310) does not revert and the transaction succeeds.
  6. Attacker can take advantage of the aforementioned security concerns to manipulate the price of XYZ, inflate his collateral balance and drain funds from the protocol.

The same behaviour can be reproduced with the other integrations listed above by transfering LP tokens of that particular protocol directly to an account and then removing liquidity through AccountManager.exec() to get the pair tokens registered into the account as collateral.

Impact

See point 6. of section above.

Code Snippet

UniV2Controller.sol #L189
AaveV2Controller.sol #L91
AaveV3Controller.sol #L79
BalancerController.sol#L137
AccountManager.sol#L347

Tool used

Manual Review

Recommendation

Check if tokens are allowed as collateral in _updateTokensIn (AccountManager.sol#L347-L355)

Diff
    function _updateTokensIn(address account, address[] memory tokensIn)
        internal
    {
        uint tokensInLen = tokensIn.length;
        for(uint i; i < tokensInLen; ++i) {
+           if (!isCollateralAllowed[tokensIn[i]])
+               revert Errors.CollateralTypeRestricted();
            if (IAccount(account).hasAsset(tokensIn[i]) == false)
                IAccount(account).addAsset(tokensIn[i]);
        }
    }

This way no asset can be added as collateral without being allowed.

Sentiment Team

Fixed as recommended. PR here and here.

Lead Senior Watson

Confirmed fix. If there are non-whitelisted tokens in the tokensIn list from a controller, it seems like the system should not reject the call, but not to add these tokens (ignore these tokens).

This issue is more obvious for the case of claim rewards from 3rd party protocols, which may include non-whitelisted tokens, but that doesn't mean it should not be allowed to claim these rewards.

Sentiment Team

We intend to track rewards as well and hence will be required to add them in the tokensIn list, all rewards will be whitelisted and only those integrations will be enabled. For rewards that we don't want to use as collateral in the system, we plan to add them to the assets and point them to the zero oracle.

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

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

Likely the function that adds incoming tokens to an account as collateral did not verify that each token was on the allowed list.

Impact

An attacker could inflate their collateral and drain funds from the protocol, though this required an oracle to be set for the token.

What the attacker needed

Oracle set for the token; attacker has an account; attacker can provide liquidity

The fix

The team fixed it by checking that each incoming token is allowed as collateral before adding it.

How it was found

  1. Admin sets an oracle for token XYZ but does not allow it as collateral.
  2. Attacker opens an account.
  3. Attacker provides liquidity to an XYZ/ETH pool on UniswapV2.
  4. Attacker transfers the LP tokens to the account.
  5. Attacker removes liquidity through the account by calling AccountManager.exec, which registers XYZ as collateral.
  6. Attacker manipulates the price of XYZ to inflate collateral and drain funds.

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.

In this lending protocol, users can deposit tokens as collateral to borrow other assets. The system is supposed to only accept approved tokens as collateral, but it forgot to check when tokens come back from external services like Uniswap. An attacker could sneak in a token that was not approved, manipulate its price, and take more money than they should.

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 Lambda

View all

64 more disclosed reports, best first.

More from Sentiment Update #3

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.