Skip to content

Commit

Permalink
update is_safe_url func with more checks (#374)
Browse files Browse the repository at this point in the history
  • Loading branch information
wenzhe-log10 authored Dec 2, 2024
1 parent 202966f commit cc17464
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/log10/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,15 @@ def chat_request(self, messages: List[Message], hparams: dict = None) -> dict:

def api_request(self, rel_url: str, request: dict):
def is_safe_url(url: str) -> bool:
ALLOWED_DOMAINS = ["log10.io"]
parsed = urlparse(url)
base_domain = urlparse(self.log10_config.url).netloc
return parsed.netloc == base_domain or not parsed.netloc
return (
parsed.scheme in {"http", "https"}
and parsed.netloc == base_domain
and not parsed.path.startswith("//")
and parsed.netloc in ALLOWED_DOMAINS
)

full_url = urljoin(self.log10_config.url, rel_url.strip())
if not is_safe_url(full_url):
Expand Down

0 comments on commit cc17464

Please sign in to comment.