fix(webhookguard): token counts in task logs keep their value; secrets under token keys stay redacted (#1720)

This commit is contained in:
sam committed 2026-11-14 23:42:46 +11:00
1 parent 14e2474a49
commit e78cb1e63e
2 files changed
+22 -7

No files matched your search

+13 -6
View File
@@ -8,7 +8,8 @@ import (
)
// TestTaskRegistryWriteRedactsSecrets guards task log lines shipped by the
// agent being stored with secret-shaped values intact (#1720).
// agent being stored with secret-shaped values intact (#1720), and numeric
// fields such as token counts being redacted for their name.
func TestTaskRegistryWriteRedactsSecrets(t *testing.T) {
const (
jwt = "eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJmYWtlIn0.fake-signature-value" //nolint:gosec // fake JWT fixture for the redaction test
@@ -19,12 +20,15 @@ func TestTaskRegistryWriteRedactsSecrets(t *testing.T) {
name string
entry Entry
leak string
keep string
}{
{"jwt in message", Entry{Message: "calling api with " + jwt + " now"}, jwt},
{"pem in message", Entry{Message: "loaded " + pem + " ok"}, "FAKEKEYMATERIAL"},
{"sensitive field key", Entry{Message: "m", Fields: map[string]any{"api_key": pw}}, pw},
{"nested sensitive key", Entry{Message: "m", Fields: map[string]any{"req": map[string]any{"password": pw}}}, pw},
{"jwt in field value", Entry{Message: "m", Fields: map[string]any{"detail": "got " + jwt}}, jwt},
{"jwt in message", Entry{Message: "calling api with " + jwt + " now"}, jwt, ""},
{"pem in message", Entry{Message: "loaded " + pem + " ok"}, "FAKEKEYMATERIAL", ""},
{"sensitive field key", Entry{Message: "m", Fields: map[string]any{"api_key": pw}}, pw, ""},
{"nested sensitive key", Entry{Message: "m", Fields: map[string]any{"req": map[string]any{"password": pw}}}, pw, ""},
{"jwt in field value", Entry{Message: "m", Fields: map[string]any{"detail": "got " + jwt}}, jwt, ""},
{"numeric otp redacted", Entry{Message: "m", Fields: map[string]any{"otp": 482913}}, "482913", ""},
{"token count kept, token string redacted", Entry{Message: "m", Fields: map[string]any{"total_tokens": 1234, "token": pw}}, pw, `"total_tokens":1234`},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -45,6 +49,9 @@ func TestTaskRegistryWriteRedactsSecrets(t *testing.T) {
if strings.Contains(string(data), tt.leak) {
t.Fatalf("log file holds secret %q: %s", tt.leak, data)
}
if tt.keep != "" && !strings.Contains(string(data), tt.keep) {
t.Fatalf("log file lost %q: %s", tt.keep, data)
}
})
}
}