Skip to content
Access control Audit finding Advanced

Detaching HSG when there's non-unregistered owners who no longer own the hat would give them control over the multi-sig

When the HatsSignerGate (HSG) is detached from a Safe, it does not remove Safe owners who no longer wear the required signer hat. An attacker with an admin hat over a signer hat can front-run the detachment to transfer the signer hat to many addresses, making them Safe owners and potentially gaining full control of the multi-sig.

bughuntoor Follow

Originally disclosed on Sherlock

Source: https://github.com/sherlock-audit/2024-11-hats-protocol-judging/issues/4

The protocol has acknowledged this issue.

Found by

bughuntoor

Summary

After a user no longer owns a hat, although they are no longer treated as a valid signer, they remain an owner within the Safe, until removeSigner is called

Solidity
  function detachHSG() public {
    _checkUnlocked();
    _checkOwner();
    ISafe s = safe; // save SLOAD

    // first remove as guard, then as module
    s.execRemoveHSGAsGuard();
    s.execDisableHSGAsOnlyModule();
    emit Detached();
  }

When HSG is detached, it does not check if there's any Safe owners who no longer wear the necessary hat. For this reason, if there's such owners, they'll remain rights within the multi-sig. Depending on their number, they might be able to overturn the multisig, or at least disallow them to reach quorum.

However, this attack can further be weaponized if one of the signer hats has admin rights over another signer hat. If the said admin hat wants to overturn the multisig and gain full access of it upon detaching, they can simply front-run the detachHSG call and do a loop of 1) transferring the lower hat to a new address 2) claiming it as a signer. Then, when the detachHSG executes, all of these addresses that the attacker had looped through would be owners of the safe and in most cases that should be enough to fully overturn the multi-sig and claim full custody of it.

Root Cause

detachHSG does not check if there are Safe owners who no longer wear the necessary hat.

Attack Path

  1. DAO plans to detach from HSG
  2. There exists a user who has admin hat over a signer hat which has a set max supply of 1.
  3. DAO calls detach from HSG
  4. The admin hat owner front-runs the tx and does a loop of transferring the hat and adding it as a signer. This gives a lot of wallets owner rights within the Safe, which would otherwise be worthless if HSG remains active
  5. The DAO gets detached and all of the wallets the admin hat owner had looped through now are owners within the Safe
  6. This would usually give full custody to the attacker, or at the very least guarantee the DAO is not able to execute anything on their own.

Impact

Attacker can gain full custody over a Safe upon HSG detachment

Affected Code

https://github.com/sherlock-audit/2024-11-hats-protocol/blob/main/hats-zodiac/src/HatsSignerGate.sol#L341

Mitigation

Upon detaching HSG, loop through all Safe owners and in case a wallet does not wear the necessary hat, unregister them as a signer.

The original report as published on Sherlock, by bughuntoor. Images and videos are our own copies; raw HTML is shown as text. View it on Sherlock.

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 detachHSG function does not verify that all Safe owners still wear the required signer hat before removing the HSG, leaving stale owners with full rights.

Impact

An attacker could gain full custody over a Safe upon HSG detachment, or at least prevent the DAO from executing transactions.

What the attacker needed

DAO plans to detach HSG; Attacker has admin hat over a signer hat; Signer hat has max supply of 1; Attacker can front-run detachment

The fix

Upon detaching HSG, loop through all Safe owners and unregister any wallet that does not wear the necessary hat.

How it was found

  1. DAO plans to detach from HSG
  2. There exists a user who has admin hat over a signer hat which has a set max supply of 1
  3. DAO calls detach from HSG
  4. The admin hat owner front-runs the tx and does a loop of transferring the hat and adding it as a signer
  5. The DAO gets detached and all of the wallets the admin hat owner had looped through now are owners within the Safe
  6. This would usually give full custody to the attacker, or at the very least guarantee the DAO is not able to execute anything on their own

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 multi-signature wallet (Safe) requires several owners to approve transactions. The HatsSignerGate (HSG) is a module that ensures only people wearing a specific 'hat' (a token) can be owners. When the HSG is removed, the wallet stops checking hats, but it also doesn't remove owners who no longer have the hat. An attacker who can give out hats can quickly add many addresses as owners just before removal, then control the wallet.

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.

More by bughuntoor

View all

16 more disclosed reports, best first.

More from HatsSignerGate v2

View all

The newest disclosed reports for this program.

Similar reports

View all

Same bug class and techniques, clearest first.

Broken access control

The lesson behind this report.

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.