Files
cc-connect/core/redact.go
T
chenhg5andClaude e8e39413e8 refactor(session): add context-aware event sending and secure arg logging
Add context-aware select statements when sending events to prevent blocking on closed channels. Implement secure argument logging using RedactArgs to mask sensitive flags. Add atomic file writes and locks for config safety. Improve session handling with mutex protection and deduplication checks.

generated by llmgit

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-04 12:38:37 +08:00

39 lines
808 B
Go

package core
import "strings"
// RedactArgs returns a copy of args with values after sensitive flag names masked.
// Sensitive flags: --api-key, --api_key, --token, --secret, -k, etc.
func RedactArgs(args []string) []string {
out := make([]string, len(args))
copy(out, args)
sensitiveFlags := []string{
"--api-key", "--api_key", "--apikey",
"--token", "--secret", "--password",
"-k",
}
for i := 0; i < len(out); i++ {
arg := strings.ToLower(out[i])
// --flag=value format
for _, f := range sensitiveFlags {
if strings.HasPrefix(arg, f+"=") {
out[i] = out[i][:strings.Index(out[i], "=")+1] + "***"
break
}
}
// --flag value format
for _, f := range sensitiveFlags {
if arg == f && i+1 < len(out) {
out[i+1] = "***"
i++
break
}
}
}
return out
}