T01 · Skill Instruction Hijacking
- Location
scripts/compact_session.js:67- Finding
User-Controlled Content Is Elevated to a System Message During Compaction
- Content
View full analysis
80 ? '...' : ''); return `- **对话目标**: ${topic}\n- **消息数量**: 共 ${messages.length} 条 (已压缩)\n- **工具调用**: ${toolCalls.length} 次\n- **关键信息**: ${facts.length} 条\n- **保留上下文**: 最新 ${Math.floor(messages.length/3)} 条消息保持完整`; ``` ```javascript const keepCount = Math.max(config.minMessagesToKeep, Math.floor(messages.length / 3)); const toKeep = messages.slice(-keepCount); const toCompact = messages.slice(0, -keepCount); // 3. 生成摘要 const summary = generateSummary(toCompact); // 4. 构建压缩后的消息数组 const compressedMessages = [ { role: 'system', content: `## 会话摘要 (已压缩早期 ${toCompact.length} 条消息)\n\n${summary}\n\n---\n*注: 为控制token使用量,早期对话已压缩为摘要。如需回顾细节,请询问。*` }, ...toKeep ]; ``` ### Technical Analysis The implementation selects messages for removal solely according to their age. Consequently, early trusted system or developer instructions may be included in `toCompact` and removed from the resulting conversation. At the same time, `generateSummary()` extracts the first user message and interpolates up to its first 80 characters directly into `summary`. That summary is then assigned the privileged `system` role. This creates a trust-boundary violation: attacker-controlled user text is promoted from user-level content to system-level instructions. The generated text is not represented as quoted or separately typed untrusted data. A downstream language model may therefore interpret an injected directive as part of its active system instructions. Merely escaping Markdown would not resolve the fundamental issue because the role elevation itself is unsafe. This behavior also contradicts the architectural claim that ...[truncated 1490 chars]- Remediation
View remediation
