T09 · Insecure Skill Coding Practices
- Location
- SKILL.md:267
- Finding
- Shell Command Injection Through Untrusted URL Interpolation<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:267-270` **Vulnerability Type**: Shell command injection **Risk Level**: High ### Vulnerable Code ```bash For many URLs, use xargs with `-P` for parallel execution: ```bash cat urls.txt | xargs -P 10 -I {} sh -c 'firecrawl scrape "{}" -o ".firecrawl/$(echo {} | md5).md"' ``` ``` ### Technical Analysis The command substitutes every line from `urls.txt` directly into a command string interpreted by `sh -c`. Although the template uses double quotes around the URL, `xargs` performs textual substitution before the resulting string is interpreted by the shell. A malicious URL containing a double quote followed by shell metacharacters can terminate the intended argument and append an arbitrary command. URL lists may be derived from mapped or scraped websites, so their contents cannot be assumed to be trusted. For example, a crafted line conceptually shaped like the following could break out of the quoted URL: ```text https://example.invalid/"; attacker_command; # ``` ### Attack Path 1. An attacker publishes or injects a crafted URL into content processed by the user. 2. The crafted URL is written to `urls.txt`, such as through website mapping or extraction. 3. The user or Agent follows the documented batch-processing command. 4. `xargs` inserts the malicious line into the `sh -c` program. 5. The shell parses the injected metacharacters and executes the attacker-supplied command. 6. The injected command runs with the same filesystem, network, and credential access as the Agent or user. ### Impact Assessment Successful exploitation permits arbitrary local command execution with the invoking user's privileges. An attacker could read accessible project files, environment variables, API keys, and user data; modify or delete files; install additional programs; or make unauthorized network requests. If the command is run from a privileged account, the impact extends to all resources available to that ...[truncated 13 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Do not interpolate untrusted URLs into a `sh -c` program. - Pass each URL as a positional argument and reference it through a safely quoted parameter. - Validate that each input is an expected HTTP or HTTPS URL before processing it. - Generate output filenames using a language or utility that does not reinterpret the URL as shell syntax. - Reject control characters, newlines, and malformed URL input. A safer pattern is: ```bash xargs -P 10 -I {} sh -c ' url=$1 case "$url" in http://*|https://*) ;; *) echo "Rejected invalid URL" >&2; exit 1 ;; esac name=$(printf "%s" "$url" | md5) firecrawl scrape "$url" -o ".firecrawl/$name.md" ' sh "{}" < urls.txt ``` Where available, prefer a small script using an argument-safe process execution API rather than invoking a shell. ]]>
