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.
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:
- The pool has 5 existing terms. Now the owner wants to create a new term in the Pool, so they call
setTerms()with the__termsthey want to set up. The new term is pending confirmation after a waiting period. - After
NEW_TERMS_WAITING_TIME, an attacker callsconfirmTerms()with_termKeysset to all 5 existing terms and__terms.aprPremium = 0. - The function executes with the input provided by the attacker. Since the
pendingAprPremiumof these terms is reset to0after it is confirmed earlier, the checkif (pendingAprPremium != __terms[i].aprPremium)is bypassed. The attacker could set the_terms[][][][]mapping of existing loans to0.
Recommended Mitigation Steps
Only allow the owner to call confirmTerms().
Assessed type
Invalid Validation
Terms must be passed in the confirm as well.
Status: Mitigation confirmed. Full details in reports from oakcobalt, minhquanym and bin2chen.
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
- The pool has existing terms and the owner calls setTerms() to propose a new term, which enters a waiting period.
- After the waiting time, an attacker calls confirmTerms() with the keys of all existing terms and aprPremium set to 0.
- 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.