Frontrunning PublicLock.initialize() can prevent upgrades due to insufficient access control
The PublicLock contract's initialize function lacked access control, allowing anyone to call it before the legitimate deployer. An attacker could front-run the setLocktemplate call, forcing the deployer to redeploy and potentially draining funds through repeated attacks.
Originally disclosed on Code4rena
Submitted by elprofesor, also found by kenzo
The unlock protocols base contract Unlock.sol uses setLocktemplate() to initialize the implementation contract for the PublicLock proxy. This function will initialize the relevant PublicLock contract which has been deployed separately. PublicLock.initialize() does not have any relevant access control and does not prevent arbitrary users from initialising. This means that a malicious user could front run the setLocktemplate() forcing the deployer of PublicLock’s implementation to redeploy. The process can be repeated, which costs the malicious user less than it would the owner of the Unlock Protocol, potentially unnecessarily draining funds from the development team.
Proof of Concept
Lack of access control on initialize
Recommended Mitigation Steps
Implement valid access control on the PublicLock contract to ensure only the relevant deployer can initialize().
julien51 (Unlock Protocol) disagreed with severity
0xleastwood (judge) commented:
I agree with the warden,
_publicLockAddressis deployed separately and henceinitializecan be called beforesetLockTemplateis called.
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 initialize function in PublicLock lacked any access control modifier, allowing any address to call it.
Impact
A malicious user could front-run the setLocktemplate call, forcing the deployer to redeploy and potentially draining funds from the development team.
What the attacker needed
Attacker can call initialize before setLocktemplate
The fix
Implement valid access control on the PublicLock contract to ensure only the relevant deployer can initialize it.
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.
When a smart contract is set up, an initialization function is often used to configure it. If that function is not protected, anyone can call it first and take control. Here, an attacker could call it before the real owner, causing the owner to have to redeploy and lose 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.