Attacker can take loan for Victim
The authority check in the loan commitment validation used the receiver address instead of the caller, so an attacker could originate a loan against a victim's collateral by setting the receiver to the victim. This forced an unwanted loan and associated fees on the collateral owner.
Anurag Jain Follow with bin2chen, cergyk and 6 others
Originally disclosed on Code4rena
Submitted by csanuragjain, also found by bin2chen, cergyk, evan, 7siech, obront, KIntern_NA, Koolex, and unforgiven
An unapproved, non-owner of collateral can still take loan for the owner/operator of collateral even when owner did not needed any loan. This is happening due to incorrect checks as shown in POC. This leads to unintended loan and associated fees for users.
Proof of Concept
- A new loan is originated via
commitToLienfunction by User X. Params used by User X are as below:
collateralId = params.tokenContract.computeId(params.tokenId) = 1
CT.ownerOf(1) = User Y
CT.getApproved(1) = User Z
CT.isApprovedForAll(User Y, User X) = false
receiver = User Y
- This internally make call to
_requestLienAndIssuePayoutwhich then calls_validateCommitmentfunction for signature verification - Lets see the signature verification part in
_validateCommitmentfunction
function _validateCommitment(
IAstariaRouter.Commitment calldata params,
address receiver
) internal view {
uint256 collateralId = params.tokenContract.computeId(params.tokenId);
ERC721 CT = ERC721(address(COLLATERAL_TOKEN()));
address holder = CT.ownerOf(collateralId);
address operator = CT.getApproved(collateralId);
if (
msg.sender != holder &&
receiver != holder &&
receiver != operator &&
!CT.isApprovedForAll(holder, msg.sender)
) {
revert InvalidRequest(InvalidRequestReason.NO_AUTHORITY);
}
VIData storage s = _loadVISlot();
address recovered = ecrecover(
keccak256(
_encodeStrategyData(
s,
params.lienRequest.strategy,
params.lienRequest.merkle.root
)
),
params.lienRequest.v,
params.lienRequest.r,
params.lienRequest.s
);
if (
(recovered != owner() && recovered != s.delegate) ||
recovered == address(0)
) {
revert IVaultImplementation.InvalidRequest(
InvalidRequestReason.INVALID_SIGNATURE
);
}
}
- Ideally the verification should fail since :
a. User X is not owner of passed collateral b. User X is not approved for this collateral c. User X is not approved for all of User Y token
- But observe the below if condition doing the required check:
uint256 collateralId = params.tokenContract.computeId(params.tokenId);
ERC721 CT = ERC721(address(COLLATERAL_TOKEN()));
address holder = CT.ownerOf(collateralId);
address operator = CT.getApproved(collateralId);
if (
msg.sender != holder &&
receiver != holder &&
receiver != operator &&
!CT.isApprovedForAll(holder, msg.sender)
) {
revert InvalidRequest(InvalidRequestReason.NO_AUTHORITY);
}
- In our case this if condition does not execute since receiver = holder
if (
msg.sender != holder && // true since User X is not the owner
receiver != holder && // false since attacker passed receiver as User Y which is owner of collateral, thus failing this if condition
receiver != operator &&
!CT.isApprovedForAll(holder, msg.sender)
) {
revert InvalidRequest(InvalidRequestReason.NO_AUTHORITY);
}
- This means the signature verification passes and loan is issued for collateral owner without his wish
Recommended Mitigation Steps
Revise the condition as shown below:
if (
msg.sender != holder &&
msg.sender != operator &&
!CT.isApprovedForAll(holder, msg.sender)
) {
revert InvalidRequest(InvalidRequestReason.NO_AUTHORITY);
}
if (
receiver != holder &&
receiver != operator
) {
revert InvalidRequest(InvalidRequestReason.NO_AUTHORITY);
}
SantiagoGregory (Astaria) confirmed via duplicate issue #565
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
The authority check compared the receiver address to the collateral holder and operator instead of comparing the caller (msg.sender), so setting receiver to the holder bypassed the permission check.
Impact
The collateral owner could be forced into an unintended loan and charged associated fees without their consent.
What the attacker needed
Victim owns the collateral NFT; attacker has a valid vault signature; attacker can call commitToLien
The fix
The authority check should be split so that the caller must be the holder, an approved operator, or approved for all, and separately the receiver must be the holder or operator.
How it was found
- The attacker calls commitToLien with a collateral ID owned by the victim, sets the receiver to the victim, and provides a valid vault signature.
- The call reaches _requestLienAndIssuePayout and then _validateCommitment for signature verification.
- In _validateCommitment, the authority check sees receiver equals holder and does not revert.
- The signature check passes and a loan is issued against the victim's collateral without their consent.
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 lets people borrow against NFTs they own. Before issuing a loan, it checks that the person asking has the right to use that NFT. The check was written so that naming the NFT's owner as the loan receiver made the check pass, even though the caller had no permission. So anyone could start a loan on someone else's NFT, sticking that owner with fees they never agreed to.
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.