T09 · Insecure Skill Coding Practices
- Location
scripts/run.py:62- Finding
Unrestricted URL Processing May Permit Access to Unintended Network Resources
- Content
View full analysis
Vulnerability Details
File Location:
scripts/run.py:62-66,scripts/run.py:91-93, andscripts/run.py:123-126
Vulnerability Type: Server-Side Request Forgery through insufficient URL validation
Risk Level: MediumVulnerable Code:
python def extract_meta(url): """Use yt-dlp to extract metadata and the direct video URL.""" log("1/4 Extracting metadata (yt-dlp) ...") out = subprocess.run( [VENV_PY, YTDLP, "--dump-json", "--no-warnings", url], capture_output=True, text=True, )python def download_video(video_url): log("2/4 Downloading video (curl) ...") r = subprocess.run( ["curl", "-s", "-L", video_url, "-o", "xhs_temp.mp4"], check=True ) if not os.path.exists("xhs_temp.mp4") or os.path.getsize("xhs_temp.mp4") < 1024: raise RuntimeError("Video download failed or file is too small")python url = sys.argv[1] meta = extract_meta(url) if not meta["video_stream_url"]: print("Error: video_stream_url was not found.", file=sys.stderr) sys.exit(1)Technical Analysis
The declared purpose is to process Xiaohongshu video links, but the script does not validate the scheme, hostname, port, resolved IP address, or redirect destination of the user-supplied URL. The URL is passed directly to
yt-dlp.The media URL returned by
yt-dlpis also trusted without validation and passed tocurlwith-L, which follows redirects. Ifyt-dlpaccepts the supplied resource or returns an attacker-controlled media URL, the process can be induced to issue requests beyond the Skill's declared Xiaohongshu scope.Although argument-list subprocess execution prevents ordinary shell metacharacter injection, it does not prevent network destination abuse. No restrictions exclude loopback, link-local, private, reserved, or cloud metadata addresses. There are also no explicit connection timeout, ...[truncated 1782 chars]
- Remediation
View remediation
Remediation Suggestions
- Parse input URLs with a standard URL parser and permit only
https. - Enforce an explicit allowlist of expected Xiaohongshu domains and reject credentials, unusual ports, malformed hostnames, and unsupported schemes.
- Resolve destination hostnames and reject loopback, private, link-local, multicast, reserved, and unspecified IPv4 and IPv6 ranges.
- Apply the same validation to the direct media URL returned by
yt-dlp. - Do not use unrestricted automatic redirects. Validate each redirect destination before following it.
- Add
curlcontrols such as connection timeout, total transfer timeout, maximum file size, protocol restrictions, and failure on HTTP errors. - Run network processing in a sandbox with egress restricted to the minimum hosts required for Xiaohongshu media retrieval.
- Store downloads in a newly created private temporary directory rather than a predictable file in the current working directory.
- Reject non-media responses and verify the downloaded content type and container before passing it to FFmpeg.
- Parse input URLs with a standard URL parser and permit only
