Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation for new detectors #257

Merged
merged 41 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
81de692
docs incorrect exponentiation
NinaTea Apr 19, 2024
dbcf15f
fix typo incorrect exponentiation
NinaTea Apr 19, 2024
9a6415f
vec considerations documentation
NinaTea Apr 19, 2024
4c918f4
add brief documentation for avoid unsafe block
NinaTea Apr 19, 2024
d81ca61
brief documentation unstable interface
NinaTea Apr 19, 2024
782bfa0
typo in inc exp
NinaTea Apr 19, 2024
c847620
update link to detector
NinaTea Apr 19, 2024
6b2ea30
fix typo
NinaTea Apr 19, 2024
8ad85e2
fix typo
NinaTea Apr 19, 2024
ff53a09
more typos
NinaTea Apr 19, 2024
55b00f4
add for consistency
NinaTea Apr 19, 2024
f298431
typos typos
NinaTea Apr 19, 2024
c927b93
typos typos
NinaTea Apr 19, 2024
3abcf2a
vulne. docs for 24-incorrect exp
NinaTea Apr 22, 2024
85d8f84
vec-considerations
NinaTea Apr 22, 2024
43fdf71
unsafe block vulnearibilities
NinaTea Apr 22, 2024
aba9d56
unstable interface vuln
NinaTea Apr 22, 2024
f6491cb
add docs for overflow-check
NinaTea Apr 23, 2024
2fec070
fix vulnerability 24-incorrect exponentiation
NinaTea Apr 25, 2024
1a8e346
25-vec-considerations README.md
NinaTea Apr 25, 2024
03ef805
fixed docs for vec considerations
NinaTea Apr 25, 2024
d7adbe3
fix broken link
NinaTea Apr 25, 2024
dab5218
more info vec consid
NinaTea Apr 25, 2024
36c1824
26 unsafe block
NinaTea Apr 25, 2024
65db79c
unstable interface
NinaTea Apr 25, 2024
842e26b
28 overflow check and read me
NinaTea Apr 25, 2024
9cc0983
docs/detector overflow check
NinaTea Apr 25, 2024
79aabd9
add space
NinaTea Apr 25, 2024
9331b39
templates new detectors
NinaTea Apr 25, 2024
dbdd5a6
temporary links
NinaTea Apr 25, 2024
2f83ff7
templates docs dont use invoke contract v1
NinaTea Apr 26, 2024
d834709
typo
NinaTea Apr 26, 2024
b3d50cd
modif invoke contract
NinaTea Apr 26, 2024
55d418e
modif dont use invoke
NinaTea Apr 26, 2024
c46a4fe
Added vulnerability doc for 29-31
faculerena Apr 26, 2024
f383355
added more docs
faculerena Apr 26, 2024
1d945c0
added detector links
faculerena Apr 26, 2024
d7a8db4
added docs 23-32
faculerena Apr 29, 2024
7646474
docu fixes
ArgimiroCF Apr 29, 2024
94576f8
erased conflicting folders
ArgimiroCF Apr 29, 2024
6211e57
vuln readme fixes
ArgimiroCF Apr 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ Visit [Scout's website](https://coinfabrik.github.io/scout/) to view the full do
| [zero-or-test-address](https://coinfabrik.github.io/scout/docs/detectors/zero-or-test-address) | [Avoid zero or test address assignment to prevent contract control loss.](https://coinfabrik.github.io/scout/docs/vulnerabilities/zero-or-test-address) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/zero-or-test-address/zero-or-test-address-1) | Medium |
| [insufficiently-random-values](https://coinfabrik.github.io/scout/docs/detectors/insufficiently-random-values) | [Avoid using block attributes for random number generation to prevent manipulation.](https://coinfabrik.github.io/scout/docs/vulnerabilities/insufficiently-random-values) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/insufficiently-random-values/insufficiently-random-values-1) | Critical |
| [unrestricted-transfer-from](https://coinfabrik.github.io/scout/docs/detectors/unrestricted-transfer-from) | [Avoid passing an user-defined parameter as a `from` field in transfer-from ](https://coinfabrik.github.io/scout/docs/vulnerabilities/unrestricted-transfer-from) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/unrestricted-transfer-from/unrestricted-transfer-from-1) | Critical |
| [assert-violation](https://coinfabrik.github.io/scout/docs/detectors/assert-violation) | [Avoid the usage of the macro `assert!`, it can panic.](https://coinfabrik.github.io/scout/docs/vulnerabilities/assert-violation) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/assert-violation/assert-violation-1) | Enhacement |
| [avoid-core-mem-forget](https://coinfabrik.github.io/scout/docs/detectors/avoid-core-mem-forget) | [The use of core::mem::forget could lead to memory leaks and logic errors](https://coinfabrik.github.io/scout/docs/vulnerabilities/avoid-core-mem-forget) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/avoid-core-mem-forget/avoid-core-mem-forget-1) | Enhacement |
| [avoid-format-string](https://coinfabrik.github.io/scout/docs/detectors/avoid-format-string) | [The `format!` macro is not recommended. A custom error is recommended instead.](https://coinfabrik.github.io/scout/docs/vulnerabilities/avoid-format-string) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/avoid-format-string/avoid-format-string-1) | Enhacement |
| [assert-violation](https://coinfabrik.github.io/scout/docs/detectors/assert-violation) | [Avoid the usage of the macro `assert!`, it can panic.](https://coinfabrik.github.io/scout/docs/vulnerabilities/assert-violation) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/assert-violation/assert-violation-1) | Enhancement |
| [avoid-core-mem-forget](https://coinfabrik.github.io/scout/docs/detectors/avoid-core-mem-forget) | [The use of core::mem::forget could lead to memory leaks and logic errors](https://coinfabrik.github.io/scout/docs/vulnerabilities/avoid-core-mem-forget) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/avoid-core-mem-forget/avoid-core-mem-forget-1) | Enhancement |
| [avoid-format-string](https://coinfabrik.github.io/scout/docs/detectors/avoid-format-string) | [The `format!` macro is not recommended. A custom error is recommended instead.](https://coinfabrik.github.io/scout/docs/vulnerabilities/avoid-format-string) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/avoid-format-string/avoid-format-string-1) | Enhancement |
| [unprotected-self-destruct](https://coinfabrik.github.io/scout/docs/detectors/unprotected-self-destruct) | [If users are allowed to call terminate_contract, they can intentionally or accidentally destroy the contract.](https://coinfabrik.github.io/scout/docs/vulnerabilities/unprotected-self-destruct) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/unprotected-self-destruct/unprotected-self-destruct-1) | Critical |
| [iterators-over-indexing](https://coinfabrik.github.io/scout/docs/detectors/iterators-over-indexing) | [Iterating with hardcoded indexes is slower than using an iterator. Also, if the index is out of bounds, it will panic.](https://coinfabrik.github.io/scout/docs/vulnerabilities/iterators-over-indexing) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/iterators-over-indexing/iterators-over-indexing-1) | Enhacement |
| [ink-version](https://coinfabrik.github.io/scout/docs/detectors/ink-version) | [Using an old version of ink! can be dangerous, as it may have bugs or security issues. Use the latest version available.](https://coinfabrik.github.io/scout/docs/vulnerabilities/ink-version) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/ink-version/ink-version-1) | Enhacement |
| [iterators-over-indexing](https://coinfabrik.github.io/scout/docs/detectors/iterators-over-indexing) | [Iterating with hardcoded indexes is slower than using an iterator. Also, if the index is out of bounds, it will panic.](https://coinfabrik.github.io/scout/docs/vulnerabilities/iterators-over-indexing) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/iterators-over-indexing/iterators-over-indexing-1) | Enhancement |
| [ink-version](https://coinfabrik.github.io/scout/docs/detectors/ink-version) | [Using an old version of ink! can be dangerous, as it may have bugs or security issues. Use the latest version available.](https://coinfabrik.github.io/scout/docs/vulnerabilities/ink-version) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/ink-version/ink-version-1) | Enhancement |
| [unprotected-set-code-hash](https://coinfabrik.github.io/scout/docs/detectors/unprotected-set-code-hash) | [If users are allowed to call terminate_contract, they can intentionally modify the contract behaviour.](https://coinfabrik.github.io/scout/docs/vulnerabilities/unprotected-set-code-hash) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/set-code-hash/set-code-hash-1) | Critical |
| [unprotected-mapping-operation](https://coinfabrik.github.io/scout/docs/detectors/unprotected-mapping-operation) | [Modifying mappings with an arbitrary key given by the user could lead to unintented modifications of critical data, modifying data belonging to other users, causing denial of service, unathorized access, and other potential issues.](https://coinfabrik.github.io/scout/docs/vulnerabilities/unprotected-mapping-operation) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/unprotected-mapping-operation/unprotected-mapping-operation-1) | Critical |
| [lazy-delegate](https://coinfabrik.github.io/scout/docs/detectors/lazy-delegate) | [Delegated calls in ink! need lazy storage.](https://coinfabrik.github.io/scout/docs/vulnerabilities/lazy-delegate) | [1](https://github.com/CoinFabrik/scout/tree/main/test-cases/lazy-delegate/lazy-delegate-1) | Critical |
Expand Down
8 changes: 4 additions & 4 deletions detectors/assert-violation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ dylint_linting::impl_pre_expansion_lint! {
LINT_MESSAGE,
AssertViolation::default(),
{
name: "Unprotected Mapping Operation",
long_message: "Modifying mappings with an arbitrary key given by the user could lead to unintented modifications of critical data, modifying data belonging to other users, causing denial of service, unathorized access, and other potential issues. ",
severity: "Critical",
help: "https://coinfabrik.github.io/scout/docs/vulnerabilities/unprotected-mapping-operation",
name: "Assert violation",
long_message: "The assert! macro can cause the contract to panic. This is not a good practice.",
severity: "Enhancement",
help: "https://coinfabrik.github.io/scout/docs/vulnerabilities/assert-violation",
vulnerability_class: "Validations and error handling",
}
}
Expand Down
4 changes: 2 additions & 2 deletions detectors/incorrect-exponentiation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_lint::{LateContext, LateLintPass};
use rustc_span::Span;
use scout_audit_clippy_utils::diagnostics::span_lint_and_help;

const LINT_MESSAGE: &str = "'^' It is not an exponential operator. It is a bitwise XOR one.";
const LINT_MESSAGE: &str = "'^' It is not an exponential operator. It is a bitwise XOR.";
const LINT_HELP: &str = "If you want to use XOR, use bitxor(). If you want to raise a number use .checked_pow() or .pow() ";

dylint_linting::declare_late_lint! {
Expand All @@ -24,7 +24,7 @@ dylint_linting::declare_late_lint! {
name: "Incorrect Exponentiation",
long_message: LINT_MESSAGE,
severity: "Critical",
help: "https://github.com/CoinFabrik/scout-soroban/tree/main/detectors/",
help: "https://coinfabrik.github.io/scout/docs/vulnerabilities/incorrect-exponentiation",
vulnerability_class: "Arithmetic",
}

Expand Down
19 changes: 0 additions & 19 deletions detectors/unstable-interface/Cargo.toml

This file was deleted.

79 changes: 0 additions & 79 deletions detectors/unstable-interface/src/lib.rs

This file was deleted.

17 changes: 0 additions & 17 deletions detectors/zero-or-test-address/README.md

This file was deleted.

4 changes: 2 additions & 2 deletions docs/docs/detectors/11-delegate-call.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Delegate call

### What it does
Checks for delegated calls to contracts passed as arguments.
Checks for delegate calls to contracts passed as arguments.

### Why is this bad?
Delegated calls to contracts passed as arguments can be used to change the expected behavior of the contract. If you need to change the target of a delegated call, you should use a storage variable, and make a function with proper access control to change it.
Delegate calls to contracts passed as arguments can be used to change the expected behavior of the contract. If you need to change the target of a delegate call, you should use a storage variable, and make a function with proper access control to change it.

### Example

Expand Down
4 changes: 3 additions & 1 deletion docs/docs/detectors/14-unrestricted-transfer-from.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ An user Alice can approve a contract to spend their tokens. An user Bob can call

### Known problems

None.
Could generate false positives when using [Cardinal Cryptography's PSP22](https://github.com/Cardinal-Cryptography/PSP22).

### Example

Expand Down Expand Up @@ -48,6 +48,7 @@ Use instead:

```rust
// build_call example
#[ink(message)]
pub fn deposit(&mut self) -> Result<(), Error> {
let call_params = build_call::<DefaultEnvironment>()
.exec_input(
Expand All @@ -62,6 +63,7 @@ Use instead:
}

// ContractRef example
#[ink(message)]
pub fn deposit(&mut self) -> Result<(), Error> {
let res = PSP22Ref::transfer_from(
&self.psp22_address,
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/detectors/17-avoid-format-string.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Checks for `format!` macro usage.

### Why is this bad?

The usage of format! is not recommended.
The usage of `format!` is not recommended.

### Example

Expand Down Expand Up @@ -35,4 +35,4 @@ Use instead:

### Implementation

The detector's implementation can be found at [this link](https://github.com/CoinFabrik/scout/tree/main/detectors/avoid-format!-string).
The detector's implementation can be found at [this link](https://github.com/CoinFabrik/scout/tree/main/detectors/avoid-format-string).
7 changes: 1 addition & 6 deletions docs/docs/detectors/18-unprotected-self-destruct.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@

### What it does

It warns you if `terminate_contract` function is called without a previous check of the address of the caller.
It warns you if `terminate_contract` function is called without previously checking the address of the caller.

### Why is this bad?

If users are allowed to call `terminate_contract`, they can intentionally or accidentally destroy the contract, leading to the loss of all associated data and functionalities given by this contract or by others that depend on it.

### Known problems

None.

### Example


```rust
#[ink(message)]
pub fn delete_contract(&mut self, beneficiary: AccountId) {
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/detectors/19-iterators-over-indexing.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### What it does

It warns if for loop uses indexing instead of iterator. If the indexing goes to `.len()` it will not warn.
It warns if a `for` loop uses indexing instead of an iterator. If the indexing goes to `.len()` it will not warn.

### Why is this bad?

Expand Down
6 changes: 3 additions & 3 deletions docs/docs/detectors/2-set-contract-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

### What it does

Checks for calls to env::set_contract_storage.
Checks for calls to `env::set_contract_storage`.

### Why is this bad?

Functions using keys as variables without proper access control or input sanitation can allow users to perform changes in arbitrary memory locations.
Functions using keys as variables without proper access control or input sanitization can allow users to perform changes in arbitrary memory locations.

### Known problems

Only check the function call, so false positives could result.
Only checks the function call, so false positives could result.

### Example

Expand Down
4 changes: 2 additions & 2 deletions docs/docs/detectors/20-ink-version.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

### What it does

Warns you if you are using an old version of ink!.
Warns you if you are using an old version of `ink!`.

### Why is this bad?

Using an old version of ink! can be dangerous, as it may have bugs or security issues.
Using an old version of `ink!` can be dangerous, as it may have bugs or security issues.

### Example

Expand Down
9 changes: 2 additions & 7 deletions docs/docs/detectors/21-unprotected-set-code-hash.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,14 @@

### What it does

It warns you if `set_code_hash` function is called without a previous check of the address of the caller.
It warns you if `set_code_hash` function is called without previously checking the address of the caller.

### Why is this bad?

If users are allowed to call `terminate_contract`, they can intentionally modify the contract behaviour, leading to the loss of all associated data/tokens and functionalities given by this contract or by others that depend on it.

### Known problems

None.
If users are allowed to call `set_code_hash`, they can intentionally modify the contract behaviour, leading to the loss of all associated data/tokens and functionalities given by this contract or by others that depend on it.

### Example


```rust
#[ink(message)]
pub fn update_code(&self, value: [u8; 32]) -> Result<(), Error> {
Expand Down
Loading
Loading