Skip to content
Access control Audit finding Intermediate

A vault owner can frontrun a plugin call and change its implementation

A vault owner can overwrite an existing plugin selector with a new implementation, allowing them to frontrun a user's call and change the logic executed. This can also cause confusion when multiple plugins with the same selector are installed, as only the last one remains active.

0xNineDec Follow

Originally disclosed on Code4rena

Submitted by 0xNineDec, also found by 0x1f8b, infosec_us_team, kenzo, pashov, and xiaoming90

Each vault owner can manage freely the creation and deletion of plugins at any time if the vault was deployed by calling VaultRegistry.createFor(). An owner can simply overwrite a current plugin selector with a new address and change the implementation of that plugin at any time. This can be used to frontrun others and change the logic of a call before it is mined.

This strategy can also be used to bypass the need to uninstall a plugin by overwriting a currently installed one with a different implementation without needing to first remove the old plugin and then install the new one. This can be made just by installing a selector that collides with a previously installed plugin and change the address that is pointing that selector.

Proof of Concept

There are two scenarios both relying on the fact that plugins can be overwritten which may lead to confusion in one case and to a malicious call in the other one.

Case A: Deployment with many clashing selectors

A user can deploy a vault owner and install more than one plugin which selectors are the same. This will make that the last plugin address of the array will be pointed as the implementation of that plugin and the other ones will be overwritten. The whole installation process will emit an event containing the same selectors but different addresses which may be deceiving. Users that are not aware on how mapping data can be overwritten can be deceived because of this process.

function test_canDeployWithCollidingSelector() public {
    // Getting the colliding selectors that point to different implementations.
    bytes4 selectorOne = bytes4(keccak256(bytes("func_2093253501(bytes)")));
    bytes4 selectorTwo = bytes4(keccak256(bytes("transfer(address,uint256)")));

    bytes4[] memory collidingSelectors = new bytes4[](2);
    address[] memory nonCollidingPlugins = new address[](2);

    collidingSelectors[0] = selectorOne;
    nonCollidingPlugins[0] = address(0xdead1);

    collidingSelectors[1] = selectorTwo;
    nonCollidingPlugins[1] = address(0xdead2);

    // Deploying a vault
    vault = alice.registry.createFor(
        merkleRoot,
        alice.addr,
        nonCollidingPlugins,
        collidingSelectors
    );
    token = registry.fNFT();
    setUpFERC1155(alice, token);

    assertEq(IVault(vault).owner(), alice.addr);
    assertEq(fERC1155.controller(), address(this));

    // Both selectors point to the same address of implementation.
    assertEq(IVault(vault).methods(selectorOne), address(0xdead2));
    assertEq(IVault(vault).methods(selectorTwo), address(0xdead2));
}

Case B: Frontrun other users call

A malicious vault owner can deploy a vault with a legit plugin that other users will call on a regular basis. The owner can develop a malicious plugin implementation, wait until there is a transaction that is targeting that plugin and frontrun it overwriting the plugin address by using the same selector. The new implementation can have unintended behavior for that user. If the owner is even more decided to continue doing this, he can backrun the transaction with another call setting the plugin address back to the legit implementation.

