Delegations cannot be removed in some cases due to vulnerable revokeDelegate() implementation
The revokeDelegate function always passes empty rights to the DelegateRegistry, so it cannot remove delegations that were created with custom rights. An old borrower can therefore keep a delegation and claim benefits (such as event tickets) that belong to a new borrower.
Submitted by oakcobalt
An old borrower can use an old delegation to claim on behalf of a new borrower.
Proof of Concept
A borrower can delegate locked collateral NFT through delegateRegistry to prove token ownership and claim airdrops, event ticketing, etc.
delegateRegistry by Delegate.Cash protocol allows custom rights to be configured to a delegatee.
Currently, MultiSourceLoan::delegate allows a borrower to configure bytes32 _rights to delegateERC721. In DelegateRegistry::delegateERC721, bytes32 rights will be hashed as part of the key to store delegation data.
//src/lib/loans/MultiSourceLoan.sol
function delegate(uint256 _loanId, Loan calldata loan, address _delegate, bytes32 _rights, bool _value) external {
if (loan.hash() != _loans[_loanId]) {
revert InvalidLoanError(_loanId);
}
if (msg.sender != loan.borrower) {
revert InvalidCallerError();
}
//@audit-info a borrower can pass custom rights to delegateERC721
|> IDelegateRegistry(getDelegateRegistry).delegateERC721(
_delegate, loan.nftCollateralAddress, loan.nftCollateralTokenId, _rights, _value
);
emit Delegated(_loanId, _delegate, _value);
}
src/lib/loans/MultiSourceLoan.sol#L484
The problem is, in MultiSourceLoan::revokeDelegate, empty rights will always be passed to delegateERC721. This means when a borrower configures custom rights in delegate(), they cannot remove the delegation. In DelegateRegistry::delegateERC721, empty rights will be hashed into a different key from the borrower’s actual delegation. Incorrect delegation data will be read and delegateERC721 call will return with no change.
//src/lib/loans/MultiSourceLoan.sol
function revokeDelegate(address _delegate, address _collection, uint256 _tokenId) external {
if (ERC721(_collection).ownerOf(_tokenId) == address(this)) {
revert InvalidMethodError();
}
//@audit revokeDelegate will always pass empty rights.
|> IDelegateRegistry(getDelegateRegistry).delegateERC721(_delegate, _collection, _tokenId, "", false);
emit RevokeDelegate(_delegate, _collection, _tokenId);
}
src/lib/loans/MultiSourceLoan.sol#L496
POC:
- The original borrower set custom rights and delegated their collateral NFT to a custom contract.
- The original borrower’s loan ended and NFT is transferred to a new borrower.
- The protocol or the new borrower calls
revokeDelegate()to remove previous delegations of the NFT. - The new borrower takes out a loan with the NFT and calls
delegate(), delegating the NFT to a hot wallet. - The original borrower’s old delegation is not cleared from
delegateRegistryand still claims an event ticket using the old delegation. The old borrower claims the new borrower’s ticket.
Recommended Mitigation Steps
In revokeDelegate(), allow passing bytes32 _rights into delegateERC721() to correctly revoke existing delegations with custom rights.
Assessed type
Error
0xend (Gondi) confirmed
0xsomeone (judge) commented:
The Warden has outlined how the protocol will incorrectly integrate with the
DelegateRegistrysystem, attempting to revoke a previous delegation via an empty payload which is a futile attempt as proper revocation would require the same_rightsto be passed in with afalsevalue for the_enableflag.I am slightly mixed in relation to this submission as the
MultiSourceLoan::delegatefunction can be utilized with a correct payload to remove delegation from the previous user correctly. I believe that users, protocols, etc., will attempt to use theMultiSourceLoan::revokeDelegatefunction to revoke their delegation, and thus, a medium-risk severity rating is appropriate even though a circumvention already exists in the code.To note, the code also goes against its
interfacespecification (src/interfaces/loans/IMultiSourceLoan.sol#L257-L261) further re-inforcing a medium-risk rating level.
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 revokeDelegate function hardcodes empty rights when calling delegateERC721, so it cannot match and remove delegations that were created with custom rights.
Impact
An old borrower could claim benefits (such as event tickets) that belong to a new borrower, because the old delegation remains active.
What the attacker needed
Borrower has an active loan with NFT collateral; borrower has delegated with custom rights; loan ends and NFT transfers to new borrower
The fix
The revokeDelegate function should accept a bytes32 _rights parameter and pass it to delegateERC721 so that delegations with custom rights can be correctly revoked.
How it was found
- The original borrower sets custom rights and delegates their collateral NFT to a custom contract.
- The original borrower’s loan ends and the NFT is transferred to a new borrower.
- The protocol or the new borrower calls revokeDelegate() to remove previous delegations of the NFT.
- The new borrower takes out a loan with the NFT and calls delegate(), delegating the NFT to a hot wallet.
- The original borrower’s old delegation is not cleared and still claims an event ticket using the old delegation.
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.
When you borrow using an NFT as collateral, you can let someone else act on your behalf (a delegation). The code that removes this permission forgets to include the specific rights that were originally granted, so the removal does nothing. This means a previous borrower can still use the old permission to claim things like tickets that should go to the new borrower.
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.