T09 · Insecure Skill Coding Practices
- Location
scripts/cleanup_sessions.sh:38- Finding
Cleanup Logic Can Recursively Delete Active and Non-Stale Sessions
- Content
View full analysis
/dev/null | wc -l) if [ "$stale_count" -gt 1 ]; then echo "Found $((stale_count - 1)) stale session(s)" if [ "$DRY_RUN" = true ]; then find /home/nvi/.openclaw/sessions -maxdepth 1 -type d -mmin +60 -exec echo "[DRY-RUN] Would remove: {}" \; else find /home/nvi/.openclaw/sessions -maxdepth 1 -type d -mmin +60 -exec rm -rf {} + 2>/dev/null || true echo "[CLEANED] Stale sessions removed" fi fi fi ``` ### Technical Analysis The `find` commands use `-maxdepth 1` but omit `-mindepth 1`. Consequently, the search may include `/home/nvi/.openclaw/sessions` itself when that root directory satisfies `-type d -mmin +60`. If both the session root and at least one child directory match, `stale_count` is greater than one and the deletion branch executes. Passing the root to `rm -rf` recursively removes everything under it, including child sessions that are newer than one hour or currently active. The count adjustment does not prevent deletion of the root; it only changes the displayed count. The code also suppresses errors with `2>/dev/null || true` and unconditionally reports that stale sessions were removed. This can conceal partial failures or unintended deletion behavior. ### Attack Path 1. `/home/nvi/.openclaw/sessions` has a modification time older than one hour. 2. At least one immediate child session directory also has a modification time older than one hour. 3. A user follows the documented instructions and runs `cleanup_sessions.sh` without `--dry-run`. 4. The count check succeeds because both the root and child dire ...[truncated 796 chars]- Remediation
View remediation
