T09 · Insecure Skill Coding Practices
- Location
SKILL.md:17- Finding
Unprotected Session Cleanup Can Delete the Main Session or Files in an Unintended Directory
- Content
View full analysis
Vulnerability Details
File Location:
SKILL.md, lines 17–19
Vulnerability Type: Unsafe destructive file operation
Risk Level: Mediumsh 2. Safe clean old session files (retain main session) cd /home/ubuntu/.openclaw/agents/main/sessions/ find . -name "*.jsonl" -mtime +3 -delete 2>/dev/nullTechnical Analysis
The cleanup instruction claims to retain the main session, but the
findexpression does not identify or exclude it. Every matching.jsonlentry older than three days is deleted, including the main session if it satisfies those conditions.The operation is irreversible and lacks a dry run, backup, confirmation prompt, or validation of the files selected for deletion. It also suppresses error output, making failures and partial cleanup harder to detect.
In addition, the deletion command depends on the preceding
cdsucceeding. If an automation runner executes subsequent commands after a failed directory change,find .operates on the runner's existing working directory. The practical scope remains limited to matching files that the executing account is permitted to delete, but it may exceed the intended OpenClaw session directory.Attack Path
- The user or automation invokes the
clean sessionstrigger. - The cleanup enters, or attempts to enter, the configured session directory.
findselects every accessible entry named*.jsonlwhose modification time is more than three days old.- No condition excludes the active or main session.
- Selected files are permanently deleted without confirmation or backup.
openclaw session rebuildreconstructs the index from the remaining files, making the deleted sessions unavailable.- If the directory change failed and the runner did not abort, matching files under an unintended current directory could instead be deleted.
Impact Assessment
The operation executes with the privileges of the account running the Skill. ...[truncated 488 chars]
- The user or automation invokes the
- Remediation
View remediation
Remediation Suggestions
-
Use a validated absolute target directory and terminate immediately if it cannot be entered:
sh SESSION_DIR="/home/ubuntu/.openclaw/agents/main/sessions" [ -d "$SESSION_DIR" ] || { echo "Session directory does not exist" >&2 exit 1 } cd -- "$SESSION_DIR" || exit 1 -
Determine the authoritative active or main session identifier through OpenClaw and explicitly exclude its file from cleanup. Do not rely only on file age to distinguish sessions.
-
Restrict selection to regular files and preview the exact deletion set before making changes:
sh find "$SESSION_DIR" -maxdepth 1 -type f -name '*.jsonl' -mtime +3 -print -
Require explicit confirmation before deletion, especially when invoked interactively.
-
Create a timestamped, recoverable backup before cleanup and verify that the backup succeeded.
-
Perform deletion only after validating that every selected file is inside the canonical session directory and is not the active session.
-
Remove
2>/dev/null; record and report deletion errors so partial failures are visible. -
Rebuild
sessions.jsononly after cleanup succeeds, then verify the rebuilt index and confirm that the main session remains present.
-
