T09 · Insecure Skill Coding Practices
Warning
- Location
- scripts/clean-sessions.sh:85
- Finding
- Backup filename collisions can overwrite previously archived sessions## Vulnerability Details **File Location**: `scripts/clean-sessions.sh:85-86` **Vulnerability Type**: Unsafe file replacement **Risk Level**: Medium ```bash mkdir -p "$BACKUP_DIR" mv "$f" "$BACKUP_DIR/" ``` ### Technical Analysis The script moves session files into a shared backup directory without checking whether the destination filename already exists. Standard `mv` behavior can replace an existing destination file with the same basename. This violates the documented guarantee that moved session files remain recoverable. The operation also lacks collision-resistant naming, a no-clobber option, and post-move integrity verification. ### Attack Path 1. A session file is moved into `sessions/backup/`. 2. A new active-directory session file is subsequently created or restored with the same basename. 3. The cleanup script classifies the new file as stale. 4. The script runs `mv "$f" "$BACKUP_DIR/"`. 5. Depending on the platform's `mv` behavior and filesystem conditions, the existing backup is replaced by the newer file. 6. The prior transcript can no longer be recovered from the backup directory. Exploitation requires the ability to cause or influence a same-named session file in the sessions directory. No privilege escalation is obtained. ### Impact Assessment The impact is limited to files accessible under the invoking user's OpenClaw session directory. A collision can cause permanent loss of an older archived transcript, undermine recovery guarantees, and remove historical session records that may be needed for operational recovery or investigation. The issue does not grant additional system privileges or network access.
- Remediation
- ## Remediation Suggestions - Use collision-resistant destination names containing a timestamp or UUID. - Check destination existence before moving and fail safely on collisions. - Use no-clobber semantics such as `mv -n` where supported, while checking the result because behavior varies by platform. - Prefer an explicit destination path rather than moving only to a directory. - Verify that the destination file exists and matches the source size or checksum before reporting success. - Preserve restrictive permissions on the backup directory and archived files. - Add tests covering repeated cleanup of files with identical basenames.
