T09 · Insecure Skill Coding Practices
- Location
run.py:14- Finding
Unrestricted Remote URL Fetching Enables Server-Side Request Forgery
- Content
View full analysis
Vulnerability Details
File Location:
run.py:14-28,run.py:112-131
Vulnerability Type: Server-Side Request Forgery (SSRF)
Risk Level: HighVulnerable Code
python def is_url(path): return path.startswith(('http://', 'https://')) def download_file(url, suffix): try: fd, temp_path = tempfile.mkstemp(suffix=suffix) os.close(fd) print(f"正在下载: {url} -> {temp_path}") # 使用 Request 对象添加 User-Agent 避免 403 req = urllib.request.Request(url, headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'}) with urllib.request.urlopen(req) as response, open(temp_path, 'wb') as out_file: out_file.write(response.read()) return temp_path except Exception as e: print(f"错误: 下载失败: {str(e)}") return Nonepython # 如果是 URL,先下载(如果是视频,ffmpeg 支持直接传 URL,但为了统一逻辑和 output 命名,图片必须下载) if is_url(input_path): if args.type == 'image': suffix = ".jpg" if args.action != 'watermark' else ".png" input_path = download_file(args.input, suffix) if not input_path: sys.exit(1) temp_files.append(input_path) else: # 视频 URL 也可以下载,或者让 ffmpeg 直接处理。 # 为了获取更好的 output 文件名,建议 m3u8 以外的下载, # 但 m3u8 必须让 ffmpeg 处理。 if "m3u8" in args.input: pass # ffmpeg direct else: input_path = download_file(args.input, ".mp4") if not input_path: sys.exit(1) temp_files.append(input_path)Technical Analysis
The application treats every string beginning with
http://orhttps://as a permitted remote resource. It performs no destination validation, DNS resolution checks, redirect validation, port restriction, or host allowlisting.Consequently, an un ...[truncated 1705 chars]
- Remediation
View remediation
Remediation Suggestions
- Prefer an explicit allowlist of trusted media domains.
- Resolve hostnames before connecting and reject loopback, private, link-local, multicast, reserved, unspecified, and metadata-service addresses for both IPv4 and IPv6.
- Revalidate the resolved destination after every redirect and protect against DNS rebinding.
- Restrict permitted schemes to HTTPS where possible and allow only required destination ports.
- Apply the same policy to m3u8 playlists, nested playlists, encryption-key URLs, and segment URLs.
- Do not pass untrusted network URLs directly to unrestricted FFmpeg. Use a controlled downloader or run FFmpeg in an isolated environment with restricted egress.
- Add network-level egress filtering as defense in depth.
