Skip to content
Access control Audit finding Beginner

Anyone can call closeLoan() to close the loan

The closeLoan function in MapleLoan.sol lacks an authorization check, allowing any caller to close a loan after it has been funded. An attacker could grief the borrower and lender by forcing early closure, potentially causing gas costs and platform fee losses.

WatchPug Follow

Originally disclosed on Code4rena

Submitted by WatchPug

MapleLoan.sol L56-L63

function closeLoan(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:CL:TRANSFER_FROM_FAILED");

    ( principal_, interest_ ) = _closeLoan();

    emit LoanClosed(principal_, interest_);
}

Based on the context, we believe that the closeLoan() should only be called by the borrower. However, the current implementation allows anyone to call closeLoan() anytime after fundLoan().

If there is no earlyFee, this enables a griefing attack, causing the borrower and lender to abandon this contract and redo everything which costs more gas.

If a platform fee exits, the lender will also suffer fund loss from the platform fee charged in fundLoan().

Recommendation

Change to:

function closeLoan(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:CL:TRANSFER_FROM_FAILED");

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

    ( principal_, interest_ ) = _closeLoan();

    emit LoanClosed(principal_, interest_);
}

deluca-mike (Maple) confirmed:

pauliax (judge) commented:

Great find, missing authorization.

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

If there is no earlyFee, this enables a griefing attack causing the borrower and lender to abandon the contract and redo everything, costing more gas; if a platform fee exists, the lender may also suffer fund loss from the platform fee.

What the attacker needed

Loan must be funded; no earlyFee or platform fee present

The fix

The function should be fixed by adding a check that msg.sender is the borrower.

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 smart contract, some functions should only be callable by specific people, like the borrower. Here, the closeLoan function can be called by anyone, so a malicious user could close the loan early and disrupt the process.

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.