T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/monitor.sh:12
- Finding
- Unrestricted URL Fetching Enables Server-Side Request Forgery and Local Resource Probing<![CDATA[ ## Vulnerability Details **File Location**: `scripts/monitor.sh`, lines 12-28 **Vulnerability Type**: Unrestricted outbound request / SSRF **Risk Level**: High ### Vulnerable Code ```bash add) URL="$2" NAME="${3:-$(echo "$URL" | sed 's|https\?://||;s|[^a-zA-Z0-9]|_|g')}" echo "$URL" > "$MONITOR_DIR/sites/$NAME.url" echo "✅ Monitoring: $NAME ($URL)" ;; list) echo "📋 Monitored sites:" for f in "$MONITOR_DIR"/sites/*.url; do [ -f "$f" ] && echo " - $(basename "$f" .url): $(cat "$f")" done ;; check) CHANGES=0 for f in "$MONITOR_DIR"/sites/*.url; do [ -f "$f" ] || continue NAME=$(basename "$f" .url) URL=$(cat "$f") CURRENT=$(curl -s --max-time 30 "$URL" | md5sum | cut -d' ' -f1) ``` ### Technical Analysis The `add` operation accepts an arbitrary URL and stores it without validating its scheme, destination hostname, resolved IP address, port, or redirect behavior. The `check` operation subsequently supplies this value directly to `curl`. Consequently, a caller can make the process issue requests to destinations that should not be reachable through a website-monitoring feature, including: - Loopback services such as `127.0.0.1` or `localhost`. - Private network services. - Link-local endpoints, including cloud instance metadata services. - Local resources through curl-supported schemes such as `file://`. - Reserved or otherwise sensitive network ranges. The response is hashed rather than displayed, but this does not remove the vulnerability. The script persists the response hash and reports whether it changes, creating a response and change-detection oracle. Request timing and success behavior may also disclose information about internal resources. The use of `curl -s` also suppresses errors, while the absence of `--fail` can cause HTTP error pages to be treated as valid monitored content. ### Attack Path 1. An attacker or untrusted caller invokes the monitor's `ad ...[truncated 1530 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Permit only explicitly supported schemes: ```bash case "$URL" in http://*|https://*) ;; *) echo "Only HTTP and HTTPS URLs are permitted" >&2; exit 1 ;; esac ``` 2. Parse the URL with a robust URL parser rather than regular expressions. 3. Resolve the destination before each request and reject all loopback, private, link-local, multicast, unspecified, and reserved IPv4 and IPv6 ranges. 4. Repeat destination validation after every redirect, or disable redirects unless they are required. This prevents an allowed public URL from redirecting to an internal address. 5. Reject embedded credentials and restrict destination ports to an approved set where possible. 6. Prefer an explicit hostname allowlist when the operational use case permits it. 7. Restrict curl protocols and improve error handling: ```bash curl --proto '=http,https' --fail --show-error --silent \ --max-time 30 -- "$URL" ``` 8. Run network retrieval in a sandbox or network namespace that cannot access loopback services, private networks, metadata endpoints, or sensitive local resources. 9. Do not update the stored baseline when retrieval fails. Record fetch failures separately from valid page changes. ]]>
