Skip to content

Commit 4d841b7

Browse files
committed
fix path problem for images
1 parent 769c17a commit 4d841b7

6 files changed

Lines changed: 24 additions & 6 deletions

File tree

agents/crewai/websearch_agent/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,10 @@ async def playground():
383383
@app.get("/images/{filename:path}", include_in_schema=False)
384384
async 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)

agents/langgraph/agentic_rag/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,10 @@ async def playground():
407407
@app.get("/images/{filename:path}", include_in_schema=False)
408408
async 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)

agents/langgraph/react_agent/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,10 @@ async def playground():
403403
@app.get("/images/{filename:path}", include_in_schema=False)
404404
async 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)

agents/langgraph/react_with_database_memory/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,10 @@ async def playground():
484484
@app.get("/images/{filename:path}", include_in_schema=False)
485485
async 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)

agents/llamaindex/websearch_agent/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,10 @@ async def playground():
469469
@app.get("/images/{filename:path}", include_in_schema=False)
470470
async 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)

agents/vanilla_python/openai_responses_agent/main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,10 @@ async def playground():
404404
@app.get("/images/{filename:path}", include_in_schema=False)
405405
async 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)

0 commit comments

Comments
 (0)