function setPassword(string memory newPassword) external {
s_password = newPassword;
emit SetNetPassword();
}
Function setPassword allows any caller from outside of the contract to change the s_password variable that represents the password of the owner. The function does not check for the msg.sender to be the owner that deployed the contract originally.
The setPassword function does not use any modifier nor check, that would ensure that the caller of the function is the address that deployed the contract. Since the function is only marked as "external", the function is accessible to anyone interacting with the contract. The function can be called with the specified string parameter causing a change of the password stored in the contract.
This should be considered a high-risk vulnerability as the contract is supposed to allow only the owner/deployer of the contract to change the password. This vulnerability allows any caller to change the password stored in the contract and can cause the deployer to lose the stored variable/password.
Contract analysis and local testing
I would recommend using onlyOwner modifier for both functions (setPassword, getPassword) to ensure only the deployer of the contract can access and modify the value itself.
modifier onlyOwner() {
if (msg.sender != s_owner) {
revert PasswordStore__NotOwner();
}
_;
}
Alternatively, I would propose using the same check as in the getPassword function that does prevent this misuse. However, the first proposal should be more gas-efficient and I would strongly recommend its implementation.
Anyone can call `setPassword` and set a new password contrary to the intended purpose.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.