Skip to content
Access control Audit finding Intermediate

Approval is not reset if the call to IFulfillHelper fails

The fulfill function approves the callTo address to spend tokens before attempting to call IFulfillHelper; if that call fails, the tokens are transferred directly to the fallback address but the approval is not revoked. A malicious callTo can later pull those tokens.

pauliax Follow

Originally disclosed on Code4rena

Submitted by pauliax, also found by 0xsanson, cmichel and shw

The function fulfill first approves the callTo to transfer an amount of toSend tokens and tries to call IFulfillHelper, but if the call fails, it transfers these assets directly. However, in such case the approval is not reset, so a malicous callTo can pull these tokens later:

// First, approve the funds to the helper if needed
    if (!LibAsset.isEther(txData.receivingAssetId) && toSend > 0) {
      require(LibERC20.approve(txData.receivingAssetId, txData.callTo, toSend), "fulfill: APPROVAL_FAILED");
    }

    // Next, call `addFunds` on the helper. Helpers should internally
    // track funds to make sure no one user is able to take all funds
    // for tx
    if (toSend > 0) {
      try
        IFulfillHelper(txData.callTo).addFunds{ value: LibAsset.isEther(txData.receivingAssetId) ? toSend : 0}(
          txData.user,
          txData.transactionId,
          txData.receivingAssetId,
          toSend
        )
      {} catch {
        // Regardless of error within the callData execution, send funds
        // to the predetermined fallback address
        require(
          LibAsset.transferAsset(txData.receivingAssetId, payable(txData.receivingAddress), toSend),
          "fulfill: TRANSFER_FAILED"
        );
      }
    }

Tuesday, August 10, 2021 Recommend that approval should be placed inside the try/catch block or approval needs to be reset if the call fails.

LayneHaber (Connext) confirmed and patched:

https://github.com/connext/nxtp/pull/39

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

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 approval to callTo is granted before the external call and is not revoked if the call reverts, leaving a lingering allowance.

Impact

A malicious callTo could later transfer the tokens that were sent to the fallback address, potentially stealing funds.

What the attacker needed

Malicious callTo address; helper call fails

The fix

The approval should be placed inside the try/catch block or reset if the call fails; the project confirmed and patched this.

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.

When you approve someone to spend your tokens, you are giving them permission to take them later. Here the contract gave that permission before trying to use a helper contract, and when the helper call failed it sent the tokens elsewhere but forgot to cancel the permission. The helper could then take the tokens that were meant for someone else.

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 pauliax

View all

16 more disclosed reports, best first.

More from Connext Amarok contest

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.