Skip to content

Commit 5e6d5d6

Browse files
Potential fix for code scanning alert no. 23: Uncontrolled data used in path expression
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent fbc5f41 commit 5e6d5d6

File tree

1 file changed

+6
-1
lines changed
  • label_studio_ml/examples/timeseries_segmenter

1 file changed

+6
-1
lines changed

label_studio_ml/examples/timeseries_segmenter/model.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ def _get_model(
8787
return _models[project_id]
8888

8989
# Try to load from disk
90-
model_path = os.path.join(self.MODEL_DIR, f"model_project_{project_id}.pt")
90+
raw_model_path = os.path.join(self.MODEL_DIR, f"model_project_{project_id}.pt")
91+
model_path = os.path.normpath(raw_model_path)
92+
93+
# Ensure the normalized path is within the intended directory
94+
if not model_path.startswith(os.path.abspath(self.MODEL_DIR)):
95+
raise ValueError(f"Invalid model path: {model_path}")
9196

9297
if not blank and os.path.exists(model_path):
9398
logger.info(f"Loading saved model for project {project_id} from {model_path}")

0 commit comments

Comments
 (0)