fix(ai): prevent customer iccid disclosure
This commit is contained in:
@@ -62,6 +62,26 @@ func TestReplyCommitRejectsSensitiveModelOutput(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestReplyCommitRedactsICCIDBeforePersisting(t *testing.T) {
|
||||
db := setupReplyCommitTestDB(t)
|
||||
aiAgent := createReplyCommitTestAIAgent(t, db)
|
||||
conversation := createReplyCommitTestConversation(t, db, aiAgent.ID)
|
||||
replyMessage, err := newReplyCommitService().CommitAIReply(replyCommitInput{
|
||||
Conversation: *conversation, Message: models.Message{ID: 104, RequestID: "trace-104"}, AIAgent: *aiAgent,
|
||||
ReplyText: "业务状态:正常\nICCID:8986042302268012345", ClientPrefix: "ai_reply",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("CommitAIReply() error = %v", err)
|
||||
}
|
||||
var stored models.Message
|
||||
if err := db.First(&stored, replyMessage.ID).Error; err != nil {
|
||||
t.Fatalf("find reply message: %v", err)
|
||||
}
|
||||
if strings.Contains(stored.Content, "8986042302268012345") || !strings.Contains(stored.Content, "系统内部标识") {
|
||||
t.Fatalf("ICCID was persisted in customer reply: %q", stored.Content)
|
||||
}
|
||||
}
|
||||
|
||||
func TestFailureReplyDeduplicatesByDeterministicClientMessageID(t *testing.T) {
|
||||
db := setupReplyCommitTestDB(t)
|
||||
aiAgent := createReplyCommitTestAIAgent(t, db)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"code.tczkiot.com/wlw/ai-agent/contract"
|
||||
applicationruntime "code.tczkiot.com/wlw/ai-agent/internal/ai/application/runtime"
|
||||
aitooling "code.tczkiot.com/wlw/ai-agent/internal/ai/tooling"
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/models"
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/enums"
|
||||
"code.tczkiot.com/wlw/ai-agent/internal/pkg/tracex"
|
||||
@@ -382,7 +383,7 @@ func (s *aiReplyService) sendBusinessIdentityMenu(ctx context.Context, replyCtx
|
||||
var builder strings.Builder
|
||||
builder.WriteString("已识别")
|
||||
builder.WriteString(objectLabel)
|
||||
if identifier := strings.TrimSpace(replyCtx.Conversation.CustomerExternalID); identifier != "" {
|
||||
if identifier := strings.TrimSpace(replyCtx.Conversation.CustomerExternalID); identifier != "" && !aitooling.ContainsRestrictedICCID(identifier) {
|
||||
builder.WriteString(":")
|
||||
builder.WriteString(identifier)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user