Skip to content

Add more random functions to B311 check#1235

Merged
lukehinds merged 4 commits intoPyCQA:mainfrom
aripollak:new-b311-check
Feb 19, 2025
Merged

Add more random functions to B311 check#1235
lukehinds merged 4 commits intoPyCQA:mainfrom
aripollak:new-b311-check

Conversation

@aripollak
Copy link
Contributor

Fixes #1215.

bad = random.uniform()
bad = random.triangular()
bad = random.randbytes()
bad = random.sample()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes will require an update to the functional tests to update the count of the number of fail checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@ericwb ericwb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might result in more false positives, but likely as much as before with the other random functions. Okay for now, but in the future we may need to consider a better way to detect random used in a cryptographic fashion to isolate a more likely security issue.

@aripollak
Copy link
Contributor Author

Agreed. I was considering a separate feature request to at least allow some obvious non-cryptography cases through, like choices from a constant list or tuple of literals, but I'm not sure how common those would be.

@lukehinds lukehinds merged commit c58c00a into PyCQA:main Feb 19, 2025
15 checks passed
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.

Add sample, randrange, and getrandbits to B311 random module check?

3 participants