diff --git a/api/services/app_dsl_service.py b/api/services/app_dsl_service.py index b6d6d05e589e92..cd14dfca484695 100644 --- a/api/services/app_dsl_service.py +++ b/api/services/app_dsl_service.py @@ -2,6 +2,7 @@ import uuid from enum import StrEnum from typing import Optional, cast +from urllib.parse import urlparse from uuid import uuid4 import yaml # type: ignore @@ -103,7 +104,7 @@ def import_app( raise ValueError(f"Invalid import_mode: {import_mode}") # Get YAML content - content: bytes | str = b"" + content: str = "" if mode == ImportMode.YAML_URL: if not yaml_url: return Import( @@ -114,12 +115,13 @@ def import_app( try: max_size = 10 * 1024 * 1024 # 10MB # tricky way to handle url from github to github raw url - if yaml_url.startswith("https://github.com") and yaml_url.endswith((".yml", ".yaml")): + host = urlparse(yaml_url).hostname + if host and host.endswith("github.com"): yaml_url = yaml_url.replace("https://github.com", "https://raw.githubusercontent.com") yaml_url = yaml_url.replace("/blob/", "/") response = ssrf_proxy.get(yaml_url.strip(), follow_redirects=True, timeout=(10, 10)) response.raise_for_status() - content = response.content + content = response.content.decode() if len(content) > max_size: return Import(