fix(webhookguard): token counts in task logs keep their value; secrets under token keys stay redacted (#1720)
This commit is contained in:
2 files changed
+22
-7
No files matched your search
@@ -70,7 +70,7 @@ func redactValue(value any) any {
|
||||
switch typed := value.(type) {
|
||||
case map[string]any:
|
||||
for key, child := range typed {
|
||||
if sensitiveKey(key) {
|
||||
if sensitiveKey(key) && !tokenCount(key, child) {
|
||||
typed[key] = redactedValue
|
||||
continue
|
||||
}
|
||||
@@ -106,6 +106,14 @@ func sensitiveValueShape(s string) bool {
|
||||
return strings.Contains(s, "-----BEGIN") && strings.Contains(s, "PRIVATE KEY-----")
|
||||
}
|
||||
|
||||
// tokenCount reports a model usage count such as total_tokens: a number under
|
||||
// a "tokens" key is a count, while a numeric value under other sensitive keys
|
||||
// (an OTP, a PIN) is still a secret.
|
||||
func tokenCount(key string, value any) bool {
|
||||
_, number := value.(json.Number)
|
||||
return number && strings.Contains(strings.ToLower(key), "tokens")
|
||||
}
|
||||
|
||||
func sensitiveKey(key string) bool {
|
||||
normalized := strings.NewReplacer("-", "_", " ", "_").Replace(strings.ToLower(key))
|
||||
for _, marker := range SensitiveKeyMarkers {
|
||||
|
||||
Reference in new issue
Block a user