Rules › Anchor (Rust)

Account data deserialized without an owner check

highAnchor (Rust)Rule anchor-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

ToolDetector or reference
Sealevel attacks2-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.

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.