Back to skill

Security audit

recursive-self-improve

Security checks for vulnerabilities and agentic risk

Overview

This skill is a disclosed self-improvement tool, but it can persistently modify other installed skills and its safety promises do not fully match the code.

Install only if you intentionally want a tool that can modify other skills. Run scan and propose first, use it on a backup or staging skills directory, review generated changes manually, avoid recording sensitive notes or preferences, and do not grant it broad write access to live skill folders without per-skill approval.

Vulnerability Patterns
  • Agent Memory PoisoningWrites attacker-controlled rules into memory that affect later sessions
  • 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
  • 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 (2)

T02 · Agent Memory Poisoning

Warning
Location
scripts/recursive_self_improve.py:91
Finding

Persistent Cross-Skill Instruction and State Modification

Content
View full analysis

Vulnerability Details

File Location: scripts/recursive_self_improve.py, lines 91–109 and 143–151
Vulnerability Type: Persistent modification of other Skills
Risk Level: Medium

Vulnerable Code

python
def _apply_one(skill_dir, issue, learner_src):
    """在 skill_dir 上安全地应用一个补丁(追加/复制,不删不覆盖)。返回是否改变。"""
    changed = False
    md = os.path.join(skill_dir, "SKILL.md")
    txt = _read(md)
    if issue == "no_self_evolve_section":
        if "自进化学习系统" not in txt:
            with open(md, "a", encoding="utf-8") as f:
                f.write(SELF_EVOLVE_SECTION)
            changed = True
    elif issue == "no_learner":
        sdir = os.path.join(skill_dir, "scripts")
        os.makedirs(sdir, exist_ok=True)
        dst = os.path.join(sdir, "learner.py")
        if learner_src and os.path.exists(learner_src) and not os.path.exists(dst):
            shutil.copyfile(learner_src, dst)
            changed = True
        # 初始化记忆
        lp = os.path.join(skill_dir, "learned_patterns.json")
        if not os.path.exists(lp):
            json.dump({"version": 1, "skill": os.path.basename(skill_dir),
                       "totalOps": 0, "totalErrors": 0, "capabilityStats": {},
                       "errorPatterns": {}, "preferences": {}, "recentOps": []},
                      open(lp, "w", encoding="utf-8"), ensure_ascii=False, indent=2)
            changed = True

The sandbox contents are subsequently committed to the source Skill:

python
for root, _, files in os.walk(sandbox):
    for fn in files:
        src = os.path.join(root, fn)
        rel = os.path.relpath(src, sandbox)
        dst = os.path.join(skill_dir, rel)
        os.makedirs(os.path.dirname(dst), exist_ok=True)
        shutil.copyfile(src, dst)

Technical Analysis

The apply operation persistently alters other Skills by:

  • Appending a self-evolution instruction section to their ...[truncated 2166 chars]
Remediation
View remediation

Remediation Suggestions

  1. Require explicit, per-Skill confirmation before changing any target.
  2. Support a mandatory allowlist rather than scanning and modifying every writable Skill by default.
  3. Display an exact unified diff and the list of files to be created before committing.
  4. Make instruction injection and learner installation opt-in, separate actions.
  5. Store learning data outside target Skill packages in a clearly scoped application-data directory.
  6. Provide a dry-run mode as the default and require an explicit commit flag for persistent changes.
  7. Record cryptographic hashes and backups so every modification can be audited and safely reverted.
  8. Minimize stored data and avoid persisting sensitive user notes or preferences without informed consent.

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/recursive_self_improve.py:143
Finding

Broad Sandbox Copy-Back Can Overwrite Unrelated or Concurrently Modified Files

Content
View full analysis

Vulnerability Details

File Location: scripts/recursive_self_improve.py, lines 143–151
Vulnerability Type: Unsafe file replacement and symlink-following write
Risk Level: Medium

Vulnerable Code

python
# 通过:把沙箱结果拷回源
for root, _, files in os.walk(sandbox):
    for fn in files:
        src = os.path.join(root, fn)
        rel = os.path.relpath(src, sandbox)
        dst = os.path.join(skill_dir, rel)
        os.makedirs(os.path.dirname(dst), exist_ok=True)
        shutil.copyfile(src, dst)
done.append(p)

Technical Analysis

After validating one proposed patch, the implementation copies every file from the sandbox snapshot back into the original Skill directory. It does not restrict the commit to the file affected by the current patch.

shutil.copyfile() replaces existing destination contents. Consequently, this implementation contradicts the documented claim that source files are never overwritten. If another process modifies a Skill file after the sandbox snapshot is created, the copy-back phase can silently replace that newer version with the stale sandbox copy.

The code also does not inspect destination components with os.lstat() or reject symbolic links. Python file-copy operations normally follow a destination symlink when opening it for writing. A local process able to alter the target directory during execution could therefore replace a destination file with a symlink before copy-back, potentially redirecting the write to another file accessible to the invoking account.

Temporary sandbox validation does not prevent these issues because validation occurs before the final destination is examined and written. There is no source hash comparison, destination hash comparison, directory lock, resolved-path containment check, or atomic conditional commit.

