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

Lack of Access control on setPassword

Summary

Access Control issues are common in all programs, not just smart contracts. One usually accesses a contract's functionality through its public or external functions.

Access controls define the restrictions around privileges and roles of users in an application.

Vulnerability Details

The consequences of neglecting access control can be disastrous. Without proper checks, unauthorized users can gain unrestricted access to sensitive functionalities, such as minting or burning tokens, altering critical contract parameters, or even transferring ownership. This unrestricted access can lead to unauthorized creation or destruction of tokens, theft of user funds, or manipulation of contract behavior.

Missed Modifier Validations — It is important to have access control validations on critical functions

The setPassword() function is used to set a new password, but the problem is this function lacked any access control. The visibility modifier was set to external allowing anyone to set a new password.

https://github.com/Cyfrin/2023-10-PasswordStore/blob/main/src/PasswordStore.sol?plain=1#L26

function setPassword(string memory newPassword) external {

Impact

Proper access control ensures that only authorized entities can execute sensitive operations or modify critical data. However, when access control mechanisms are improperly implemented or omitted entirely, vulnerabilities emerge.

The visibility modifier was set to external allowing anyone to set a new password.

Tools Used

Manual code review

Recommendations

Implementing proper access control mechanisms involves using modifiers, conditionals, or external role-based contracts to restrict function execution to authorized entities.

To fix this issue, you should use the onlyowner modifier to restrict access to the function so that only the current owner can call it.

modifier onlyowner {
require(msg.sender == owner);
_;
}
function setPassword(string memory newPassword) external onlyowner {
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.