Wrong design/implementation of permission control allows malicious/compromised Registry or Factory admin to steal funds from users’ wallet balances
The Vault contract allows any address registered as a market by the Registry to transfer tokens from any user who has approved the Vault, and assign the attribution to an arbitrary beneficiary. A malicious or compromised Registry owner can register an attacker-controlled address as a market and steal all approved token balances.
Submitted by WatchPug
The current design/implementation allows a market address (registered on registry) to call Vault#addValue() and transfer tokens from an arbitrary address to a specified _beneficiary up the approved amount at any time, and the _beneficiary can withdraw the funds by calling Vault#withdrawAllAttribution() immediately.
This poses a very dangerous risk to all the users that approved their tokens to the Vault contracts (each one holds all users’ allowances for that token).
modifier onlyMarket() {
require(
IRegistry(registry).isListed(msg.sender),
"ERROR_ONLY_MARKET"
);
_;
}
function addValue(
uint256 _amount,
address _from,
address _beneficiary
) external override onlyMarket returns (uint256 _attributions) {
if (totalAttributions == 0) {
_attributions = _amount;
} else {
uint256 _pool = valueAll();
_attributions = (_amount * totalAttributions) / _pool;
}
IERC20(token).safeTransferFrom(_from, address(this), _amount);
balance += _amount;
totalAttributions += _attributions;
attributions[_beneficiary] += _attributions;
}
Registry owner can call Registry#supportMarket() and mark an arbitrary address as a market.
function supportMarket(address _market) external override {
require(!markets[_market], "ERROR: ALREADY_REGISTERED");
require(
msg.sender == factory || msg.sender == ownership.owner(),
"ERROR: UNAUTHORIZED_CALLER"
);
require(_market != address(0), "ERROR: ZERO_ADDRESS");
allMarkets.push(_market);
markets[_market] = true;
emit NewMarketRegistered(_market);
}
Or, the owner of the Factory can call createMarket() to add a malicous market contract via a custom template contract to the markets list.
Proof of Concept
A malicious/compromised Registry owner can:
- Call
Registry#supportMarket()and setmarkets[attackerAddress]totrue; - Call
Vault#addValue(token.balanceOf(victimAddress), victimAddress, attackerAddress)and transferring all the balanceOf victim’s wallet to the vault, owned byattackerAddress. - Call
Vault#withdrawAllAttribution(attackerAddress)and retrive the funds.
The malicious/compromised Registry owner can repeat the steps above for all the users who approved the Vault contract for all the Vault contracts.
As a result, the attacker can steal all the wallet balances of the tokens approved to the protocol.
Root Cause
Improper access control for using users’ allowances.
Recommendation
Consider changing the design/implementation to make sure that the allowances approved by the users can only be used by themselves.
oishun1112 (Insure) acknowledged and disagreed with severity:
this is an issue only when ownership control has fail. This architecture is necessary to achieve simplicity of the code. We assume ownership control works fine.
Agree with warden that the privilege addresses should not be able to use approvals in a way that rugs users funds.
Based on the fact that we have seen many rug pulls in the space based on compromised “owner” keys, this is a valid attack path.
3 — High: Assets can be stolen/lost/compromised directly (or indirectly if there is a valid attack path that does not have hand-wavy hypotheticals).
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 Vault's onlyMarket modifier trusts any address listed by the Registry, and the addValue function lets that market transfer tokens from any user and assign the credit to any beneficiary, so control of the Registry (or Factory) gives full access to all user allowances.
Impact
A malicious or compromised Registry owner could steal all wallet balances of tokens approved to the protocol.
What the attacker needed
Compromised or malicious Registry owner; users have approved tokens to the Vault
The fix
The design should be changed so that user approvals can only be used by the users themselves.
How it was found
- Call Registry#supportMarket() to mark the attacker's address as a market.
- Call Vault#addValue() with the victim's token balance, the victim's address, and the attacker's address as beneficiary.
- Call Vault#withdrawAllAttribution() for the attacker's address to retrieve the funds.
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 vault holds tokens that users have approved for spending. The vault trusts any address that the registry says is a 'market' to move those tokens. If the registry owner is malicious or their key is stolen, they can mark an attacker's address as a market and drain all approved tokens.
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.