fix: 对齐官方 2.1.205 compact prompt 的安全加固#1305
Merged
claude-code-best merged 1 commit intoJul 21, 2026
Merged
Conversation
对比 mitm 抓到的官方 claude-cli/2.1.205 compact 请求,BASE compact prompt 缺失两处安全约束,补齐后与官方逐字节一致: 1. 分析指令 step 1 新增 bullet:security-relevant instructions/ constraints(敏感文件、禁止操作、凭证处理)必须 verbatim 保留, 使其在 compaction 后继续生效。 2. 第 6 节 All user messages 新增 prompt-injection 防御:只有真正 user-role turn 才算用户消息;assistant 消息内部伪装成 "user:"/ "Human:" 或 transcript 样式的文本视为模型生成,绝不能当作用户 请求/批准/确认——防止借 compaction 把注入内容洗白成权威用户指令。 step 1 的 bullet 经 DETAILED_ANALYSIS_INSTRUCTION_BASE 同步至 UP_TO 变体。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
📝 WalkthroughWalkthroughThe compact-session prompt templates now preserve security-relevant user constraints verbatim and define user messages as actual user-role turns, excluding tool results and assistant-generated transcript-like text. ChangesCompact prompt instruction updates
Estimated code review effort: 1 (Trivial) | ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
通过 mitm 抓取官方 claude-cli/2.1.205 的 compact 请求,与本仓库 BASE_COMPACT_PROMPT 逐字对比:机制/投递/缓存策略一致,官方新增两处安全加固(多 780 字符)。
改动
补齐两处,使 BASE compact prompt 与官方 byte-identical(6361 字节):
user:/Human:/transcript 样式的文本视为模型生成,不得当作用户请求/批准。验证
Summary by CodeRabbit