mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-09 03:18:18 +00:00
refac
This commit is contained in:
parent
0fff2fbcab
commit
62ab30f593
1 changed files with 7 additions and 1 deletions
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue