Skip to content

Commit 6d6e524

Browse files
authored
[flake8-bandit] Fix mixed-case hash algorithm names (S324) (#16552)
The PR solves issue #16525
1 parent 0dfa810 commit 6d6e524

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

crates/ruff_linter/resources/test/fixtures/flake8_bandit/S324.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@
4545
crypt.mksalt()
4646
crypt.mksalt(crypt.METHOD_SHA256)
4747
crypt.mksalt(crypt.METHOD_SHA512)
48+
49+
# From issue: https://github.com/astral-sh/ruff/issues/16525#issuecomment-2706188584
50+
# Errors
51+
hashlib.new("Md5")
52+
53+
# OK
54+
hashlib.new('Sha256')

crates/ruff_linter/src/rules/flake8_bandit/rules/hashlib_insecure_hash_functions.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,11 @@ fn detect_insecure_hashlib_calls(
135135
return;
136136
};
137137

138-
// `hashlib.new` accepts both lowercase and uppercase names for hash
138+
// `hashlib.new` accepts mixed lowercase and uppercase names for hash
139139
// functions.
140140
if matches!(
141-
hash_func_name,
142-
"md4" | "md5" | "sha" | "sha1" | "MD4" | "MD5" | "SHA" | "SHA1"
141+
hash_func_name.to_ascii_lowercase().as_str(),
142+
"md4" | "md5" | "sha" | "sha1"
143143
) {
144144
checker.report_diagnostic(Diagnostic::new(
145145
HashlibInsecureHashFunction {

crates/ruff_linter/src/rules/flake8_bandit/snapshots/ruff_linter__rules__flake8_bandit__tests__S324_S324.py.snap

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,3 +195,13 @@ S324.py:29:14: S324 Probable use of insecure hash functions in `crypt`: `crypt.M
195195
30 |
196196
31 | # OK
197197
|
198+
199+
S324.py:51:13: S324 Probable use of insecure hash functions in `hashlib`: `Md5`
200+
|
201+
49 | # From issue: https://github.com/astral-sh/ruff/issues/16525#issuecomment-2706188584
202+
50 | # Errors
203+
51 | hashlib.new("Md5")
204+
| ^^^^^ S324
205+
52 |
206+
53 | # OK
207+
|

0 commit comments

Comments
 (0)