This repository was archived by the owner on Aug 14, 2026. It is now read-only.
Repository navigation
Secure Source of Randomness - #436
Closed
pixeebot[bot] wants to merge 2 commits into
Closed
pixeebot[bot] wants to merge 2 commits into
pixeebot[bot] wants to merge 2 commits into
Conversation
pixeebot
Bot
requested review from
dwanderson-intel and
tjs-intel
as code owners
February 20, 2024 21:26
for more information, see https://pre-commit.ci
Contributor
|
aesthetic change only: moving the import lines back into stdlib, which is i think where they belong (not a 3rd party install) |
Contributor
|
non-crypto uses of random |
dwanderson-intel
deleted the
pixeebot/drip-2024-02-20-pixee-python/secure-random
branch
February 20, 2024 22:03
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This codemod replaces all instances of functions in the
randommodule (e.g.random.random()with their, much more secure, equivalents from thesecretsmodule (e.g.secrets.SystemRandom().random()).There is significant algorithmic complexity in getting computers to generate genuinely unguessable random bits. The
random.random()function uses a method of pseudo-random number generation that unfortunately emits fairly predictable numbers.If the numbers it emits are predictable, then it's obviously not safe to use in cryptographic operations, file name creation, token construction, password generation, and anything else that's related to security. In fact, it may affect security even if it's not directly obvious.
Switching to a more secure version is simple and the changes look something like this:
More reading
I have additional improvements ready for this repo! If you want to see them, leave the comment:
... and I will open a new PR right away!
Powered by: pixeebot (codemod ID: pixee:python/secure-random)