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

Non owner can set new password

Summary

Function setPassword() not check owner so attacker (not owner) can set new password in contract

Vulnerability Details

Set new password with function setPassword(), now when call get getPassword() contract will return changed password. Add function test below in PasswordStore.t.sol for detail POC:

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

Impact

User can't retrieve correct password or attacker can get unauthorized access if password in contract use to check authenticate in other applications/system

Tools Used

Manual Review/ Foundry

Recommendations

Implement an owner check at the beginning of the function, ex:

if (msg.sender != s_owner) {
revert PasswordStore__NotOwner();
}
Updates

Lead Judging Commences

inallhonesty Lead Judge
almost 2 years ago
inallhonesty Lead Judge almost 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.