From 99c7744e4fe2337469254248427b1419e523ac86 Mon Sep 17 00:00:00 2001 From: anupamme Date: Mon, 3 Aug 2026 03:11:24 +0000 Subject: [PATCH] fix: V-003 security vulnerability Automated security fix generated by OrbisAI Security --- api.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/api.py b/api.py index 234782d6..f33fb799 100644 --- a/api.py +++ b/api.py @@ -1324,24 +1324,38 @@ async def control(command: str = None): return handle_control(command) +def _is_safe_path(path: str) -> bool: + if not path: + return True + return ".." not in os.path.normpath(path).split(os.sep) + + @app.post("/change_refer") async def change_refer(request: Request): json_post_raw = await request.json() + refer_wav_path = json_post_raw.get("refer_wav_path") + if not _is_safe_path(refer_wav_path): + return JSONResponse({"code": 400, "message": "Invalid file path"}, status_code=400) return handle_change( - json_post_raw.get("refer_wav_path"), json_post_raw.get("prompt_text"), json_post_raw.get("prompt_language") + refer_wav_path, json_post_raw.get("prompt_text"), json_post_raw.get("prompt_language") ) @app.get("/change_refer") async def change_refer(refer_wav_path: str = None, prompt_text: str = None, prompt_language: str = None): + if not _is_safe_path(refer_wav_path): + return JSONResponse({"code": 400, "message": "Invalid file path"}, status_code=400) return handle_change(refer_wav_path, prompt_text, prompt_language) @app.post("/") async def tts_endpoint(request: Request): json_post_raw = await request.json() + refer_wav_path = json_post_raw.get("refer_wav_path") + if not _is_safe_path(refer_wav_path): + return JSONResponse({"code": 400, "message": "Invalid file path"}, status_code=400) return handle( - json_post_raw.get("refer_wav_path"), + refer_wav_path, json_post_raw.get("prompt_text"), json_post_raw.get("prompt_language"), json_post_raw.get("text"), @@ -1373,6 +1387,8 @@ async def tts_endpoint( sample_steps: int = 32, if_sr: bool = False, ): + if not _is_safe_path(refer_wav_path): + return JSONResponse({"code": 400, "message": "Invalid file path"}, status_code=400) return handle( refer_wav_path, prompt_text,