# Lack of access control in the `MarketFactory.updateExtension()` function.

MarketFactory.updateExtension lacked onlyOwner, letting anyone register themselves as a protocol-wide extension and act as operator on any account to withdraw collateral.

- Payout: Audit contest
- Severity: high
- Program: Perennial
- Found by: Nyx
- Disclosed: 2024-08-17
- Write-up quality: 6/10
- Original: https://github.com/sherlock-audit/2024-08-perennial-v2-update-3-judging/issues/52
- Library page: https://bugbountylibrary.com/r/sherlock%3A2024-08-perennial-v2-update-3%3AH-5
- Tags: area:web3 domain:web3 impact:funds-loss impact:privesc kind:contest platform:sherlock sev:high tech:evm tech:solidity technique:source-review vuln:access-control vuln:auth-bypass

**Target:** MarketFactory.updateExtension / authorization in Perennial V2 contracts
**Root cause:** updateExtension() is external with no onlyOwner modifier, so any caller can set extensions[attacker]=true; authorization() treats extensions[sender] as a valid operator for any account.
**Steps:**
1. Call `MarketFactory.updateExtension(address(this), true)` from attacker contract.
2. Now `authorization(anyAccount, attacker, ...)` returns isOperator=true via `extensions[sender]`.
3. Call `Market.update(account, ...)` with attacker as msg.sender, passing InvariantLib operator check.
4. Submit order withdrawing victim's collateral to attacker.
**How found:** Manual code review of newly added signer/extension authorization feature; noticed updateExtension lacked access control and traced extensions[] usage into authorization() and InvariantLib operator check.
**Exploitation:** Attacker registers self as extension, then submits Market.update orders on behalf of any account; InvariantLib accepts sender as operator, allowing collateral withdrawal and position manipulation to drain funds.
**Insight:** When a new authorization primitive (extensions/signers) is added, audit every setter that populates the mapping it reads — a missing onlyOwner on a config setter silently grants protocol-wide operator rights.

## Proof of concept (copied exactly from the original report)

**authorization trusts extensions mapping**

```
account == sender || extensions[sender] || operators[account][sender],
85:             account == signer || signers[account][signer],
86:             referralFees(orderReferrer)
```

