T09 · Insecure Skill Coding Practices
- Location
README.md:40- Finding
Unchecked Directory Change Can Cause Deletion in an Unintended Directory
- Content
View full analysis
Vulnerability Details
File Location:
README.md, lines 40–42
Vulnerability Type: Unsafe destructive shell commands following an unchecked directory change
Risk Level: MediumVulnerable Code:
bash cd ~/.openclaw/agents/main/sessions rm -f *.jsonl.deleted.* find . -name "*.jsonl.reset.*" -mtime +7 -deleteTechnical Analysis
The documented cleanup sequence changes directories without verifying that the
cdcommand succeeded. Standard interactive shells do not terminate automatically whencdfails. If the sessions directory is absent, inaccessible, or resolves incorrectly, the subsequentrmandfindcommands execute from the caller's existing working directory.The
find .operation recursively traverses that directory and deletes every file matching*.jsonl.reset.*that is older than seven days. It is not constrained with-maxdepth 1, so deletion can extend into every accessible descendant directory. Therm -fcommand may also delete matching files in the unintended current directory while suppressing diagnostics for missing operands.Attack Path
- A user follows the command sequence documented in
README.md. - The expected
~/.openclaw/agents/main/sessionsdirectory does not exist, is inaccessible, or cannot be entered. - The
cdcommand fails, but shell execution continues. rm -f *.jsonl.deleted.*operates in the user's previous working directory.find . -name "*.jsonl.reset.*" -mtime +7 -deleterecursively searches the previous working directory.- Matching files in that directory and its descendants are permanently deleted without confirmation.
A malicious party capable of influencing where the user invokes these instructions, or of causing the expected sessions directory to be unavailable, could increase the likelihood that deletion occurs in a sensitive directory tree.
Impact Assessment
The commands execute with the invoking user's pri ...[truncated 582 chars]
- A user follows the command sequence documented in
- Remediation
View remediation
Remediation Suggestions
-
Make directory validation mandatory and stop immediately if it fails:
bash sessions_dir="$HOME/.openclaw/agents/main/sessions" if [ ! -d "$sessions_dir" ]; then printf 'Error: sessions directory does not exist: %s\n' "$sessions_dir" >&2 exit 1 fi cd -- "$sessions_dir" || exit 1 -
Constrain searches to the intended directory level and require regular files:
bash find . -maxdepth 1 -type f -name '*.jsonl.deleted.*' -print find . -maxdepth 1 -type f -name '*.jsonl.reset.*' -mtime +7 -print -
Present the exact candidate list and obtain explicit user confirmation before deletion.
-
After confirmation, delete only the reviewed candidates:
bash find . -maxdepth 1 -type f -name '*.jsonl.deleted.*' -delete find . -maxdepth 1 -type f -name '*.jsonl.reset.*' -mtime +7 -delete -
Prefer a verified cleanup script with fail-fast behavior, such as
set -eu, rather than documenting independent destructive commands. The package currently referencescleanup.sh, but that script is not present in the audited project and therefore cannot provide the advertised safeguards.
-
