Back to skill

Security audit

Memory Shrink

Security checks for vulnerabilities and agentic risk

Overview

This memory-cleanup skill is purpose-aligned, but it can move persistent memory files too broadly and without clear confirmation or rollback.

Review before installing if you rely on persistent memory for active tasks. Use it only on a workspace you intend to clean up, inspect what would be archived first, and consider fixing the script to require confirmation, validate the workspace path, preserve active memory files, and avoid overwriting existing archives.

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
scripts/shrink.sh:27
Finding
Unsafe and Overbroad Memory File Archival## Vulnerability Details **File Location**: `scripts/shrink.sh`, lines 27-34 **Vulnerability Type**: Unsafe pathname handling, archive overwrite, and insufficient retention controls **Risk Level**: Medium ```bash OLD_FILES=$(find "$MEMORY_DIR" -maxdepth 1 -name "*.md" -mtime +7 2>/dev/null) if [ -n "$OLD_FILES" ]; then for file in $OLD_FILES; do basename=$(basename "$file") mv "$file" "$ARCHIVE_DIR/${TIMESTAMP}_${basename}" echo "Archived: $basename" done echo "Archive complete." ``` ### Technical Analysis The output of `find` is stored as newline-delimited text and subsequently expanded through the unquoted expression `$OLD_FILES`. Shell word splitting therefore treats spaces, tabs, and newlines within filenames as separators. A valid memory filename containing such characters can be interpreted as multiple paths, causing incorrect moves or terminating the script partway because `set -e` is enabled. Archive destinations use a timestamp with only minute-level precision and the original basename. The script invokes `mv` without collision protection, so an existing regular file with the same destination name may be silently replaced. The destination is predictable from the execution time and source basename. The selection rule also archives every top-level Markdown file older than seven days without inspecting its content or excluding protected files. This conflicts with the documented requirement to retain unfinished-task progress, current team state, and ongoing discussions. Consequently, an old file that still contains operationally active information can be removed from the live memory directory. The workspace is derived from a caller-controlled first argument at line 7: ```bash WORKSPACE="${1:-/root/.openclaw/workspace-code_analyst}" ``` No approved-root or canonical-path validation is applied. A caller capable of invoking the script can therefore direct its file-moving be ...[truncated 1508 chars]
Remediation
## Remediation Suggestions - Process paths using null delimiters rather than command substitution and shell word splitting: ```bash find "$MEMORY_DIR" -maxdepth 1 -type f -name '*.md' -mtime +7 -print0 | while IFS= read -r -d '' file; do name=${file##*/} destination="$ARCHIVE_DIR/${TIMESTAMP}_${name}" mv -n -- "$file" "$destination" done ``` - Use a collision-resistant archive name containing seconds or a securely generated unique suffix. Check whether the destination exists and fail safely instead of overwriting it. Use `mv -n --` where supported. - Explicitly exclude protected files such as `MEMORY.md` and evaluate documented retention criteria before moving a record. File age alone must not determine whether active operational information is archived. - Canonicalize the supplied workspace path and require it to reside under an approved workspace root. Reject paths outside that boundary, including paths redirected through symbolic links. - Validate that the memory and archive directories are not symbolic links before modifying them. - Record each selected source and destination, report failures accurately, and avoid leaving partially completed archival operations. Consider staging changes and committing them only after all validation succeeds.
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 (5)

Tp4

High
Category
MCP Tool Poisoning
Confidence
93% confidence
Finding
The skill promises context-threshold and heartbeat-triggered memory shrinking, but the described implementation delegates to an external script and the finding indicates the real behavior archives files by age instead of actual context pressure. In a memory-management skill, this mismatch is dangerous because operators may trust it to preserve active state while freeing context, yet it can delete or archive unrelated memory at the wrong time and fail to act during actual high-context conditions.

Missing User Warnings

Medium
Confidence
89% confidence
Finding
The skill describes updating memory files and deleting archived content without requiring a clear user warning or confirmation before destructive actions. This is risky because memory files can contain persistent workflow state, and silent modification or deletion can cause loss of important context, auditability, or task continuity.

Natural-Language Policy Violations

Medium
Confidence
93% confidence
Finding
This markdown file contains all operational instructions in Chinese and does not provide an opt-in, alternative language, or justification for limiting the skill guidance to that locale. Under the policy rule, forcing a specific language without user choice is a natural-language policy violation.

Natural-Language Policy Violations

Low
Confidence
93% confidence
Finding
The natural-language content of the skill is entirely in Chinese, and there is no indication that language choice is optional or that the skill is intended only for a Chinese-language environment. Under the stated policy, forcing a specific language without user opt-in is a locale/language policy concern.

Natural-Language Policy Violations

Low
Confidence
91% confidence
Finding
The script includes operational comments in Chinese (for example, lines describing archive and directory checks), which imposes a specific language for maintainers or auditors without offering a language choice or documenting a locale-specific requirement. This matches the policy category for language or locale constraints expressed in natural language.