Skip to content
Access control Audit finding Intermediate

Adversary can steal user’s NFT’s if they have set Magnetar as isApprovedForAll == true

Magnetar, a router contract, allowed any user to call ERC721.approve on behalf of an owner who had set Magnetar as isApprovedForAll. An attacker could therefore approve themselves for any of the victim's NFTs and then transfer them away.

deadrxsezzz Follow

Originally disclosed on Code4rena

Submitted by deadrxsezzz

Since Magnetar is supposed to be used as a router for multiple operations, it can be expected that user will have it pre-approved for their NFTs (such as tOLP as oTAP ones, as they’ll be the ones primarily used).

The Magnetar contract allows for any user to make a ERC721.approve, via _processPermitOperation:

    function _processPermitOperation(address _target, bytes calldata _actionCalldata, bool _allowFailure) private {
        if (!cluster.isWhitelisted(0, _target)) revert Magnetar_NotAuthorized(_target, _target);

        /// @dev owner address should always be first param.
        // permitAction(bytes,uint16)
        // permit(address owner...)
        // revoke(address owner...)
        // permitAll(address from,..)
        // permit(address from,...)
        // setApprovalForAll(address from,...)
        // setApprovalForAsset(address from,...)
        bytes4 funcSig = bytes4(_actionCalldata[:4]);
        if (
            funcSig == IPermitAll.permitAll.selector || funcSig == IPermitAll.revokeAll.selector
                || funcSig == IPermit.permit.selector || funcSig == IPermit.revoke.selector
                || funcSig == IYieldBox.setApprovalForAll.selector || funcSig == IYieldBox.setApprovalForAsset.selector
                || funcSig == IERC20.approve.selector || funcSig == IPearlmit.approve.selector
                || funcSig == IERC721.approve.selector
        ) {
            /// @dev Owner param check. See Warning above.
            _checkSender(abi.decode(_actionCalldata[4:36], (address)));
            // No need to send value on permit
            _executeCall(_target, _actionCalldata, 0, _allowFailure);
            return;
        }
        revert Magnetar_ActionNotValid(MagnetarAction.Permit, _actionCalldata);
    }

The problem is that for OZ ERC721s (such as oTAP and tOLP), if an NFT owner has approved a spender as isApprovedForAll, the spender can call approve for any NFTs belonging to the owner.

In other words, if user A has set Magnetar as approvedForAll, user B can call NFT.approve(userB, id) and get access to user A’s NFT:

    function approve(address to, uint256 tokenId) public virtual override {
        address owner = ERC721.ownerOf(tokenId);
        require(to != owner, "ERC721: approval to current owner");

        require(
            _msgSender() == owner || isApprovedForAll(owner, _msgSender()),
            "ERC721: approve caller is not token owner or approved for all"
        );

        _approve(to, tokenId);
    }

Recommended Mitigation Steps

Do not allow users to make a call with ERC721.approve selector.

0xWeiss (Tapioca) confirmed


The original report as published on Code4rena, by deadrxsezzz. Images and videos are our own copies; raw HTML is shown as text. View it on Code4rena.

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 permit operation checked the owner parameter against the caller, but because Magnetar was already approved for all, the ERC721.approve call succeeded for any caller who passed their own address as owner.

Impact

Any user who had set Magnetar as isApprovedForAll could have their NFTs approved to an attacker and stolen.

What the attacker needed

Victim set Magnetar as isApprovedForAll; attacker knows a token ID

The fix

The report recommends disallowing calls with the ERC721.approve selector.

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.

Some NFT contracts let an owner give a contract permission to manage all their tokens, called isApprovedForAll. Magnetar accepted a request to approve a specific token from anyone, and only checked that the caller was the owner in a way that the approval itself satisfied. So anyone could tell Magnetar to approve themselves for a victim's NFT and then take it.

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.

More by deadrxsezzz

View all

11 more disclosed reports, best first.

More from Tapioca Invitational

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.