Old permissions in handlerCan mapping are still attached to the safeHandler of a transferred safe
When a safe is transferred to a new owner, the handlerCan mapping that stores which addresses are allowed to act on the safe's handler is not cleared. An attacker who previously owned the safe could still use those permissions to bypass handlerAllowed checks on the new owner's safe.
Originally disclosed on Code4rena
Submitted by MrPotatoMagic
A safe is associated with a unique safeHandler. This safeHandler can give permissions to addresses through the allowHandler() function which stores these approvals/disapprovals in the handlerCan mapping. Now let’s say there is a safeHandler which has permissioned some addresses in the handlerCan mapping. When this safe is transferred to a new owner, the previous permissions that were added to the safeHandler are still attached to it without the new owner realizing it.
Proof of Concept
Here is the whole process:
- Safe handler of a safe (owned by owner A) approves addresses [X,Y,Z] to the handlerCan mapping through the allowHandler() function.
File: ODSafeManager.sol
112: function allowHandler(address _usr, uint256 _ok) external {
113: handlerCan[msg.sender][_usr] = _ok;
114: emit AllowHandler(msg.sender, _usr, _ok);
115: }
- Owner A now transfers the safe (associated with the safe handler) to an Owner B through the safeTransferFrom() function in the Vault721.sol contract which inherits the ERC721Enumerable contract (that inherits the ERC721 contract). During the call, the _afterTokenTransfer() hook is called (overridden in the Vault721.sol contract), which further calls the transferSAFEOwnership() function. In the function, we can see that the safe is transferred but the handlerCan mapping is not updated for the safeHandler, which means the old permissions (addresses [X,Y,Z]) for the safeHandler are still attached without the new owner B realizing it.
File: ODSafeManager.sol
136: function transferSAFEOwnership(uint256 _safe, address _dst) external {
137: require(msg.sender == address(vault721), 'SafeMngr: Only Vault721');
138:
139:
140: if (_dst == address(0)) revert ZeroAddress();
141: SAFEData memory _sData = _safeData[_safe];
142: if (_dst == _sData.owner) revert AlreadySafeOwner();
143:
144:
145: _usrSafes[_sData.owner].remove(_safe);
146: _usrSafesPerCollat[_sData.owner][_sData.collateralType].remove(_safe);
147:
148:
149: _usrSafes[_dst].add(_safe);
150: _usrSafesPerCollat[_dst][_sData.collateralType].add(_safe);
151:
152:
153: _safeData[_safe].owner = _dst;
154:
155:
156: emit TransferSAFEOwnership(msg.sender, _safe, _dst);
157: }
Recommended Mitigation Steps
It is not possible to remove the handlerCan permissions in the transferSAFEOwnership() function since it is stored in a mapping. The only solution to this would be to add another key field (named _owner) to update the safeHandler permissions correctly whenever a safe is transferred. We can see this pattern implemented for the safeCan mapping, which correctly updates the safe permissions on transfer.
Solution (use this mapping instead):
File: ODSafeManager.sol
41: mapping(address _owner => (address _safeHandler => mapping(address _caller => uint256 _ok))) public handlerCan;
MiloTruck (Judge) decreased severity to Medium and commented:
The warden has demonstrated how handler permissions in
handlerCanare not cleared on transfer, which allows the previous owner of the safe to bypasshandlerAllowed()checks for a safe handler he previously owned.There is probably an impact worthy of high severity due to this bug (eg. a malicious owner can call
quitSystem()with his own safe and new owner’s safe handler to transfer his debt to the new owner). However, since this report does not have any elaboration on how this bug can be exploited to cause harm to the protocol/users, I don’t think it is deserving of high severity.
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
Impact
The previous owner of a safe could still use the old handler permissions to bypass handlerAllowed checks on the new owner's safe, potentially allowing actions such as transferring debt to the new owner.
What the attacker needed
Attacker previously owned the safe; attacker had granted handler permissions; safe is transferred to a new owner
The fix
The handlerCan mapping should include the owner as a key so that permissions are correctly updated when a safe is transferred, similar to the safeCan mapping.
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 safe is like a digital vault. The vault has a helper (the handler) that can be given permission to do things. When the vault is sold to a new owner, the old owner's permissions to that helper are not removed. So the old owner can still control the helper, even though they no longer own the vault.
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.