T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/download_video.py:122
- Finding
- Unrestricted Page URL Fetching Enables Server-Side Request Forgery<![CDATA[ ## Vulnerability Details **File Location**: `scripts/download_video.py`, lines 122–125 and 153 **Vulnerability Type**: Server-Side Request Forgery (SSRF) **Risk Level**: High ### Vulnerable Code ```python def fetch_page_content(page_url: str) -> Optional[str]: try: response = requests.get(page_url, headers=HEADERS, timeout=30) response.raise_for_status() return response.text except requests.RequestException as e: print(f"Failed to fetch page: {e}") return None ``` The function is called directly with the user-supplied command-line argument: ```python html_content = fetch_page_content(args.url) ``` ### Technical Analysis The application performs an HTTP request to a user-controlled URL without validating: - The URL scheme - The destination hostname - The resolved IP address - The destination port - Redirect destinations - Whether the destination belongs to Xiaohongshu Although the Skill is intended to process Xiaohongshu pages, the implementation does not enforce this restriction. The `requests` library also follows redirects by default, so validating only an initial URL in a future partial fix would not be sufficient. An attacker can provide a URL targeting loopback addresses, private network ranges, link-local services, or cloud instance metadata endpoints. DNS rebinding or an attacker-controlled redirect can similarly route a superficially legitimate request to a prohibited destination. ### Attack Path 1. An attacker supplies a URL such as `http://127.0.0.1:PORT/internal`, a private-network service, or a URL that redirects to such a destination. 2. `args.url` is passed directly to `fetch_page_content()`. 3. `requests.get()` connects to the attacker-selected destination from the environment running the Skill. 4. The target response is read and processed as HTML. 5. Observable output, response differences, or subsequent media extraction can disclose service availability or cause further request ...[truncated 644 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Permit only `https` URLs. 2. Apply an explicit hostname allowlist for supported Xiaohongshu domains. 3. Reject embedded credentials, unexpected ports, malformed hostnames, and IP-address literals. 4. Resolve the hostname before connecting and reject loopback, private, link-local, multicast, reserved, and unspecified addresses for both IPv4 and IPv6. 5. Disable automatic redirects or validate every redirect destination using the same policy. 6. Account for DNS rebinding by ensuring that the address validated is the address used for the connection. 7. Apply connection and response-size limits in addition to the existing timeout. 8. Return a clear validation error before making any network request when the URL is outside the approved scope. ]]>
