Mystery Box

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

Ownership Transfer Vulnerability

Summary

The MysteryBox::changeOwner() function lacks proper access control, allowing anyone to change the contract's owner without restrictions. This vulnerability could allow any user to gain control over the contract, enabling them to withdraw all funds and change important parameters.

Vulnerability Details

Affected Code

function changeOwner(address _newOwner) public {
owner = _newOwner;
}

Impact

An attacker can gain full ownership of the contract, enabling them to:

  • Withdraw all funds using MysteryBox::withdrawFunds().

  • Change the MysteryBox::boxPrice or manipulate rewards using the MysteryBox::setBoxPrice() and MysteryBox::addReward() functions.

Tools Used

  • Visual Studio Code

  • Solidity

  • Foundry

Recommended Mitigation

Restrict access to MysteryBox::changeOwner() to only the current owner.

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