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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positive: [B324:hashlib] Use of insecure MD5 hash function when usedforsecurity=False #994

Closed
Lucas-C opened this issue Mar 10, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@Lucas-C
Copy link
Contributor

Lucas-C commented Mar 10, 2023

Describe the bug

Since the latest 1.7.5 release,
code that used to not raise warnings is now detected as invalid by bandit

Reproduction steps

  1. Put the following code in a file named bandit_bug.py
import hashlib
file_hash = hashlib.new("md5", usedforsecurity=False)
file_hash.update(b"Hello world!")
print(file_hash.hexdigest())
  1. Call bandit bandit_bug.py
    With bandit 1.7.5 you will get the following output:
>> Issue: [B324:hashlib] Use of insecure MD5 hash function.
   Severity: Medium   Confidence: High
   CWE: CWE-327 (https://cwe.mitre.org/data/definitions/327.html)
   More Info: https://bandit.readthedocs.io/en/1.7.5/plugins/b324_hashlib.html
   Location: bandit_bug.py:3:12

Expected behavior

There has been some work done on usedforsecurity=False in bandit in the past:

I was expecting no warning when usedforsecurity=False is passed to hashlib.new("md5")

Bandit version

1.7.5 (Default)

Python version

3.8

Additional context

No response

@Lucas-C Lucas-C added the bug Something isn't working label Mar 10, 2023
@Lucas-C
Copy link
Contributor Author

Lucas-C commented Mar 10, 2023

Sorry for the noise, this was just me being silly:
the problem came from me using a version 3.8 of Python.
All is fine when using a more recent version: https://github.com/PyCQA/bandit/blob/main/examples/hashlib_new_insecure_functions.py#L19

@Lucas-C Lucas-C closed this as completed Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant