File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -31,6 +31,7 @@ class Cwe:
3131 IMPROPER_CHECK_OF_EXCEPT_COND = 703
3232 INCORRECT_PERMISSION_ASSIGNMENT = 732
3333 INAPPROPRIATE_ENCODING_FOR_OUTPUT_CONTEXT = 838
34+ DOWNLOAD_OF_CODE_WITHOUT_INTEGRITY_CHECK = 494
3435
3536 MITRE_URL_PATTERN = "https://cwe.mitre.org/data/definitions/%s.html"
3637
Original file line number Diff line number Diff line change 1- # Copyright (c) 2024 PyCQA
2- #
31# SPDX-License-Identifier: Apache-2.0
42r"""
53================================================
5856 - https://cwe.mitre.org/data/definitions/494.html
5957 - https://huggingface.co/docs/huggingface_hub/en/guides/download
6058
61- .. versionadded:: 1.9.0
59+ .. versionadded:: 1.8.6
6260
6361"""
62+ import string
63+
6464import bandit
6565from bandit .core import issue
6666from bandit .core import test_properties as test
@@ -129,8 +129,7 @@ def huggingface_unsafe_download(context):
129129
130130 # Check if it looks like a commit hash (hexadecimal string)
131131 # 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 )
134133 if len (revision_str ) >= 7 and is_hex :
135134 # This looks like a commit hash, which is secure
136135 return
@@ -149,6 +148,6 @@ def huggingface_unsafe_download(context):
149148 f"Unsafe Hugging Face Hub download without revision pinning "
150149 f"in { func_name } ()"
151150 ),
152- cwe = issue .Cwe .IMPROPER_INPUT_VALIDATION ,
151+ cwe = issue .Cwe .DOWNLOAD_OF_CODE_WITHOUT_INTEGRITY_CHECK ,
153152 lineno = context .get_lineno_for_call_arg (func_name ),
154153 )
Original file line number Diff line number Diff line change @@ -157,15 +157,15 @@ bandit.plugins =
157157 # bandit/plugins/pytorch_load.py
158158 pytorch_load = bandit.plugins.pytorch_load:pytorch_load
159159
160- # bandit/plugins/huggingface_unsafe_download.py
161- huggingface_unsafe_download = bandit.plugins.huggingface_unsafe_download:huggingface_unsafe_download
162-
163160 # bandit/plugins/trojansource.py
164161 trojansource = bandit.plugins.trojansource:trojansource
165162
166163 # bandit/plugins/markupsafe_markup_xss.py
167164 markupsafe_markup_xss = bandit.plugins.markupsafe_markup_xss:markupsafe_markup_xss
168165
166+ # bandit/plugins/huggingface_unsafe_download.py
167+ huggingface_unsafe_download = bandit.plugins.huggingface_unsafe_download:huggingface_unsafe_download
168+
169169[build_sphinx]
170170all_files = 1
171171build-dir = doc/build
You can’t perform that action at this time.
0 commit comments