Mystery Box

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

Everyone can set the owner of the `MysteryBox` contract

Summary

Every user can set the owner of `MysteryBox` contract. There aren't any restrictions wheter msg.sender == currentOwner

Impact

Every user can make himself as owner and withdraw contract funds.

Tools Used

Foundry and solidity. Add the following code inside TestMysteryBox.t.sol:

<details>
<summary>Code</summary>
```javascript
function testchangeOwner_NotOwnerCanSetTheNewOwner() public {
vm.prank(user1);
mysteryBox.changeOwner(user1);
assertEq(mysteryBox.owner(), user1);
}
```
</details>

Recommendations

Add check wheter msg.sender == currentOwner or add modifier to execute the check.

```diff
function changeOwner(address _newOwner) public {
+ require(msg.sender == owner);
owner = _newOwner;
}
```
Updates

Lead Judging Commences

inallhonesty Lead Judge
about 1 year ago

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!