The updateRegistry function in GivingThanks.sol is publicly accessible without any access control, allowing any address to modify the registry reference. This vulnerability enables unauthorized users to redirect the registry to an arbitrary address, potentially controlled by a malicious actor. As a result, verification checks can be bypassed or manipulated, compromising the contract’s integrity.
The updateRegistry function currently lacks an onlyOwner modifier or other access control, allowing any user to change the registry variable. This enables unauthorized addresses to set registry to any address, including a malicious contract, which could disrupt core contract functionality and redirect donations improperly.
Here is a proof of code that shows a donor can change the Registry address:
Logs:
This allows any address to update the registry reference, giving it an address of whatever malicious contract they might have, which can lead to critical attacks, including:
Redirecting Verification Checks: Unauthorized addresses can pass as verified, redirecting donations.
Blocking Legitimate Charities: A malicious registry could restrict legitimate charities from verification.
Complete Contract Control Disruption: The entire system’s integrity is compromised as core functionality is reliant on registry.
Manual code review
Custom test case testUnauthorizedRegistryUpdate to confirm unauthorized access with Foundry
To secure the updateRegistry function, add an onlyOwner modifier to restrict access to the contract owner. This change ensures that only the contract owner can update the registry reference, protecting the integrity of the verification process.
Consider using OpenZeppelin’s Ownable contract, which simplifies ownership management and already includes onlyOwner functionality. This would require:
Removing the manually defined owner variable in GivingThanks.
Adding Ownable to the inheritance chain of GivingThanks by initializing it in the constructor with Ownable’s constructor, which automatically sets msg.sender as the owner.
For detailed documentation on using Ownable, refer to OpenZeppelin’s Ownable Documentation.
Likelyhood: High, anyone can change it at anytime Impact: High, can bypass the verification process
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.