---
title: "Missing or wrong access control"
url: https://dontgetrekt.today/dev/access-control
section: "Who can call it?"
owasp: SC01:2026
---

# Missing or wrong access control

A function that moves funds, mints tokens or changes settings has no check of who calls it, or the check is wrong. Anyone can call it.

## How the attack works

1. A privileged function is `public` or `external` and has no `onlyOwner`, no role check, or a check on the wrong variable.
2. The attacker reads the verified source or the bytecode and finds the open function.
3. The attacker calls it directly: sets themselves as owner, mints tokens, changes the fee receiver, or withdraws.
4. Variants: auth with `tx.origin`, a role granted to a contract that anyone can call, a helper that should be `internal`.

## Vulnerable code

```solidity
function setFeeReceiver(address r) external {
    feeReceiver = r;           // no check: anyone can redirect fees
}

function withdraw(uint256 amt) external {
    require(tx.origin == owner); // a phishing contract passes this
    payable(msg.sender).transfer(amt);
}
```

## Fixed code

```solidity
import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";

bytes32 public constant ADMIN = keccak256("ADMIN");

function setFeeReceiver(address r) external onlyRole(ADMIN) {
    require(r != address(0), "zero");
    feeReceiver = r;
}

function withdraw(uint256 amt) external onlyRole(ADMIN) {
    payable(msg.sender).transfer(amt);  // msg.sender, never tx.origin
}
```

## Review checklist

- List every `external` and `public` function that changes state. For each one, write who may call it.
- Use `msg.sender` for auth. Never use `tx.origin`.
- Use a tested library (OpenZeppelin `Ownable2Step` or `AccessControl`), not a hand-written check.
- Put admin roles behind a multisig and a timelock, so one stolen key cannot drain the protocol.
- Make helpers `internal` or `private` unless an outside caller needs them.

## How to test for it

- For each privileged function, write a test that calls it from a random address and expects a revert.
- Run Slither: the detectors `arbitrary-send-eth`, `suicidal`, `tx-origin` and `unprotected-upgrade` find many cases.

## Real exploits (131)

- 2025-02-24 Infini ($49.5M): Infini lost about $49.5M in USDC when a former developer, who still held an admin role on its vault, drained the funds. [rekt.news](https://rekt.news/infini-rekt)
- 2017-07-19 Parity Multisig Wallet ($30.0M): Parity multisig wallets lost 153,037 ETH (~$30M) because the initWallet() function was public and could be called again, so an attacker made himself owner and drained the funds. [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2017-07/Parity_first_hack_exp.sol)
- 2023-03-28 Safemoon ($8.9M): Safemoon lost $8.9M (28k BNB) from its SFM/BNB pool because an upgrade left burn() publicly callable, letting anyone burn tokens from any address. [rekt.news](https://rekt.news/safemoon-rekt) [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2023-03/safeMoon_exp.sol)
- 2026-09-15 RsETHSafeModule (rsETH whale Gnosis Safe via private DeFi-Saver-style Router) ($7.8M): A whale's Gnosis Safe lost about 2,900 aEthrsETH (~$7.8M) because a Router's multicall authorization could be bypassed by targeting the Router itself, which reached an enabled Safe module and a DELEGATECALL. [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2026-09/RsETHSafeModule_exp.sol)
- 2025-04-14 KiloEx ($7.5M): KiloEx, a multi-chain perpetuals protocol, lost about $7.5M because its MinimalForwarder did not verify callers, letting anyone set the price oracle. [rekt.news](https://rekt.news/kiloex-rekt)
- 2026-10-26 Safe (2-of-7 multisig, victim Safe 0x631f...b9b8) ($7.5M): A 2-of-7 Safe on Avalanche lost about $7.45M because it had unlimited ERC20 approvals to an empty counterfactual address, which an attacker could occupy by reproducing CREATE2/CREATE address math. [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2026-10/SafeApprovalSquat_exp.sol)
- 2026-05-07 TrustedVolumes ($5.9M): TrustedVolumes lost about $5.87M on Ethereum when its custom RFQ swap proxy let anyone register as an order signer and pull funds from the inventory's unlimited approvals. [rekt.news](https://rekt.news/trustedvolumes-rekt) [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2026-05/TrustedVolumes_exp.sol)
- 2021-08-29 X-Token (xSNX) ($4.5M): X-Token's xSNX lost about $4.5M because callFunction on xSNXAdmin had a wrong require and could be called by anyone, letting an attacker use a flash loan to trade SNX at a depressed price. [rekt.news](https://rekt.news/xtoken-rekt-x2)
- 2026-05-25 New Market Trading ($4.0M): New Market Trading lost about $3.98M from 88 Gnosis Safes on Ethereum, Base and Arbitrum because its Safe module trusted a caller-supplied delegate address and source string instead of checking msg.sender. [rekt.news](https://rekt.news/newmarkettrading-rekt) [PoC](https://github.com/SunWeb3Sec/DeFiHackLabs/blob/main/src/test/2026-05/NewMarketTrading_exp.sol)
- 2025-12-12 Aevo (Ribbon Finance legacy vaults) ($2.7M): Aevo's legacy Ribbon vaults lost about $2.7M after an oracle upgrade left the price-feed proxy admin functions unprotected, so an attacker could set arbitrary expiry prices. [rekt.news](https://rekt.news/aevo-rekt)

## References

- [OWASP SC01:2026](https://scs.owasp.org/sctop10/SC01-AccessControlVulnerabilities/)
- [SWC-105: Unprotected Ether withdrawal](https://swcregistry.io/docs/SWC-105/)
- [SWC-115: Authorization through tx.origin](https://swcregistry.io/docs/SWC-115/)
- [OpenZeppelin: Access control](https://docs.openzeppelin.com/contracts/5.x/access-control)
