Rules › Anchor (Rust)
Account data deserialized without an owner check
try_from_slice on raw account data trusts bytes that any program could have written.
Why it matters
Raw account data is just bytes; any program can create an account with bytes that deserialize into your struct. Reading it with try_from_slice without checking account.owner == your program id (and a discriminator) lets an attacker feed forged state: a fake config, a fake balance. Anchor's Account<'info, T> does both checks for you.
Vulnerable
let data = Config::try_from_slice(&ctx.accounts.config.data.borrow())?;
Fixed
#[account(seeds = [b"config"], bump = config.bump)]
pub config: Account<'info, Config>, // owner + discriminator checked
What other tools call it
| Tool | Detector or reference |
|---|---|
| Sealevel attacks | 2-owner-checks, 3-type-cosplay |
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
- Unchecked account without a /// CHECK: note
- Authority account that isn't a Signer
- CPI to a program the caller chooses
- init_if_needed (reinitialization risk)
- Account closed by draining lamports by hand
- overflow-checks not enabled for release builds
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.