diff --git a/internal/gateway/stream.go b/internal/gateway/stream.go index db499a170..19a5579d6 100644 --- a/internal/gateway/stream.go +++ b/internal/gateway/stream.go @@ -4,6 +4,8 @@ import ( "encoding/json" "fmt" "strings" + + "github.com/samcharles93/archie-core/internal/webhookguard" ) // toolSummaryMaxRunes bounds a rendered tool summary. Tool output is @@ -190,13 +192,7 @@ func redactToolParameters(value any, sensitive bool) any { func sensitiveParameterKey(key string) bool { normalized := strings.NewReplacer("-", "_", " ", "_").Replace(strings.ToLower(key)) - for _, marker := range []string{ - "token", "secret", "password", "passwd", "pwd", "passphrase", - "api_key", "apikey", "api_secret", "client_secret", "private_key", "secret_key", - "signing_key", "authorization", "bearer", "credential", "cookie", "session", - "access_token", "refresh_token", "id_token", "bot_token", "webhook_secret", - "x_api_key", "x_auth_token", "jwt", "oauth", "csrf", "otp", "signature", - } { + for _, marker := range webhookguard.SensitiveKeyMarkers { if strings.Contains(normalized, marker) { return true } diff --git a/internal/gateway/stream_test.go b/internal/gateway/stream_test.go index c2ba90c72..d90bec757 100644 --- a/internal/gateway/stream_test.go +++ b/internal/gateway/stream_test.go @@ -1,10 +1,35 @@ package gateway import ( + "encoding/json" "strings" "testing" + + "github.com/samcharles93/archie-core/internal/webhookguard" ) +func TestRedactionConsumersShareMarkerSet(t *testing.T) { + if len(webhookguard.SensitiveKeyMarkers) == 0 { + t.Fatal("webhookguard.SensitiveKeyMarkers is empty, want a non-empty shared set") + } + for _, marker := range webhookguard.SensitiveKeyMarkers { + if !sensitiveParameterKey(marker) { + t.Errorf("sensitiveParameterKey(%q) = false, want true (shared marker set)", marker) + } + payload, err := json.Marshal(map[string]string{marker: "secret"}) + if err != nil { + t.Fatal(err) + } + got, err := webhookguard.RedactPayload(payload) + if err != nil { + t.Fatalf("RedactPayload(%q): %v", marker, err) + } + if string(got) == string(payload) { + t.Errorf("webhookguard did not redact shared marker key %q", marker) + } + } +} + func TestSummarizeToolParameters(t *testing.T) { tests := []struct { name string diff --git a/internal/webhookguard/redact.go b/internal/webhookguard/redact.go index c90710852..4146f111e 100644 --- a/internal/webhookguard/redact.go +++ b/internal/webhookguard/redact.go @@ -10,14 +10,15 @@ import ( // redactedValue replaces a value whose key (or shape) looks sensitive. const redactedValue = "[redacted]" -// sensitiveKeyMarkers is the key-name heuristic, matching -// internal/gateway/stream.go's sensitiveParameterKey exactly so the two -// redaction paths agree on what counts as sensitive. It is intentionally +// SensitiveKeyMarkers is the key-name heuristic shared by both redaction +// paths -- webhook-capture redaction here and chat-transcript +// summarization in internal/gateway/stream.go's sensitiveParameterKey -- +// so they agree on what counts as sensitive. It is intentionally // conservative: a value whose key matches is redacted wholesale, so a marker // that is too broad (e.g. bare "key" or "auth", which would match "Key: 42" // or "author") would destroy the schema-by-example mapping use case the // captured payload exists to serve. -var sensitiveKeyMarkers = []string{ +var SensitiveKeyMarkers = []string{ "token", "secret", "password", "passwd", "pwd", "passphrase", "api_key", "apikey", "api_secret", "client_secret", "private_key", "secret_key", "signing_key", "authorization", "bearer", "credential", "cookie", "session", @@ -107,7 +108,7 @@ func sensitiveValueShape(s string) bool { func sensitiveKey(key string) bool { normalized := strings.NewReplacer("-", "_", " ", "_").Replace(strings.ToLower(key)) - for _, marker := range sensitiveKeyMarkers { + for _, marker := range SensitiveKeyMarkers { if strings.Contains(normalized, marker) { return true }