T09 · Insecure Skill Coding Practices
- Location
scripts/api.sh:279- Finding
Media Fetch Allows SSRF Through Private DNS Resolution and Redirect Targets
- Content
View full analysis
Vulnerability Details
File Location:
scripts/api.sh, lines 279–333
Vulnerability Type: Server-Side Request Forgery through incomplete destination validation
Risk Level: MediumVulnerable Code
bash fetch_media() { [[ $# -eq 2 ]] || usage local url=$2 local host temp_file final_file content_type extension status if [[ ! $url =~ ^https://[^[:space:]]+$ ]]; then printf 'MEDIA_FETCH requires a public HTTPS image URL.\n' >&2 exit 64 fi host=${url#https://} host=${host%%/*} host=${host%%:*} host=${host,,} # shellcheck disable=SC1009 # shellcheck disable=SC1020 # shellcheck disable=SC1072 # shellcheck disable=SC1073 if [[ -z $host || $host == localhost || $host == *"@"* || $host != *.* || $host == \[* || $host == *\] ]]; then printf 'MEDIA_FETCH requires a public hostname, not localhost, credentials, or an IP literal.\n' >&2 exit 77 fi prepare_media_dir temp_file=$(mktemp "${media_root}/media.XXXXXX") chmod 600 -- "$temp_file" content_type=$( curl \ --silent \ --show-error \ --fail \ --location \ --max-redirs 3 \ --proto '=https' \ --proto-redir '=https' \ --max-filesize 52428800 \ --output "$temp_file" \ --write-out '%{content_type}' \ "$url" ) status=$? if [[ $status -ne 0 ]]; then rm -f -- "$temp_file" exit "$status" fiTechnical Analysis
The
MEDIA_FETCHoperation is intended to retrieve an image from a public HTTPS host. It performs textual hostname checks that rejectlocalhost, apparent credentials, and literal IPv6 addresses. However, it never resolves the hostname and verifies that all resulting addresses are public.Consequently, a syntactically public-looking hostname can resolve to a loopback, private, link-local, reserved, or internal address. The use of
curl --locationalso permits up to three redirects, but the code validates only the original URL. `--proto-redir '=htt ...[truncated 2388 chars]- Remediation
View remediation
Remediation Suggestions
- Resolve the destination hostname before making the request and reject every address in loopback, private, link-local, multicast, carrier-grade NAT, documentation, reserved, and other non-public ranges for both IPv4 and IPv6.
- Disable automatic redirects and process each redirect manually. Parse, resolve, and validate every redirect destination before following it.
- Protect against DNS rebinding by ensuring the connection uses the previously validated address while preserving the original hostname for TLS verification, or by enforcing equivalent controls through a hardened outbound proxy.
- Apply network-level egress controls so the Skill runtime cannot reach local, private, metadata-service, or management networks.
- Use a robust URL parser rather than shell substring operations. Reject user-information components, unusual ports, malformed authorities, and ambiguous hostname representations.
- Continue enforcing HTTPS, certificate validation, size limits, MIME allowlisting, private temporary-file permissions, and the helper-owned upload path restrictions already present.
