token -> vault mapping can be overwritten
The addToken function allows overwriting an existing token-to-vault mapping, which disassociates the token from its previous vault without removing it from that vault's token list. This can cause tokens to become stuck and break access control checks like the onlyVault modifier.
Submitted by cmichel
One vault can have many tokens, but each token should only be assigned to a single vault. The Manager contract keeps a mapping of tokens to vaults in the vaults[_token] => _vault map, and a mapping of vault to tokens in tokens[vault] => token[].
The addToken function can assign any token to a single vault and allows overwriting an existing vaults[_token] map entry with a different vault. This indirectly disassociates the previous vault for the token. Note that the previous vault’s tokens[_previousVault] map still contains the token.
Impact
The token disappears from the system for the previous vault but the actual tokens are still in there, getting stuck. Only the new vault is considered for the token anymore, which leads to many issues, see Controller.getBestStrategyWithdraw and the onlyVault modifier that doesn’t work correctly anymore.
Recommended Mitigation Steps
It should check if the token is already used in a map, and either revert or correctly remove the token from the vault - from the tokens array. It should do the same cleanup procedure as in removeToken:
if (found) {
// remove the token from the vault
tokens[_vault][index] = tokens[_vault][k-1];
tokens[_vault].pop();
delete vaults[_token];
emit TokenRemoved(_vault, _token);
}
addToken should also check that the token is not already in the tokens[_vault] array.
GalloDaSballo (judge) commented:
Mapping mismatch can cause undefined behaviour
Recommend having one source of truth to keep things simple
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 addToken function lacks a check to prevent overwriting an existing token-to-vault mapping and does not clean up the previous vault's token list.
Impact
Tokens can become stuck in the previous vault and access control modifiers like onlyVault may not work correctly, potentially leading to undefined behaviour.
What the attacker needed
Ability to call addToken
The fix
The addToken function should check if the token is already mapped and either revert or properly remove the token from the previous vault's token array, similar to the cleanup in removeToken.
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 keeps track of which vault owns each token. The function that adds a token to a vault does not check if the token already belongs to another vault, so it can silently reassign the token. This leaves the old vault thinking it still has the token, but the system no longer recognises that, so the token can get stuck and security checks may fail.
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.