Skip to content
Access control Audit finding Intermediate

Anyone can remove existing term without queueing through setTerms()

The confirmTerms function in PoolOfferHandler can be called by anyone and uses caller-supplied terms to overwrite existing terms, allowing an attacker to set all existing terms' aprPremium to zero without the owner's intent.

minhquanym Follow

Originally disclosed on Code4rena

Submitted by minhquanym

In PoolOfferHandler, new terms require a two-step process for setting (setTerms() and confirmTerms()). The setTerm() function is onlyOwner, but the confirmTerms() function can be called by anyone. This function uses the provided input __terms from the caller to execute the logic. This could enable an attacker to remove all existing terms, even if the owner does not intend to do so (without pending through the setTerms() function).

function confirmTerms(TermsKey[] calldata _termKeys, Terms[] calldata __terms) external {
    if (block.timestamp - pendingTermsSetTime < NEW_TERMS_WAITING_TIME) {
        revert TooSoonError();
    }
    for (uint256 i = 0; i < __terms.length; i++) {
        if (_termKeys[i].duration > getMaxDuration) {
            revert InvalidDurationError();
        }
        uint256 pendingAprPremium = _pendingTerms[_termKeys[i].collection][_termKeys[i].duration][_termKeys[i]
            .maxSeniorRepayment][__terms[i].principalAmount];
        // @audit Can be used to remove terms without pending through setTerm()
        if (pendingAprPremium != __terms[i].aprPremium) {
            revert InvalidTermsError();
        }
        _terms[_termKeys[i].collection][_termKeys[i].duration][_termKeys[i].maxSeniorRepayment][__terms[i]
            .principalAmount] = __terms[i].aprPremium;
        delete _pendingTerms[_termKeys[i].collection][_termKeys[i].duration][_termKeys[i]
            .maxSeniorRepayment][__terms[i].principalAmount];
    }
    pendingTermsSetTime = type(uint256).max;

    emit TermsSet(_termKeys, __terms);
}

Proof of Concept

Consider the following scenario:

  1. The pool has 5 existing terms. Now the owner wants to create a new term in the Pool, so they call setTerms() with the __terms they want to set up. The new term is pending confirmation after a waiting period.
  2. After NEW_TERMS_WAITING_TIME, an attacker calls confirmTerms() with _termKeys set to all 5 existing terms and __terms.aprPremium = 0.
  3. The function executes with the input provided by the attacker. Since the pendingAprPremium of these terms is reset to 0 after it is confirmed earlier, the check if (pendingAprPremium != __terms[i].aprPremium) is bypassed. The attacker could set the _terms[][][][] mapping of existing loans to 0.

Recommended Mitigation Steps

Only allow the owner to call confirmTerms().

Assessed type

Invalid Validation

0xend (Gondi) confirmed

Gondi mitigated:

Terms must be passed in the confirm as well.

Status: Mitigation confirmed. Full details in reports from oakcobalt, minhquanym and bin2chen.


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

Likely the confirmTerms function lacks access control and uses caller-provided terms instead of the pending terms set by the owner.

Impact

An attacker could remove all existing terms by setting their aprPremium to zero, disrupting the pool's configuration.

What the attacker needed

Waiting period elapsed; attacker can call confirmTerms

The fix

The project mitigated the issue by requiring terms to be passed in the confirm step as well, and the mitigation was confirmed.

How it was found

  1. The pool has existing terms and the owner calls setTerms() to propose a new term, which enters a waiting period.
  2. After the waiting time, an attacker calls confirmTerms() with the keys of all existing terms and aprPremium set to 0.
  3. The check against pendingAprPremium passes because existing terms have pendingAprPremium 0, so the attacker overwrites the terms mapping with 0.

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.

A smart contract has a function that lets anyone confirm new terms, but it also lets the caller provide the terms themselves. Because the check only compares against a pending value that is zero for existing terms, an attacker can pass zero and overwrite real terms. This means the attacker can change important settings without permission.

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 minhquanym

View all

28 more disclosed reports, best first.

More from Gondi Invitational

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.