Skip to content

Commit

Permalink
fix: resolve image urls
Browse files Browse the repository at this point in the history
when image paths are not absolute resolve them from gui cache if possible
  • Loading branch information
JarbasAl committed Nov 15, 2024
1 parent 58cd0e2 commit 38ea4f1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ovos_bus_client/apis/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,13 +549,15 @@ def _resolve_url(self, url: str) -> str:
"""
if not url or not isinstance(url, str):
raise ValueError("URL must be a non-empty string")

if url.startswith("http"):
return url

# Sanitize the url to prevent path traversal
url = os.path.normpath(url)
if url.startswith("..") or url.startswith("/"):
return url

if not url.startswith("http") and not os.path.isfile(url):
if not os.path.isfile(url):
GUI_CACHE_PATH = get_xdg_cache_save_path('ovos_gui')
# Use os.path.join for path construction
gui_cache = os.path.join(GUI_CACHE_PATH, self.skill_id, url)
Expand All @@ -569,6 +571,7 @@ def _resolve_url(self, url: str) -> str:
LOG.debug(f"Resolved image: {gui_cache}")
return gui_cache
return url

def show_image(self, url: str, caption: Optional[str] = None,
title: Optional[str] = None,
fill: str = None, background_color: str = None,
Expand Down

0 comments on commit 38ea4f1

Please sign in to comment.