In the contract, s_owner is set to msg.sender in the constructor. This means that the address that deploys the contract becomes the owner. In the setPassword function, there's no require statement that checks if msg.sender is equal to the owner before setting a password.
If the is no check that the sender is equal to the owner it leaves a huge risk, If it is not checked, this gives access to a bad actor or anyone who is not s_owner to exploit it. Using a require statement to check if the sender is equal to the owner makes it more secure and less vulnerable to attacks.
Here's an example of a contract without the require statement:
In this contract, any address can call the set function, not just the owner. This could be a problem if the data is sensitive and should only be modified by the owner.
Now, let's write a test case in JavaScript to show this:
In this test case, we're using a non-owner account to call the set function. The set function changes the data state variable in the contract. The test passes, showing that a non-owner can change the data, thus exploiting the contract.
Mocha, Chai, Foundry
Check that the sender is equal to the owner of the 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.