Mystery Box

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

`MysteryBox::changeOwner` has no access control, let everyone can change the owner!

Summary

In changeOwner function, it only do one thing : change the owner, and the owner has all the setting power of setBoxPrice, addReward and withdrawFunds. So the owner has power to drain the protocol.

Vulnerability Details

  1. user2 call changeOwner to himself.

  2. now the owner is user2!!!

Add following code to test file:

function testAnyOneCanChangeOwner() public {
assertEq(mysteryBox.owner(), owner);
vm.prank(user2);
mysteryBox.changeOwner(user2);
assertEq(mysteryBox.owner(), user2);
}

Impact

Malicious user can change the owner to themselves, then maybe set the very expecsive value rewards, and even more they can take away all money of protocol by calling withdrawFunds

Tools Used

manual review

Recommendations

Add access control!

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.

Give us feedback!