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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Secure Source of Randomness #1

Merged
merged 1 commit into from
May 2, 2024

Conversation

pixeebot[bot]
Copy link

@pixeebot pixeebot bot commented May 2, 2024

This codemod replaces all instances of functions in the random module (e.g. random.random() with their, much more secure, equivalents from the secrets module (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:

- import random
+ import secrets
  ...
- random.random()
+ secrets.SystemRandom().random()
More reading

馃馃Powered by Pixeebot (codemod ID: pixee:python/secure-random)

@pixeeai pixeeai merged commit 4af909d into main May 2, 2024
@pixeebot pixeebot bot deleted the pixeebot/drip-2024-05-02-pixee-python/secure-random branch May 2, 2024 23:05
pixeeai added a commit that referenced this pull request May 7, 2024
pixeeai added a commit that referenced this pull request May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant