From 62ab30f593b1d6f9b2cda0616e49e6ecb7b65703 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Sun, 1 Mar 2026 13:28:32 -0600 Subject: [PATCH] refac --- backend/open_webui/routers/audio.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/routers/audio.py b/backend/open_webui/routers/audio.py index 01a857a2b..a877d1e8d 100644 --- a/backend/open_webui/routers/audio.py +++ b/backend/open_webui/routers/audio.py @@ -1194,7 +1194,9 @@ def transcription( ) try: - ext = file.filename.split(".")[-1] + ext = file.filename.split(".")[-1] if file.filename else "" + ext = ext.replace("/", "").replace("\\", "").replace("..", "") + id = uuid.uuid4() filename = f"{id}.{ext}" @@ -1204,6 +1206,10 @@ def transcription( os.makedirs(file_dir, exist_ok=True) file_path = f"{file_dir}/{filename}" + # Defense-in-depth: ensure resolved path stays within intended directory + if not os.path.realpath(file_path).startswith(os.path.realpath(file_dir)): + raise ValueError("Invalid file path detected") + with open(file_path, "wb") as f: f.write(contents)