Skip to content
Access control Audit finding Intermediate

All allowances to DepositStableCoinToDealer and GeneralRepay can be stolen due to unsafe call

The helper contracts DepositStableCoinToDealer and GeneralRepay make an unprotected external call to any address, allowing an attacker to invoke token contracts directly and transfer tokens from users who have approved the contract. This lets an attacker steal all allowances.

0x52 Follow with 0xkazim, ArbitraryExecution and 13 others

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2023-04-jojo-judging/issues/428

Found by

0x52, 0xkazim, ArbitraryExecution, Bauer, BowTiedOriole, GalloDaSballo, Inspex, Jigsaw, MalfurionWhitehat, XDZIBEC, ctf_sec, dingo, jprod15, lil.eth, tvdung94, yy

Summary

DepositStableCoinToDealer.sol and GeneralRepay.sol are helper contracts that allow a user to swap and enter JOJODealer and JUSDBank respectively. The issue is that the call is unsafe allowing the contract to call the token contracts directly and transfer tokens from anyone who has approved the contract.

Vulnerability Detail

https://github.com/sherlock-audit/2023-04-jojo/blob/main/smart-contract-EVM/contracts/stableCoin/DepositStableCoinToDealer.sol#L30-L44

    IERC20(asset).safeTransferFrom(msg.sender, address(this), amount);
    (address approveTarget, address swapTarget, bytes memory data) = abi
    .decode(param, (address, address, bytes));
    // if usdt
    IERC20(asset).approve(approveTarget, 0);
    IERC20(asset).approve(approveTarget, amount);
    (bool success, ) = swapTarget.call(data);
    if (success == false) {
        assembly {
            let ptr := mload(0x40)
            let size := returndatasize()
            returndatacopy(ptr, 0, size)
            revert(ptr, size)
        }
    }

We can see above that the call is totally unprotected allowing a user to make any call to any contract. This can be abused by calling the token contract and using the allowances of others. The attack would go as follows:

  1. User A approves the contract for 100 USDT
  2. User B sees this approval and calls depositStableCoin with the swap target as the USDT contract with themselves as the receiver
  3. This transfers all of user A USDT to them

Impact

All allowances can be stolen

Code Snippet

https://github.com/sherlock-audit/2023-04-jojo/blob/main/smart-contract-EVM/contracts/stableCoin/DepositStableCoinToDealer.sol#L23C14-L50

Tool used

Manual Review

Recommendation

Only allow users to call certain whitelisted contracts.

Discussion

JoscelynFarr

fix link: https://github.com/JOJOexchange/JUSDV1/commit/5770d15edac41c78d9726f02e988aa8e14601f3e https://github.com/JOJOexchange/smart-contract-EVM/commit/94ea554ec1c563e945bd388051f6438826818b47

IAm0x52

Fixes look good. GeneralRepay and DepositStableCoinToDealer now implement contract whitelists

The original report as published on Sherlock, by 0x52. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 contract performs an arbitrary external call without restricting the target or the data, so an attacker can make it call a token contract and use existing allowances.

Impact

All allowances can be stolen.

What the attacker needed

Victim has approved the contract; attacker can call the contract

The fix

The contracts were fixed by implementing contract whitelists to restrict which contracts can be called.

How it was found

  1. User A approves the contract for 100 USDT
  2. User B sees this approval and calls depositStableCoin with the swap target as the USDT contract with themselves as the receiver
  3. This transfers all of user A USDT to them

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.

These contracts let users swap tokens, but they also let anyone make the contract call any other contract. An attacker can make the contract call a token contract and move tokens that other users have approved for spending. This means anyone who approved the contract could lose their tokens.

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.

More by 0x52

View all

211 more disclosed reports, best first.

More from JOJO Exchange

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.