The setPassword()
function does not limit who can call it and set a new password, but the purpose was that only the owner of the contract would be able to set a new password.
The function setPassword()
is used to set a new password for the owner of the contract and store the new value in the s_password
state variable. Since it's the owner's password, the function should limit itself to be called only by the owner. This limitation is also documented in the comments where it is stated @notice This function allows only the owner to set a new password.
But this limitation does not exist, no check on who called the function and the function is set to public, so anyone can call this function and set a new password for the owner.
Anyone can change the owner's password which is directly in contrast to its purpose as stated in the comments.
We don't really know what the password is used for, but passwords are usually used to protect sensitive information or funds. Therefore, a compromised password very often means a lot of damage. Also, as can be seen in the test code provided below, it's straightforward to change the password. This is why the severity for this bug is high.
Here is a test function with comments, to show that an attacker (non-owner) can set s_password
to whatever he or she wants:
Foundry
To mitigate the issue, add an access control check on the caller of the function -> require(msg.sender == owner)
.
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.