Back to skill

Security audit

Session Cleaner

Security checks for vulnerabilities and agentic risk

Overview

This skill is a disclosed OpenClaw session cleanup tool, but it can delete session history and rewrite session indexes with broad rules and weak built-in safeguards.

Install only if you are comfortable letting this skill modify OpenClaw session history. Before using it, make backups of every affected sessions.json and session file, review the exact sessions to remove, avoid broad confirmations like '全部清理' unless the deletion set is clear, and stop or quiesce the Gateway before changing session indexes.

Vulnerability Patterns
  • Insecure Skill Coding PracticesFinds exploitable flaws such as hardcoded secrets or command injection
  • Skill Instruction HijackingAlters the agent's session goals or safety constraints when the skill loads
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • Remote Payload Retrieval and ExecutionFetches external code whose behavior can change after review
  • Embedded Malicious CodeShips malicious scripts inside the skill and executes them locally
Findings (1)

T09 · Insecure Skill Coding Practices

Warning
Location
SKILL.md:102
Finding
Overbroad and Non-Atomic Session Index Deletion## Vulnerability Details **File Location**: `SKILL.md`, lines 102-111 **Vulnerability Type**: Destructive session-state modification caused by insufficient validation and unsafe file replacement **Risk Level**: Medium ### Vulnerable Code ```python if agent == 'main' and 'main' not in agent_ids: new_data = {} print(f"[{agent}] main 不存在,清空 ({len(data)} 条)") else: new_data = {k: v for k, v in data.items() if ':main' in k or v.get('status') == 'running'} print(f"[{agent}] 保留 {len(new_data)},删 {len(data)-len(new_data)}") with open(sf, 'w') as f: json.dump(new_data, f) ``` ### Technical Analysis The cleanup algorithm retains only records whose key contains `:main` or whose status is exactly `running`. Consequently, it deletes every other entry without verifying that the session is actually expired, invalid, orphaned, or safe to remove. Sessions with unknown, absent, newly introduced, or temporarily inconsistent status values are treated as disposable. If the `main` agent is absent from the configuration, the code unconditionally replaces its entire session index with an empty object. It does not verify whether those sessions remain valuable, whether their files are still referenced elsewhere, or whether removal is consistent with the active Gateway state. The script then opens `sessions.json` directly in write mode. This truncates the original file before serialization completes. There is no mandatory backup, file lock, Gateway shutdown, temporary-file write, atomic rename, schema validation, or concurrency check. An interruption, serialization failure, or concurrent Gateway update can therefore leave the index corrupted or cause newly written session state to be lost. Although the documentation suggests creating a backup, backup creation is optional and is not enforced by the provided script. ### Attack Path 1. A user invokes the session-cleaner Skill and requests cleanup. 2. ...[truncated 1670 chars]
Remediation
## Remediation Suggestions 1. **Use explicit eligibility rules:** Delete only sessions with recognized terminal states such as `done`, `timeout`, or `failed`, and only after validating retention-age requirements. Preserve records with missing or unknown statuses by default. 2. **Verify orphan status:** Before removing an index entry, verify whether its transcript and related files exist and whether another component still references the session. 3. **Require record-level confirmation:** Present the exact agent ID, session key, status, age, and files affected for every proposed deletion. Confirmation should apply to that immutable deletion plan rather than to a broad category. 4. **Create a mandatory backup:** Copy each `sessions.json` to a timestamped backup before modification and verify that the backup can be parsed. 5. **Use atomic replacement:** Serialize and validate the new index in the same directory, flush it to disk, and atomically replace the original with `os.replace`. 6. **Prevent concurrent writes:** Stop the Gateway before editing or use the locking or session-management API provided by OpenClaw. Confirm that the source index has not changed between analysis and replacement. 7. **Validate output before replacement:** Confirm that the generated JSON matches the expected schema and that protected sessions remain present. 8. **Avoid unconditional clearing:** Do not erase all `main` agent sessions solely because the agent is absent from the current configuration. Archive them or require a separate, explicit confirmation. 9. **Support recovery:** Keep backups until the Gateway restarts successfully and post-cleanup verification confirms that retained sessions are accessible. 10. **Align implementation and documentation:** The documentation claims that orphaned transcript, trajectory, and checkpoint files are deleted, but the supplied script only rewrites indexes. Either implement a separately reviewed and confirmed orphan-file cleanup p ...[truncated 26 chars]
Vulnerability Patterns
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Trigger AbuseOverly Broad Trigger, Shadow Command Trigger, Keyword Baiting Trigger
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
Findings (7)

Intent-Code Divergence

High
Confidence
98% confidence
Finding
The document states that deletion must never occur before user confirmation, yet the provided cleanup script performs deletion logic unconditionally once run. That contradiction creates a sharp edge: the skill presents itself as safe and confirmation-driven, but its executable content bypasses that safety guarantee entirely, increasing the likelihood of destructive operator error.

Missing User Warnings

Medium
Confidence
94% confidence
Finding
The skill explicitly describes deleting session files and removing entries from sessions.json, but the early feature description does not clearly foreground that these actions are destructive and may be irreversible. In this context, session artifacts may contain active work history, audit trails, or recoverable state, so insufficient warning increases the risk of users invoking cleanup without understanding the consequences.

Vague Triggers

Medium
Confidence
92% confidence
Finding
The documented trigger phrases are very broad, natural-language commands such as '清理会话' and '删除旧 session', which can be uttered in normal conversation and unintentionally invoke a destructive cleanup action. Because the skill deletes session metadata and files, accidental activation can cause unintended data loss or removal of forensic/history records without a strong confirmation boundary.

Vague Triggers

Medium
Confidence
89% confidence
Finding
The trigger phrases are broad operational commands such as '清理会话' and '整理会话列表', without exclusions or stronger conditions to ensure the user intends destructive maintenance rather than mere inspection. In a cleanup skill with deletion capability, overly permissive invocation increases the chance the agent activates this workflow in ambiguous contexts and nudges users toward destructive actions they did not clearly request.

Natural-Language Policy Violations

Medium
Confidence
94% confidence
Finding
All user-facing instructions, examples, and required confirmation text are written in Chinese, including the mandated prompt at L070. There is no indication that the user may choose another language or that the Chinese-only behavior is required for a region-specific or compliance reason.

Description-Behavior Mismatch

Medium
Confidence
95% confidence
Finding
The embedded Python script directly rewrites each agent's sessions.json and drops entries based on hard-coded retention logic, but it contains no built-in confirmation gate, dry-run mode, or validation that the operator has completed the earlier review step. In a skill whose purpose is operational cleanup, this mismatch is dangerous because an agent or user may copy/paste and execute the script immediately, causing irreversible loss of session metadata and accidental deletion of non-target sessions.

Natural-Language Policy Violations

Low
Confidence
95% confidence
Finding
The README instructs users to invoke the skill with Chinese phrases and frames interaction as directly telling the assistant in Chinese, without mentioning alternative languages or user choice. This creates a language/locale constraint in the natural-language instructions that is not documented as optional or region-specific.

Static analysis

No suspicious patterns detected.