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

Anyone can call set new password

Summary

Anyone can call PasswordStore.setPassword() method to set new password

Vulnerability Details

The setPassword() method has external visibility and no restriction to validate the caller is the owner of the contract or not.

function setPassword(string memory newPassword) external {
s_password = newPassword;
emit SetNetPassword();
}

Impact

Anyone can can set new password for this contract means that if external contract logic utilizing the password might fail.
Here is my PoC code using Foundry unit test

function test_anyone_can_set_password() public {
vm.startPrank(address(1));
string memory expectedPassword = "newPassword";
passwordStore.setPassword(expectedPassword);
vm.stopPrank();
vm.startPrank(owner);
string memory actualPassword = passwordStore.getPassword();
assertEq(actualPassword, expectedPassword);
}

Tools Used

Manual review

Recommendations

Adding caller restriction for setPassword() method
Here is my implementation:

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.