Users are forced to approve Router for full collection to use commitToLiens() function
The authority check in the loan commitment validation only accepts the caller if it is approved for all NFTs, not if it is approved for the single collateral NFT. As a result, the normal flow where the Router (approved for one NFT) calls the function reverts, forcing users to grant blanket approval to the Router.
Submitted by obront
https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/AstariaRouter.sol#L780-L785 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/VaultImplementation.sol#L287-L306 https://github.com/code-423n4/2023-01-astaria/blob/1bfc58b42109b839528ab1c21dc9803d663df898/src/VaultImplementation.sol#L233-L244
When a user calls Router#commitToLiens(), the Router calls commitToLien(). The comments specify:
//router must be approved for the collateral to take a loan,
However, the Router being approved isn’t enough. It must be approved for all, which is a level of approvals that many users are not comfortable with. This is because, when the commitment is validated, it is checked as follows:
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);
}
Proof of Concept
The check above allows the following situations pass:
- caller of the function == owner of the NFT
- receiver of the loan == owner of the NFT
- receiver of the loan == address approved for the individual NFT
- caller of the function == address approved for all
This is inconsistent and doesn’t make much sense. The approved users should have the same permissions.
More importantly, the most common flow (that the address approved for the individual NFT — the Router — is the caller) does not work and will lead to the function reverting.
Recommended Mitigation Steps
Change the check to include msg.sender != operator rather than receiver != operator.
SantiagoGregory (Astaria) confirmed
Keeping medium severity, considering this is a broken functionality.
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 authority check compares the single-token approval against the receiver instead of the caller, so a caller holding only per-token approval is rejected.
Impact
The common flow where the Router is approved for the individual NFT reverts, so users are pushed into granting approval for all of their collateral, a broader permission than needed.
What the attacker needed
User owns a collateral NFT; Router approved for a single NFT
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.
An NFT owner can let another address act on one specific token, or on every token they own. The code here only accepts the broad 'every token' permission from the caller, so the narrow permission fails and the action is rejected. Users then have to give the broad permission just to take a loan.
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.