mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-28 23:33:13 +00:00
fix(security-audit): harden role scan, startup, probe, and localhost dial
Scan client-injected assistant/tool/model turns, fail closed when config cannot be trusted after startup or stale invalidation, reuse probe tokens only for the same base URL, and restrict localhost dials to loopback addresses. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
0f7f8a317e
commit
df9d9e2e40
9 files changed
+147
-32
No files matched your search
@@ -92,7 +92,10 @@ func extractProtocolSegments(protocol string, document any) []string {
|
||||
}
|
||||
}
|
||||
|
||||
var clientInstructionRoles = []string{"user", "system", "developer"}
|
||||
// clientInstructionRoles are roles a client may freely populate. Attackers can
|
||||
// place jailbreak/PII text in assistant/tool turns, so blocking audit must scan
|
||||
// them too—not only user/system/developer instructions.
|
||||
var clientInstructionRoles = []string{"user", "system", "developer", "assistant", "tool"}
|
||||
|
||||
func extractChatLikeSegments(root map[string]any) []string {
|
||||
if root == nil {
|
||||
@@ -168,7 +171,7 @@ func extractResponses(value any) []string {
|
||||
result = append(result, entry)
|
||||
case map[string]any:
|
||||
role := strings.ToLower(stringValue(entry["role"]))
|
||||
if role != "" && role != "user" && role != "system" && role != "developer" {
|
||||
if role != "" && !isClientInstructionRole(role) {
|
||||
continue
|
||||
}
|
||||
if content, exists := entry["content"]; exists {
|
||||
@@ -183,7 +186,7 @@ func extractResponses(value any) []string {
|
||||
return result
|
||||
case map[string]any:
|
||||
role := strings.ToLower(stringValue(typed["role"]))
|
||||
if role != "" && role != "user" && role != "system" && role != "developer" {
|
||||
if role != "" && !isClientInstructionRole(role) {
|
||||
return nil
|
||||
}
|
||||
return contentTexts(typed["content"])
|
||||
@@ -192,6 +195,15 @@ func extractResponses(value any) []string {
|
||||
}
|
||||
}
|
||||
|
||||
func isClientInstructionRole(role string) bool {
|
||||
switch strings.ToLower(strings.TrimSpace(role)) {
|
||||
case "user", "system", "developer", "assistant", "tool", "model":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func extractGemini(value any) []string {
|
||||
var contents []any
|
||||
switch typed := value.(type) {
|
||||
@@ -209,7 +221,7 @@ func extractGemini(value any) []string {
|
||||
continue
|
||||
}
|
||||
role := strings.ToLower(stringValue(content["role"]))
|
||||
if role != "" && role != "user" {
|
||||
if role != "" && !isClientInstructionRole(role) {
|
||||
continue
|
||||
}
|
||||
parts, _ := content["parts"].([]any)
|
||||
|
||||
Reference in new issue
Block a user