T01 · Skill Instruction Hijacking
- Location
- scripts/core/smart_stitch.py:120
- Finding
- Persistent Cross-Skill Instruction and Memory Poisoning<![CDATA[ ## Vulnerability Details **File Location**: `scripts/core/smart_stitch.py:120-211` **Related Location**: `scripts/core/align_all.py:13-23` **Vulnerability Type**: Persistent insertion of untrusted instructions into Agent memory and Skill text **Risk Level**: Critical ### Vulnerable Code ```python # scripts/core/smart_stitch.py for context, instruction in data.get('context_triggers', {}).items(): context_lower = context.lower().replace(' ', '_') context_file = experience_dir / 'contexts' / f'{context_lower}.json' if context_file.exists(): with open(context_file, 'r', encoding='utf-8') as f: ctx_data = json.load(f) else: ctx_data = {'name': context, 'instructions': []} if instruction not in ctx_data['instructions']: ctx_data['instructions'].append(instruction) index['index']['total_experiences'] += 1 with open(context_file, 'w', encoding='utf-8') as f: json.dump(ctx_data, f, indent=2, ensure_ascii=False) ``` ```python if data.get("context_triggers"): evolution_section.append("\n### Context Triggers") for trigger, instruction in data["context_triggers"].items(): evolution_section.append(f"\n- **{trigger}**: {instruction}") if data.get("custom_prompts"): evolution_section.append("\n### Custom Instruction Injection") evolution_section.append(f"\n{data['custom_prompts']}") evolution_block = "\n".join(evolution_section) content = skill_md_path.read_text(encoding='utf-8') pattern = r"(\n+## User-Learned Best Practices & Constraints.*$)" match = re.search(pattern, content, re.DOTALL) if match: new_content = content[:match.start()] + evolution_block else: new_content = content + evolution_block skill_md_path.write_text(new_content, encoding='utf-8') ``` ```python # scripts/core/align_all.py for item in os.listdir(skills_root): skill_dir = os.path.join(skills_root, item) if not os.path.isdir(skill_dir): continue evoluti ...[truncated 2086 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove support for writing free-form `custom_prompts` or executable instructions into `SKILL.md`. 2. Store learned information only in a strict, non-executable data schema. 3. Permit only narrowly defined data fields such as technology names, version numbers, error signatures, and reviewed remediation notes. 4. Reject content containing instruction-like directives, role changes, tool requests, policy overrides, or encoded payloads. 5. Require explicit per-Skill user approval before changing an installed Skill. 6. Display an exact diff and require confirmation before applying it. 7. Remove or strongly restrict `align_all.py`; do not bulk-rewrite all Skills based solely on the presence of `evolution.json`. 8. Record the provenance, author, timestamp, and integrity hash of every learned entry. 9. Keep remote, generated, and user-provided content clearly marked as untrusted data and never concatenate it into Agent instruction files. 10. Add tests proving that prompt-like content cannot enter `SKILL.md` or persistent instruction stores. ]]>
