The function setPassword doesn't verify msg.sender is the contract owner, which allows any account calling this function to set a new password within the PasswordStore contract.
Access controls limit which accounts can access certain features of smart contracts. In the PasswordStore contract, the setPassword function is missing an access control implementation that requires msg.sender to be s_owner in order to successfully call this function. As a result, any account can call setPassword and change s_password. When getPassword is called, it will return the value of s_password, which can no longer be considered accurate.
Example:
Contract owner A deploys a new PasswordStore contract and sets the initial password to "Password" by calling setPassword.
Malicious actor B then calls setPassword to overwrite the initial password set by A to a new value of "NewPassword".
When A calls getPassword, the retrieved value is "NewPassword" set by B instead of "Password" set by A.
The following foundry test verifies the ability of a non-owner account to modify the value of s_password:
The first core feature of the PasswordStore contract (storing the password) is vulnerable to manipulation. As any account is able to call setPassword, one must assume the value of s_password is incorrect. As a result, the second core function of the PasswordStore contract (retrieving the password) cannot be called with the expectation of retrieving an accurate value for s_password. The exploitation of setPassword renders getPassword unreliable, resulting in the entire PasswordStore contract being unusable for its intended purpose.
Manual analysis and Foundry (for testing).
Implement an access control that verifies msg.sender is s_owner and reverts using the existing PasswordStore__NotOwner() error if this condition is false, as shown below:
Previous setPassword implementation:
New setPassword implementation with access control:
By adding the following code snippet to setPassword:
the setPassword function will revert if msg.sender is not s_owner, allowing only the contract owner to set s_password.
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.