File tree Expand file tree Collapse file tree 3 files changed +9
-9
lines changed Expand file tree Collapse file tree 3 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ class Cwe:
31
31
IMPROPER_CHECK_OF_EXCEPT_COND = 703
32
32
INCORRECT_PERMISSION_ASSIGNMENT = 732
33
33
INAPPROPRIATE_ENCODING_FOR_OUTPUT_CONTEXT = 838
34
+ DOWNLOAD_OF_CODE_WITHOUT_INTEGRITY_CHECK = 494
34
35
35
36
MITRE_URL_PATTERN = "https://cwe.mitre.org/data/definitions/%s.html"
36
37
Original file line number Diff line number Diff line change 1
- # Copyright (c) 2024 PyCQA
2
- #
3
1
# SPDX-License-Identifier: Apache-2.0
4
2
r"""
5
3
================================================
58
56
- https://cwe.mitre.org/data/definitions/494.html
59
57
- https://huggingface.co/docs/huggingface_hub/en/guides/download
60
58
61
- .. versionadded:: 1.9.0
59
+ .. versionadded:: 1.8.6
62
60
63
61
"""
62
+ import string
63
+
64
64
import bandit
65
65
from bandit .core import issue
66
66
from bandit .core import test_properties as test
@@ -129,8 +129,7 @@ def huggingface_unsafe_download(context):
129
129
130
130
# Check if it looks like a commit hash (hexadecimal string)
131
131
# Must be at least 7 characters and all hexadecimal
132
- hex_chars = "0123456789abcdefABCDEF"
133
- is_hex = all (c in hex_chars for c in revision_str )
132
+ is_hex = all (c in string .hexdigits for c in revision_str )
134
133
if len (revision_str ) >= 7 and is_hex :
135
134
# This looks like a commit hash, which is secure
136
135
return
@@ -149,6 +148,6 @@ def huggingface_unsafe_download(context):
149
148
f"Unsafe Hugging Face Hub download without revision pinning "
150
149
f"in { func_name } ()"
151
150
),
152
- cwe = issue .Cwe .IMPROPER_INPUT_VALIDATION ,
151
+ cwe = issue .Cwe .DOWNLOAD_OF_CODE_WITHOUT_INTEGRITY_CHECK ,
153
152
lineno = context .get_lineno_for_call_arg (func_name ),
154
153
)
Original file line number Diff line number Diff line change @@ -157,15 +157,15 @@ bandit.plugins =
157
157
# bandit/plugins/pytorch_load.py
158
158
pytorch_load = bandit.plugins.pytorch_load:pytorch_load
159
159
160
- # bandit/plugins/huggingface_unsafe_download.py
161
- huggingface_unsafe_download = bandit.plugins.huggingface_unsafe_download:huggingface_unsafe_download
162
-
163
160
# bandit/plugins/trojansource.py
164
161
trojansource = bandit.plugins.trojansource:trojansource
165
162
166
163
# bandit/plugins/markupsafe_markup_xss.py
167
164
markupsafe_markup_xss = bandit.plugins.markupsafe_markup_xss:markupsafe_markup_xss
168
165
166
+ # bandit/plugins/huggingface_unsafe_download.py
167
+ huggingface_unsafe_download = bandit.plugins.huggingface_unsafe_download:huggingface_unsafe_download
168
+
169
169
[build_sphinx]
170
170
all_files = 1
171
171
build-dir = doc/build
You can’t perform that action at this time.
0 commit comments