-
-
Notifications
You must be signed in to change notification settings - Fork 622
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
document that random.choices() isn't secure either #728
Conversation
I believe this also needs to be added to a test/example file to ensure no regression |
@sigmavirus24 Something like this? |
examples/random_module.py
Outdated
|
||
bad = random.random() | ||
bad = random.randrange() | ||
bad = random.randint() | ||
bad = random.choice() | ||
if sys.version_info.major >= 3 and sys.version_info.minor >= 6: | ||
bad = random.choices() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is never actually ran, so there's little reason to have this guard I think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes a lot of sense. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just need a quick fix to the functional tests.
@@ -6,6 +6,7 @@ | |||
bad = random.randrange() | |||
bad = random.randint() | |||
bad = random.choice() | |||
bad = random.choices() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Okay, thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* document that random.choices() isn't secure either * add random.choices() to tests
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.