The changeOwner function lacks access control, allowing any user to transfer ownership of the contract to an arbitrary address. This grants unauthorized users administrative privileges to manipulate critical contract functions, including setting box prices, adding rewards, and withdrawing funds.
In the MysteryBox.sol contract, the changeOwner function is defined without any access restrictions:
This function can be called by any address, enabling any user to set themselves or another address as the new owner. Once ownership is transferred, the malicious owner can perform all administrative actions, including:
Setting box prices arbitrarily.
Adding or removing rewards.
Withdrawing all funds from the contract.
This undermines the contract's security model, as ownership should be restricted to authorized administrators only.
An attacker can seize complete control over the contract by simply calling the changeOwner function. This allows them to manipulate the contract's parameters and withdraw all funds, resulting in substantial financial losses and loss of user trust.
An attacker can execute the following transaction to take ownership:
After this call, the attacker becomes the owner and can execute administrative functions:
This test verifies that any user, not just the owner, can call the changeOwner function to transfer ownership of the contract. This lack of access control poses a significant security risk.
Manual code review
Restrict the changeOwner function to be callable only by the current owner. Implement an access control mechanism to ensure that only authorized addresses can perform sensitive actions.
Example modification with access control:
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.