The function setPassword()
in contract PasswordStore.sol
can be called by any user, not only by owner. That means, everyone can set new password to the owner
.
The setPassword()
function currently lacks appropriate access control measures. Despite the @notice
indicating that only the owner
can set a new password, there is no verification process in place to enforce this. The function setPassword()
is external and can be called by any user, allowing them to alter the password. This represents a significant security vulnerability that needs to be fixed.
The function setPassword()
is external and it doesn't revert when executed by non-owner, thereby allowing unauthorized users to change the password.
This security flaw is demonstrated in the test function test_non_owner_can_set_password_reverts()
which shows that setPassword()
doesn't revert when a non-owner executes it. This test function can be added to the PasswordStore.t.sol
file and executed in Foundry
using the following command: forge test --match-test test_non_owner_can_set_password_reverts -vvv
After executing the test, the result is:
Also, there is no test case in PasswordStore.t.sol
where a non-owner calls the function setPassword()
.
VS Code, Foundry
In getPassword()
function there is a statement that checks if the function is invoked by the owner and it reverts if not. Add a similar verification statement in setPassword()
function to enhance security.
Also, you can use onlyOwner
modifier from the OpenZeppelin's Ownable
contract to restrict access to the setPassword and getPassword functions to the owner of the contract. The owner is set to the address that deploys the contract, and can be transferred to another address using the transferOwnership()
function provided by the Ownable
contract.
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.