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

The `setPassword` function lacks owner-only access control, allowing anyone to update the password

Summary

No check is performed only to allow the owner of the contract to update the password in setPassword function, so anybody can update the password

Vulnerability Details

Use the proof of code below to verify the vulnerability.

Proof of code

// SPDX-License-Identifier: MIT
pragma solidity 0.8.18;
import {Test, console} from "forge-std/Test.sol";
import {PasswordStore} from "../src/PasswordStore.sol";
import {DeployPasswordStore} from "../script/DeployPasswordStore.s.sol";
contract PasswordStoreTest is Test {
PasswordStore public passwordStore;
DeployPasswordStore public deployer;
address public owner;
function setUp() public {
deployer = new DeployPasswordStore();
passwordStore = deployer.run();
owner = msg.sender;
}
// Test no other user can set the password
function testOtherUsersCanNotSetPassword() public {
// Sending transaction as an other then owner user.
vm.prank(address(1));
// Expecting revert as no other user should be able to store password.
vm.expectRevert();
passwordStore.setPassword("Password");
}
}

Impact

Anybody can update the password.

Tools Used

Manual analysis

Recommendations

In setPassword function add the following owner-only access control before updating the password.

+ if (msg.sender != s_owner) {
+ revert PasswordStore__NotOwner();
+ }
Updates

Lead Judging Commences

inallhonesty Lead Judge
almost 2 years ago
inallhonesty Lead Judge almost 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.