[flake8-bandit] Fix mixed-case hash algorithm names (S324) (#16552)

The PR solves issue #16525
This commit is contained in:
Vasco Schiavo 2025-03-07 16:21:07 +01:00 committed by GitHub
parent 0dfa810e9a
commit 6d6e524b90
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 20 additions and 3 deletions

View file

@ -45,3 +45,10 @@ crypt.crypt("test", salt=crypt.METHOD_SHA512)
crypt.mksalt()
crypt.mksalt(crypt.METHOD_SHA256)
crypt.mksalt(crypt.METHOD_SHA512)
# From issue: https://github.com/astral-sh/ruff/issues/16525#issuecomment-2706188584
# Errors
hashlib.new("Md5")
# OK
hashlib.new('Sha256')

View file

@ -135,11 +135,11 @@ fn detect_insecure_hashlib_calls(
return;
};
// `hashlib.new` accepts both lowercase and uppercase names for hash
// `hashlib.new` accepts mixed lowercase and uppercase names for hash
// functions.
if matches!(
hash_func_name,
"md4" | "md5" | "sha" | "sha1" | "MD4" | "MD5" | "SHA" | "SHA1"
hash_func_name.to_ascii_lowercase().as_str(),
"md4" | "md5" | "sha" | "sha1"
) {
checker.report_diagnostic(Diagnostic::new(
HashlibInsecureHashFunction {

View file

@ -195,3 +195,13 @@ S324.py:29:14: S324 Probable use of insecure hash functions in `crypt`: `crypt.M
30 |
31 | # OK
|
S324.py:51:13: S324 Probable use of insecure hash functions in `hashlib`: `Md5`
|
49 | # From issue: https://github.com/astral-sh/ruff/issues/16525#issuecomment-2706188584
50 | # Errors
51 | hashlib.new("Md5")
| ^^^^^ S324
52 |
53 | # OK
|