Initialize function in L2GraphToken.sol , BridgeEscrow.sol , L2GraphTokenGateway.sol , L1GraphTokenGateway.sol can be invoked multiple times from the implementation contract
The initialize functions in four upgradeable contracts lack the initializer modifier, allowing them to be called multiple times from the implementation contract. If the implementation contract is compromised, an attacker could reinitialize the contracts, become the governor, and drain GRT tokens from BridgeEscrow.
Submitted by ladboy233, also found by csanuragjain
L2GraphTokenGateway.sol#L87 L2GraphToken.sol#L48 L1GraphTokenGateway.sol#L99 BridgeEscrow.sol#L20
Initialize function in L2GraphToken.sol, BridgeEscrow.sol, L2GraphTokenGateway.sol, and L1GraphTokenGateway.sol can be invoked multiple times from the implementation contract. This means a compromised implementation can reinitialize the contract above and become the owner to complete the privilege escalation then drain the user’s fund.
Usually in Upgradeable contract, an initialize function is protected by the modifier
initializer
to make sure the contract can only be initialized once.
Proof of Concept
- The implementation contract is compromised,
- The attacker reinitialize the BridgeEscrow contract
function initialize(address _controller) external onlyImpl {
Managed._initialize(_controller);
}
the onlyGovernor modifier’s result depends on the controller because
function _onlyGovernor() internal view {
require(msg.sender == controller.getGovernor(), "Caller must be Controller governor");
}
- The attacker has the governor access to the BridgeEscrow,
- The attack can call the approve function to approve malicious contract
function approveAll(address _spender) external onlyGovernor {
graphToken().approve(_spender, type(uint256).max);
}
- The attack can drain all the GRT token from the BridgeEscrow.
Recommended Mitigation Steps
We recommend the project use the modifier
initializer
to protect the initialize function from being reinitiated
function initialize(address _owner) external onlyImpl initializer {
Sponsor - please also review #72 which is a duplicate but has a slightly different impact statement to the same underlying issue.
pcarranzav (The Graph) confirmed and commented:
The impact from #72 was discussed with a warden and I consider it valid and worth fixing.
The impact from this one requires the implementation to be compromised in a way that allows calling
initialize(). Since all implementations useGraphUpgradeable, I don’t see how that’s possible without also compromising theGraphProxyAdminand therefore compromising the governor, which would mean much bigger problems.I still consider this risky enough that a Medium severity is reasonable, both in #72 and this one.
Exploit of this bug requires ProxyAdmin compromise, and if attacker has that then there are many ways to severely damage the proxy. It’s a good observation and should be fixed, but it seems to be a best practice issue.
pcarranzav (The Graph) resolved and commented:
Fix PRd in https://github.com/graphprotocol/contracts/pull/741
@Trust - makes reasonable points, but I think it’s still correct to award this as Medium.
Trust (warden) reviewed mitigation:
Fixed in standalone PR. Fixed by using OpenZeppelin’s initializer guard in contracts BridgeEscrow, L1GraphTokenGateway, L2GraphTokenGateway and L2GraphToken.
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 initialize functions in the four contracts lack the initializer modifier, allowing them to be called multiple times.
Impact
If the implementation contract is compromised, an attacker could reinitialize the contracts, become governor, and drain all GRT tokens from BridgeEscrow; however, the sponsor notes this requires compromising the GraphProxyAdmin, which would already imply severe damage.
What the attacker needed
Compromise of implementation contract; Compromise of GraphProxyAdmin
The fix
The contracts were fixed by using OpenZeppelin’s initializer guard in BridgeEscrow, L1GraphTokenGateway, L2GraphTokenGateway, and L2GraphToken.
How it was found
- Compromise the implementation contract.
- Reinitialize the BridgeEscrow contract by calling its initialize function.
- Gain governor access to BridgeEscrow.
- Call approveAll to approve a malicious contract to spend GRT tokens.
- Drain all GRT tokens from BridgeEscrow.
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.
Upgradeable smart contracts often have an initialize function that sets up the contract once, similar to a constructor. This report found that the initialize functions in several contracts could be called more than once, which is dangerous if an attacker gains control of the implementation contract. The attacker could then reset the contract's owner and steal funds.
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.