T09 · Insecure Skill Coding Practices
- Location
scripts/search.sh:6- Finding
Unrestricted Output Path Allows Arbitrary File Overwrite in Search Script
- Content
View full analysis
[max_results] [output_file]" exit 1 fi # 优先用 Tavily,其次 DuckDuckGo if [ -n "$TAVILY_API_KEY" ]; then curl -s "https://api.tavily.com/search" \ -H "Authorization: Bearer $TAVILY_API_KEY" \ -H "Content-Type: application/json" \ -d "{\"query\": \"$QUERY\", \"max_results\": $MAX_RESULTS}" \ > "$OUTPUT_FILE" else # DuckDuckGo 免费 curl -s "https://api.duckduckgo.com/?q=$(echo "$QUERY" | urlencode)&format=json&no_html=1" \ > "$OUTPUT_FILE" fi ``` ### Technical Analysis The third positional argument is used directly as the destination of a shell redirection. Although the variable is quoted and therefore does not permit shell metacharacter injection, the script does not restrict the path to an approved output directory. Shell redirection opens the specified file with truncation before `curl` writes its response. Absolute paths, relative traversal paths such as `../../file`, and paths reached through symbolic links are accepted. Consequently, a caller that controls the script arguments can truncate or replace any file writable by the account running the Skill. ### Attack Path 1. An attacker supplies a research request or workflow input that influences the output-file argument. 2. The Agent invokes the script with a path outside the intended research directory, for example: ```bash ./scripts/search.sh "query" 5 "../../writable-configuration-file" ``` 3. The shell resolves the traversal path and opens the target using truncating redirection. 4. The target is emptied and then populated with the external API response, or left empty if the request produces no output. 5. Subsequent tools or sessions that depend on ...[truncated 638 chars]- Remediation
View remediation
