From 15a9bcebdfcb7157703244341a17f6616fbcfbf7 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Sat, 24 Oct 2026 20:56:31 +1100 Subject: [PATCH] Revert "fix(messaging): mask secrets embedded in chat tool arguments" This reverts commit 89221085d949c51b04cc0d9d45cd42d2a9820971. --- internal/domain/messaging/tool_params_test.go | 4 ---- internal/domain/messaging/tool_render.go | 2 -- internal/webhookguard/redact.go | 15 --------------- 3 files changed, 21 deletions(-) diff --git a/internal/domain/messaging/tool_params_test.go b/internal/domain/messaging/tool_params_test.go index cf84af304..dfe0eb4fb 100644 --- a/internal/domain/messaging/tool_params_test.go +++ b/internal/domain/messaging/tool_params_test.go @@ -9,10 +9,6 @@ func TestSummarizeToolParameters(t *testing.T) { {"plain values are shown", `{"command":"git diff --stat"}`, `{"command":"git diff --stat"}`}, {"sensitive keys are redacted", `{"api_key":"sk-1","path":"a.go"}`, `{"api_key":"[redacted]","path":"a.go"}`}, {"nested sensitive keys are redacted", `{"headers":{"Authorization":"Bearer x"}}`, `{"headers":{"Authorization":"[redacted]"}}`}, - {"a bearer token inside a command is masked", `{"command":"curl -H 'Authorization: Bearer abc123' https://x"}`, `{"command":"curl -H '[redacted]' https://x"}`}, - {"a token-shaped value is masked in place", `{"command":"git push https://ghp_abcdefghijklmnopqrstuvwxyz0123@github.com/a/b"}`, `{"command":"git push https://[redacted]@github.com/a/b"}`}, - {"a prefixed key in prose is masked", `{"text":"use sk-abcdefghijklmnopqrstuvwx now"}`, `{"text":"use [redacted] now"}`}, - {"a token flag is masked", `{"command":"tool --token=s3cr3tvalue run"}`, `{"command":"tool [redacted] run"}`}, {"unparseable input is withheld", `not json`, `[unavailable]`}, } for _, tt := range tests { diff --git a/internal/domain/messaging/tool_render.go b/internal/domain/messaging/tool_render.go index 13d14aea6..023cab4ca 100644 --- a/internal/domain/messaging/tool_render.go +++ b/internal/domain/messaging/tool_render.go @@ -284,8 +284,6 @@ func redactToolParameters(value any, sensitive bool) any { typed[i] = redactToolParameters(child, sensitive) } return typed - case string: - return webhookguard.ScrubSecrets(typed) default: return value } diff --git a/internal/webhookguard/redact.go b/internal/webhookguard/redact.go index 83af1c18f..60382ba3a 100644 --- a/internal/webhookguard/redact.go +++ b/internal/webhookguard/redact.go @@ -90,18 +90,3 @@ func sensitiveKey(key string) bool { } return false } - -// embeddedSecretRe matches secrets written inside a longer value, such as a -// token in a shell command: credential-carrying headers and flags, JWTs, PEM -// private keys, and token formats whose prefix marks them as credentials. -var embeddedSecretRe = regexp.MustCompile(`(?i)(?:(?:authorization|x-api-key|x-auth-token|private-token)\s*:\s*(?:bearer\s+|basic\s+|token\s+)?|bearer\s+|--?(?:token|password|api-key)[=\s]+)['"]?[^\s'"]+` + - `|eyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+` + - `|-----BEGIN [A-Z ]*PRIVATE KEY-----[\s\S]*?(?:-----END [A-Z ]*PRIVATE KEY-----|$)` + - `|\b(?:gh[pousr]_[A-Za-z0-9]{20,}|github_pat_[A-Za-z0-9_]{20,}|glpat-[A-Za-z0-9_-]{20,}|sk-[A-Za-z0-9_-]{20,}|xox[abprs]-[A-Za-z0-9-]{10,}|AKIA[0-9A-Z]{16})` + - `|://[^/\s:@]+:[^/\s@]+@`) - -// ScrubSecrets masks every secret-shaped run inside s and leaves the rest, -// so a command stays readable without the credential it carried. -func ScrubSecrets(s string) string { - return embeddedSecretRe.ReplaceAllString(s, redactedValue) -}