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

Any user can modify / set a new password

In the PasswordStore.sol contract, specifically in the setPassword function, there are no checks to verify that only the owner can change the password. This allows any user to change the password, regardless of whether they are the owner or not.

Here is a simple POC in foundry to verify that any user can change the password:
function test_random_user_can_set_password() public {
vm.startPrank(address(1));
string memory expectedPassword = "myNewPassword";
passwordStore.setPassword(expectedPassword);
vm.stopPrank();
vm.prank(owner);
string memory actualPassword = passwordStore.getPassword();
assertEq(actualPassword, expectedPassword);
}

I recommend adding an ownership check on top of the function call to only allow the owner to make changes.

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.