T02 · Agent Memory Poisoning
- Location
scripts/compress_session.py:181- Finding
Persistent Prompt Injection Through AI-Generated Session Summaries
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
The skill has a coherent token-saving purpose, but it needs review because it can silently persist AI-generated memory, send session or user-chosen file contents to configurable external API endpoints, and its cleanup/test paths can affect global OpenClaw memory.
Install only after you are comfortable with this skill sending session summaries or selected files to the configured AI endpoint and writing persistent global memory that future OpenClaw sessions may load. Avoid using the arbitrary file argument for sensitive files, verify the API URL and credentials, back up ~/.openclaw/memory before use, do not run the documented uninstall command that deletes the whole memory directory unless you intend to erase all OpenClaw memory, and isolate TOKEN_OPTIMIZER_MEMORY_DIR before running tests.
scripts/compress_session.py:181Persistent Prompt Injection Through AI-Generated Session Summaries
scripts/compress_session.py:246Arbitrary Local File Disclosure to an Unrestricted External API Endpoint
tests/test_session_guard.py:12Test Suite Overwrites Live OpenClaw Session State
requirements.txt:1Unbounded and Unhashed Third-Party Dependency
Tool parameters are crafted to achieve unintended or unsafe behavior. Parameter abuse can bypass intended safety checks (e.g. shell=True, --force, dangerous glob patterns).
# 删除技能目录
rm -rf ~/.openclaw/workspace/skills/token-optimizer
# 可选:删除记忆文件
rm -rf ~/.openclaw/memory
Tool parameters are crafted to achieve unintended or unsafe behavior. Parameter abuse can bypass intended safety checks (e.g. shell=True, --force, dangerous glob patterns).
# 删除技能目录
rm -rf ~/.openclaw/workspace/skills/token-optimizer
# 可选:删除记忆文件
rm -rf ~/.openclaw/memory
The uninstall instructions include deletion of ~/.openclaw/memory, which the document earlier states is a global memory directory shared by OpenClaw rather than being scoped to this skill. Removing that path can destroy unrelated user data and session history, and the warning is only marked as optional rather than clearly describing the data-loss consequences.
This duplicate finding correctly identifies a high-risk deletion command aimed at a global application directory rather than the skill itself. Because the documentation notes that memory is stored globally under ~/.openclaw/memory/, the uninstall step can cause substantial unintended data loss beyond this skill's footprint.
rm -rf ~/.openclaw/workspace/skills/token-optimizer
rm -rf ~/.openclaw/memory
## 获取帮助
This duplicate finding correctly identifies a high-risk deletion command aimed at a global application directory rather than the skill itself. Because the documentation notes that memory is stored globally under ~/.openclaw/memory/, the uninstall step can cause substantial unintended data loss beyond this skill's footprint.
rm -rf ~/.openclaw/workspace/skills/token-optimizer
rm -rf ~/.openclaw/memory
## 获取帮助
All user-facing instructions in the file are presented in Chinese, and there is no indication that the skill is region-specific or that alternative language documentation is available. This can violate language or locale policy when users are not given an explicit language choice.
Code scans file system directories looking for sensitive files. This could be reconnaissance for credential theft.
python3 scripts/status.py
ls -la ~/.openclaw/memory/
## 使用示例
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
如果看到权限警告:
chmod 600 ~/.openclaw/config.json
The README promotes automatic compression and persistent memory storage as core features without warning that user conversation history may be modified, reduced, and stored outside the skill directory. In a tool that operates on session context, failing to disclose persistence and mutation of user data can lead to unintended data loss, privacy issues, and user surprise during normal use.
The usage section includes a dry-run and then an actual compression command that saves changes, but it does not clearly warn that compression may irreversibly reduce session context fidelity or overwrite the latest summary state. Users may execute the command expecting a safe optimization step, when it actually alters persisted memory and future agent behavior.
The skill explicitly states that session compression will run automatically and silently, while also describing writes to global memory files under ~/.openclaw/memory/. Silent modification of persistent conversation summaries can change what future sessions load without the user noticing, creating risks of unintended data retention, context tampering, or leakage of sensitive information into long-lived memory.
The natural-language description forces a specific language presentation in the manifest metadata. Under the policy, locale or language restrictions should either offer user opt-in or be clearly justified as region-specific, neither of which is present here.
The script loads API credentials from local configuration/environment and uses them to send session summary content to a remote LLM service. Even if this is the intended feature, it creates a real data-exposure boundary because potentially sensitive local session data is transmitted off-host without strong scoping, redaction, or explicit consent at the point of use.
Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.
# 提取 AI 配置
if 'ai' in openclaw_config:
ai_config = openclaw_config['ai']
config['api_url'] = ai_config.get('baseURL', 'https://api.openai.com/v1')
config['api_key'] = ai_config.get('apiKey', '')
config['model'] = ai_config.get('model', 'gpt-4')
elif 'llm' in openclaw_config:
Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.
# 提取 AI 配置
if 'ai' in openclaw_config:
ai_config = openclaw_config['ai']
config['api_url'] = ai_config.get('baseURL', 'https://api.openai.com/v1')
config['api_key'] = ai_config.get('apiKey', '')
config['model'] = ai_config.get('model', 'gpt-4')
elif 'llm' in openclaw_config:
Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.
# 提取 AI 配置
if 'ai' in openclaw_config:
ai_config = openclaw_config['ai']
config['api_url'] = ai_config.get('baseURL', 'https://api.openai.com/v1')
config['api_key'] = ai_config.get('apiKey', '')
config['model'] = ai_config.get('model', 'gpt-4')
elif 'llm' in openclaw_config:
Data is being sent to an external URL. This could be legitimate telemetry or data exfiltration. Manual review is recommended.
# 提取 AI 配置
if 'ai' in openclaw_config:
ai_config = openclaw_config['ai']
config['api_url'] = ai_config.get('baseURL', 'https://api.openai.com/v1')
config['api_key'] = ai_config.get('apiKey', '')
config['model'] = ai_config.get('model', 'gpt-4')
elif 'llm' in openclaw_config:
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
# 检查是否其他用户可读(权限过于宽松)
if file_mode & stat.S_IROTH:
print(f'[警告] 配置文件 {filepath} 权限过于宽松(其他用户可读)')
print(f' 建议执行: chmod 600 {filepath}')
except Exception:
pass # 权限检查失败不影响主流程
The code removes backup files in cleanup_old_backups and later writes a new latest-summary.md, changing persistent local state. While there are status prints for backup and completion, there is no clear up-front disclosure in the tool description/help that running the command will overwrite the latest summary and automatically delete backups older than 7 days.
The code sends full session content to an external AI API but does not present a clear runtime warning that local data will leave the machine. Users may reasonably assume a summarization utility operates locally, so the absence of explicit disclosure increases the risk of unintentional leakage of secrets, personal data, or internal project details.
The compression prompt explicitly tells the model to retain key configuration, paths, validated solutions, lessons learned, and important decisions in a persistent summary. That increases the chance that sensitive operational details, environment structure, or security-relevant context are preserved long-term and possibly transmitted to a third party during compression.
This code file contains natural-language instructions, docstrings, and command usage text exclusively in Chinese, which can force a specific language experience on users. The policy allows locale constraints only when they are documented and justified or when users are given a choice, neither of which is present here.
This Python file's docstring, CLI descriptions, and printed guidance are entirely in Chinese, and the header states the agent should call this script before every reply. That creates a natural-language locale constraint without any opt-in, fallback, or justification that the skill is intended only for a Chinese-speaking environment.
The script builds MEMORY_DIR from the TOKEN_OPTIMIZER_MEMORY_DIR environment variable and then writes state to STATE_FILE under that path without validation. If an attacker can influence the environment in which the agent runs, they can redirect writes to an arbitrary filesystem location the process can access, causing unintended file creation or overwrite and potentially corrupting other application state.
def save_state(state: dict):
"""保存会话状态"""
os.makedirs(SESSIONS_DIR, exist_ok=True)
with open(STATE_FILE, 'w', encoding='utf-8') as f:
json.dump(state, f, ensure_ascii=False, indent=2)
The module docstring and user-facing descriptions are entirely in Chinese, including the usage/help text shown to users. This imposes a specific language/locale without opt-in or justification, which matches the policy category for language or locale violations.