Skip to content

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

Closed
@Lucas-C

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions