T05 · Unauthorized Access and Privilege Escalation
- Location
scripts/memory_handler.py:211- Finding
Cross-Session Disclosure of Stored Agent Memory
- Content
View full analysis
- Remediation
View remediation
Security audit
Security checks for vulnerabilities and agentic risk
This skill is a legitimate PostgreSQL memory system, but it handles sensitive cross-session agent history with several overbroad and unsafe database, credential, and restore behaviors that require review before installation.
Install only if you are comfortable administering PostgreSQL for sensitive agent memory. Use a dedicated least-privilege database role, restrict network access to trusted hosts or a VPN, require TLS for remote PostgreSQL, chmod credential files to 600, avoid the --reset/restore --drop paths unless you have verified backups, and do not enable shared multi-agent use until session scoping is fixed and tested.
scripts/memory_handler.py:211Cross-Session Disclosure of Stored Agent Memory
scripts/pg_memory.py:2459Shell Command Injection in Database Backup and Restore
client-setup.sh:184Plaintext Database Credential File Created Without Enforced Restrictive Permissions
server-setup.sh:152SQL Injection During Privileged Database Setup and Excessive CREATEDB Grant
server-setup.sh:205Unsafe Remote PostgreSQL Exposure Guidance Without Enforced TLS Verification
install.sh:111Unpinned Third-Party Dependency Installed at Runtime
The skill exposes full database restore capability and optionally drops and recreates the database first. In an agent-accessible component, this is highly dangerous because a bad prompt, misuse, or compromised caller could irreversibly destroy or overwrite all stored data.
Tool calls are chained to bypass individual safety checks or escalate capabilities beyond what any single tool call would allow.
sudo -u postgres psql -d openclaw_memory < /tmp/migration_*.sql
gunzip -c /tmp/migration_*.sql.gz | sudo -u postgres psql -d openclaw_memory
### Step 3: Reconfigure Client
Tool calls are chained to bypass individual safety checks or escalate capabilities beyond what any single tool call would allow.
sudo -u postgres psql -d openclaw_memory < /tmp/migration_*.sql
# Or if compressed:
gunzip -c /tmp/migration_*.sql.gz | sudo -u postgres psql -d openclaw_memory
```
### Step 3: Reconfigure Client
The troubleshooting guidance tells users to set listen_addresses = '*' and allow host all all 0.0.0.0/0 md5, which can expose PostgreSQL to the entire internet or local network if copied verbatim. Even though a later checklist says not to use 0.0.0.0/0, placing this as troubleshooting advice creates a strong insecure-default pattern that could lead to unauthorized access or brute-force attempts against the database.
The description presents a feature-rich structured memory system, but the provided code chunk is only an installer/bootstrap script. Its actual actions are limited to environment checks, package installation, PostgreSQL connectivity/user/database setup, schema initialization, optional destructive reset, CLI chmod, and config generation. While these setup tasks are consistent with supporting a PostgreSQL-backed memory system, the chunk does not evidence several prominent declared features such as compaction hooks, dual-write, markdown backup, context preservation logic, or multi-agent behavior. Because the declared purpose emphasizes runtime capabilities that are not represented here, and the chunk’s primary purpose is installation rather than the described memory functionality, this is a description/behavior mismatch.
The declared description presents the skill as a structured PostgreSQL memory system with compaction hooks, dual-write behavior, markdown backup, and context preservation for agents. The supplied code chunk does not implement those storage or lifecycle functions. Instead, it adds a separate natural-language querying feature: it constructs prompts, calls a local Ollama model through subprocess, extracts and sanitizes generated SQL, and runs SELECT queries on the pg-memory database. This is materially different from the declared primary purpose and introduces an undeclared capability (LLM-backed NL-to-SQL query execution). While it is related to the broader pg-memory ecosystem, this specific code chunk is not accurately represented by the supplied description.
The code generally matches the broad claim of being a PostgreSQL-based structured memory system with markdown export/backup behavior and multi-instance/multi-agent support. However, the description omits several substantial capabilities present in the code: natural-language querying (including optional LLM-assisted SQL generation via Ollama), backup/restore through external database tools, JSON import/export, markdown bulk import, reminder and chain management, template support, conflict tracking, and auto-creation of project/task observations. More importantly, some specifically declared features are not supported by the supplied chunk: there is no clear implementation of pre/post-compaction integration, no demonstrated dual-write mechanism, and no concrete full-context-preservation subsystem beyond general storage/export features. Because both undeclared significant capabilities and unsubstantiated declared features are present, this is a description-behavior mismatch.
The declared description presents a general-purpose PostgreSQL structured memory system emphasizing full context preservation, dual-write behavior, markdown backup, and compaction integration. The supplied code chunk instead implements a standalone pruning/cleanup script for an existing PostgreSQL memory database. Its primary behavior is retention enforcement: selecting old rows from raw_exchanges, tool_executions, and sessions; archiving some records to compressed JSONL files under a filesystem path; soft-deleting/hard-deleting data; running VACUUM ANALYZE; showing stats; and printing partitioning SQL. Those are materially different capabilities from the declared purpose. Most notably, the code deletes old memory and therefore conflicts with 'full context preservation,' and it does not show dual-write, markdown backup, or compaction integration.
The declared description presents a broad agent memory subsystem with specialized memory features, but the supplied code chunk is narrowly focused on operational database partition management. Its primary purpose is maintaining monthly PostgreSQL partitions for raw_exchanges, including creating future partitions and archiving old ones to compressed JSONL before deleting the detached table. This is materially different from a structured memory system and introduces undeclared capabilities, including filesystem archival and destructive schema/data maintenance actions. While it imports AgentMemory for database connectivity, that appears to be a supporting dependency rather than evidence that this chunk implements the declared memory functionality. Therefore, the description does not accurately represent this code chunk.
The declared description presents a full PostgreSQL-backed memory system with pre/post-compaction integration, dual-write support, markdown backup, and multi-agent context preservation. The supplied code chunk does not implement that system; it is a narrow operational script for regenerating embeddings on existing observations. It accesses PostgreSQL and an Ollama HTTP API, selects records needing embeddings, generates new vectors, and writes them back. None of the headline features in the description—dual-write, markdown backup, compaction integration, or multi-agent orchestration—are evidenced here. While embedding maintenance could be related to a memory system, this chunk’s actual purpose is materially narrower and includes an undeclared external capability (embedding generation via Ollama).
The explicit rm -rf /opt/homebrew/var/postgresql@16 instruction is a concrete high-risk deletion primitive. Because the skill also implies shell-based setup and maintenance, this materially increases the chance of unsafe execution and permanent loss of the agent's stored history and database state.
cat /opt/homebrew/var/log/postgresql@16.log
rm -rf /opt/homebrew/var/postgresql@16 initdb --locale=en_US.UTF-8 -E UTF8 /opt/homebrew/var/postgresql@16
The explicit rm -rf /opt/homebrew/var/postgresql@16 instruction is a concrete high-risk deletion primitive. Because the skill also implies shell-based setup and maintenance, this materially increases the chance of unsafe execution and permanent loss of the agent's stored history and database state.
cat /opt/homebrew/var/log/postgresql@16.log
rm -rf /opt/homebrew/var/postgresql@16 initdb --locale=en_US.UTF-8 -E UTF8 /opt/homebrew/var/postgresql@16
When connection testing fails, the installer proceeds to attempt creation of a PostgreSQL superuser without a clear warning or consent gate. Automatically escalating database privileges is dangerous because it can alter shared local database security posture and create a highly privileged account tied to an application user.
The installer attempts to run createuser -s "$DB_USER", which grants PostgreSQL superuser privileges to the configured database user. For a memory-storage skill, this is unnecessary and materially increases blast radius: compromise of the application or that DB user would enable unrestricted database-level actions across the PostgreSQL instance.
The code sends arbitrary natural-language input and the full database schema to an external LLM process, then executes the model-generated SQL directly against the database. Although it tries to restrict queries to SELECT and block obvious write operations, this is still dangerous because an LLM can generate expensive, data-exfiltrating, or side-effecting read queries, and the guardrails are based on brittle string filtering rather than robust query allowlisting or SQL parsing.
A structured memory skill would reasonably query PostgreSQL, but spawning subprocesses to run 'ollama list' is not an obvious requirement of memory storage or markdown backup. This adds host-level command execution capability unrelated to the manifest's stated core purpose.
The skill expands beyond memory storage into backup and restore of the whole PostgreSQL database, including filesystem writes and invocation of administrative tools. In an agent skill context, this significantly broadens capability and blast radius, making accidental misuse, data exfiltration, or destructive operations more likely.
This is a classic tool-parameter abuse issue: attacker-influenced values are embedded into a shell command and executed with shell=True. In a skill that may receive parameters from an LLM-driven workflow, that context materially increases exploitability and risk of arbitrary command execution.
# Add compression if requested
if compress:
cmd_str = " ".join(cmd) + f" | gzip > {backup_path}"
result = subprocess.run(cmd_str, shell=True, capture_output=True, text=True)
else:
# Run pg_dump and redirect to file
with open(backup_path, 'w') as f:
The restore path combines shell execution with attacker-influenced parameters and a highly privileged operation. This creates a compound risk: arbitrary command execution plus potential full database destruction or overwrite, making it especially severe in an agent-integrated skill.
if is_compressed:
cmd_str = f"gunzip -c {backup_path} | psql -h {db_host} -p {db_port} -U {db_user} -d {db_name}"
result = subprocess.run(cmd_str, shell=True, capture_output=True, text=True)
else:
cmd = [
"psql",
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
# (On Synology: Package Center → PostgreSQL)
# Create database
sudo -u postgres createdb openclaw_memory
# Enable extensions
sudo -u postgres psql -d openclaw_memory -c "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
# (On Synology: Package Center → PostgreSQL)
# Create database
sudo -u postgres createdb openclaw_memory
# Enable extensions
sudo -u postgres psql -d openclaw_memory -c "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
# (On Synology: Package Center → PostgreSQL)
# Create database
sudo -u postgres createdb openclaw_memory
# Enable extensions
sudo -u postgres psql -d openclaw_memory -c "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
# (On Synology: Package Center → PostgreSQL)
# Create database
sudo -u postgres createdb openclaw_memory
# Enable extensions
sudo -u postgres psql -d openclaw_memory -c "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
# (On Synology: Package Center → PostgreSQL)
# Create database
sudo -u postgres createdb openclaw_memory
# Enable extensions
sudo -u postgres psql -d openclaw_memory -c "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"
Commands invoke sudo or root privileges. Verify this elevated access is necessary and justified.
# (On Synology: Package Center → PostgreSQL)
# Create database
sudo -u postgres createdb openclaw_memory
# Enable extensions
sudo -u postgres psql -d openclaw_memory -c "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";"