addNewTranche() no authorization from borrower
The addNewTranche function only verified the lender's signature, not the borrower's authorisation, so any lender could add a tranche to any loan. A lender could set a very high APR and a fee equal to the principal, harming the borrower.
bin2chen Follow with oakcobalt, minhquanym and 1 other
Originally disclosed on Code4rena
Submitted by bin2chen, also found by oakcobalt, minhquanym, and zhaojie
For addNewTranche(), the code implementation is as follows:
function addNewTranche(
RenegotiationOffer calldata _renegotiationOffer,
Loan memory _loan,
bytes calldata _renegotiationOfferSignature
) external nonReentrant returns (uint256, Loan memory) {
uint256 loanId = _renegotiationOffer.loanId;
_baseLoanChecks(loanId, _loan);
_baseRenegotiationChecks(_renegotiationOffer, _loan);
@> _checkSignature(_renegotiationOffer.lender, _renegotiationOffer.hash(), _renegotiationOfferSignature);
if (_loan.tranche.length == getMaxTranches) {
revert TooManyTranchesError();
}
uint256 newLoanId = _getAndSetNewLoanId();
Loan memory loanWithTranche = _addNewTranche(newLoanId, _loan, _renegotiationOffer);
_loans[newLoanId] = loanWithTranche.hash();
delete _loans[loanId];
ERC20(_loan.principalAddress).safeTransferFrom(
_renegotiationOffer.lender, _loan.borrower, _renegotiationOffer.principalAmount - _renegotiationOffer.fee
);
if (_renegotiationOffer.fee > 0) {
/// @dev Cached
ProtocolFee memory protocolFee = _protocolFee;
ERC20(_loan.principalAddress).safeTransferFrom(
_renegotiationOffer.lender,
protocolFee.recipient,
_renegotiationOffer.fee.mulDivUp(protocolFee.fraction, _PRECISION)
);
}
emit LoanRefinanced(
_renegotiationOffer.renegotiationId, loanId, newLoanId, loanWithTranche, _renegotiationOffer.fee
);
return (newLoanId, loanWithTranche);
}
Currently only the signature of the lender is checked, not the authorization of the borrower. Then, any lender can add tranche to any loan by:
- Specifying a very high apr.
- Specifying any
_renegotiationOffer.fee; for example: set_renegotiationOffer.fee==_renegotiationOffer.principalAmount.
This doesn’t make sense for borrower. It is recommended that only the borrower performs this method.
Impact
lender can be specified to generate a malicious tranche to compromise borrower.
Recommended Mitigation
function addNewTranche(
RenegotiationOffer calldata _renegotiationOffer,
Loan memory _loan,
bytes calldata _renegotiationOfferSignature
) external nonReentrant returns (uint256, Loan memory) {
uint256 loanId = _renegotiationOffer.loanId;
+ if (msg.sender != _loan.borrower) {
+ revert InvalidCallerError();
+ }
_baseLoanChecks(loanId, _loan);
_baseRenegotiationChecks(_renegotiationOffer, _loan);
_checkSignature(_renegotiationOffer.lender, _renegotiationOffer.hash(), _renegotiationOfferSignature);
if (_loan.tranche.length == getMaxTranches) {
revert TooManyTranchesError();
}
Assessed type
Context
0xend (Gondi) confirmed via duplicate Issue #52
Added caller check.
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
Impact
A lender could add a malicious tranche to a borrower's loan, compromising the borrower.
What the attacker needed
Attacker acts as a lender; a loan exists to target
The fix
The function was fixed by adding a check that the caller is the borrower.
How it was found
- A lender calls addNewTranche on any loan.
- The lender specifies a very high APR.
- The lender sets the fee equal to the principal amount.
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 tranche is a slice of a loan with its own terms. The function that adds a tranche checked only that the lender had signed, not that the borrower agreed. So a lender could add a bad tranche to someone else's loan 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.