From 6eef4ee2e398039bda9639cdd25d414456b6a080 Mon Sep 17 00:00:00 2001 From: Aryan Ahirwar <25COA2BCA0068@sageuniversity.in> Date: Mon, 15 Jun 2026 22:27:38 +0530 Subject: [PATCH] Potential fix for code scanning alert no. 4: Uncontrolled data used in path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- src/models/predict.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/models/predict.py b/src/models/predict.py index 5e5c3d7..02f1d94 100644 --- a/src/models/predict.py +++ b/src/models/predict.py @@ -34,12 +34,13 @@ def _allowed_model_names() -> set[str]: def _sanitize_model_name(model_name: str | None) -> str: """ Ensure model_name is restricted to known local model artifacts. + Return a canonical trusted value sourced from the local allowlist. """ candidate = _default_model_name() if model_name is None else model_name allowed = _allowed_model_names() if candidate not in allowed: raise ValueError(f"Unsupported model '{candidate}'. Allowed models: {sorted(allowed)}") - return candidate + return next(name for name in allowed if name == candidate) def _safe_model_path(model_name: str) -> str: