Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Valid

Anyone can change the password

Summary

The function setPassword does not have a check that would restrict calls from anyone other than the contract owner.

Vulnerability Details

The setPassword function allows anyone to set a new password.

Impact

This vulnerability has a severe impact since it allows anyone to change the password.

function test_anyone_can_set_password() public {
/* Not owner account*/
vm.startPrank(address(1));
string memory expectedPassword = "myNewPassword2";
passwordStore.setPassword(expectedPassword);
/* Owner account */
vm.startPrank(owner);
string memory actualPassword = passwordStore.getPassword();
assertEq(actualPassword, expectedPassword);
}

Tools Used

Foundry

Recommendations

Check who is calling the setPassword function

function setPassword(string memory newPassword) external {
+ if (msg.sender != s_owner) {
+ revert PasswordStore__NotOwner();
+ }
s_password = newPassword;
emit SetNetPassword();
}
Updates

Lead Judging Commences

inallhonesty Lead Judge
about 2 years ago
inallhonesty Lead Judge about 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

finding-lacking-access-control

Anyone can call `setPassword` and set a new password contrary to the intended purpose.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.