File tree Expand file tree Collapse file tree
react_with_database_memory
llamaindex/websearch_agent
vanilla_python/openai_responses_agent Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -383,7 +383,10 @@ async def playground():
383383@app .get ("/images/{filename:path}" , include_in_schema = False )
384384async def serve_image (filename : str ):
385385 """Serve images from the project-level images directory."""
386- file_path = _IMAGES_DIR / filename
386+ base = _IMAGES_DIR .resolve ()
387+ file_path = (base / filename ).resolve ()
388+ if not file_path .is_relative_to (base ):
389+ raise HTTPException (status_code = 404 , detail = "Image not found" )
387390 if not file_path .is_file ():
388391 raise HTTPException (status_code = 404 , detail = "Image not found" )
389392 return FileResponse (file_path )
Original file line number Diff line number Diff line change @@ -407,7 +407,10 @@ async def playground():
407407@app .get ("/images/{filename:path}" , include_in_schema = False )
408408async def serve_image (filename : str ):
409409 """Serve images from the project-level images directory."""
410- file_path = _IMAGES_DIR / filename
410+ base = _IMAGES_DIR .resolve ()
411+ file_path = (base / filename ).resolve ()
412+ if not file_path .is_relative_to (base ):
413+ raise HTTPException (status_code = 404 , detail = "Image not found" )
411414 if not file_path .is_file ():
412415 raise HTTPException (status_code = 404 , detail = "Image not found" )
413416 return FileResponse (file_path )
Original file line number Diff line number Diff line change @@ -403,7 +403,10 @@ async def playground():
403403@app .get ("/images/{filename:path}" , include_in_schema = False )
404404async def serve_image (filename : str ):
405405 """Serve images from the project-level images directory."""
406- file_path = _IMAGES_DIR / filename
406+ base = _IMAGES_DIR .resolve ()
407+ file_path = (base / filename ).resolve ()
408+ if not file_path .is_relative_to (base ):
409+ raise HTTPException (status_code = 404 , detail = "Image not found" )
407410 if not file_path .is_file ():
408411 raise HTTPException (status_code = 404 , detail = "Image not found" )
409412 return FileResponse (file_path )
Original file line number Diff line number Diff line change @@ -484,7 +484,10 @@ async def playground():
484484@app .get ("/images/{filename:path}" , include_in_schema = False )
485485async def serve_image (filename : str ):
486486 """Serve images from the project-level images directory."""
487- file_path = _IMAGES_DIR / filename
487+ base = _IMAGES_DIR .resolve ()
488+ file_path = (base / filename ).resolve ()
489+ if not file_path .is_relative_to (base ):
490+ raise HTTPException (status_code = 404 , detail = "Image not found" )
488491 if not file_path .is_file ():
489492 raise HTTPException (status_code = 404 , detail = "Image not found" )
490493 return FileResponse (file_path )
Original file line number Diff line number Diff line change @@ -469,7 +469,10 @@ async def playground():
469469@app .get ("/images/{filename:path}" , include_in_schema = False )
470470async def serve_image (filename : str ):
471471 """Serve images from the project-level images directory."""
472- file_path = _IMAGES_DIR / filename
472+ base = _IMAGES_DIR .resolve ()
473+ file_path = (base / filename ).resolve ()
474+ if not file_path .is_relative_to (base ):
475+ raise HTTPException (status_code = 404 , detail = "Image not found" )
473476 if not file_path .is_file ():
474477 raise HTTPException (status_code = 404 , detail = "Image not found" )
475478 return FileResponse (file_path )
Original file line number Diff line number Diff line change @@ -404,7 +404,10 @@ async def playground():
404404@app .get ("/images/{filename:path}" , include_in_schema = False )
405405async def serve_image (filename : str ):
406406 """Serve images from the project-level images directory."""
407- file_path = _IMAGES_DIR / filename
407+ base = _IMAGES_DIR .resolve ()
408+ file_path = (base / filename ).resolve ()
409+ if not file_path .is_relative_to (base ):
410+ raise HTTPException (status_code = 404 , detail = "Image not found" )
408411 if not file_path .is_file ():
409412 raise HTTPException (status_code = 404 , detail = "Image not found" )
410413 return FileResponse (file_path )
You can’t perform that action at this time.
0 commit comments