unauthorize() can be front-run so that the malicious authorized user would get their authority back
The Caller contract allows an authorized user to call authorize() on behalf of the original user, so a malicious delegate can front-run an unauthorize() transaction by adding another address, then use that address to re-authorize themselves after removal. This lets the attacker keep executing transactions on behalf of the victim and potentially steal funds.
0xA5DF Follow with 0xbepresent and ladboy233
Originally disclosed on Code4rena
Submitted by 0xA5DF, also found by 0xbepresent and ladboy233
The Caller contract enables users to authorize other users to execute tx on their behalf. This option enables the authorized/delegated user to add more users to the authorized users list. In case the original user is trying to remove an authorized user (i.e. run unauthorize()), the delegated user can simply front run that tx to add another user, then after unauthorized() is executed the delegated can use the added user to gain his authority back.
This would allow the malicious delegated user to keep executing txs on behalf of the original user and cause them a loss of funds (e.g. collecting funds on their behalf and sending it to the attacker’s address).
Proof of Concept
The test below demonstrates such a scenario:
- Alice authorizes Bob
- Bob becomes malicious and Alice now wants to remove him
- Bob noticed the tx to unauthorize him and front runs it by authorizing Eve
- Alice
unauthorize()tx is executed - Bob now authorizes himself back again via Eve’s account
Front running can be done either by sending a tx with a higher gas price (usually tx are ordered in a block by the gas price / total fee), or by paying an additional fee to the validator if they manage to run their tx without reverting (i.e. by sending additional ETH to block.coinbase, hoping validator will notice it). It’s true that Alice can run unauthorize() again and again and needs to succeed only once, but:
- Bob can keep adding other users and Alice would have to keep removing them all
- This is an ongoing battle that can last forever, and Alice might not have enough knowledge, resources and time to deal with it right away. This might take hours or days, and in the meanwhile Alice might be receiving a significant amount of drips that would be stolen by Bob.
diff --git a/test/Caller.t.sol b/test/Caller.t.sol
index 861b351..3e4be22 100644
--- a/test/Caller.t.sol
+++ b/test/Caller.t.sol
@@ -125,6 +125,24 @@ contract CallerTest is Test {
vm.expectRevert(ERROR_UNAUTHORIZED);
caller.callAs(sender, address(target), data);
}
+
+ function testFrontRunUnauthorize() public {
+ bytes memory data = abi.encodeWithSelector(target.run.selector, 1);
+ address bob = address(0xbab);
+ address eve = address(0xefe);
+ // Bob is authorized by Alice
+ authorize(sender, bob);
+
+ // Bob became malicious and Alice now wants to remove him
+ // Bob sees the `unauthorize()` call and front runs it with authorizing Eve
+ authorizeCallAs(sender, bob, eve);
+
+ unauthorize(sender, bob);
+
+ // Eve can now give Bob his authority back
+ authorizeCallAs(sender, eve, bob);
+
+ }
function testAuthorizingAuthorizedReverts() public {
authorize(sender, address(this));
@@ -257,6 +275,13 @@ contract CallerTest is Test {
assertTrue(caller.isAuthorized(authorizing, authorized), "Authorization failed");
}
+ function authorizeCallAs(address originalUser,address delegated, address authorized) internal {
+ bytes memory data = abi.encodeWithSelector(Caller.authorize.selector, authorized);
+ vm.prank(delegated);
+ caller.callAs(originalUser, address(caller), data);
+ assertTrue(caller.isAuthorized(originalUser, authorized), "Authorization failed");
+ }
+
function unauthorize(address authorizing, address unauthorized) internal {
vm.prank(authorizing);
caller.unauthorize(unauthorized);
Recommended Mitigation Steps
Don’t allow authorized users to call authorize() on behalf of the original user.
This can be done by replacing _msgSender() with msg.sender at authorize(), if the devs want to enable authorizing by signing I think the best way would be to add a dedicated function for that (other ways to prevent calling authorize() from callAs() can increase gas cost for normal calls, esp. since we’ll need to cover all edge cases of recursive calls with callBatched()).
Known behavior. I think it is debatable. The
authorizemeans an other address is completely trusted in terms of access to funds. In most cases this will be the same actor like Alice. Just another address of Alice.
CodeSandwich (Drips) disagreed with severity and commented:
Like Manuel said, this is known, authorizing somebody gives them extreme privileges anyway, like stealing all the funds available for the user in the protocol.
I disagree that it’s a High severity issue, because the attacked user with some effort can defend themselves. In a single batch they need to authorize a contract that would iterate over all addresses returned by
allAuthorizedand for each of them to callunauthorizeon behalf of the attacked user.I think that the above emergency defense mechanism could be built right into
Caller’s API to make it cheaper and easier to run, basically adding anunauthorizeAllfunction that will clear the authorized addresses list. That’s why I agree that it is an issue to solve, but a low severity one, it’s only a quality of life improvement.The proposed mitigation of banning authorized users from authorizing others is too heavy handed, because it hurts use cases like a slow DAO authorizing a trusted operator, who then needs to rotate keys or authorize a “script contract” performing automated operations on Drips protocol. Authorization by signing hurts all non-EOA addresses like DAOs or multisigs which don’t have private keys.
Alex the Entreprenerd (judge) decreased severity to Medium and commented:
Because of the fact that the only requirement for the attack is for the authorized to be malicious, I have considered High Severity.
After further reflection, because of the ability to remove the malicious attacker via a Macro, per the Sponsor’s comment above, I believe Medium Severity to be the most appropriate.
The approval should be considered an extremely dangerous operation, which can cause drastic losses, however, a malicious approved can eventually be unapproved via a macro contract.
The approval should be considered an extremely dangerous operation, which can cause drastic losses, however, a malicious approval can eventually be unapproved via a macro contract
Yes, we agree here. We envision it more like the same actor/organization is using multiple addresses.
Like the multi-sig of an organization is used as the main address (address with the ens name) but not all actions might require multiple signatures. Therefore, they can approve another address. etc.
However, we assume full trust.
Alex the Entreprenerd (judge) commented:
Confirming Medium severity because:
- The risk is not in giving the approval, that is the feature offered
- The risk is in not being able to revoke an approval, due to a lack of
revokeAllor similar functionality, which can create a temporary griefBecause that can cause a denial of functionality which is limited in time, I believe Medium Severity to be the most appropriate.
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
Root cause
The authorize() function uses _msgSender() instead of msg.sender, allowing an authorized user to call authorize() via callAs() and add new authorized users on behalf of the original user.
Impact
A malicious authorized user could keep executing transactions on behalf of the original user and cause loss of funds, though the original user can defend by using a batch transaction to remove all authorized addresses.
What the attacker needed
Victim has authorized a malicious user; attacker can front-run transactions
The fix
The recommended mitigation is to prevent authorized users from calling authorize() on behalf of the original user, for example by using msg.sender instead of _msgSender() in authorize(), or by adding a dedicated function for authorizing by signature.
How it was found
- Alice authorizes Bob.
- Bob becomes malicious and Alice wants to remove him.
- Bob sees the unauthorize transaction and front-runs it by authorizing Eve.
- Alice's unauthorize transaction for Bob is executed.
- Bob uses Eve's account to authorize himself again.
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.
In this smart contract, a user can let someone else act on their behalf. That person can also let other people act on the original user's behalf. If the original user tries to remove that person, the person can quickly add another helper before the removal happens, and then that helper can add the person back. This means the original user cannot easily get rid of the malicious person.
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.