Skip to content

Commit ae8154b

Browse files
Potential fix for code scanning alert no. 438: Uncontrolled data used in path expression (#45)
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 6552c03 commit ae8154b

1 file changed

Lines changed: 3 additions & 11 deletions

File tree

ml/main.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,9 @@ def process(payload: dict):
5252
logger.warning("Missing minio_object in payload", extra={"status": "error"})
5353
return {"error": "minio_object is required"}
5454

55-
# Fix #1: only extract the suffix from user input — never use minio_object
56-
# as a path component directly, preventing path traversal via object keys
57-
ext = Path(minio_object).suffix.lower()
58-
if ext not in ALLOWED_SUFFIXES:
59-
logger.warning(
60-
f"Rejected unsupported extension — {ext!r}",
61-
extra={"status": "error"}
62-
)
63-
return {"error": "Unsupported file type"}
64-
65-
filename = f"{uuid.uuid4()}{ext}"
55+
# Use a trusted local temp filename that does not depend on user input.
56+
# This prevents untrusted data from influencing filesystem paths.
57+
filename = f"{uuid.uuid4()}.bin"
6658

6759
# Fix #2: initialise tmp_path before try so finally block never hits NameError
6860
# Fix #3: keep as Path throughout — only cast to str at call sites that need it

0 commit comments

Comments
 (0)