Unrevoked approvals allow NFT recovery by previous owner
The smart contract does not clear token approvals when an NFT is transferred, so a previously approved address can still transfer the NFT away from its new owner. This allows the previous owner or an approved address to reclaim the NFT after a sale or transfer.
Japy69 Follow with zhaojohnson, ZanyBonzy and 7 others
Originally disclosed on Code4rena
Submitted by Japy69, also found by zhaojohnson, ZanyBonzy, Testerbot, IzuMan, Shubham, SBSecurity, Nikki, SpicyMeatball, and oakcobalt
The vulnerability arises from the fact that after a token transfer, the approval status for the token is not revoked. Specifically, the getApproved[_tokenId] is not updated on transfer. This allows the previous owner (or any approved address) to reclaim the NFT by using the approval mechanism to re-transfer the token back to themselves. This is critical because the new owner of the NFT may lose their asset without realizing it, leading to potential exploitation, loss of assets, and decreased trust in the platform.
Details
In the provided approve function, any user can approve themselves or another address for a specific token ID:
/// @inheritdoc IERC721Metadata
function approve(address _approved, uint256 _tokenId) external payable {
_requireAuthorised(msg.sender, _tokenId);
getApproved[_tokenId] = _approved;
}
Since the approval is not revoked upon transfer, the previous owner retains the ability to re-transfer the NFT. The _requireAuthorised function is the only check on transfer permission:
function _requireAuthorised(address _from, uint256 _tokenId) internal view {
// revert if the sender is not authorised or the owner
bool isAllowed =
msg.sender == _from ||
isApprovedForAll[_from][msg.sender] ||
msg.sender == getApproved[_tokenId];
require(isAllowed, "not allowed");
require(ownerOf(_tokenId) == _from, "_from is not the owner!");
}
Step-by-Step PoC:
- Initial Approval: The owner of a token (
owner1) approves an address (addr2) to transfer their token. - Token Transfer: The token is transferred from
owner1tonewOwner. - Approval Not Revoked: The approval for
addr2is not revoked after the transfer. - NFT Recovery:
addr2can still use their approval to transfer the NFT back to themselves, effectively recovering the NFT fromnewOwner.
There is no existing tests for this specific smart contract (because it is in solidity). A coded POC for this easy-to-understand vulnerability would involve to create all deployment logic.
Recommended Mitigation Steps
To prevent this vulnerability, any existing approvals should be revoked when a token is transferred. This can be achieved by adding a line in the transfer function to clear the approval:
getApproved[_tokenId] = address(0);
This line should be added to the token transfer function to ensure that any previously approved addresses cannot transfer the NFT after it has been sold or transferred to a new owner.
Assessed type
Token-Transfer
af-afk (Superposition) confirmed via duplicate issue #56
The submission details how approvals are not cleared whenever an NFT transfer occurs, permitting the NFT to be recovered after it has been transferred which breaks a crucial invariant of NFTs and would affect any and all integrations of the NFT (i.e., staking systems, marketplaces, etc.). As such, I believe a high-risk severity rating is appropriate.
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 transfer function does not reset the token's approval to zero, leaving the previous approval active.
Impact
The new owner could lose the NFT without realising it, which may affect any integration such as marketplaces or staking systems.
What the attacker needed
Token owner approves an address; token is transferred to a new owner
The fix
The transfer function should clear the token's approval by setting it to the zero address.
How it was found
- The owner approves an address to transfer the token.
- The token is transferred to a new owner.
- The approval is not revoked after the transfer.
- The approved address uses the still-valid approval to transfer the NFT back to itself.
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 own an NFT, you can give someone else permission to move it for you. This report found that the permission is not removed when the NFT changes hands, so the old permission still works and the new owner can lose the NFT.
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.