Mystery Box

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

Protocol can be lost due to lack of validation in the `changeOwner` function.

Summary

there is no validation in changeOwner() function to ensure that ownership is not lost.

Vulnerability Details

The changeOwner function is used to change the contract owner to a new owner. But the issue here is that anyone can call changeOwner() and set themselves as the owner of the contract thereby stealing the protocol.

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

Impact

Ownership is lost

Tools Used

Manual review

Recommendations

Use the onlyOwnermodifier or implement checks that ensures that only the contract owner can call the function to transfer ownership.

// Define the 'onlyOwner' modifier
modifier onlyOwner() {
require(msg.sender == owner, "Caller is not the owner");
_;
}
function changeOwner(address _newOwner) public onlyOwner {
require(_newOwner != address(0), "New owner cannot be the zero address");
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!