T09 · Insecure Skill Coding Practices
- Location
scripts/clean-sessions.sh:85- Finding
Backup filename collisions can overwrite previously archived sessions
- Content
View full analysis
Vulnerability Details
File Location:
scripts/clean-sessions.sh:85-86
Vulnerability Type: Unsafe file replacement
Risk Level: Mediumbash 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
mvbehavior 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
- A session file is moved into
sessions/backup/. - A new active-directory session file is subsequently created or restored with the same basename.
- The cleanup script classifies the new file as stale.
- The script runs
mv "$f" "$BACKUP_DIR/". - Depending on the platform's
mvbehavior and filesystem conditions, the existing backup is replaced by the newer file. - 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.
- A session file is moved into
- Remediation
View 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 -nwhere 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.
