Back to skill

Security audit

metacognitive-monitoring

Security checks for vulnerabilities and agentic risk

Overview

The core monitoring tool is local and understandable, but the skill also creates persistent learning/preferences and tells agents to modify future behavior without enough scoping or controls.

Review this before installing if you do not want a skill to keep local history or preferences. Use it only in a controlled skill directory, treat learned_patterns.json as untrusted data, and do not allow automatic SKILL.md rewrites or automatic adoption of stored preferences without human review.

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/learner.py:88
Finding

Untrusted Preferences Can Persistently Influence Future Agent Behavior

Content
View full analysis

Vulnerability Details

File Location: scripts/learner.py:88-92; related behavioral instructions in SKILL.md:66-77
Vulnerability Type: Persistent memory poisoning
Risk Level: Medium

Vulnerable Code

python
def record_preference(skill_dir, key, value):
    data = load_learning(skill_dir)
    data["preferences"][key] = value
    save_learning(skill_dir, data)
    return data

The command-line interface passes unrestricted values directly to this function:

python
p_pre  = sub.add_parser("prefer"); p_pre.add_argument("skill_dir")
p_pre.add_argument("--key", required=True); p_pre.add_argument("--val", required=True)

Technical Analysis

The prefer operation accepts arbitrary preference keys and values and stores them persistently in learned_patterns.json. There is no schema, allowlist, length restriction, provenance record, trust classification, expiration policy, or approval step.

The accompanying skill instructions direct future skill executions to use recorded preferences automatically. Consequently, instruction-like text supplied by an untrusted caller can cross a session boundary and later be treated as trusted behavioral guidance.

The Python module does not itself execute the preference content. Exploitation therefore depends on a downstream agent or integration loading the stored preferences and applying them as instructions. Nevertheless, the persistence mechanism and documented automatic reuse create the complete memory-poisoning channel.

Attack Path

  1. An attacker or untrusted user invokes the preference command with an instruction-like key or value.
  2. record_preference() writes the content into the persistent preferences object in learned_patterns.json.
  3. The content remains available after the current process or agent session ends.
  4. A later agent run follows the skill documentation and loads the stored preference.
  5. If that agent treats the ...[truncated 757 chars]
Remediation
View remediation

Remediation Suggestions

  1. Define a strict, typed allowlist of supported preference keys and acceptable values.
  2. Reject instruction-like free-form preferences where a fixed enumeration or structured value is sufficient.
  3. Apply length limits and normalize values before persistence.
  4. Store provenance, author identity, creation time, trust level, and expiration time for every preference.
  5. Treat all persisted values as untrusted data and never merge them into system or developer instructions.
  6. Require explicit user confirmation before a stored preference affects a security-sensitive operation.
  7. Provide commands to inspect, revoke, and reset preferences.
  8. Separate benign presentation preferences from policy or behavioral configuration.
  9. Ensure downstream integrations use preferences only through validated application logic rather than direct prompt interpolation.

T09 · Insecure Skill Coding Practices

Warning
Location
scripts/learner.py:28
Finding

Caller-Controlled Directory and Symlink Handling Permit Unintended File Overwrite

Content
View full analysis

Vulnerability Details

File Location: scripts/learner.py:28-39, 51-56
Vulnerability Type: Unrestricted path selection and symlink-following file write
Risk Level: Medium

Vulnerable Code

python
def resolve_skill_dir(arg):
    """Support an absolute directory path or a skill name under the configured skills directory."""
    if os.path.isdir(arg):
        return arg
    alt = os.path.join(os.path.expanduser("~/.workbuddy/skills"), arg)
    if os.path.isdir(alt):
        return alt
    return arg

def learn_path(skill_dir):
    return os.path.join(skill_dir, "learned_patterns.json")
python
def save_learning(skill_dir, data):
    data["lastUpdated"] = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M")
    p = learn_path(skill_dir)
    with open(p, "w", encoding="utf-8") as f:
        f.write(json.dumps(data, indent=2, ensure_ascii=False))

Technical Analysis

The command-line caller can supply any existing directory as skill_dir. The path is not canonicalized or restricted to an approved skill root. save_learning() then opens the fixed child name learned_patterns.json in truncating write mode.

Python's normal open() behavior follows symbolic links. The implementation does not inspect the destination using lstat(), reject symbolic links, verify ownership or file type, use O_NOFOLLOW, or perform an atomic replacement. A maliciously prepared learned_patterns.json symlink can therefore redirect the write to another file writable by the process.

The destination content does not need to contain valid learning data. load_learning() catches parsing and other exceptions and returns default data, after which save_learning() overwrites the symlink target with generated JSON. The attacker controls portions of that JSON through capability names, error details, notes, preference keys, and preference values.

Attack Path

  1. The attacker identifies a file writ ...[truncated 1544 chars]
Remediation
View remediation

Remediation Suggestions

  1. Resolve the requested skill directory with realpath() and verify that it remains beneath an explicitly approved root directory.
  2. Reject path traversal, unexpected absolute paths, and directories not owned by the expected user.
  3. Inspect the destination with lstat() and reject symbolic links and non-regular files.
  4. On supported platforms, open files using os.open() with O_NOFOLLOW, O_CREAT, and appropriate restrictive permissions.
  5. Verify the opened file using fstat() to prevent check-to-use races.
  6. Write to a securely created temporary file in the validated directory, flush and synchronize it, and atomically replace the destination.
  7. Set restrictive file permissions, such as owner read/write only, where stored preferences or notes may be sensitive.
  8. Do not silently treat every load failure as an empty data file. Distinguish a missing file from malformed content, permission failures, symlinks, and unexpected file types.
  9. If privileged automation invokes this script, ensure untrusted users cannot choose skill_dir or modify the validated skill directory.
