T09 · Insecure Skill Coding Practices
- Location
scripts/ctrlz.sh:62- Finding
SQL Injection Through Unvalidated CLI Arguments
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
This undo skill is purpose-aligned, but it needs Review because it can overwrite or delete user files from unvalidated stored records without confirmation and keeps plaintext backups.
Review carefully before installing. Use only in disposable or well-backed-up workspaces unless the skill adds path scoping, a dry-run preview, explicit confirmation for undo and clear, SQL/input hardening, and clear handling of retained backups. Do not rely on it to fully reverse package installs or shell command side effects.
scripts/ctrlz.sh:62SQL Injection Through Unvalidated CLI Arguments
scripts/ctrlz.sh:171Unvalidated Undo Records Permit Arbitrary File Deletion and Overwrite
scripts/ctrlz.sh:168Delimiter-Based SQLite Output Parsing Can Redirect Undo Operations
scripts/ctrlz.sh:260Sensitive File Backups Lack Secure Permissions and Complete Retention Cleanup
README.md:16Installation Instructions Retrieve an Unpinned Mutable Repository Revision
The skill promises automatic, conversation-scoped undo of file changes and installations, but the documented behavior depends on external callers to start sessions and record operations, and package installs are not actually reverted. This mismatch can cause users to rely on rollback guarantees that do not exist, leading to incomplete recovery after destructive actions and a false sense of safety when making changes.
The clear command irreversibly removes all undo metadata and backups with no warning, eliminating the ability to recover prior changes. In the context of an undo system, this is especially dangerous because it defeats the primary safety mechanism and can be triggered as a single destructive action.
The script uses rm -rf to delete the entire backups directory derived from $HOME, with no confirmation or additional guardrails. Even though the path is quoted, this is still a dangerous destructive primitive in a safety-focused skill because environment manipulation, misconfiguration, or accidental invocation can wipe all rollback backups at once.
# Clear all records
clear_all() {
sqlite3 "$DB_PATH" "DELETE FROM undo_operations; DELETE FROM undo_sessions;"
rm -rf "$HOME/.openclaw/skills/ctrlz/backups"
echo "{\"cleared\": true}"
}
The README prominently advertises one-command reversal of file modifications, deletions, and other changes, but does not provide a clear warning that undo may itself be destructive or irreversible if state tracking is incomplete. In practice, users may invoke the feature without understanding that recent edits, created files, or deleted content could be reverted unexpectedly, increasing the chance of data loss or operational disruption.
The natural-language triggers include very broad phrases such as "undo" and "ctrl+z", which can appear in ordinary conversation or in ambiguous contexts. In a skill that performs destructive rollback actions, this raises the risk of unintended activation and accidental deletion or reversion of user changes without sufficiently explicit confirmation.
The skill description advertises reverting file modifications and installations but does not prominently warn that undo is destructive and may restore older file states or only partially reverse changes. Users may activate it without understanding that important work can be lost or that some effects, such as installs and command side effects, may remain.
The natural-language trigger includes the single broad term "undo," which is ambiguous and likely to appear in normal conversation outside a genuine rollback request. In an automation context, this can cause unintended invocation of destructive reversal actions against files or prior work without sufficient user confirmation.
The skill persists undo session data and backups across conversation rounds, creating retained records of file paths, change history, and possibly file contents. While persistence is part of the feature, retaining this data without documented limits, protections, or minimization increases exposure if local storage is accessed by other processes or users.
Operation types:
- `file_write` - Write/overwrite file
- `file_edit` - Edit existing file
- `file_delete` - Delete file
- `dir_create` - Create directory
These test cases repeatedly demonstrate destructive undo actions such as deleting files and entire directories, but they do not prominently warn that running them can cause irreversible data loss if paths are mis-specified or reused outside an isolated test environment. In a skill explicitly designed to revert system changes, missing safety warnings materially increases the chance that a user or agent will run destructive examples against real data.
Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.
# Scenario: Set up AI News Agent but config wrong, want to revert everything
# 1. Create original file
cp ~/.openclaw/cron/jobs.json ~/.openclaw/cron/jobs.json.bak
# 2. Start a big session
Skill establishes unauthorized persistence across sessions via cron jobs, startup scripts, or state files. Session persistence allows an attacker to maintain access beyond the current interaction.
ctrlz record $SESSION file_edit ~/.openclaw/cron/jobs.json
# ... modify json ...
# 4. Create database
ctrlz record $SESSION dir_create ~/.openclaw/agents/ai-news-agent
echo "CREATE TABLE..." | sqlite3 ~/.openclaw/agents/ai-news-agent/news.db
The undo routine performs rm -f and rm -rf on recorded paths without user confirmation or path validation. Because the tool is designed to operate automatically in response to 'undo last step', a malformed, stale, or attacker-influenced record could cause deletion of unintended files or directories.
The skill description promises that installations will be reverted automatically, but the implementation only prints suggested uninstall commands and leaves installed packages in place. In an undo tool, this mismatch is security-relevant because users may rely on the skill to roll back environmental changes and falsely assume risky packages or dependencies were removed.
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
elif [[ "$pkg" == pip:* ]]; then
echo " pip uninstall ${pkg#pip:}" >&2
elif [[ "$pkg" == apt:* ]]; then
echo " sudo apt remove ${pkg#apt:}" >&2
else
echo " # Package: $pkg" >&2
fi
The clear command permanently deletes all undo records and backup files, which exceeds the user-facing promise of undoing the last step and destroys recovery data. In a safety tool, including an unrestricted destructive reset path increases the chance of accidental or abusive loss of forensic and rollback state.
Skill enables autonomous high-impact decisions without human-in-the-loop verification. Critical operations (destructive commands, financial transactions, data deletion) should require explicit user confirmation.
case "$cmd" in
init)
# Initialize database (auto-executed)
echo "{\"initialized\": true, \"db_path\": \"$DB_PATH\"}"
;;
The run_test helper executes its second argument using eval, which causes the shell to re-parse and execute arbitrary command strings. If any test name, path, or future test input becomes attacker-controlled or improperly escaped, this can lead to command injection and arbitrary code execution during testing.
The teardown routine deletes the entire temporary test directory with rm -rf, which is a destructive operation. Although this is part of cleanup logic, the script provides no prior warning in comments or user-facing output that it will remove files under the generated test path.