T01 · Skill Instruction Hijacking
Error
- Location
- tools/compaction_manager.py:239
- Finding
- Untrusted conversation content is promoted to system-level authority during compaction<![CDATA[ ## Vulnerability Details **File Location**: `tools/compaction_manager.py:239-250, 274-291` **Vulnerability Type**: Trust-boundary violation and prompt-injection privilege escalation **Risk Level**: Critical ### Vulnerable Code ```python # 保留最近 N 条消息 recent = messages[-PRESERVE["recent_messages"]:] older = messages[:-PRESERVE["recent_messages"]] # 生成旧消息的摘要 older_summary = self._summarize_messages(older) # 构建压缩后的消息列表 compacted = [ { "type": "system", "role": "system", "content": f"[早期对话已压缩为摘要,共 {len(older)} 条消息,约 {self.estimate_tokens(''.join(m.get('content','') for m in older))} tokens]\n\n摘要:{older_summary}", "_compact": "auto" } ] + recent ``` The summary is generated by copying excerpts from every message without considering its original trust level: ```python def _summarize_messages(self, messages: List[Dict], max_length: int = 2000) -> str: """生成消息摘要""" if not messages: return "无" # 提取关键信息 topics = [] for msg in messages: content = msg.get("content", "")[:200] # 每条取前200字符 if content: # 提取前几个字作为主题 first_line = content.split('\n')[0][:50] if first_line: topics.append(first_line) summary = f"讨论了 {len(messages)} 条消息,主题包括:{';'.join(topics[:5])}" if len(summary) > max_length: summary = summary[:max_length] + "..." return summary ``` ### Technical Analysis The compaction mechanism does not distinguish between trusted system instructions and untrusted user or tool-result content when generating its summary. `_summarize_messages()` copies the first line of each old message, including user-controlled messages, into `older_summary`. `auto_compact()` then assigns that summary both `"type": "system"` and `"role": "system"`. This crosses a fundamental instruction trust boundary: text originally supplied at user authority can reappear in a system-authority message. The summary algorithm is extra ...[truncated 1760 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Never convert user or tool content into a system-role message. Retain the original trust level or represent summaries in a dedicated non-authoritative data structure. 2. Keep the actual system prompt separate and immutable during compaction. 3. If a summary must be inserted as a message, use a non-system role and explicitly state that the content is untrusted historical data, not instructions. 4. Generate structured summaries containing facts, decisions, and unresolved tasks rather than copying raw first-line excerpts. 5. Exclude or neutralize imperative phrases, role declarations, tool directives, and instruction-like content originating from users or tool outputs. 6. Track provenance for each summary element, including the original role and message identifier. 7. Add tests proving that user content such as “ignore previous instructions” can never appear in a system-role message after compaction. 8. Require downstream consumers to treat compacted summaries as data and prevent them from overriding active system or developer instructions. ]]>
