Skip to content

Commit d570366

Browse files
authored
chore(pre_commit): convert bandit into Ruff's S rule & add TODOs for security improvements (#2039)
1 parent 95ef33a commit d570366

File tree

5 files changed

+14
-20
lines changed

5 files changed

+14
-20
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
ci:
32
autofix_prs: true
43
autoupdate_schedule: weekly
@@ -24,13 +23,6 @@ repos:
2423
- id: end-of-file-fixer
2524
- id: mixed-line-ending
2625

27-
- repo: https://github.com/PyCQA/bandit
28-
rev: '1.9.2'
29-
hooks:
30-
- id: bandit
31-
args: ["-c", "pyproject.toml"]
32-
additional_dependencies: ["bandit[toml]"]
33-
3426
- repo: https://github.com/astral-sh/ruff-pre-commit
3527
rev: v0.14.10
3628
hooks:

examples/time_in_zone/scripts/stream_from_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def run_command_in_thread(command: list) -> Thread:
7777

7878

7979
def run_command(command: list) -> int:
80-
process = subprocess.run(command)
80+
process = subprocess.run(command) # noqa: S603 # TODO: Validate command input to prevent execution of untrusted input
8181
return process.returncode
8282

8383

pyproject.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ build = [
8585
"build>=0.10,<1.4"
8686
]
8787

88-
[tool.bandit]
89-
target = ["test", "supervision"]
90-
tests = ["B201", "B301", "B318", "B314", "B303", "B413", "B412"]
91-
9288
[tool.autoflake]
9389
check = true
9490
imports = ["cv2", "supervision"]
@@ -129,7 +125,7 @@ indent-width = 4
129125

130126
[tool.ruff.lint]
131127
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
132-
select = ["E", "F", "I", "A", "Q", "W", "RUF", "UP"]
128+
select = ["E", "F", "I", "A", "Q", "W", "RUF", "UP", "S"]
133129
ignore = []
134130
# Allow autofix for all enabled rules (when `--fix`) is provided.
135131
fixable = [
@@ -193,6 +189,12 @@ convention = "google"
193189

194190
[tool.ruff.lint.per-file-ignores]
195191
"__init__.py" = ["E402", "F401"]
192+
"test/**" = [
193+
"S101" # Use of `assert` detected
194+
]
195+
"supervision/**" = [
196+
"S101" # TODO: Replace asserts with proper error handling
197+
]
196198

197199
[tool.ruff.lint.mccabe]
198200
# Flag errors (`C901`) whenever the complexity level exceeds 5.

supervision/assets/downloader.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def is_md5_hash_matching(filename: str, original_md5_hash: str) -> bool:
2727

2828
with open(filename, "rb") as file:
2929
file_contents = file.read()
30-
computed_md5_hash = hash_new(name="MD5")
30+
computed_md5_hash = hash_new(name="MD5") # noqa: S324 # TODO: Replace MD5 with a secure hash function like SHA-256
3131
computed_md5_hash.update(file_contents)
3232

3333
return computed_md5_hash.hexdigest() == original_md5_hash
@@ -57,7 +57,7 @@ def download_assets(asset_name: VideoAssets | str) -> str:
5757

5858
if not Path(filename).exists() and filename in VIDEO_ASSETS:
5959
print(f"Downloading {filename} assets \n")
60-
response = get(VIDEO_ASSETS[filename][0], stream=True, allow_redirects=True)
60+
response = get(VIDEO_ASSETS[filename][0], stream=True, allow_redirects=True) # noqa: S113 # TODO: Add timeout to requests call
6161
response.raise_for_status()
6262

6363
file_size = int(response.headers.get("Content-Length", 0))

test/test_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ def random_boxes(
8484
out = np.zeros((count, 4), dtype=np.float32)
8585

8686
for i in range(count):
87-
w = random.uniform(min_box_size, max_box_size)
88-
h = random.uniform(min_box_size, max_box_size)
87+
w = random.uniform(min_box_size, max_box_size) # noqa: S311 # TODO: Use secrets module if cryptographic security is needed
88+
h = random.uniform(min_box_size, max_box_size) # noqa: S311 # TODO: Use secrets module if cryptographic security is needed
8989

90-
x_min = random.uniform(0, img_w - w)
91-
y_min = random.uniform(0, img_h - h)
90+
x_min = random.uniform(0, img_w - w) # noqa: S311 # TODO: Use secrets module if cryptographic security is needed
91+
y_min = random.uniform(0, img_h - h) # noqa: S311 # TODO: Use secrets module if cryptographic security is needed
9292
x_max = x_min + w
9393
y_max = y_min + h
9494

0 commit comments

Comments
 (0)