Vulnerability Patterns
  • Prompt InjectionInstruction Override, Hidden Instructions, Exfiltration Commands
  • Excessive AgencyUnrestricted Tool Access, Autonomous Decision Making, Scope Creep
  • MCP Least PrivilegeUnderdeclared Capability, Wildcard Permission, Missing Permission Declaration
  • MCP Tool PoisoningHidden Instructions, Unicode Deception, Parameter Description Injection
  • Data ExfiltrationExternal Transmission, Env Variable Harvesting, File System Enumeration
Findings (13)

Tp4

High
Category
MCP Tool Poisoning
Confidence
99% confidence
Finding

The documented purpose is a guardrail for metacognitive monitoring, but the behavior described by the file also includes undeclared persistence of usage history, error patterns, and user preferences, plus retrospective analytics. A guardrail component that silently acquires stateful data collection capabilities can mislead operators about what it actually does and expands risk beyond its stated safety role.

Content

No source excerpt is available for this finding.

Context-Inappropriate Capability

High
Category
Not specified by scanner
Confidence
98% confidence
Finding

Allowing the skill to rewrite its own SKILL.md turns a monitoring helper into a self-modifying component. Self-modification of instructions or documentation can bypass review, alter future behavior, and create a pathway for persistence of unsafe changes or prompt-injection-derived policy drift.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

High
Category
Not specified by scanner
Confidence
98% confidence
Finding

The file's documented and implemented behavior is a generic cross-skill learning and persistence system, not a metacognitive confidence monitor or decision-gating guard layer as described in the manifest. This mismatch is dangerous because users or orchestrators may grant the skill trust and permissions appropriate for safety monitoring while it actually collects and stores broader operational data for arbitrary skills.

Content

No source excerpt is available for this finding.

Undeclared Tool Scope

Medium
Category
MCP Least Privilege
Confidence
89% confidence
Finding

The skill documentation instructs use of local file writes through scripts/learner.py and persistence to learned_patterns.json, but it declares no tool scope or permissions. That mismatch weakens user and platform visibility into side effects, making unexpected local state changes more likely and reducing containment if the skill is reused in broader agent workflows.

Content

No source excerpt is available for this finding.

Description-Behavior Mismatch

Medium
Category
Not specified by scanner
Confidence
93% confidence
Finding

The skill broadens a local monitoring role into a self-improving system that stores experience and preferences over time. This creates persistent state and behavioral drift in a component that users would reasonably expect to remain a narrow, deterministic guardrail, increasing the chance of privacy issues, unexpected outputs, or unsafe adaptation.

Content

No source excerpt is available for this finding.

Context-Inappropriate Capability

Medium
Category
Not specified by scanner
Confidence
92% confidence
Finding

Persistent collection of user preferences and decision history is not necessary for basic metacognitive monitoring, so it introduces avoidable privacy and integrity risk. Once stored, that data can influence future runs in ways the user may not anticipate, especially if it is treated as authoritative without review.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
94% confidence
Finding

The skill directs persistent writes to local files and possible modification of SKILL.md without an explicit warning that local files will be changed. Hidden or insufficiently disclosed writes are dangerous because they undermine user consent, complicate auditing, and can leave durable state that affects later executions.

Content

No source excerpt is available for this finding.

Intent-Code Divergence

Medium
Category
Not specified by scanner
Confidence
92% confidence
Finding

The docstring explicitly markets the component as a skill-agnostic self-evolving module for any WorkBuddy skill, which conflicts with the manifest's representation of a reliability guard layer. Security-relevant misrepresentation is harmful because it can bypass review expectations, confuse operators about what data is handled, and hide broader capabilities under a safety-oriented label.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The natural-language interface, usage descriptions, and user-facing messages are written entirely in Chinese, with no indication that another language can be selected. This can violate language/locale policy when a skill imposes a specific language without explicit user opt-in or documented regional justification.

Content

No source excerpt is available for this finding.

Context-Inappropriate Capability

Medium
Category
Not specified by scanner
Confidence
95% confidence
Finding

The module persistently records user preferences, capability usage, error notes, and recent operations for arbitrary skills, which exceeds the stated need of local confidence monitoring. In a safety-guard skill context, this unnecessary data retention increases privacy risk, expands the blast radius of compromise, and creates opportunities for silent cross-skill profiling.

Content

No source excerpt is available for this finding.

Missing User Warnings

Medium
Category
Not specified by scanner
Confidence
96% confidence
Finding

The save path writes accumulated preferences and operational history to disk with no user-facing warning, consent flow, or visibility into what is stored. Silent persistence of potentially sensitive notes and behavior data is a privacy/security issue, especially in a component presented as a safety monitor rather than a telemetry collector.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
81% confidence
Finding

The natural-language instructions and examples are entirely in Chinese, including user-facing labels and preference keys, and there is no indication that users may choose another language. Under the language/locale policy, forcing a specific language without opt-in can be a policy issue unless the locale restriction is explicit and justified.

Content

No source excerpt is available for this finding.

Natural-Language Policy Violations

Low
Category
Not specified by scanner
Confidence
87% confidence
Finding

This JSON includes natural-language values such as "元认知监控" for capability naming, and the file provides no indication that the language choice is optional or limited to a justified region-specific context. Under the stated policy, forcing a specific language without user opt-in can be a natural-language policy violation.

Content

No source excerpt is available for this finding.