Skip to content

Commit 04a9d5f

Browse files
committed
Additional Changes to Huggingface Revision Checks
- Add an entry for CWE 494 - Use string.hexdigits - Set to 18.6 release - Remove Copywright - Order after markupsafe
1 parent b2f0611 commit 04a9d5f

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

bandit/core/issue.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

bandit/plugins/huggingface_unsafe_download.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Copyright (c) 2024 PyCQA
2-
#
31
# SPDX-License-Identifier: Apache-2.0
42
r"""
53
================================================
@@ -58,9 +56,11 @@
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+
6464
import bandit
6565
from bandit.core import issue
6666
from 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
)

setup.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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]
170170
all_files = 1
171171
build-dir = doc/build

0 commit comments

Comments
 (0)