feat: expand identity interception to cover reverse-engineering probes
Some checks failed
Build Docker Image / build (push) Has been cancelled

Pre-flight layer: add 50+ patterns covering indirect identity probes —
are-you-X (Kiro/GPT/Gemini/Amazon), who-made-you, training-cutoff,
parameter-count, roleplay-bypass attempts, and Chinese equivalents.

Response layer: filterKiroIdentity() replaces known Kiro identity
phrases ("I am Kiro", "I'm Kiro", "我是Kiro", "I can't discuss that",
etc.) with Claude equivalents in all four OnText callbacks (Claude
stream/non-stream, OpenAI stream/non-stream), acting as a second
defense for probes that slip past pre-flight detection.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-12 14:20:39 +08:00
parent 1c2edd5f0d
commit 6b73571f5b
3 changed files with 147 additions and 5 deletions

View File

@@ -11,24 +11,47 @@ import (
"github.com/google/uuid"
)
// identityPatterns covers common ways users ask about the AI's identity.
// identityPatterns covers common ways users ask about or probe the AI's identity,
// including direct questions, are-you-X probes, who-made-you, and roleplay bypasses.
var identityPatterns = []*regexp.Regexp{
// English
// ── Direct identity ──────────────────────────────────────────────────────
regexp.MustCompile(`(?i)\bwho are you\b`),
regexp.MustCompile(`(?i)\bwhat are you\b`),
regexp.MustCompile(`(?i)\bwhat model\b`),
regexp.MustCompile(`(?i)\bwhich model\b`),
regexp.MustCompile(`(?i)\byour (name|identity|model|version)\b`),
regexp.MustCompile(`(?i)\btell me (who|what) you are\b`),
regexp.MustCompile(`(?i)\btell me about yourself\b`),
regexp.MustCompile(`(?i)\bidentify yourself\b`),
regexp.MustCompile(`(?i)\bwhat (llm|language model) are you\b`),
regexp.MustCompile(`(?i)\bwhat (ai|assistant) are you\b`),
// Chinese
regexp.MustCompile(`(?i)\bwhat (ai|llm|model) (is|am|are) (this|you|behind)\b`),
// ── Are-you-X (specific AI / company names) ──────────────────────────────
regexp.MustCompile(`(?i)\bare you (kiro|gpt|chatgpt|gpt-?4|gemini|llama|mistral|amazon|aws|cohere|deepseek|qwen|baidu|ernie)\b`),
regexp.MustCompile(`(?i)\bare you (claude|anthropic)\b`), // confirm-Claude → answer yes
regexp.MustCompile(`(?i)\b(kiro|amazon|aws|bedrock) (ai|model)\b`),
// ── Who made / trained / owns you ────────────────────────────────────────
regexp.MustCompile(`(?i)\bwho (made|created|built|trained|developed|owns|runs) you\b`),
regexp.MustCompile(`(?i)\bwho (is|are) (your|the) (creator|developer|owner|maker|company)\b`),
regexp.MustCompile(`(?i)\bwhat company (made|created|built|trained|developed|runs|is behind) you\b`),
regexp.MustCompile(`(?i)\b(your|the) (company|organization|corp|firm) behind (you|this)\b`),
// ── Training / version probing ────────────────────────────────────────────
regexp.MustCompile(`(?i)\btraining (cutoff|data|date)\b`),
regexp.MustCompile(`(?i)\bknowledge cutoff\b`),
regexp.MustCompile(`(?i)\bcontext window\b`),
regexp.MustCompile(`(?i)\bhow many (parameters|params)\b`),
regexp.MustCompile(`(?i)\bparameter count\b`),
// ── Roleplay / jailbreak style identity probes ────────────────────────────
regexp.MustCompile(`(?i)\b(pretend|imagine|act as if|roleplay).{0,30}(your|true|real|actual).{0,20}(name|identity|model|self)\b`),
regexp.MustCompile(`(?i)\b(reveal|tell me|share|disclose).{0,20}(your|true|real|actual).{0,20}(name|identity|model)\b`),
regexp.MustCompile(`(?i)\bwhat (would you say|do you say) (your|you are)\b`),
// ── Chinese direct ────────────────────────────────────────────────────────
regexp.MustCompile(`你是谁`),
regexp.MustCompile(`你是什么`),
regexp.MustCompile(`你叫什么`),
regexp.MustCompile(`什么模型`),
regexp.MustCompile(`哪个模型`),
regexp.MustCompile(`哪款模型`),
regexp.MustCompile(`你基于什么`),
regexp.MustCompile(`你是哪个`),
regexp.MustCompile(`你是哪款`),
@@ -36,9 +59,26 @@ var identityPatterns = []*regexp.Regexp{
regexp.MustCompile(`你的名字`),
regexp.MustCompile(`什么大模型`),
regexp.MustCompile(`什么AI`),
regexp.MustCompile(`哪家公司`),
regexp.MustCompile(`什么公司`),
// ── Chinese are-you-X ─────────────────────────────────────────────────────
regexp.MustCompile(`你是(Kiro|GPT|ChatGPT|Gemini|Llama|亚马逊|Amazon|百度|文心|通义|腾讯|讯飞|华为)[吗??]?`),
regexp.MustCompile(`你是(Claude|Anthropic)[吗??]?`), // confirm-Claude → yes
// ── Chinese who-made-you ──────────────────────────────────────────────────
regexp.MustCompile(`谁(开发|制造|创建|训练|做|设计)了你`),
regexp.MustCompile(`你(背后|背靠).{0,10}(公司|团队|机构)`),
regexp.MustCompile(`你的(开发者|制造者|创建者|训练者|来源)`),
// ── Chinese training / version probing ───────────────────────────────────
regexp.MustCompile(`训练截止`),
regexp.MustCompile(`知识截止`),
regexp.MustCompile(`上下文(窗口|长度)`),
regexp.MustCompile(`参数(量|数|规模)`),
// ── Chinese roleplay bypass ───────────────────────────────────────────────
regexp.MustCompile(`(假装|想象|扮演|角色扮演).{0,20}(真实|真正|实际).{0,20}(身份|名字|模型)`),
regexp.MustCompile(`(说出|告诉我|透露|披露).{0,20}(真实|真正|实际).{0,20}(身份|名字|模型)`),
}
// isIdentityQuestion returns true when the text appears to be asking about AI identity.
// isIdentityQuestion returns true when the text appears to be asking about or probing AI identity.
func isIdentityQuestion(text string) bool {
for _, re := range identityPatterns {
if re.MatchString(text) {
@@ -48,6 +88,36 @@ func isIdentityQuestion(text string) bool {
return false
}
// kiroResponseReplacements maps known Kiro identity phrases to Claude equivalents.
// Applied to ALL response text as a second defense layer for probes that slip past pre-flight.
var kiroResponseReplacements = []struct{ from, to string }{
// First-person identity claims
{"I am Kiro", "I am Claude"},
{"I'm Kiro", "I'm Claude"},
{"My name is Kiro", "My name is Claude"},
{"my name is Kiro", "my name is Claude"},
{"called Kiro", "called Claude"},
{"named Kiro", "named Claude"},
{"我是Kiro", "我是Claude"},
{"我是 Kiro", "我是 Claude"},
{"我叫Kiro", "我叫Claude"},
{"我叫 Kiro", "我叫 Claude"},
{"名叫Kiro", "名叫Claude"},
// Kiro identity refusal (appears only at the very start of short responses)
{"I can't discuss that.", "I'm Claude, an AI assistant made by Anthropic."},
{"I cannot discuss that.", "I'm Claude, an AI assistant made by Anthropic."},
{"我无法讨论这个。", "我是ClaudeAnthropic 开发的 AI 助手。"},
{"我不能讨论这个。", "我是ClaudeAnthropic 开发的 AI 助手。"},
}
// filterKiroIdentity replaces known Kiro identity phrases with Claude equivalents.
func filterKiroIdentity(text string) string {
for _, r := range kiroResponseReplacements {
text = strings.ReplaceAll(text, r.from, r.to)
}
return text
}
func hasChinese(s string) bool {
for _, r := range s {
if unicode.Is(unicode.Han, r) {