Skip to content

Commit c58c00a

Browse files
Add more random functions to B311 check (#1235)
* Add sample, randrange, and getrandbits to B311 check * Add to bad examples * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Update test_functional.py --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 8ff25e0 commit c58c00a

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

bandit/blacklists/calls.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@
205205
| | | - random.uniform | |
206206
| | | - random.triangular | |
207207
| | | - random.randbytes | |
208+
| | | - random.randrange | |
209+
| | | - random.sample | |
210+
| | | - random.getrandbits | |
208211
+------+---------------------+------------------------------------+-----------+
209212
210213
B312: telnetlib
@@ -515,6 +518,9 @@ def gen_blacklist():
515518
"random.uniform",
516519
"random.triangular",
517520
"random.randbytes",
521+
"random.sample",
522+
"random.randrange",
523+
"random.getrandbits",
518524
],
519525
"Standard pseudo-random generators are not suitable for "
520526
"security/cryptographic purposes.",

examples/random_module.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
bad = random.uniform()
1212
bad = random.triangular()
1313
bad = random.randbytes()
14+
bad = random.sample()
15+
bad = random.randrange()
16+
bad = random.getrandbits()
1417

1518
good = os.urandom()
1619
good = random.SystemRandom()

tests/functional/test_functional.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,8 @@ def test_popen_wrappers(self):
365365
def test_random_module(self):
366366
"""Test for the `random` module."""
367367
expect = {
368-
"SEVERITY": {"UNDEFINED": 0, "LOW": 9, "MEDIUM": 0, "HIGH": 0},
369-
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 9},
368+
"SEVERITY": {"UNDEFINED": 0, "LOW": 12, "MEDIUM": 0, "HIGH": 0},
369+
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 12},
370370
}
371371
self.check_example("random_module.py", expect)
372372

0 commit comments

Comments
 (0)