From 2b550f3e66bdb3da6d229efc0a6ee89d2c21b9b7 Mon Sep 17 00:00:00 2001 From: Richard Bullington-McGuire Date: Thu, 16 Jan 2025 11:34:50 -0500 Subject: [PATCH] Potential fix for code scanning alert no. 22: Uncontrolled data used in path expression Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> --- freezing/web/views/api.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/freezing/web/views/api.py b/freezing/web/views/api.py index bfc5b74..2ce5176 100644 --- a/freezing/web/views/api.py +++ b/freezing/web/views/api.py @@ -422,6 +422,8 @@ def _get_cached(key: str, compute): content = compute() cache_file.parent.mkdir(parents=True, exist_ok=True) + if not str(cache_file).startswith(str(Path(cache_dir).resolve()) + os.sep): + raise Exception("Invalid cache file path") cache_file.write_bytes(content) return content