T09 · Insecure Skill Coding Practices
- Location
scripts/search_by_name.sh:5- Finding
Argument Injection into fd Enables Unintended Command Execution
- Content
View full analysis
Vulnerability Details
File Location:
scripts/search_by_name.sh, lines 5-20
Vulnerability Type: Argument injection leading to command execution
Risk Level: HighVulnerable Code
bash PATTERN="$1" DIR="${2:-$HOME}" if [ -z "$PATTERN" ]; then echo "Usage: $0 <pattern> [directory]" echo "Example: $0 'screenshot' ~/Desktop" exit 1 fi # Check if fd is available if command -v fd &> /dev/null; then fd -e jpg -e jpeg -e png -e heic -e webp -e gif -e tiff -e raw "$PATTERN" "$DIR" else # Fallback to find + grep find "$DIR" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.heic" -o -iname "*.webp" -o -iname "*.gif" -o -iname "*.tiff" -o -iname "*.raw" \) 2>/dev/null | grep -i "$PATTERN" fiTechnical Analysis
The user-controlled
PATTERNvalue is passed tofdwithout an end-of-options delimiter. Shell quoting protects the value from shell word splitting and shell metacharacter expansion, but it does not stopfdfrom interpreting a value beginning with-as a command-line option.This is security-sensitive because
fdsupports command-execution options such as--execand--exec-batch. A crafted pattern can therefore alter the intended operation from a filename search into execution of another local command. The second script argument, nominally the search directory, may then be consumed byfdas the command or executable associated with the injected option.The fallback branch has a related argument-parsing weakness:
grep -i "$PATTERN"can interpret a dash-prefixed pattern as an option. This fallback issue can alter search behavior or expose unintended files, although the confirmed command-execution impact specifically applies to thefdbranch.Attack Path
- An attacker influences the filename pattern and directory arguments passed to
search_by_name.sh. - The target environment has
fdinsta ...[truncated 1179 chars]
- An attacker influences the filename pattern and directory arguments passed to
- Remediation
View remediation
Remediation Suggestions
Terminate
fdoption processing before passing user-controlled positional arguments:bash fd -e jpg -e jpeg -e png -e heic -e webp -e gif -e tiff -e raw -- "$PATTERN" "$DIR"Apply the same defense to the fallback
grepinvocation:bash find "$DIR" -type f \( \ -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o \ -iname "*.heic" -o -iname "*.webp" -o -iname "*.gif" -o \ -iname "*.tiff" -o -iname "*.raw" \ \) 2>/dev/null | grep -i -- "$PATTERN"Additional hardening should include:
- Validate that
DIRexists and is a directory before invoking the search tool. - Reject unexpected control characters in search input.
- Run ShellCheck and add tests for patterns such as
--exec,--exec-batch,-e, and--help. - Execute the skill under a least-privileged account when processing arguments from untrusted sources.
- Validate that
