Mystery Box

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

Missing access control for contract ownership function

Summary

The contract allows any user to change ownership of the MysteryBox contract. This is due to missing access control on the changeOwner function.

Vulnerability Details

The changeOwner()function is missing access control, allowing any user to gain ownership of the contract, which would then allow them to drain all user funds using the withdrawFunds()function.

Impact

Owner change of contract, ability to drain contract of all user funds.

Tools Used

Manual review, OpenZeppelin.

Recommendations

Apply an onlyOwner modifier to the function. This can be done either by creating the modifier, or preferrably, importing the OpenZeppelin Ownable contract which has the modifier available.

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
contract MysteryBox is Ownable {
...
function changeOwner(address _newOwner) public onlyOwner {
owner = _newOwner;
}
}
Updates

Appeal created

inallhonesty Lead Judge 11 months 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.