From a9c22bffc9bf999bc79295fb783defd6867144c0 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Wed, 14 May 2025 15:15:05 +0400 Subject: [PATCH] refac/security: pipelines upload path traversal --- backend/open_webui/routers/pipelines.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/routers/pipelines.py b/backend/open_webui/routers/pipelines.py index f14002502..5a96f8cb5 100644 --- a/backend/open_webui/routers/pipelines.py +++ b/backend/open_webui/routers/pipelines.py @@ -197,8 +197,10 @@ async def upload_pipeline( user=Depends(get_admin_user), ): log.info(f"upload_pipeline: urlIdx={urlIdx}, filename={file.filename}") + filename = os.path.basename(file.filename) + # Check if the uploaded file is a python file - if not (file.filename and file.filename.endswith(".py")): + if not (filename and filename.endswith(".py")): raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, detail="Only Python (.py) files are allowed.", @@ -206,7 +208,7 @@ async def upload_pipeline( upload_folder = f"{CACHE_DIR}/pipelines" os.makedirs(upload_folder, exist_ok=True) - file_path = os.path.join(upload_folder, file.filename) + file_path = os.path.join(upload_folder, filename) r = None try: