Rules › Solidity
Initializer anyone can call
An initialize function without the initializer modifier or an access check can be called again, or first, by an attacker.
Why it matters
Upgradeable contracts use an initialize function instead of a constructor. Without the initializer modifier (or an equivalent guard), anyone can call it first after deployment, or call it again later, and make themselves owner. The implementation contract behind a proxy also needs _disableInitializers() in its constructor, or an attacker can initialize it directly.
Vulnerable
function initialize(address _owner) external {
owner = _owner;
}
Fixed
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() { _disableInitializers(); }
function initialize(address _owner) external initializer {
__Ownable_init(_owner);
}
What other tools call it
| Tool | Detector or reference |
|---|---|
| Slither | unprotected-upgrade, uninitialized-state |
| Aderyn | unprotected-initializer |
| SWC registry | SWC-118 |
Check your code
Paste a contract into the in-browser checker, or let the Claude Code plugin scan before every deploy. The quick check for this rule is a pattern match: treat a hit as "look here", and a miss as no guarantee.
Related rules
- tx.origin used for authorization
- State written after an external call (reentrancy)
- Return value of a low-level call is ignored
- delegatecall to an address the caller controls
- Privileged function without access control
- selfdestruct in contract code
Static analysis finds known bug classes; it can't prove code is safe and isn't an audit. Get a professional audit before deploying code that will hold value.