T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- scripts/download_article_images.sh:29
- Finding
- Unrestricted Article URL Fetching Enables Server-Side Request Forgery<![CDATA[ ## Vulnerability Details **File Location**: `scripts/download_article_images.sh:29-57, 71` **Vulnerability Type**: Server-Side Request Forgery through unrestricted URL fetching **Risk Level**: High ### Vulnerable Code ```bash URL="$1" OUTPUT_DIR="$2" CUSTOM_REFERER="$3" # Auto-detect referer based on URL domain detect_referer() { local url="$1" if [[ "$url" == *"cnblogs.com"* ]]; then echo "https://www.cnblogs.com/" elif [[ "$url" == *"toutiao.com"* ]]; then echo "https://www.toutiao.com/" elif [[ "$url" == *"csdn.net"* ]]; then echo "https://blog.csdn.net/" elif [[ "$url" == *"weixin.qq.com"* ]]; then echo "https://mp.weixin.qq.com/" elif [[ "$url" == *"jianshu.com"* ]]; then echo "https://www.jianshu.com/" elif [[ "$url" == *"zhihu.com"* ]]; then echo "https://zhuanlan.zhihu.com/" else # Extract domain from URL echo "https://$(echo "$url" | sed -E 's|https?://([^/]+).*|\1|')/" fi } # Determine referer if [ -n "$CUSTOM_REFERER" ]; then REFERER="$CUSTOM_REFERER" else REFERER=$(detect_referer "$URL") fi # Fetch HTML content echo "Fetching page content..." HTML=$(curl -sL "$URL" 2>/dev/null) ``` The documented workflow also encourages passing a user-provided article URL directly into this script: ```bash bash {baseDir}/scripts/download_article_images.sh "$ARTICLE_URL" /tmp/article-img/ ``` ### Technical Analysis The script passes an arbitrary user-controlled URL directly to `curl`. It does not validate: - The URL scheme. - The destination hostname. - The resolved IP address. - Whether the address is loopback, private, link-local, reserved, or a cloud metadata address. - Redirect destinations followed by `curl -L`. - The presence of URL credentials. - Whether the URL belongs to a supported public article domain. Substring checks in `detect_referer` only select a Referer value and do not restrict the actual request destination. Conseq ...[truncated 1861 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Accept only well-formed `https://` URLs; reject all other schemes. 2. Reject embedded usernames, passwords, malformed hosts, and ambiguous URL encodings. 3. Resolve the hostname before connecting and reject every address in: - Loopback ranges. - Private IPv4 and IPv6 ranges. - Link-local ranges. - Multicast and reserved ranges. - Cloud metadata address ranges. 4. Pin the connection to an approved resolved public address to reduce DNS rebinding risk. 5. Disable automatic redirects or validate the scheme, hostname, and resolved destination after every redirect. 6. Prefer a strict allowlist of supported public article domains. 7. Run network-fetching scripts in a sandbox without access to internal networks or metadata services. 8. Add connection and total request timeouts. 9. Do not rely on substring hostname matching. Parse the URL and compare normalized hostnames exactly. ]]>
