Skip to content

Commit

Permalink
feat(rules): flag Random and randbytes in S311
Browse files Browse the repository at this point in the history
  • Loading branch information
mkniewallner committed Mar 8, 2024
1 parent f3d2d99 commit 144e32c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Expand Up @@ -15,6 +15,7 @@
random.choices()
random.uniform()
random.triangular()
random.randbytes()

# Unrelated
os.urandom()
Expand Down
Expand Up @@ -867,7 +867,7 @@ pub(crate) fn suspicious_function_call(checker: &mut Checker, call: &ExprCall) {
["urllib", "request", "URLopener" | "FancyURLopener"] |
["six", "moves", "urllib", "request", "URLopener" | "FancyURLopener"] => Some(SuspiciousURLOpenUsage.into()),
// NonCryptographicRandom
["random", "random" | "randrange" | "randint" | "choice" | "choices" | "uniform" | "triangular"] => Some(SuspiciousNonCryptographicRandomUsage.into()),
["random", "Random" | "random" | "randrange" | "randint" | "choice" | "choices" | "uniform" | "triangular" | "randbytes"] => Some(SuspiciousNonCryptographicRandomUsage.into()),
// UnverifiedContext
["ssl", "_create_unverified_context"] => Some(SuspiciousUnverifiedContextUsage.into()),
// XMLCElementTree
Expand Down
@@ -1,6 +1,15 @@
---
source: crates/ruff_linter/src/rules/flake8_bandit/mod.rs
---
S311.py:10:1: S311 Standard pseudo-random generators are not suitable for cryptographic purposes
|
9 | # Errors
10 | random.Random()
| ^^^^^^^^^^^^^^^ S311
11 | random.random()
12 | random.randrange()
|

S311.py:11:1: S311 Standard pseudo-random generators are not suitable for cryptographic purposes
|
9 | # Errors
Expand Down Expand Up @@ -58,6 +67,7 @@ S311.py:16:1: S311 Standard pseudo-random generators are not suitable for crypto
16 | random.uniform()
| ^^^^^^^^^^^^^^^^ S311
17 | random.triangular()
18 | random.randbytes()
|

S311.py:17:1: S311 Standard pseudo-random generators are not suitable for cryptographic purposes
Expand All @@ -66,6 +76,15 @@ S311.py:17:1: S311 Standard pseudo-random generators are not suitable for crypto
16 | random.uniform()
17 | random.triangular()
| ^^^^^^^^^^^^^^^^^^^ S311
18 |
19 | # Unrelated
18 | random.randbytes()
|

S311.py:18:1: S311 Standard pseudo-random generators are not suitable for cryptographic purposes
|
16 | random.uniform()
17 | random.triangular()
18 | random.randbytes()
| ^^^^^^^^^^^^^^^^^^ S311
19 |
20 | # Unrelated
|

0 comments on commit 144e32c

Please sign in to comment.