T01 · Skill Instruction Hijacking
- Location
src/anime_character_loader/legacy.py:506- Finding
Untrusted API Content Can Become Persistent Agent Instructions
- Content
View full analysis
str: """生成 SOUL.md""" data = match.data name = self._sanitize_field(data.get("name", "Unknown")) source_work = self._sanitize_field(match.source_work) # 清洗描述 description = self._clean_description(data.get("description", "")) # 提取性格特征 traits = self._extract_personality(description) # 构建 SOUL lines = [ f"# {name}", "", f"**Source:** {source_work}", "", ] if data.get("name_native"): native_name = self._sanitize_field(data['name_native']) lines.append(f"**Japanese Name:** {native_name}") if data.get("aliases"): safe_aliases = [self._sanitize_field(a) for a in data['aliases'][:3]] lines.append(f"**Also Known As:** {', '.join(safe_aliases)}") lines.extend([ "", "---", "", "## Identity", "", f"You are {name}, a character from {match.source_work}.", "", ]) if description: lines.extend([ "## Background", "", description[:800] if len(description) > 800 else description, "", ]) lines.extend([ "## Personality", "", ]) if traits: for trait in traits[:5]: lines.append(f"- {trait}") ``` ```python def _clean_description(self, desc: str) -> str: """清洗描述文本 - 防止 prompt injection""" if not desc: return "" # 移除 HTML 标签 desc = re.sub(r'<[^>]+>', '', desc) # 移除 markdown 链接 desc = re.sub(r'\[([^\]]+)\]\([^\)]+\)', r'\1', desc) # 清理多余换行 desc = re.sub(r'\n{3,}', '\n\n', desc) # 防止 prompt injection: 移除角色标记和指令覆盖尝试 # 移除常见的 injection 模式 ...[truncated 3635 chars]- Remediation
View remediation
