mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
[flake8-bandit] Fix mixed-case hash algorithm names (S324) (#16552)
The PR solves issue #16525
This commit is contained in:
parent
0dfa810e9a
commit
6d6e524b90
3 changed files with 20 additions and 3 deletions
|
@ -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')
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue