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

Unauthorized Access Control Leading to Anyone changing the password.

Summary

Unauthorized users may exploit the access control vulnerability by calling the setPassword function and changing the password, potentially leading to unauthorized access and changes in the contract state.

Vulnerability Details

The vulnerability arises from a lack of proper access control in the smart contract. As a result, any user can potentially set a new password, which should only be allowed for the contract owner. Unauthorized changes to the password can compromise the security and integrity of the contract.

Impact

The impact of this vulnerability is high risk, as it allows any unauthorized users to alter the password, undermining the security of the PasswordStore contract and potentially causing disruptions to the intended functionality.

Tools Used

No specific tools are involved in this vulnerability. It's a fundamental access control issue that can be addressed through code and design improvements.

Recommendations

To mitigate this access control vulnerability, it is crucial to implement proper access control mechanisms. The following steps can be taken to secure the contract:

  1. Create an onlyOwner modifier that checks the msg.sender against the owner's address and apply this modifier to the setPassword function:

    error ONLY_OWNER_CAN_CALL_THIS_FUNCTION();
    modifier onlyOwner() {
    if(msg.sender != s_owner){
    revert ONLY_OWNER_CAN_CALL_THIS_FUNCTION();
    }
    _;
    }
    function setPassword(string memory newPassword) external onlyOwner {
    s_password = newPassword;
    emit SetNetPassword();
    }
  2. An alternative approach is to inherit the Ownable contract from OpenZeppelin to provide built-in access control functionality:

    import "@openzeppelin/contracts/access/Ownable.sol";
    contract PasswordStore is Ownable {
    // Rest of the contract code
    function setPassword(string memory newPassword) external onlyOwner {
    // Rest of the function code
    }
    }

    These recommendations help ensure that only the owner of the contract can set the password, enhancing security and access control.

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.