Skip to content

Commit

Permalink
Add random.Random to B311 checks (#940)
Browse files Browse the repository at this point in the history
The lowercase `random.random` already matches `random.Random` on Windows as well
(due to being case-insensitive), but not on other platforms.

Resolves: #926

Co-authored-by: Eric Brown <ericwb@users.noreply.github.com>
  • Loading branch information
shiftinv and ericwb committed May 22, 2023
1 parent 9e8813a commit 4182f6b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion bandit/blacklists/calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@
+------+---------------------+------------------------------------+-----------+
| ID | Name | Calls | Severity |
+======+=====================+====================================+===========+
| B311 | random | - random.random | Low |
| B311 | random | - random.Random | Low |
| | | - random.random | |
| | | - random.randrange | |
| | | - random.randint | |
| | | - random.choice | |
Expand Down Expand Up @@ -513,6 +514,7 @@ def gen_blacklist():
"B311",
issue.Cwe.INSUFFICIENT_RANDOM_VALUES,
[
"random.Random",
"random.random",
"random.randrange",
"random.randint",
Expand Down
1 change: 1 addition & 0 deletions examples/random_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import somelib

bad = random.Random()
bad = random.random()
bad = random.randrange()
bad = random.randint()
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ def test_popen_wrappers(self):
def test_random_module(self):
"""Test for the `random` module."""
expect = {
"SEVERITY": {"UNDEFINED": 0, "LOW": 7, "MEDIUM": 0, "HIGH": 0},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 7},
"SEVERITY": {"UNDEFINED": 0, "LOW": 8, "MEDIUM": 0, "HIGH": 0},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 8},
}
self.check_example("random_module.py", expect)

Expand Down

0 comments on commit 4182f6b

Please sign in to comment.