Skip to content

Commit

Permalink
Add more random functions to B311 check (PyCQA#1235)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
aripollak and pre-commit-ci[bot] authored Feb 19, 2025
1 parent 8ff25e0 commit c58c00a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
6 changes: 6 additions & 0 deletions bandit/blacklists/calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@
| | | - random.uniform | |
| | | - random.triangular | |
| | | - random.randbytes | |
| | | - random.randrange | |
| | | - random.sample | |
| | | - random.getrandbits | |
+------+---------------------+------------------------------------+-----------+
B312: telnetlib
Expand Down Expand Up @@ -515,6 +518,9 @@ def gen_blacklist():
"random.uniform",
"random.triangular",
"random.randbytes",
"random.sample",
"random.randrange",
"random.getrandbits",
],
"Standard pseudo-random generators are not suitable for "
"security/cryptographic purposes.",
Expand Down
3 changes: 3 additions & 0 deletions examples/random_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
bad = random.uniform()
bad = random.triangular()
bad = random.randbytes()
bad = random.sample()
bad = random.randrange()
bad = random.getrandbits()

good = os.urandom()
good = random.SystemRandom()
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 @@ -365,8 +365,8 @@ def test_popen_wrappers(self):
def test_random_module(self):
"""Test for the `random` module."""
expect = {
"SEVERITY": {"UNDEFINED": 0, "LOW": 9, "MEDIUM": 0, "HIGH": 0},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 9},
"SEVERITY": {"UNDEFINED": 0, "LOW": 12, "MEDIUM": 0, "HIGH": 0},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 12},
}
self.check_example("random_module.py", expect)

Expand Down

0 comments on commit c58c00a

Please # to comment.