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

Add random.Random to B311 checks #940

Merged
merged 2 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Add random.Random to B311 checks
The lowercase `random.random` already matches `random.Random` on Windows as well
(due to being case-insensitive), but not on other platforms.

Resolves: #926
  • Loading branch information
shiftinv committed Aug 12, 2022
commit 004fcf4159da573053a88ff1a850d90292d82203
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 @@ -519,6 +520,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