File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -360,7 +360,18 @@ async def plugin_static_file(plugin_id: str, filepath: str):
360360 raise HTTPException (status_code = status .HTTP_403_FORBIDDEN , detail = "Forbidden" )
361361
362362 plugin_base_dir = AsyncPath (settings .ROOT_PATH ) / "app" / "plugins" / plugin_id .lower ()
363- plugin_file_path = plugin_base_dir / filepath
363+ plugin_file_path = plugin_base_dir / filepath .lstrip ('/' )
364+
365+ try :
366+ resolved_base = await plugin_base_dir .resolve ()
367+ resolved_file = await plugin_file_path .resolve ()
368+ except Exception :
369+ raise HTTPException (status_code = status .HTTP_400_BAD_REQUEST , detail = "Invalid path" )
370+
371+ if not resolved_file .is_relative_to (resolved_base ):
372+ logger .warning (f"Static File API: Path traversal attempt detected: { plugin_id } /{ filepath } " )
373+ raise HTTPException (status_code = status .HTTP_403_FORBIDDEN , detail = "Forbidden" )
374+
364375 if not await plugin_file_path .exists ():
365376 raise HTTPException (status_code = status .HTTP_404_NOT_FOUND , detail = f"{ plugin_file_path } 不存在" )
366377 if not await plugin_file_path .is_file ():
You can’t perform that action at this time.
0 commit comments