T09 · Insecure Skill Coding Practices
- Location
scripts/cleanup.sh:84- Finding
Unconfirmed File Deletion with Unsafe Filename Handling
- Content
View full analysis
/dev/null) if [ -n "$swp_files" ]; then log "找到vim交换文件:" echo "$swp_files" | while read -r file; do log_warning " $file" done echo "$swp_files" | xargs -r rm -v ``` ### Technical Analysis The script recursively locates `.swp` and `.swx` entries under `~/.openclaw` and deletes them automatically. It does not request confirmation, even though `SKILL.md` states that files should be listed and confirmed before deletion. The script transports pathnames through command substitution, newline-delimited text, `echo`, and `xargs`. Unix filenames may contain spaces, tabs, quotes, backslashes, and newline characters. Consequently, the pathnames produced by `find` can be split or reinterpreted by `xargs` as multiple independent arguments to `rm`. The `find` expression also lacks `-type f` and explicit grouping: ```bash find "$OPENCLAW_DIR" -name "*.swp" -o -name "*.swx" ``` Although operator precedence makes the two name patterns function as alternatives in this particular expression, omitting `-type f` allows matching non-regular filesystem entries. The deletion command also lacks an explicit `--` end-of-options marker. ### Attack Path 1. An attacker or compromised process obtains permission to create directories and files beneath the victim's `~/.openclaw` directory. 2. The attacker creates a directory hierarchy containing whitespace so that the actual matching pathname is parsed by `xargs` into multiple path operands. For example, a path component ending in a space can cause the remainder of the emitted pathname to appear as a separate absolute-looking operand after whitespace tokenization. 3. The attacker places a matching `.swp` or `.swx` entry at ...[truncated 1141 chars]- Remediation
View remediation
0)); then log "Found Vim swap files:" printf ' %q\n' "${swp_files[@]}" read -r -p "Delete these swap files? (y/N): " confirm if [[ "$confirm" =~ ^[Yy]$ ]]; then rm -v -- "${swp_files[@]}" else log "Skipped swap-file cleanup" fi fi ``` 4. For unattended execution, make deletion opt-in through an explicit option such as `--force` or `--non-interactive`; default to report-only behavior. 5. Consider detecting whether a swap file is associated with a running editor before deletion. At minimum, apply an age threshold and clearly warn that swap files may contain recoverable unsaved work. 6. Run the cleanup script only with the minimum required user privileges. Do not invoke it as root unless privileged cleanup is explicitly necessary. ]]>
