T01 · Skill Instruction Hijacking
Error
- Location
- SKILL.md:62
- Finding
- Untrusted book content is embedded into executable skill instructions<![CDATA[ ## Vulnerability Details **File Location**: `SKILL.md:62-78, 186-231` **Vulnerability Type**: Untrusted content injection into generated agent instructions **Risk Level**: High ### Vulnerable Code ```python def analyze_book(text): """分析书籍内容,提取关键信息""" # 提取书名(尝试从文件名或内容推断) book_title = extract_title(text) # 提取核心主题 themes = extract_themes(text) # 提取方法论/框架 methodologies = extract_methodologies(text) # 提取关键概念 concepts = extract_concepts(text) # 提取实践步骤 practices = extract_practices(text) # 定义员工角色 agent_role = { "name": f"{book_title}专家", "title": f"基于《{book_title}》的{themes[0] if themes else '专业'}顾问", "description": f"我是一位基于《{book_title}》训练的 AI 专家员工。我掌握了书中{len(methodologies)}个核心方法论和{len(concepts)}个关键概念,可以帮助你{practices[0] if practices else '解决相关问题'}。", "expertise": themes, "methodologies": methodologies, "key_concepts": concepts, "services": practices, "activation_phrase": f"请作为《{book_title}》专家帮助我...", "capabilities": generate_capabilities(methodologies, practices) } return agent_role ``` ```python def generate_skill_md(agent_def, output_path): """生成 Skill.md 文件""" md_content = f'''# {agent_def["name"]} ## 角色定位 {agent_def["title"]} ## 核心能力 {chr(10).join(f"- {cap}" for cap in agent_def["capabilities"])} ## 专业知识 基于《{agent_def["title"].split("的")[1].split("顾问")[0] if "的" in agent_def["title"] else "专业书籍"}》深度训练,掌握: ### 核心方法论 {chr(10).join(f"- {m}" for m in agent_def["methodologies"][:5])} ### 关键概念 {chr(10).join(f"- {c}" for c in agent_def["key_concepts"][:8])} ## 使用场景 当我需要: {chr(10).join(f"- {s}" for s in agent_def["services"])} ## 激活方式 对我说:"{agent_def["activation_phrase"]}" ## 工作流程 1. **理解需求**: 分析用户的具体问题和背景 2. **调用知识**: 从书中提取相关的方法论和案例 3. **提供方案**: 给出结构化、可执行的建议 4. **跟进优化**: 根据反馈调整方案 ## 专业领域 {chr(10).join(f"- {e}" for e in agent_def["expertise"])} --- *此 AI 员工由 Book-to-Agent 技能自动生成* ''' with open(outp ...[truncated 2298 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Do not place raw or lightly processed book content into an executable skill instruction file. 2. Keep trusted instructions in a fixed, reviewed template and store extracted knowledge in a separate data file treated explicitly as untrusted reference material. 3. Apply strict schemas to all generated fields: - Enforce short maximum lengths. - Permit only expected character classes. - Reject control characters and unexpected line breaks. - Reject Markdown headings, fenced code blocks, HTML, links, and instruction-like directives. 4. Escape Markdown metacharacters before rendering any untrusted value. 5. Use a structured serialization format for reference data rather than embedding it directly into instruction sections. 6. Add an explicit trusted instruction stating that book-derived content is evidence only and must never override system, developer, or skill-level rules. 7. Require human review and approval of the complete generated skill before installation. 8. Add adversarial tests using books containing headings, prompt-injection phrases, code blocks, and attempts to override previous instructions. ]]>
