NFTXVaultFactoryUpgradeable implementation can be replaced in production breaking the system
The owner can change the vault factory address in several helper contracts without any restriction, but the new factory would not have the existing vault and asset data. An owner mistake or malicious action could therefore break the system by pointing these contracts at an empty factory.
Submitted by hyh
NFTXVaultFactory contract holds information regarding vaults, assets and permissions (vaults, _vaultsForAsset and excludedFromFees mappings). As there is no mechanics present that transfers this information to another implementation, the switch of nftxVaultFactory to another address performed while in production will break the system.
Proof of Concept
setNFTXVaultFactory function allows an owner to reset nftxVaultFactory without restrictions in the following contracts:
NFTXLPStaking https://github.com/code-423n4/2021-12-nftx/blob/main/nftx-protocol-v2/contracts/solidity/NFTXLPStaking.sol#L59
NFTXInventoryStaking https://github.com/code-423n4/2021-12-nftx/blob/main/nftx-protocol-v2/contracts/solidity/NFTXInventoryStaking.sol#L51
NFTXSimpleFeeDistributor https://github.com/code-423n4/2021-12-nftx/blob/main/nftx-protocol-v2/contracts/solidity/NFTXSimpleFeeDistributor.sol#L135
Recommended Mitigation Steps
Either restrict the ability to change the factory implementation to pre-production stages or make nftxVaultFactory immutable by allowing changing it only once:
Now:
function setNFTXVaultFactory(address newFactory) external virtual override onlyOwner {
require(newFactory != address(0));
nftxVaultFactory = INFTXVaultFactory(newFactory);
}
To be:
function setNFTXVaultFactory(address newFactory) external virtual override onlyOwner {
require(nftxVaultFactory == address(0), "nftxVaultFactory is immutable");
nftxVaultFactory = INFTXVaultFactory(newFactory);
}
If the implementation upgrades in production is desired, the factory data migration logic should be implemented and then used atomically together with the implementation switch in all affected contracts.
0xKiwi (NFTX) confirmed and commented:
This is not a contract that is designed to be replaced, but upgraded. But it is a valid concern that these assistant contracts can have their factory be changed and rendered broken. (even if it were permissioned) Confirming.
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 setter for the factory address has no guard and no data migration, so it can be changed to a contract that lacks the existing vault and asset mappings.
Impact
If the owner changes the factory in production, the helper contracts would lose access to the existing vault data and the system would break; the report does not describe an attacker gaining funds or data.
What the attacker needed
Owner calls the setter; new factory lacks existing data
The fix
The setter should be restricted so the factory can only be set once, or a data migration should be implemented and run atomically with the switch in all affected contracts.
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 called the vault factory keeps a list of all vaults and which assets belong to them. Several other contracts are told to ask this factory for that information. The report says the owner can point those contracts at a different factory at any time, but the new factory would start with an empty list, so everything that depends on the old list would stop working.
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.