Attack Path

Concurrent overwrite path:

  1. The program copies a target Skill into a temporary sandbox.
  2. Another pro ...[truncated 1569 chars]
Remediation
View remediation

Remediation Suggestions

  1. Commit only the file or files explicitly changed by the current patch; never copy the entire sandbox snapshot back.
  2. Record the original hash and metadata of each target before creating the sandbox.
  3. Immediately before commit, verify that the destination still has the same hash and metadata. Abort if it changed.
  4. Use os.lstat() on the destination and every parent component, rejecting symbolic links and unexpected file types.
  5. Resolve source and destination paths and verify containment within the approved Skill directory.
  6. Write new content to a temporary file in the destination directory, flush and synchronize it, then use an atomic replacement only after all validations pass.
  7. Use a lock or another concurrency-control mechanism for each Skill during validation and commit.
  8. Preserve a backup and implement transactional rollback if a multi-file patch cannot be committed completely.
  9. Add tests covering concurrent destination changes, destination symlinks, interrupted commits, and unrelated files present in the sandbox.
Vulnerability Patterns
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
  • Rogue AgentSelf-Modification, Session Persistence
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
Findings (18)

Tp4

High
Category
MCP Tool Poisoning
Confidence
96% confidence
Finding

代码的核心功能是记录与汇总操作数据,并根据简单阈值给出改进建议,属于“学习日志/复盘助手”。声明描述的是一个更强、更主动的元改进系统,需要扫描技能目录、发现配置或结构缺陷、提出并试应用补丁、校验结果并写回记忆。两者在主目的和能力范围上存在明显差异。虽然代码中有‘自进化学习’和‘反思建议’的元素,与声明中的‘记忆/改进’主题有弱相关,但仅停留在统计和文本建议层面,缺少声明里最关键的自动扫描、补丁生成、试应用、校验和递归生态级处理,因此应判定为描述与行为不匹配。

Content

No source excerpt is available for this finding.

Self-Modification

High
Category
Rogue Agent
Confidence
96% confidence
Finding

The skill is explicitly designed to propose, trial, validate, and then persist modifications to skills and self-improvement state, which is a self-modification capability. Even with stated guardrails like append-only and sandbox trials, self-editing systems materially increase the risk of policy drift, privilege expansion, persistence of unsafe logic, and tamper propagation across the skill ecosystem.

Content

Scanner excerpt · SKILL.md (reported line 25)May include surrounding context.

md
2. **提案(propose)**:把每个机会映射成安全补丁动作(仅追加/复制,从不删除/覆盖源),产出可审计的补丁计划。
3. **试应用(apply·沙箱)**:补丁先在临时副本上试跑,确认目标标记出现、文件不损坏后才允许落盘;任何异常都回滚。
4. **校验(verify)**:应用后重跑 scan,断言该机会已消除,否则判定补丁失败并保留原状。
5. **记忆(record)**:通过的补丁写入技能级 `self_improve_log.json`,并回写 evolver 的 `self_patches`,使整个生态的元改进轨迹可追溯。

## 何时使用

Self-Modification

High
Category
Rogue Agent
Confidence
92% confidence
Finding

This skill is explicitly designed to inspect and modify other skills under ~/.workbuddy/skills, including inserting content and helper scripts. Even without overtly malicious code, self-modification of executable/configuration assets is high risk because a logic error, bad heuristic, or poisoned source learner.py can propagate unsafe changes across multiple skills.

Content

Scanner excerpt · scripts/recursive_self_improve.py (reported line 18)May include surrounding context.

python
SKILLS_DEFAULT = os.path.expanduser("~/.workbuddy/skills")

# 自进化章节(与 skill-self-improve 的 section.md 保持一致)
SELF_EVOLVE_SECTION = """

## 自进化学习系统(越用越好用、越用越高效)

Self-Modification

High
Category
Rogue Agent
Confidence
91% confidence
Finding

The action map formalizes automatic self-improvement operations that alter skill contents based on heuristic findings. In this context, the danger comes from granting a recursive tool authority to mutate the skill ecosystem, which can scale mistakes or maliciously influenced inputs into broad persistence changes.

Content

Scanner excerpt · scripts/recursive_self_improve.py (reported line 27)May include surrounding context.

python
ACTION_FOR = {
    "no_learner": "inject_learner",
    "no_self_evolve_section": "append_self_evolve_section",
    "invalid_frontmatter": "prepend_yaml_frontmatter",
}

Self-Modification

High
Category
Rogue Agent
Confidence
90% confidence
Finding

Skill modifies its own code, configuration, or behavior at runtime. Self-modification enables an agent to escalate privileges, disable safety constraints, or install persistent backdoors.

Content

Scanner excerpt · scripts/recursive_self_improve.py (reported line 69)May include surrounding context.

python
if not os.path.exists(os.path.join(d, "scripts", "learner.py")):
            issues.append("no_learner")
        if "自进化学习系统" not in txt:
            issues.append("no_self_evolve_section")
        if issues:
            cands.append({"skill": name, "issues": issues, "body_len": len(txt)})
    return cands

Self-Modification

High
Category
Rogue Agent
Confidence
90% confidence
Finding

Skill modifies its own code, configuration, or behavior at runtime. Self-modification enables an agent to escalate privileges, disable safety constraints, or install persistent backdoors.

Content

Scanner excerpt · scripts/recursive_self_improve.py (reported line 177)May include surrounding context.

python
if not os.path.exists(os.path.join(d, "scripts", "learner.py")):
            issues.append("no_learner")
        if "自进化学习系统" not in txt:
            issues.append("no_self_evolve_section")
        if issues:
            cands.append({"skill": name, "issues": issues, "body_len": len(txt)})
    return cands

Self-Modification

High
Category
Rogue Agent
Confidence
95% confidence
Finding

This branch performs persistent mutation of SKILL.md by appending a predefined section when the marker is missing. In the context of a recursive self-improvement tool, automatic edits to other skills create a supply-chain style integrity risk, especially because the target set is discovered dynamically from a shared skills directory.

Content

Scanner excerpt · scripts/recursive_self_improve.py (reported line 94)May include surrounding context.

python
changed = False
    md = os.path.join(skill_dir, "SKILL.md")
    txt = _read(md)
    if issue == "no_self_evolve_section":
        if "自进化学习系统" not in txt:
            with open(md, "a", encoding="utf-8") as f:
                f.write(SELF_EVOLVE_SECTION)

Self-Modification

High
Category
Rogue Agent
Confidence
96% confidence
Finding

This logic copies learner.py into other skills and initializes persistent memory files, effectively spreading executable code across the skill ecosystem. Replicating code into multiple targets is dangerous because a compromised or buggy learner source becomes a mass-propagation mechanism and increases persistence across many skills.

Content

Scanner excerpt · scripts/recursive_self_improve.py (reported line 97)May include surrounding context.

python
if issue == "no_self_evolve_section":
        if "自进化学习系统" not in txt:
            with open(md, "a", encoding="utf-8") as f:
                f.write(SELF_EVOLVE_SECTION)
            changed = True
    elif issue == "no_learner":
        sdir = os.path.join(skill_dir, "scripts")

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
90% confidence
Finding

The skill describes file read/write behavior over the skills directory and persistent memory files, but it declares no explicit tool scope or permissions boundary. That creates an authorization ambiguity where a host agent may grant broader filesystem access than users expect, increasing the chance of unintended file modification or data exposure.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The skill’s natural-language description and usage guidance are entirely presented in Chinese, with no indication that users may choose another language or locale. This creates a language/locale policy concern because the skill appears to impose a specific language by default rather than offering user choice.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The document states writes are limited to skills and meta-evolver JSON memory, but later introduces a local learning memory file in the skill directory, creating inconsistent data-handling guarantees. Contradictory storage claims can bypass reviewer expectations and lead to unapproved persistence of operational or user-derived data.

Content

No source excerpt is available for this finding.

Ssd 3

Medium
Category
Not specified by scanner
Confidence
90% confidence
Finding

The persistent learning log collects operational history, errors, and user preferences, but the skill provides no clear minimization rules, redaction requirements, or retention controls. This creates a realistic risk of accumulating sensitive context that can be leaked, over-retained, or reused outside the original purpose.

Content

No source excerpt is available for this finding.

Ssd 3

Medium
Category
Not specified by scanner
Confidence
91% confidence
Finding

The skill instructs persistent storage and reuse of user preferences across runs without defining minimization, consent, or isolation boundaries. That can cause sensitive user-provided information to be retained longer than necessary and later surfaced to other tasks, users, or contexts.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

This Python file contains its module description, CLI help text, comments, and runtime output entirely in Chinese, which creates a language-specific user experience with no opt-in or alternative locale. Under the policy, forcing a specific language without user choice is a natural-language policy violation unless the locale restriction is explicitly justified.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

This Python file contains natural-language docstrings and CLI output entirely in Chinese, including the skill description and operational status text. Under the policy, forcing a specific language without user opt-in is a natural-language policy violation unless the locale constraint is explicitly justified, which is not present here.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
97% confidence
Finding

The module promises it will never delete or overwrite source skill files, but the write-back stage copies every file from the sandbox over the original tree with shutil.copyfile. That means existing files such as SKILL.md can be silently replaced after sandbox mutation, violating the safety contract and creating integrity risk for user-managed skills.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The comments and docstrings describe an append/copy-only patch flow, but _apply_one rewrites SKILL.md for invalid frontmatter and the final sync replaces destination files wholesale. Misrepresenting mutation behavior is dangerous because operators may grant this tool more trust or automation permissions than they would if they knew it performs in-place replacement.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Low
Category
Not specified by scanner
Confidence
91% confidence
Finding

L58 声称‘每次使用后自动复盘、积累经验’,表述为自动发生的内建行为;但 L63-L67 紧接着要求用户在使用后显式执行 python scripts/learner.py record/insight/reflect。这不是信息缺失,而是自动与手动触发机制的直接冲突。

Content

No source excerpt is available for this finding.