T09 · Insecure Skill Coding Practices
Warning
- Location
- seo-analyze.sh:7
- Finding
- Unrestricted User-Controlled URL Fetching Enables SSRF and Local Resource Access<![CDATA[ ## Vulnerability Details **File Location**: `seo-analyze.sh`, lines 7-11 **Vulnerability Type**: Server-Side Request Forgery (SSRF) and unsafe URL handling **Risk Level**: Medium ### Vulnerable Code ```bash if [[ "${1:-}" == "-" ]]; then HTML=$(cat) URL="(stdin)" else URL="${1:?Usage: seo-analyze.sh <URL>}" HTML=$(curl -sL --max-time 15 -A "Mozilla/5.0 SEO-Analyzer/1.0" "$URL") fi ``` ### Technical Analysis The script accepts a user-controlled URL and passes it directly to `curl` without validating its scheme, destination, resolved IP address, or redirect targets. Consequently, an attacker may cause the host running the skill to request resources that are not normally accessible to the attacker, including: - Loopback services such as `http://127.0.0.1`. - Private-network services. - Link-local cloud metadata endpoints. - Local files through schemes such as `file://`, where supported by the installed `curl`. - A permitted-looking public URL that redirects to an internal destination, because `curl -L` follows redirects without revalidating the target. The script also does not place the `--` end-of-options marker before the user-controlled argument. A value beginning with a hyphen may therefore be interpreted as a `curl` option rather than as a URL. The fetched response is analyzed and selected data is printed in the report, including the title, metadata, canonical URL, heading counts, and keyword statistics. This creates a limited disclosure channel for data obtained from local or internal resources. ### Attack Path 1. An attacker provides a URL pointing to a resource accessible from the Agent host, such as a loopback service, private-network application, or cloud metadata endpoint. 2. Alternatively, the attacker supplies a public URL that redirects to an internal or link-local address. 3. The Agent invokes `seo-analyze.sh` with the attacker-controlled URL as documented by the skill. 4. `curl` accesses the destination using the Agent ...[truncated 971 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Accept only explicitly permitted `http://` and `https://` URLs. 2. Reject URLs containing embedded credentials or malformed host components. 3. Resolve the destination hostname before making the request and reject loopback, private, link-local, multicast, reserved, and otherwise non-public IP addresses for both IPv4 and IPv6. 4. Protect against DNS rebinding by ensuring the address used for the connection is the validated address. 5. Disable all unnecessary `curl` protocols and restrict redirect protocols: ```bash HTML=$(curl \ --proto '=http,https' \ --proto-redir '=http,https' \ -sL \ --max-time 15 \ -A "Mozilla/5.0 SEO-Analyzer/1.0" \ -- "$URL") ``` 6. Do not rely on protocol restrictions alone. Validate every redirect destination and reject redirects to non-public addresses. If this cannot be implemented safely with the current shell design, disable redirects or perform each redirect manually with validation between requests. 7. Add connection and response-size limits to reduce denial-of-service risk. 8. Run the analyzer in a sandbox with restricted network access, no access to cloud metadata endpoints, minimal filesystem permissions, and no sensitive credentials. 9. Add security tests covering loopback addresses, private IPv4 and IPv6 ranges, link-local metadata addresses, alternate IP representations, DNS rebinding, redirect-based bypasses, `file://` URLs, and arguments beginning with `-`. ]]>
