T09 · Insecure Skill Coding Practices
- Location
scripts/batcher.sh:166- Finding
Argument Injection in Large-File Search Can Trigger Destructive find Actions
- Content
View full analysis
Vulnerability Details
File Location:
scripts/batcher.sh, lines 166-177
Vulnerability Type: Shell argument injection
Risk Level: HighVulnerable Code
bash find_large() { local folder="$1" local size="${2:-100M}" if [ ! -d "$folder" ]; then echo "❌ Folder not found: $folder" return 1 fi echo "🔍 Files larger than $size in $folder:" echo "" find "$folder" -type f -size +$size -exec ls -lh {} \; 2>/dev/null | awk '{print $5, $9}' | sort -hr | head -20 }Technical Analysis
The attacker-controlled
sizevariable is expanded without quotation in-size +$size. Bash consequently performs word splitting on its value. Although shell metacharacters introduced through variable expansion are not reparsed as shell syntax, whitespace can inject additional arguments directly intofind.This allows a supplied size value to add arbitrary
findpredicates and actions. For example, a single argument containing1c -deleteis expanded into:bash find "$folder" -type f -size +1c -delete -exec ls -lh {} \;The injected
-deleteaction removes every regular file under the selected folder that is larger than one byte. Otherfindactions may also be injectable, subject to the implementation and argument ordering.The documented interface compounds the issue: documentation uses
--size 500M, but the script passes only$3tofind_largeand ignores$4. Thus, normal documented usage provides--sizeas the size expression rather than500M.Attack Path
- An attacker influences a request that invokes the large-file operation and controls its size argument.
- The attacker supplies one argument containing whitespace and an additional
findaction, such as1c -delete. local size="$2"preserves the complete string.- The unquoted
+$sizeexpansion splits that string into+1cand `-delete ...[truncated 585 chars]
- Remediation
View remediation
Remediation Suggestions
-
Validate the size value against a strict allowlist before invoking
find. For example:bash if [[ ! "$size" =~ ^[0-9]+[bcwkMG]$ ]]; then printf 'Invalid size: %s\n' "$size" >&2 return 2 fi -
Pass the complete size expression as one quoted argument:
bash find "$folder" -type f -size "+$size" -exec ls -lh -- {} \; -
Parse the documented
--sizeoption explicitly and reject unknown or extra options. -
Use
--where supported when passing file names to utilities. -
Add regression tests with whitespace, option-like strings,
-delete,-exec, and malformed units to verify rejection.
-
