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

fix: Secure Source of Randomness #3413

Closed
wants to merge 1 commit into from
Closed

Conversation

pixeeai
Copy link

@pixeeai pixeeai 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)

Co-authored-by: pixeebot[bot] <104101892+pixeebot[bot]@users.noreply.github.com>
@pixeeai pixeeai changed the title Secure Source of Randomness fix: Secure Source of Randomness May 3, 2024
@binste
Copy link
Contributor

binste commented May 3, 2024

We don't use random in cryptographic contexts so this is not relevant for Altair.

@binste binste closed this May 3, 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
Development

Successfully merging this pull request may close these issues.

None yet

2 participants