InitialETHCrowdfund + ReraiseETHCrowdfund : Gatekeeper checks wrong address
The InitialETHCrowdfund and ReraiseETHCrowdfund contracts check the contributor address instead of the caller (msg.sender) when enforcing a gatekeeper allowlist. This lets any user contribute on behalf of an allowlisted address, bypassing the intended restriction that only allowlisted users can contribute.
Originally disclosed on Code4rena
Submitted by HollaDieWaldfee
This vulnerability exists in both the InitialETHCrowdfund and ReraiseETHCrowdfund contracts in exactly the same way.
I will continue this report by explaining the issue in only one contract. The mitigation section however contains the fix for both instances.
When making a contribution there is a check with the gatekeeper (if it is configured):
// Must not be blocked by gatekeeper.
IGateKeeper _gateKeeper = gateKeeper;
if (_gateKeeper != IGateKeeper(address(0))) {
if (!_gateKeeper.isAllowed(contributor, gateKeeperId, gateData)) {
revert NotAllowedByGateKeeperError(
contributor,
_gateKeeper,
gateKeeperId,
gateData
);
}
}
The issue is that the first argument to the isAllowed function is wrong. It is contributor but it should be msg.sender.
The impact of this is that it will be possible for unauthorized users to make contributions.
Proof of Concept
Fortunately the new InitialETHCrowdfund and ReraiseETHCrowdfund contracts are very similar to the already audited other crowdfund contracts.
So we can look into the Crowdfund.sol code and see how the gatekeeper.isAllowed function should be called:
function _contribute(
address contributor,
address delegate,
uint96 amount,
uint96 previousTotalContributions,
bytes memory gateData
) private {
if (contributor == address(this)) revert InvalidContributorError();
if (amount == 0) return;
// Must not be blocked by gatekeeper.
{
IGateKeeper _gateKeeper = gateKeeper;
if (_gateKeeper != IGateKeeper(address(0))) {
if (!_gateKeeper.isAllowed(msg.sender, gateKeeperId, gateData)) {
revert NotAllowedByGateKeeperError(
msg.sender,
_gateKeeper,
gateKeeperId,
gateData
);
}
}
}
We can see that the first argument to the gatekeeper.isAllowed function is msg.sender.
This means that when User A contributes for User B, the address that is checked is the address of User A and not the address of User B.
The new crowdfund contracts however check contributor:
// Must not be blocked by gatekeeper.
IGateKeeper _gateKeeper = gateKeeper;
if (_gateKeeper != IGateKeeper(address(0))) {
if (!_gateKeeper.isAllowed(contributor, gateKeeperId, gateData)) {
revert NotAllowedByGateKeeperError(
contributor,
_gateKeeper,
gateKeeperId,
gateData
);
}
}
This means that when User A contributes for User B, the address of User B is checked. However it should be the address of User A (as seen above).
Imagine a situation where three addresses are whitelisted by the gatekeeper:
Alice
Bob
Chris
What should be checked by the gatekeeper is that only Alice, Bob and Chris can make contributions but they should be able to make contributions for everyone (check msg.sender instead of contributor).
What is actually checked is that any user can make a contribution but they can only contribute to Alice, Bob and Chris (check contributor instead of msg.sender).
Tools Used
VSCode
Recommended Mitigation Steps
In both contracts the msg.sender needs to be checked instead of contributor.
diff --git a/contracts/crowdfund/InitialETHCrowdfund.sol b/contracts/crowdfund/InitialETHCrowdfund.sol
index 8ab3b5c..fa8ec5d 100644
--- a/contracts/crowdfund/InitialETHCrowdfund.sol
+++ b/contracts/crowdfund/InitialETHCrowdfund.sol
@@ -282,9 +282,9 @@ contract InitialETHCrowdfund is ETHCrowdfundBase {
// Must not be blocked by gatekeeper.
IGateKeeper _gateKeeper = gateKeeper;
if (_gateKeeper != IGateKeeper(address(0))) {
- if (!_gateKeeper.isAllowed(contributor, gateKeeperId, gateData)) {
+ if (!_gateKeeper.isAllowed(msg.sender, gateKeeperId, gateData)) {
revert NotAllowedByGateKeeperError(
- contributor,
+ msg.sender,
_gateKeeper,
gateKeeperId,
gateData
diff --git a/contracts/crowdfund/ReraiseETHCrowdfund.sol b/contracts/crowdfund/ReraiseETHCrowdfund.sol
index 580623d..72f3a20 100644
--- a/contracts/crowdfund/ReraiseETHCrowdfund.sol
+++ b/contracts/crowdfund/ReraiseETHCrowdfund.sol
@@ -215,9 +215,9 @@ contract ReraiseETHCrowdfund is ETHCrowdfundBase, CrowdfundNFT {
// Must not be blocked by gatekeeper.
IGateKeeper _gateKeeper = gateKeeper;
if (_gateKeeper != IGateKeeper(address(0))) {
- if (!_gateKeeper.isAllowed(contributor, gateKeeperId, gateData)) {
+ if (!_gateKeeper.isAllowed(msg.sender, gateKeeperId, gateData)) {
revert NotAllowedByGateKeeperError(
- contributor,
+ msg.sender,
_gateKeeper,
gateKeeperId,
gateData
On this note it is important to mention that there is also an issue in Crowdfund.sol which is out of scope but the issue is of importance here:
The issue is in the Crowdfund.batchContributeFor function.
The function calls this.contributeFor Link.
So when the call is made, msg.sender is the address of the crowdfund and not the address of the user.
Therefore the gatekeeper check is wrong Link.
This is clearly not how the gatekeeper should be used. The gatekeeper should check the address of the user.
If you implement in the ReraiseETHCrowdfund and InitialETHCrowdfund contracts the changes I suggested, the same issue will be introduced there.
The solution is to call _contributeFor directly and to remove the revertOnFailure option. Or do a more involved change with supplying the correct msg.sender.
Will leave open for sponsor review.
I think the crux of it comes down to this assumption by the warden:
“This is clearly not how the gatekeeper should be used. The gatekeeper should check the address of the user.”
I believe the design is meant to check instead for the address of the
contributorbut cannot find that explicitly documented.
0xble (Party) confirmed and commented:
I think it makes the most sense to be consistent with the behavior of prior crowdfunds here. Will implement the recommended mitigation.
The note about
Crowdfund.batchContributeForis also interesting and something we’ll look into. Very glad it was brought up even though it was out of scope.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Impact
Unauthorized users could make contributions by specifying an allowlisted address as the contributor, bypassing the gatekeeper restriction.
What the attacker needed
Gatekeeper is configured; attacker knows an allowlisted address
The fix
The contracts should be fixed by checking msg.sender instead of contributor in the gatekeeper call, and the report also notes a related issue in Crowdfund.batchContributeFor where msg.sender becomes the contract itself.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A gatekeeper is a contract that checks if an address is allowed to do something, like a VIP list. The crowdfund contracts were checking the wrong address: they checked the person receiving the contribution instead of the person sending it. So anyone could send money on behalf of a VIP and get in, even if they themselves were not on the list.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.