T02 Β· Agent Memory Poisoning
Warning
- Location
- scripts/analyze_profile.py:756
- Finding
- Untrusted Archetype Configuration Can Poison Persistent Agent Instructions<![CDATA[ ## Vulnerability Details **File Location**: `scripts/analyze_profile.py:684-699`, `scripts/analyze_profile.py:756-789`; persistent-use guidance at `SKILL.md:62-73` **Vulnerability Type**: Untrusted content embedded in persistent Agent configuration **Risk Level**: Medium ### Vulnerable Code ```python def load_custom_archetypes(filepath: str) -> Dict[str, Any]: """Load custom archetype definitions from YAML.""" try: import yaml with open(filepath, 'r') as f: data = yaml.safe_load(f) return data.get('archetypes', {}) except ImportError: print("Warning: PyYAML not installed. Using default archetypes only.") return {} except Exception as e: print(f"Warning: Could not load custom archetypes: {e}") return {} ``` ```python else: # prompt-snippet snippet = f"""## User Cognitive Profile <!-- Generated by user-cognitive-profiles skill --> - **Primary Archetype:** {profile['insights']['primary_mode']} - **Confidence:** {profile['insights']['primary_confidence']} - **Context Switching:** {profile['insights']['context_switching']} ### Communication Style """ for archetype in profile['archetypes']: rec = archetype['recommendations'] snippet += f""" **{archetype['name']}** ({archetype['metrics']['conversation_count']} conversations) - AI Role: {rec['ai_role']} - Style: {rec['communication_style']} - Keywords: {', '.join(archetype['keywords'][:5])} """ ``` The Skill documentation subsequently instructs users to add generated insights to persistent Agent configuration: ```markdown ### 3. Apply to Your Agent Add to your `SOUL.md` or `AGENTS.md`: ``` ### Technical Analysis `yaml.safe_load` prevents YAML from directly constructing arbitrary Python objects, but it does not establish that loaded strings are safe to use as Agent instructions. Custom archetype fields such as `name`, `ai_role`, and `description` can contain arbitrary multiline text. These val ...[truncated 2409 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. **Define and enforce a strict schema** - Require archetype names, roles, and descriptions to be strings. - Apply conservative maximum lengths. - Reject control characters and unexpected multiline content. - Validate all nested structures before profile generation. 2. **Separate data from instructions** - Generate a structured profile rather than directly producing trusted Agent directives. - Clearly mark custom values as untrusted metadata. - Avoid representing user-controlled descriptions as imperative instructions. 3. **Escape generated Markdown** - Escape headings, comments, list markers, code fences, and other syntax capable of changing the output structure. - Normalize or reject line breaks in fields intended to occupy one line. 4. **Add instruction-injection detection** - Warn or fail when custom fields contain phrases that attempt to override policies, request secrets, direct tool use, or introduce new Agent rules. - Treat detection as defense in depth rather than the sole control. 5. **Require explicit review** - Add a prominent warning that generated prompt snippets must be manually reviewed before insertion into `SOUL.md` or `AGENTS.md`. - Display which fields came from custom configuration. 6. **Use an allowlisted rendering model** - Convert analysis results into recommendations selected from fixed, trusted templates. - Do not interpolate arbitrary custom prose into persistent Agent instructions. ]]>
