transferSAFEOwnership() does not fully transfer ownership
The transferSAFEOwnership function does not clear the safeCan mapping, so addresses previously granted permission to a safe retain access even after ownership changes. If the original owner later regains the safe, those addresses can still perform critical operations on it.
Submitted by lsaudit, also found by klau5, twicek, tnquanghuy0512, 0xPsuedoPandit, xAriextz, 0xhacksmithh, Stormreckson, and ZanyBonzy
Function transferSAFEOwnership() is only callable by Only Vault721: require(msg.sender == address(vault721), 'SafeMngr: Only Vault721'); and its purpose is to give the safe ownership to a dst address. However, transferSAFEOwnership() does not reset safeCan mapping which is used by safeAllowed modifier.
This leads to some security issues. The modifier safeAllowed is used to verify if user has permission to the safe. Multiple of functions which perform critical operations on the safe use this modifier to verify is user has permission to call that operation on a given safe.
Since transferSAFEOwnership() transfer ownership to a different address, it should also reset all previously set privileges by the previous owner. However, safeCan mapping is not being reset in transferSAFEOwnership()
Proof of Concept
Firstly, let’s take a look how safeAllowed modifier is defined:
modifier safeAllowed(uint256 _safe) {
address _owner = _safeData[_safe].owner;
if (msg.sender != _owner && safeCan[_owner][_safe][msg.sender] == 0) revert SafeNotAllowed();
_;
}
For this PoC, let’s consider user A, who’s the owner of safe 123.
He gives access to the safe to X, Y, so he calls:
allowSAFE(123, X, 1), allowSAFE(123, Y, 1);
function allowSAFE(uint256 _safe, address _usr, uint256 _ok) external safeAllowed(_safe) {
address _owner = _safeData[_safe].owner;
safeCan[_owner][_safe][_usr] = _ok;
emit AllowSAFE(msg.sender, _safe, _usr, _ok);
}
After calling this function, safeCan mapping looks like this: safeCan[A][123][X] = 1 and safeCan[A][123][Y] = 1.
Now, there’s a call to transfer safe ownership to _dst B: transferSAFEOwnership(123, B).
function transferSAFEOwnership(uint256 _safe, address _dst) external {
require(msg.sender == address(vault721), 'SafeMngr: Only Vault721');
if (_dst == address(0)) revert ZeroAddress();
SAFEData memory _sData = _safeData[_safe];
if (_dst == _sData.owner) revert AlreadySafeOwner();
_usrSafes[_sData.owner].remove(_safe);
_usrSafesPerCollat[_sData.owner][_sData.collateralType].remove(_safe);
_usrSafes[_dst].add(_safe);
_usrSafesPerCollat[_dst][_sData.collateralType].add(_safe);
_safeData[_safe].owner = _dst;
emit TransferSAFEOwnership(msg.sender, _safe, _dst);
}
It modifies only _usrSafes, _usrSafesPerCollat and _safeData mappings and does not modify safeCan mapping. After transferSAFEOwnership(123, B) call, those mappings look like this:
_usrSafes[B] = [123]
_usrSafesPerCollat[B][_sData.collateralType] = [123]
_safeData[123].owner = B;
safeCan[A][123][X] // notice this is from previous allowSAFE() call
safeCan[A][123][Y] // notice this is from previous allowSAFE() call
Now, at some point in the future, the safe goes back to user A. Function transferSAFEOwnership() is being called once again: transferSAFEOwnership(123, A).
User A get access to the safe. However, he does not remember that he previously sets access to users X and Y. Those mappings:
safeCan[A][123][X]
safeCan[A][123][Y]
are still there - meaning that X and Y has still access to that safe, even though the safe was just transferred back to A and safe’s permissions should be cleared.
Now, when user X or Y will try to call any function with safeAllowed modifier - they will be allowed, since safeAllowed will return true for them, because X and Y are still in safeCan mapping.
Recommended Mitigation Steps
Whenever transfer ownership - make sure to reset safeCan[old_owner][safe] mapping.
pi0neerpat (OpenDollar) confirmed and commented:
Agreed, we would expect that permissions on a safe are cleared upon transfer. It would be unexpected for permissions to persist through such transfers, even if you received back a safe you previously owned.
The warden has demonstrated how
transferSAFEOwnership()does not clear safe permissions insafeCan, which will cause previously “approved” addresses to still have access under the following conditions:
- An owner regains ownership of the safe after transferring it away.
- The previously “approved” address becomes malicious.
- The owner does not call
allowSAFE()beforehand to remove the “approved” address.This is unintended functionality, but given that it requires multiple unlikely conditions for this to become a problem, I believe medium severity is appropriate.
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 transferSAFEOwnership function updates ownership records but fails to clear the safeCan mapping that stores per-address permissions.
Impact
Previously approved addresses could still perform critical operations on a safe after ownership changes, but this requires the original owner to regain the safe and the approved address to become malicious.
What the attacker needed
Owner grants permissions to other addresses; safe is transferred away and later back to original owner; a previously approved address becomes malicious
The fix
The transferSAFEOwnership function should reset the safeCan mapping for the previous owner and safe.
How it was found
- User A owns safe 123 and calls allowSAFE to grant access to users X and Y.
- Ownership of safe 123 is transferred to user B via transferSAFEOwnership.
- Later, ownership is transferred back to user A.
- The safeCan entries for X and Y remain, so they still pass the safeAllowed check.
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 lets the owner of a 'safe' (a kind of account) give other people permission to use it. When the safe is transferred to a new owner, those permissions should be wiped, but they are not. So if the safe later comes back to the original owner, the old helpers still have access, which could be dangerous if one of them turns malicious.
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.