Skip to content
Access control Audit finding Intermediate

Vault#setController() owner of the Vault contracts can drain funds from the Vault

The Vault contract lets its owner point the controller at any address, and the migration and utilize functions then move all vault funds to that address. A malicious or compromised owner could therefore drain every token held by the vault.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

https://github.com/code-423n4/2022-01-insure/blob/19d1a7819fe7ce795e6d4814e7ddf8b8e1323df3/contracts/Vault.sol#L485-L496

function setController(address _controller) public override onlyOwner {
    require(_controller != address(0), "ERROR_ZERO_ADDRESS");

    if (address(controller) != address(0)) {
        controller.migrate(address(_controller));
        controller = IController(_controller);
    } else {
        controller = IController(_controller);
    }

    emit ControllerSet(_controller);
}

The owner of the Vault contract can set an arbitrary address as the controller.

https://github.com/code-423n4/2022-01-insure/blob/19d1a7819fe7ce795e6d4814e7ddf8b8e1323df3/contracts/Vault.sol#L342-L352

function utilize() external override returns (uint256 _amount) {
    if (keeper != address(0)) {
        require(msg.sender == keeper, "ERROR_NOT_KEEPER");
    }
    _amount = available(); //balance
    if (_amount > 0) {
        IERC20(token).safeTransfer(address(controller), _amount);
        balance -= _amount;
        controller.earn(address(token), _amount);
    }
}

A malicious controller contract can transfer funds from the Vault to the attacker.

Proof of Concept

A malicious/compromised can:

  1. Call Vault#setController() and set controller to a malicious contract;

    • L489 the old controller will transfer funds to the new, malicious controller.
  2. Call Vault#utilize() to deposit all the balance in the Vault contract into the malicious controller contract.

  3. Withdraw all the funds from the malicious controller contract.

Recommendation

Consider disallowing Vault#setController() to set a new address if a controller is existing, which terminates the possibility of migrating funds to a specified address provided by the owner. Or, putting a timelock to this function at least.

oishun1112 (Insure) acknowledged and disagreed with severity:

we assume ownership control is driven safely

0xean (judge) commented:

Agree with warden that the privilege addresses should not be able to use approvals in a way that rugs users funds.

Based on the fact that we have seen many rug pulls in the space based on compromised “owner” keys, this is a valid attack path. 3 — High: Assets can be stolen/lost/compromised directly (or indirectly if there is a valid attack path that does not have hand-wavy hypotheticals).

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

Likely the owner can replace the controller at any time and the migration and utilize paths forward the vault's full balance to whatever address the owner names, with no timelock or restriction.

Impact

A malicious or compromised owner could steal all assets held by the vault; the project argued that ownership is assumed to be handled safely, but the judge accepted the attack path as high severity.

What the attacker needed

Owner key is malicious or compromised

The fix

The setController function should be disallowed from changing an existing controller, or at least be placed behind a timelock; the text does not say it was fixed.

How it was found

  1. Call the setController function and set the controller to a malicious contract, which receives the old controller's funds.
  2. Call the utilize function so the vault sends its whole balance to the malicious controller.
  3. Withdraw all the funds from the malicious controller contract.

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.

A vault is a smart contract that holds other people's tokens. Its owner can swap out the helper contract that manages those tokens, and the vault then sends its whole balance to that helper. If the owner is malicious or their key is stolen, they can point the helper at their own contract and walk away with the money.

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 InsureDAO 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.