Skip to content

Commit

Permalink
fix: improve YAML URL handling and content decoding in AppDslService
Browse files Browse the repository at this point in the history
Signed-off-by: -LAN- <laipz8200@outlook.com>
  • Loading branch information
laipz8200 committed Jan 2, 2025
1 parent 065304d commit f1f4c3d
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions api/services/app_dsl_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down

0 comments on commit f1f4c3d

Please sign in to comment.