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

detachHSG leaves stale Safe owners who lost their signer hat, letting an admin-hat holder front-run detachment to mint many owners and seize the multisig.

- Payout: Audit contest
- Severity: high
- Program: Hats Protocol
- Found by: bughuntoor
- Disclosed: 2024-11-15
- Write-up quality: 8/10
- Original: https://github.com/sherlock-audit/2024-11-hats-protocol-judging/issues/4
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-11-hats-protocol%3AH-1
- Tags: area:web3 domain:web3 impact:funds-loss impact:privesc kind:contest platform:sherlock sev:high tech:solidity technique:chained technique:race-window vuln:access-control vuln:business-logic

**Target:** HatsSignerGate.sol detachHSG / Safe multisig ownership
**Root cause:** detachHSG removes HSG as guard and module but never unregisters Safe owners who no longer wear the required signer hat, so they retain owner rights after detachment.
**Steps:**
1. DAO schedules `detachHSG()` on HatsSignerGate.
2. Attacker holds an admin hat with authority over a signer hat whose max supply is 1.
3. Attacker front-runs `detachHSG` and loops: transfer the signer hat to a fresh address, then claim it as a signer via HSG.
4. Each looped address becomes a Safe owner while HSG is still attached.
5. `detachHSG` executes, removing guard/module but leaving all looped addresses as Safe owners.
6. Attacker now controls enough owners to meet quorum and execute Safe transactions.
**How found:** Observed that losing a hat only removes signer validity, not Safe ownership, until removeSigner is called; noted detachHSG skips unregistering stale owners, then reasoned an admin-hat holder could weaponize the gap by front-running detachment.
**Exploitation:** Front-run the DAO's detachHSG transaction; using admin rights over a max-supply-1 signer hat, repeatedly transfer the hat to new addresses and register each as a signer, inflating Safe owner count. After detachment the stale owners persist, granting the attacker quorum control and full custody of the Safe.
**Escalation:** Chains hat admin privileges over a signer hat into full multisig takeover; even without full quorum, stale owners can block the DAO from reaching quorum.
**Insight:** When a guard/module is detached from a Safe, audit whether off-chain/on-chain signer validity is reconciled with actual Safe owner set; stale owners surviving module removal are a takeover vector, especially when hat admin rights allow minting many signers pre-detachment.

