Skip to content

Commit 7df4eee

Browse files
committed
add missing-owner-readme
1 parent 660917d commit 7df4eee

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

lints/missing_owner_check/README.md

+23-9
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,34 @@
22

33
**What it does:**
44

5+
This lint checks that for each account referenced in a program, that there is a
6+
corresponding owner check on that account. Specifically, this means that the owner
7+
field is referenced on that account.
8+
59
**Why is this bad?**
610

7-
**Known problems:** None.
11+
The missing-owner-check vulnerability occurs when a program uses an account, but does
12+
not check that it is owned by the expected program. This could lead to vulnerabilities
13+
where a malicious actor passes in an account owned by program `X` when what was expected
14+
was an account owned by program `Y`. The code may then perform unexpected operations
15+
on that spoofed account.
16+
17+
For example, suppose a program expected an account to be owned by the SPL Token program.
18+
If no owner check is done on the account, then a malicious actor could pass in an
19+
account owned by some other program. The code may then perform some actions on the
20+
unauthorized account that is not owned by the SPL Token program.
21+
22+
**Known problems:**
23+
24+
Key checks can be strengthened. Currently, the lint only checks that the account's owner
25+
field is referenced somewhere, ie, `AccountInfo.owner`.
826

927
**Example:**
1028

11-
```rust
12-
// example code where a warning is issued
13-
```
29+
See https://github.com/coral-xyz/sealevel-attacks/blob/master/programs/2-owner-checks/insecure/src/lib.rs
30+
for an insecure example.
1431

1532
Use instead:
1633

17-
```rust
18-
// example code that does not raise a warning
19-
```
20-
21-
Checks if `expr` is an owner field reference on `account_expr`
34+
See https://github.com/coral-xyz/sealevel-attacks/blob/master/programs/2-owner-checks/secure/src/lib.rs
35+
for a secure example.

lints/missing_owner_check/src/lib.rs

+18-9
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,28 @@ use solana_lints::{paths, utils::visit_expr_no_bodies};
1717
dylint_linting::declare_late_lint! {
1818
/// **What it does:**
1919
///
20+
/// This lint checks that for each account referenced in a program, that there is a
21+
/// corresponding owner check on that account. Specifically, this means that the owner
22+
/// field is referenced on that account.
23+
///
2024
/// **Why is this bad?**
2125
///
22-
/// **Known problems:** None.
26+
/// The missing-owner-check vulnerability occurs when a program uses an account, but does
27+
/// not check that it is owned by the expected program. This could lead to vulnerabilities
28+
/// where a malicious actor passes in an account owned by program `X` when what was expected
29+
/// was an account owned by program `Y`. The code may then perform unexpected operations
30+
/// on that spoofed account.
31+
32+
/// For example, suppose a program expected an account to be owned by the SPL Token program.
33+
/// If no owner check is done on the account, then a malicious actor could pass in an
34+
/// account owned by some other program. The code may then perform some actions on the
35+
/// unauthorized account that is not owned by the SPL Token program.
36+
///
37+
/// **Known problems:**
2338
///
24-
/// **Example:**
39+
/// Key checks can be strengthened. Currently, the lint only checks that the account's owner
40+
/// field is referenced somewhere, ie, `AccountInfo.owner`.
2541
///
26-
/// ```rust
27-
/// // example code where a warning is issued
28-
/// ```
29-
/// Use instead:
30-
/// ```rust
31-
/// // example code that does not raise a warning
32-
/// ```
3342
pub MISSING_OWNER_CHECK,
3443
Warn,
3544
"using an account without checking if its owner is as expected"

0 commit comments

Comments
 (0)