T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/lib.sh:61
- Finding
- Unrestricted documentation URL enables server-side request forgery<![CDATA[ ## Vulnerability Details **File Location**: `scripts/lib.sh:61-79`, `scripts/lib.sh:99-113`, and `scripts/fetch-doc.sh:9-15` **Vulnerability Type**: Unrestricted outbound request / SSRF **Risk Level**: High ### Vulnerable Code ```bash normalize_doc_url() { local input="${1:-}" if [[ -z "$input" ]]; then echo "Usage: provide a docs path like gateway/configuration or a full docs.openclaw.ai URL" >&2 return 1 fi if [[ "$input" =~ ^https?:// ]]; then local base_no_query query base_no_query="${input%%\?*}" query="" if [[ "$input" == *\?* ]]; then query="?${input#*\?}" fi if [[ "$base_no_query" != *.md ]]; then base_no_query="${base_no_query%/}.md" fi printf '%s%s\n' "$base_no_query" "$query" return fi local path="$input" path="${path#/}" path="${path%.html}" if [[ "$path" != *.md ]]; then path="${path}.md" fi printf '%s/%s\n' "$BASE_URL" "$path" } download_doc() { local url="$1" local dest tmp force_fetch ensure_cache_dirs dest=$(doc_cache_path "$url") mkdir -p "$(dirname "$dest")" force_fetch="${OPENCLAW_DOCS_FORCE_FETCH:-0}" if [[ -s "$dest" && "$force_fetch" != "1" ]]; then printf '%s\n' "$dest" return fi tmp="${dest}.tmp" curl -fsSL "$url" -o "$tmp" mv "$tmp" "$dest" printf '%s\n' "$dest" } ``` The vulnerable functionality is directly exposed by `fetch-doc.sh`: ```bash url=$(normalize_doc_url "$1") cache_path=$(download_doc "$url") echo "# Source: $url" echo "# Cached: $cache_path" echo cat "$cache_path" ``` ### Technical Analysis `normalize_doc_url` accepts every string beginning with `http://` or `https://`. It does not require the exact documented host, `docs.openclaw.ai`, and does not reject loopback, link-local, private-network, or other non-documentation destinations. The resulting URL is passed directly to `curl`. The `-L` option also permits redirects, but the final redirect destination is not validated. Consequently, vali ...[truncated 1674 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Accept only HTTPS URLs whose parsed hostname is exactly `docs.openclaw.ai`. 2. Reject URL user-information, non-default ports, fragments, backslashes, control characters, and ambiguous or encoded path separators. 3. For path-only input, permit only a conservative documentation-path character set and reject `.` and `..` path segments. 4. Disable redirects where they are unnecessary. If redirects are required, validate the destination of every redirect before following it. 5. Apply an explicit curl protocol policy, such as HTTPS-only restrictions, in addition to application-level validation. 6. Reject loopback, private, link-local, and reserved IP destinations after DNS resolution as defense in depth. 7. Keep `OPENCLAW_DOCS_BASE_URL` and `OPENCLAW_DOCS_INDEX_URL` overrides disabled or separately validated in untrusted execution environments. 8. Add negative tests for foreign hosts, deceptive hostnames, alternate ports, URL credentials, encoded traversal, and redirects from the approved host to an unapproved host. ]]>
