Back to skill

Security audit

asclaude-compact

Security checks for vulnerabilities and agentic risk

Overview

This skill is a local session compaction tool, but it can persist sensitive conversation logs and has an unvalidated session-id path issue that can read or rewrite out-of-scope JSONL files.

Review this before installing if your OpenClaw sessions may contain secrets, private code, or personal data. Only run it on trusted session IDs, avoid passing path-like arguments, and expect full archives, summaries, and backups to remain on disk unless you delete them yourself.

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

Error
Location
scripts/micro-compact.py:51
Finding

Unvalidated Session Identifier Enables Path Traversal and Out-of-Scope JSONL File Access

Content
View full analysis

Vulnerability Details

File Locations:

  • scripts/micro-compact.py:51-57 — constructs a session path from an unvalidated identifier.
  • scripts/micro-compact.py:228-242 — backs up and overwrites the selected file.
  • scripts/compact-trigger.py:47-53 — constructs a session path from an unvalidated identifier.
  • scripts/compact-trigger.py:128-134 — constructs source and archive paths from the same unvalidated identifier.

Vulnerability Type: Path traversal and unrestricted filesystem access
Risk Level: High

Vulnerable Code

scripts/micro-compact.py:51-57:

python
def read_session(session_id):
    """读取会话文件"""
    sessions_dir = Path(CONFIG['sessions_dir'])
    session_file = sessions_dir / f"{session_id}.jsonl"
    
    if not session_file.exists():
        return None

scripts/micro-compact.py:228-242:

python
def save_session(session_data, modified_messages):
    """保存修改后的会话"""
    session_file = session_data['file_path']
    
    # 备份原文件
    backup_file = session_file.with_suffix('.jsonl.backup')
    if session_file.exists():
        import shutil
        shutil.copy2(session_file, backup_file)
        print(f"   📦 备份原文件: {backup_file}")
    
    # 写入新文件
    with open(session_file, 'w', encoding='utf-8') as f:
        for item in modified_messages:
            f.write(json.dumps(item['data'], ensure_ascii=False) + '\n')

scripts/compact-trigger.py:47-53:

python
def read_session(session_id):
    """读取会话文件"""
    sessions_dir = get_sessions_dir()
    session_file = sessions_dir / f"{session_id}.jsonl"
    
    if not session_file.exists():
        return None

scripts/compact-trigger.py:128-134:

python
def archive_session(session_data, archive_dir):
    """归档会话到归档目录"""
    session_id = session_data['session_id']
    archive_path = archive_dir / f"{session_id}.jsonl"
    
    sessions_dir = get_session
...[truncated 3282 chars]
Remediation
View remediation

Remediation Suggestions

  1. Treat the session argument strictly as an identifier, not as a path. Enforce an allowlist such as ^[A-Za-z0-9_-]+$ and reject empty values, path separators, drive prefixes, absolute paths, and .. components.

  2. Resolve the trusted base directory and candidate path before access, then require the candidate to be a direct child of the base directory:

    python
    import re
    from pathlib import Path
    
    SESSION_ID_PATTERN = re.compile(r"^[A-Za-z0-9_-]+$")
    
    def safe_session_path(session_id):
        if not SESSION_ID_PATTERN.fullmatch(session_id):
            raise ValueError("Invalid session identifier")
    
        base = Path(CONFIG["sessions_dir"]).expanduser().resolve()
        candidate = (base / f"{session_id}.jsonl").resolve()
    
        if candidate.parent != base:
            raise ValueError("Session path escapes the session directory")
    
        return candidate
    
  3. Apply an independent containment check to every archive destination. Do not assume that validating a source path automatically validates a separately constructed destination.

  4. Reject symlinked session files or securely verify their final resolved targets if symlinks are not required by the Skill.

  5. Replace direct truncating writes with an atomic update: write to a securely created temporary file in the validated session directory, flush and synchronize it, then use os.replace().

  6. Preserve the original file on parsing or writing failure and assign restrictive permissions to backups because session archives may contain credentials, source code, tool output, and other sensitive conversation data.

  7. Add tests covering absolute paths, ../ traversal, nested paths, symlinks, malformed identifiers, archive-path escape attempts, and valid session identifiers.

Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Privilege EscalationExcessive Permissions, Sudo/Root Execution, Credential Access
  • Supply ChainUnpinned Dependencies, External Script Fetching, Obfuscated Code
Findings (6)

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The module docstring presents this as a manual trigger for conversation compaction, and the final status output states '压缩后:仅保留摘要文件'. In reality, the code copies the full session JSONL into an archived-sessions directory, so the original conversation content is still retained rather than reduced to only a summary.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
86% confidence
Finding

The user-facing docstring and runtime messages are written only in Chinese, which imposes a language choice without offering an alternative or opt-in. Under the stated policy, language constraints should be optional or clearly justified.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The script copies entire conversation logs, potentially containing secrets or sensitive personal data, into a workspace archive without warning or confirmation. In an agent environment, users may reasonably believe 'compression' reduces retained data, so silent persistence increases privacy and exposure risk if the workspace is later accessed, synced, or backed up.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The summary file persists excerpts of recent message content to disk without disclosing that conversation text will be stored. Even partial summaries can capture credentials, internal project data, or personal information, making this a genuine privacy issue in the context of local agent memory management.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

This code file contains natural-language instructions, descriptions, and runtime messages exclusively in Chinese, which effectively forces a specific language for users. The policy allows locale constraints only when users can opt in or when the restriction is clearly justified, neither of which is present here.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Low
Category
Not specified by scanner
Confidence
99% confidence
Finding

The docstring for update_session_memory explicitly says '更新 session-memory.md', implying modification of a specific file. However, the implementation never writes to session-memory.md and instead creates a new file like memory/YYYY-MM-DD-compact.md.

Content

No source excerpt is available for this finding.