Revert "fix(messaging): mask secrets embedded in chat tool arguments"

This reverts commit 89221085d9.
This commit is contained in:
sam committed 2026-10-24 20:56:31 +11:00
1 parent 89221085d9
commit 15a9bcebdf
3 files changed
-21

No files matched your search

@@ -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 {
-2
View File
@@ -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
}
-15
View File
@@ -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)
}