GivingThanks

First Flight #28
Beginner FriendlyFoundry
100 EXP
View results
Submission Details
Severity: high
Valid

Insecure Access Control for GivingThanks::updateRegistry Function

Summary

The contract allows the owner to update the registry address through the updateRegistry function. However, without verifying the integrity of the new registry contract or adding stricter checks, an attacker or an untrusted party could potentially set the registry address to a malicious contract, which could compromise the functionality and security of the contract.

Vulnerability Details

The updateRegistry function is publicly accessible and allows the contract owner to change the address of the CharityRegistry contract. While the function is restricted to the owner via the onlyOwner modifier, no additional checks ensure that the new registry contract is a legitimate, verified contract. This leaves the contract vulnerable to being pointed to a malicious or compromised CharityRegistry contract.

Impact

If an attacker or unauthorized user gains access to the contract owner account, they could update the registry address to a malicious contract. This would allow the attacker to manipulate the behavior of the donation process (e.g., validating fake charities), potentially leading to funds being redirected to malicious entities. This could result in financial loss and loss of trust in the contract.

Tools Used

Manual code review

Recommendations

To secure the updateRegistry function, add the onlyOwner modifier to restrict access to the contract owner, check that the new registry address is a contract using Address.isContract, and emit an event (e.g., RegistryUpdated) to provide transparency for any registry changes. This approach minimizes the risk of setting an invalid or malicious registry address and makes updates traceable.

Here's the revised function:

function updateRegistry(address _registry) public onlyOwner {
require(Address.isContract(_registry), "Address is not a contract");
registry = CharityRegistry(_registry);
emit RegistryUpdated(_registry);
}
event RegistryUpdated(address indexed newRegistry);
Updates

Lead Judging Commences

n0kto Lead Judge 12 months ago
Submission Judgement Published
Validated
Assigned finding tags:

finding-anyone-can-change-registry

Likelyhood: High, anyone can change it at anytime Impact: High, can bypass the verification process

Support

FAQs

Can't find an answer? Chat with us on Discord, Twitter or Linkedin.