document that random.choices() isn't secure either#728
Merged
Conversation
sigmavirus24
approved these changes
Aug 22, 2021
Member
|
I believe this also needs to be added to a test/example file to ensure no regression |
Contributor
Author
|
@sigmavirus24 Something like this? |
| bad = random.randint() | ||
| bad = random.choice() | ||
| if sys.version_info.major >= 3 and sys.version_info.minor >= 6: | ||
| bad = random.choices() |
Member
There was a problem hiding this comment.
This code is never actually ran, so there's little reason to have this guard I think?
Contributor
Author
There was a problem hiding this comment.
That makes a lot of sense. Fixed.
sigmavirus24
approved these changes
Aug 23, 2021
ericwb
requested changes
Aug 23, 2021
Member
ericwb
left a comment
There was a problem hiding this comment.
Just need a quick fix to the functional tests.
| bad = random.randrange() | ||
| bad = random.randint() | ||
| bad = random.choice() | ||
| bad = random.choices() |
Member
There was a problem hiding this comment.
You've introduced a new functional test by including this line. As a result the tests will fail, because Bandit will flag this line as a vulnerability. You'll want to update test_functional.test_random_module()
Contributor
Author
There was a problem hiding this comment.
I see. Okay, thank you.
mikespallino
pushed a commit
to mikespallino/bandit
that referenced
this pull request
Jan 7, 2022
* document that random.choices() isn't secure either * add random.choices() to tests
This was referenced Jan 25, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Because
random.choices()wasn't explicitly listed in the "don't use this" list, I initially thought it was safer version ofrandom.choice().I realized my mistake and used
secret.choice()eventually, but this PR is to addrandom.choices()to the unsafe list.