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 55import time
66import uuid
77from contextlib import asynccontextmanager
8- import os
98from os import getenv
109from pathlib import Path
1110
@@ -386,9 +385,9 @@ async def serve_image(filename: str):
386385 """Serve images from the project-level images directory."""
387386 base = _IMAGES_DIR .resolve ()
388387 file_path = (base / filename ).resolve ()
389- base_str = str ( base )
390- file_path_str = str ( file_path )
391- if not ( file_path_str == base_str or file_path_str . startswith ( base_str + os . path . sep )) :
388+ try :
389+ file_path . relative_to ( base )
390+ except ValueError :
392391 raise HTTPException (status_code = 404 , detail = "Image not found" )
393392 if not file_path .is_file ():
394393 raise HTTPException (status_code = 404 , detail = "Image not found" )
Original file line number Diff line number Diff line change 33import time
44import uuid
55from contextlib import asynccontextmanager
6- import os
76from os import getenv
87from pathlib import Path
98
@@ -410,9 +409,9 @@ async def serve_image(filename: str):
410409 """Serve images from the project-level images directory."""
411410 base = _IMAGES_DIR .resolve ()
412411 file_path = (base / filename ).resolve ()
413- base_str = str ( base )
414- file_path_str = str ( file_path )
415- if not ( file_path_str == base_str or file_path_str . startswith ( base_str + os . path . sep )) :
412+ try :
413+ file_path . relative_to ( base )
414+ except ValueError :
416415 raise HTTPException (status_code = 404 , detail = "Image not found" )
417416 if not file_path .is_file ():
418417 raise HTTPException (status_code = 404 , detail = "Image not found" )
Original file line number Diff line number Diff line change 33import time
44import uuid
55from contextlib import asynccontextmanager
6- import os
76from os import getenv
87from pathlib import Path
98
@@ -406,9 +405,9 @@ async def serve_image(filename: str):
406405 """Serve images from the project-level images directory."""
407406 base = _IMAGES_DIR .resolve ()
408407 file_path = (base / filename ).resolve ()
409- base_str = str ( base )
410- file_path_str = str ( file_path )
411- if not ( file_path_str == base_str or file_path_str . startswith ( base_str + os . path . sep )) :
408+ try :
409+ file_path . relative_to ( base )
410+ except ValueError :
412411 raise HTTPException (status_code = 404 , detail = "Image not found" )
413412 if not file_path .is_file ():
414413 raise HTTPException (status_code = 404 , detail = "Image not found" )
Original file line number Diff line number Diff line change 1212from langgraph .checkpoint .postgres import PostgresSaver
1313from langgraph .checkpoint .postgres .aio import AsyncPostgresSaver
1414from pydantic import BaseModel , Field
15- import os
1615from os import getenv
1716
1817from react_with_database_memory .agent import get_graph_closure
@@ -487,9 +486,9 @@ async def serve_image(filename: str):
487486 """Serve images from the project-level images directory."""
488487 base = _IMAGES_DIR .resolve ()
489488 file_path = (base / filename ).resolve ()
490- base_str = str ( base )
491- file_path_str = str ( file_path )
492- if not ( file_path_str == base_str or file_path_str . startswith ( base_str + os . path . sep )) :
489+ try :
490+ file_path . relative_to ( base )
491+ except ValueError :
493492 raise HTTPException (status_code = 404 , detail = "Image not found" )
494493 if not file_path .is_file ():
495494 raise HTTPException (status_code = 404 , detail = "Image not found" )
Original file line number Diff line number Diff line change 33import time
44import uuid
55from contextlib import asynccontextmanager
6- import os
76from os import getenv
87from pathlib import Path
98
@@ -472,9 +471,9 @@ async def serve_image(filename: str):
472471 """Serve images from the project-level images directory."""
473472 base = _IMAGES_DIR .resolve ()
474473 file_path = (base / filename ).resolve ()
475- base_str = str ( base )
476- file_path_str = str ( file_path )
477- if not ( file_path_str == base_str or file_path_str . startswith ( base_str + os . path . sep )) :
474+ try :
475+ file_path . relative_to ( base )
476+ except ValueError :
478477 raise HTTPException (status_code = 404 , detail = "Image not found" )
479478 if not file_path .is_file ():
480479 raise HTTPException (status_code = 404 , detail = "Image not found" )
Original file line number Diff line number Diff line change 44import time
55import uuid
66from contextlib import asynccontextmanager
7- import os
87from os import getenv
98from pathlib import Path
109
@@ -407,9 +406,9 @@ async def serve_image(filename: str):
407406 """Serve images from the project-level images directory."""
408407 base = _IMAGES_DIR .resolve ()
409408 file_path = (base / filename ).resolve ()
410- base_str = str ( base )
411- file_path_str = str ( file_path )
412- if not ( file_path_str == base_str or file_path_str . startswith ( base_str + os . path . sep )) :
409+ try :
410+ file_path . relative_to ( base )
411+ except ValueError :
413412 raise HTTPException (status_code = 404 , detail = "Image not found" )
414413 if not file_path .is_file ():
415414 raise HTTPException (status_code = 404 , detail = "Image not found" )
You can’t perform that action at this time.
0 commit comments