function test_canOverwritePlugin() public {
        // Generating the colliding selectors
        bytes4 selectorOne = bytes4(keccak256(bytes("collate_propagate_storage(bytes16)")));
        bytes4 selectorTwo = bytes4(keccak256(bytes("burn(uint256)")));

        bytes4[] memory collidingSelectors = new bytes4[](1);
        address[] memory nonCollidingPlugins = new address[](1);

        collidingSelectors[0] = selectorOne;
        nonCollidingPlugins[0] = address(0xdead1);

        // Deploying a vault
        vault = alice.registry.createFor(
            merkleRoot,
            alice.addr,
            nonCollidingPlugins,
            collidingSelectors
        );
        token = registry.fNFT();
        setUpFERC1155(alice, token);

        assertEq(IVault(vault).owner(), alice.addr);
        assertEq(fERC1155.controller(), address(this));

        // Checking that the selector one was properly installed and that points to 0xdead1
        assertEq(IVault(vault).methods(selectorOne), address(0xdead1));

        // At any time the owner will be able to overwrite the plugin by clashing with the existing one.
        // this can be used to frontrun a call that targets selectorOne and modify its implementation.
        vm.startPrank(alice.addr);
        bytes4[] memory clashingSelector = new bytes4[](1);
        address[] memory newPluginAddress = new address[](1);

        clashingSelector[0] = selectorTwo; // The one declared before.
        newPluginAddress[0] = address(0xdead2);

        IVault(vault).install(clashingSelector, newPluginAddress);
        vm.stopPrank();

        // Checking that the selector was indeed overwritten and now is pointing to 0xdead2
        assertEq(IVault(vault).methods(selectorOne), address(0xdead2));
        assertEq(IVault(vault).methods(selectorTwo), address(0xdead2)); // Redundant assertion.

        vm.startPrank(alice.addr);
        // Also, there is no need to have a clashing function with other name.
        // It is just enough to use the same function name as before with a new address.
        clashingSelector[0] = selectorOne;
        newPluginAddress[0] = address(0xdead3);

        IVault(vault).install(clashingSelector, newPluginAddress);
        vm.stopPrank();
        assertEq(IVault(vault).methods(selectorOne), address(0xdead3));
        assertEq(IVault(vault).methods(selectorTwo), address(0xdead3));
    }

Recommended Mitigation Steps

First of all, it is important to unify the criteria related on which are the entry points for a user to deploy a vault. Having different functions that lead to distinct access control roles within a deployed vault is potentially an issue (as shown before).

Also, regarding plugin installation it is important to check if the plugin that is willing to be installed is not overwriting the methods mapping (in other words, checking if methods(selector) is empty in order to perform the installation) and if plugins are not intended to work as emergency functions that need to be injected into a vault quickly, I would consider timelocking the process of plugin installation.

mehtaculous (Fractional) confirmed

HardlyDifficult (judge) commented:

Similar to #487 the concern here is about potentially malicious plugins. Here the concern is focused around changing the implementation logic vs modifying proxy storage presumed to be immutable by plugins. The way these concerns are addressed by differ.

Due to this concern there is a lot of trust placed in the vault owner. This is the same level of trust that any upgradeable contract requires — however a unique consideration here is that normally upgradeable contracts place trust in a platform admin while these vaults are more general purpose. The suggestion above of adding a timelock helps to mitigate this concern, and checking for signature dupes could help to prevent user error. Additionally an allow list of plugins managed by the platform or DAO could be considered.

Due to the nuances above, I’m inclined to agree with the warden here that it’s a Medium risk issue.


The original report as published on Code4rena, by 0xNineDec. 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 vault's plugin installation function allows overwriting an existing selector without checking if it is already in use, and the owner has unchecked power to change implementations at will.

Impact

A malicious vault owner could frontrun a user's call and change the plugin implementation to execute unintended behaviour, potentially causing harm to the user.

What the attacker needed

Vault owner is malicious; victim interacts with the vault

The fix

The report recommends checking that the selector is not already in use before installation and considering a timelock for plugin installations.

How it was found

  1. Deploy a vault with a legitimate plugin that users will call.
  2. Develop a malicious plugin implementation.
  3. Wait for a user transaction targeting the legitimate plugin.
  4. Frontrun the transaction by installing the malicious plugin with the same selector.
  5. Optionally backrun to restore the legitimate plugin.

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 like a digital safe that can run small programs called plugins. The owner of the safe can swap out a plugin for a different one at any time, even while someone else is trying to use it. This means the owner could trick a user into running malicious code instead of the expected plugin.

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 0xNineDec

View all

8 more disclosed reports, best first.

More from Fractional v2 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.