Skip to content

Latest commit

 

History

History
68 lines (40 loc) · 2.56 KB

File metadata and controls

68 lines (40 loc) · 2.56 KB

Dry Garnet Cobra

High

_countValidSignatures Does Not Validate Approved Hashes Or Contract Signatures

Summary

Insufficient signature validity checks result in unauthorized use of the Safe.

Root Cause

The _countValidSignatures function in HatsSignerGate can be bypassed by an attacker to authorize malicious transactions.

Consider the following two cases:

if (v == 0) {
        // If v is 0 then it is a contract signature
        // When handling contract signatures the address of the contract is encoded into r
        currentOwner = address(uint160(uint256(r)));
}

https://github.com/sherlock-audit/2024-11-hats-protocol/blob/49de29508904e95b3cfaaf27d2e76c527429c019/hats-zodiac/src/HatsSignerGate.sol#L658C7-L662C8

else if (v == 1) {
        // If v is 1 then it is an approved hash
        // When handling approved hashes the address of the approver is encoded into r
        currentOwner = address(uint160(uint256(r)));
}

https://github.com/sherlock-audit/2024-11-hats-protocol/blob/49de29508904e95b3cfaaf27d2e76c527429c019/hats-zodiac/src/HatsSignerGate.sol#L662C9-L666C8

Notice that the _countValidSignatures function will accept the currentOwner as the contents of the r parameter from the parsed signature array without validation.

This means an attacker can simply create an array of mock signatures comprised of only the public addresses of valid owners in order to masquerade as them, since neither the approved hash or contract signature is actually validated for authenticity.

Internal pre-conditions

  1. Admin authorizes HSG for their vault and uses a number of registeredSignerHats that exceeds the signing threshold.

External pre-conditions

No response

Attack Path

  1. Attacker submits malicious payload using signatures calldata containing abi encoded registeredSignerHatsaddresses which enter only the v == 0 and v == 1 cases.

Impact

Attackers can steal all funds from Safes that authorize the HSG.

PoC

No response

Mitigation

The specified addresses must be validated.

When validating contract signatures, use: https://github.com/safe-global/safe-smart-account/blob/c36bcab46578a442862d043e12a83fec41143dec/contracts/GnosisSafe.sol#L257C13-L286C14

When validating approved hashes, use: https://github.com/safe-global/safe-smart-account/blob/c36bcab46578a442862d043e12a83fec41143dec/contracts/GnosisSafe.sol#L286C15-L292C14