The getPassword
function includes a direct ownership check using the condition:
While this effectively ensures that only the owner can call the getPassword
function, similar logic is recommended to be added to the setPassword
function as noted in my previous report "No Access Control on setPassword
Function". Having the same ownership verification logic in multiple functions leads to redundancy and can make the contract less maintainable. In Solidity, it's best practice to use a modifier for common checks like ownership verification, ensuring that the logic is defined in one place and can be easily applied to multiple functions.
Low. While the current implementation does not introduce a direct security vulnerability, it makes the contract less maintainable and more prone to errors in the future. If the ownership logic needs to be updated or if more functions are added that require the same check, having the logic spread out in multiple places increases the risk of inconsistencies or oversight.
Create an onlyOwner
modifier in the contract that encapsulates the ownership check and the associated revert logic. For example:
Apply this onlyOwner
modifier to the getPassword
function, and any other functions that require owner-only access, including the recommended modification to setPassword
.
By using the modifier, the code becomes cleaner, more maintainable, and less error-prone. Ensure that all functions that require owner-only access consistently use this modifier, making the contract's security posture clearer and more robust.
The contest is live. Earn rewards by submitting a finding.
This is your time to appeal against judgements on your submissions.
Appeals are being carefully reviewed by our judges.