Approved address can approve other addresses for an owner’s safe
The allowSAFE function used a modifier that allowed any previously approved address to grant further approvals on the owner's safe. An approved address could therefore give another address permission to act on the safe, which the owner did not intend.
MrPotatoMagic Follow with hals, Tendency and 10 others
Originally disclosed on Code4rena
Submitted by MrPotatoMagic, also found by hals, Tendency, HChang26, merlin, COSMIC-BEE-REACH, twcctop, tnquanghuy0512, Bughunter101, josephdara, Stormreckson, T1MOH, and klau5
An owner of a safe can give permissions/approval of their safe to another address (let’s say address B) through the allowSafe() function in the ODSafeManager.sol contract. But this other address (address B) also gets the power to approve other addresses for the owner’s safe. This is a permissioning problem in the allowSafe() function (specifically the safeAllowed() modifier) which creates a security risk for the owner’s safe.
Proof of Concept
Here is the whole process:
- Owner of the safe gives permission/approval to
address _usr(address 0x01 for example purposes) foruint256 _safethrough theallowSafe()function. - On Line 107,
safeCan[_owner][_safe][_usr] = _ok;is set to any value other than 0 to represent approval.
File: ODSafeManager.sol
105: function allowSAFE(uint256 _safe, address _usr, uint256 _ok) external safeAllowed(_safe) {
106: address _owner = _safeData[_safe].owner;
107: safeCan[_owner][_safe][_usr] = _ok;
108: emit AllowSAFE(msg.sender, _safe, _usr, _ok);
109: }
- The previously set
address _usr(address 0x01) can now call theallowSafe()function with parametersuint256 _safewhich will be the owner’s safe and anotheraddress _usr(address 0x02), which will give address 0x02 permissions/approval for the owner’s safe. - This issue arises because of how the checks are evaluated in the safeAllowed() modifier. Here is what happens:
- On Line 50, the owner of the safe is extracted.
- On Line 51, there are two conditions present that are separated by the && operator.
- On Line 51, the first check evaluates to true, since the msg.sender (address 0x01) is not the owner of the safe
- On Line 51, the second check evaluates to false, since the msg.sender (address 0x01) was previously approved by the owner in step 1 above.
- Since true && false = false, we do not revert and this gives address 0x02 permissions to the owner’s safe in the
allowSafe()function.
File: ODSafeManager.sol
49: modifier safeAllowed(uint256 _safe) {
50: address _owner = _safeData[_safe].owner;
51: if (msg.sender != _owner && safeCan[_owner][_safe][msg.sender] == 0) revert SafeNotAllowed();
52: _;
53: }
Recommended Mitigation Steps
Consider implementing a separate modifier for the allowSafe() function that only checks if the msg.sender is the owner. If true, then allow execution but if not then revert.
Solution:
File: ODSafeManager.sol
modifier onlySafeOwner(uint256 _safe) {
address _owner = _safeData[_safe].owner;
if (msg.sender != _owner) revert SafeNotAllowed();
_;
}
pi0neerpat (OpenDollar) confirmed, but disagreed with severity and commented:
Medium vulnerability recommended. Safe access is still limited, requiring user confirmation. The design could be improved, as described here, to remove the unexpected behavior of allowing additional approvals beyond the initial recipient.
MiloTruck (Judge) decreased severity to Medium and commented:
The warden has demonstrated how incorrect use of the
safeAllowed()modifier on theallowSAFE()function allows permissioned addresses that are not the safe owner to give permissions to other addresses, which is not intended.As this finding is contingent on the owner granting permissions to an address that becomes malicious, 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
The allowSAFE function reused the safeAllowed modifier, which accepts any caller already approved for the safe, instead of checking that the caller is the owner.
Impact
An approved address could grant safe permissions to others without the owner's consent, though the program noted that safe access still requires user confirmation.
What the attacker needed
Owner approves an address; approved address acts maliciously
The fix
The allowSAFE function should use a separate modifier that only allows the safe owner to call it.
How it was found
- The owner calls allowSAFE to approve address 0x01 for their safe.
- Address 0x01 calls allowSAFE for the same safe and names address 0x02.
- The safeAllowed modifier sees that 0x01 is not the owner but is already approved, so it does not revert.
- Address 0x02 is now approved for the owner's safe.
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 owner can let another person (address B) use their safe. The code also let address B pass that permission on to a third person (address C). The owner never agreed to that, so the access control was too loose.
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.