https://github.com/Cyfrin/2024-11-giving-thanks/blob/main/src/GivingThanks.sol#L11
https://github.com/Cyfrin/2024-11-giving-thanks/blob/main/src/GivingThanks.sol#L56-L58
GivingThanks::updateRegistry
is intended to update the charity information stored in the contract. It can be assumed that only the owner should be able to call on it since the CharityRegistry public registry;
state variable is a critical component of the contracts functionality. However, due to a lack of user validation on who can successfully execute this function, any user can deploy their own CharityRegistry contract (becoming the admin of their CharityRegistry), verify themselves or their own malicious charity(s), and then update the registry info in the GivingThanks
contract with that malicious information.
The contract GivingThanks
stores a key state variable CharityRegistry public registry;
which is used in GivingThanks::donate
to check which charity address has been verified by the admin of the CharityRegistry contract:
This variable handles a critical part of the GivingThanks platform as it ensures that donors can't donate to charities that haven't been verified first. However, the vulnerability that can break this lies in the function GivingThanks::updateRegistry
provided below:
An attacker can easily exploit this function due to the lack of access control, and could update the registry
state variable with a list of malicious charities that the attacker has validated themselves. They could do this through the following steps:
Deploy their own CharityRegistry
contract, making the attacker an admin
Register and Validate any number of malicious charity addresses
Call on GivingThanks::updateRegistry
with this new malicious charity registry
Unknowing donor who is convinced to donate, calls on the GivingThanks::donate
, sending money to a malicious "charity"
Likelihood: High/Medium
Severity: High
The registry
state variables is a critical component of the GivingThanks
behavior and security. Because of the lack of access control, two scenarios could happen:
Users who want to donate to a previously registered charity will be unable to, resulting in a denial of funds
Users who trust the contract see a verified charity and send funds, causing those funds to be sent to an address that, in actuality, is not a charity and is a malicious actor.
This directly affects any interaction with the contract.
Please add the following test under test/GivingThanks.t.sol
:
Then run the following CLI command:
Manual Review
To properly handle access control, I recommend adding a require
statement to the top of GivingThanks::updateRegistry
:
Once implemented, only the owner of the contract will be able to update the registry information.
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.