Mystery Box

First Flight #25
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Valid

Anyone can change owner

Relevant GitHub Links

https://github.com/Cyfrin/2024-09-mystery-box/blob/main/src/MysteryBox.sol#L111

Summary

Anyone can call the MysteryBox::changeOwner function and change the contract’s owner. After that, the new owner (attacker) gains access to all onlyOwner functions and can steal funds by calling MysteryBox::withdrawFunds.

Impact

An attacker can exploit this by calling MysteryBox::changeOwner, setting themselves as the owner, and then calling MysteryBox::withdrawFunds to steal funds.

Recommendations

Add a check in the MysteryBox::changeOwner function to verify that the msg.sender is the current owner:

function changeOwner(address _newOwner) public {
+ require(msg.sender == owner, "Only owner can change owner");
owner = _newOwner;
}
Updates

Appeal created

inallhonesty Lead Judge about 1 year ago
Submission Judgement Published
Validated
Assigned finding tags:

Anyone can change owner

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.