Skip to content
Access control Audit finding Intermediate

makePayment() Lack of access control allows malicious lender to retrieve a large portion of the funds earlier, making the borrower suffer fund loss

The makePayment function lacked access control, allowing any caller to repay the loan using the contract's drawable funds. A malicious lender could call it repeatedly after funding to reclaim most of their principal early, leaving the borrower owing interest on unused funds or facing collateral loss.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

MapleLoan.sol L86-L93

function makePayment(uint256 amount_) external override returns (uint256 principal_, uint256 interest_) {
    // The amount specified is an optional amount to be transfer from the caller, as a convenience for EOAs.
    require(amount_ == uint256(0) || ERC20Helper.transferFrom(_fundsAsset, msg.sender, address(this), amount_), "ML:MP:TRANSFER_FROM_FAILED");

    ( principal_, interest_ ) = _makePayment();

    emit PaymentMade(principal_, interest_);
}

The current implementation allows anyone to call makePayment() and repay the loan with _drawableFunds.

This makes it possible for a malicious lender to call makePayment() multiple times right after fundLoan() and retrieve most of the funds back immediately, while then borrower must continue to make payments or lose the collateral.

PoC

Given:

  • _collateralRequired = 1 BTC
  • _principalRequested = 12,000 USDC
  • _paymentInterval = 30 day
  • _paymentsRemaining = 12
  • _gracePeriod = 1 day
  • interestRate_ = 2e17
  • The borrower calls postCollateral() and added 1 BTC as _collateralAsset;
  • The lender calls fundLoan() and added 12,000 USDC as _fundsAsset;
  • The lender calls makePayment() 11 times, then:
  • _drawableFunds = 96
  • _claimableFunds = 11903
  • _principal = 1553
  • The lender calls _claimFunds() get 11,903 USDC of _fundsAsset back;

Now, for the borrower 1,579 USDC is due, but only 96 USDC can be used. The borrower is now forced to pay the interests for the funds that never be used or lose the collateral.

Recommendation

Change to:

function makePayment(uint256 amount_) external override returns (uint256 principal_, uint256 interest_) {
    // The amount specified is an optional amount to be transfer from the caller, as a convenience for EOAs.
    require(amount_ == uint256(0) || ERC20Helper.transferFrom(_fundsAsset, msg.sender, address(this), amount_), "ML:MP:TRANSFER_FROM_FAILED");

    require(msg.sender == _borrower, "ML:DF:NOT_BORROWER");

    ( principal_, interest_ ) = _makePayment();

    emit PaymentMade(principal_, interest_);
}

deluca-mike (Maple) confirmed:

Good catch. However, we do want accounts other than the borrower to make payments (this is actually functionality that our current borrowers use), so instead of this fix, we may enforce that a payment can only be made some window of time before it is due, to prevent anyone from prematurely paying it down.

pauliax (judge) commented:

Great find, with a POC, deserves a severity of high as it may incur in funds lost for the borrower. The sponsor has acknowledged and mitigated the issue.

The original report as published on Code4rena, by WatchPug. 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

Impact

The borrower could be forced to pay interest on funds they never used or lose their collateral, as the lender retrieves most of the funds early.

What the attacker needed

A loan contract with drawable funds; lender has funded the loan; borrower has posted collateral

The fix

The project acknowledged the issue and planned to mitigate it by restricting when payments can be made, rather than simply limiting the caller to the borrower.

How it was found

  1. The borrower posts 1 BTC as collateral.
  2. The lender funds the loan with 12,000 USDC.
  3. The lender calls makePayment 11 times.
  4. The lender calls _claimFunds and receives 11,903 USDC back.

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 a loan contract, the borrower is supposed to make payments. Here, anyone could trigger a payment using money already sitting in the contract. A lender could abuse this to take back most of their money right after lending it, while the borrower still owes interest on the full amount.

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 WatchPug

View all

197 more disclosed reports, best first.

More from Maple Finance 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.