T09 · Insecure Skill Coding Practices
Error
- Location
- SKILL.md:88
- Finding
- Unrestricted URL Fetching Enables Server-Side Request Forgery## Vulnerability Details **File Location**: `SKILL.md`, lines 88-105 **Vulnerability Type**: Server-Side Request Forgery through unrestricted URL fetching **Risk Level**: High ### Vulnerable Code ```bash safe_fetch() { local url="$1" local max_chars="${2:-50000}" # 取得とログ記録 echo "[$(date)] フェッチ開始: $url" >> /var/log/fetch.log # コンテンツ取得 curl -s -L --max-time 30 "$url" \ | head -c "$max_chars" \ | sanitize_content /dev/stdin /tmp/fetch-output.txt # スポットライト境界で包装 echo "=== EXTERNAL CONTENT START ===" > /tmp/final-output.txt cat /tmp/fetch-output.txt >> /tmp/final-output.txt echo "=== EXTERNAL CONTENT END ===" >> /tmp/final-output.txt cat /tmp/final-output.txt } ``` ### Technical Analysis The `safe_fetch` function passes a caller-controlled URL directly to `curl`. It does not restrict the URL scheme, destination hostname, resolved IP address, port, or network range. The `-L` option follows redirects without validating each redirect destination. Consequently, an attacker able to influence `url` can request loopback services, private network resources, link-local cloud metadata endpoints, or other destinations reachable from the host. Depending on the protocols enabled in the installed curl build, non-HTTP schemes may also be reachable. Limiting the number of returned characters does not prevent the outbound request or protect sensitive resources from being queried. ### Attack Path 1. An attacker supplies a URL such as a loopback, private-network, or cloud metadata address. 2. Alternatively, the attacker supplies an apparently public URL that redirects to an internal address. 3. `curl -L` follows the request or redirect without destination validation. 4. The internal response is written to the temporary output and returned by `safe_fetch`. 5. The attacker obtains data from a service that was not intended to be exter ...[truncated 437 chars]
- Remediation
- ## Remediation Suggestions - Permit only explicitly required schemes, preferably HTTPS. - Maintain an allowlist of approved destination hostnames and ports. - Resolve hostnames before connecting and reject loopback, link-local, private, multicast, and reserved addresses. - Disable redirects or validate the scheme, hostname, resolved address, and port of every redirect target. - Account for DNS rebinding by binding validation to the actual connection address. - Run network retrieval in an isolated process with outbound firewall restrictions. - Enforce response-size, timeout, and content-type limits. - Do not return fetched content until the destination and response have passed validation.
