diff --git a/internal/redact/redact.go b/internal/redact/redact.go index 31b6ef334..6d8101b88 100644 --- a/internal/redact/redact.go +++ b/internal/redact/redact.go @@ -404,11 +404,17 @@ func inUserinfo(s string, a int) bool { // (cnbc.com/…/sk-hynix-third-quarter-profit.html), which went to the model // as a key. A key's characters are random: it has a capital, or a run of // 16 or more with no hyphen (DeepSeek's sk- and 32 hex digits, OpenRouter's -// sk-or-v1- and 64). +// sk-or-v1- and 64), or hex digits alone, as a UUID's groups (sk- and a +// UUID in lower case) are, which no word but a few like "face" is. func notASlug(v string) bool { if strings.ContainsFunc(v, func(r rune) bool { return r >= 'A' && r <= 'Z' }) { return true } + if !strings.ContainsFunc(strings.TrimPrefix(v, "sk-"), func(r rune) bool { + return r != '-' && r != '_' && (r < '0' || r > '9') && (r < 'a' || r > 'f') + }) { + return true + } for _, w := range strings.FieldsFunc(v, func(r rune) bool { return r == '-' || r == '_' }) { if len(w) >= 16 { return true diff --git a/internal/redact/slug_test.go b/internal/redact/slug_test.go index 1c495a5aa..b67375d3a 100644 --- a/internal/redact/slug_test.go +++ b/internal/redact/slug_test.go @@ -26,6 +26,7 @@ func TestSlugIsNoKey(t *testing.T) { "sk-" + strings.Repeat("0123456789abcdef", 2), "sk-or-v1-" + strings.Repeat("0123456789abcdef", 4), // built, as a literal one stops GitHub's push "sk-ant-api03-Ab3dE-fGh1_jKl2mN-oPq3rSt4", + "sk-" + "1f0e3dad-9990-4b5c-8a1b-2c3d4e5f6a7b", // a UUID in lower case: no capital, no run of 16 } { in := "url sk-hynix-third-quarter-profit key " + key out, n := Mask(in, o)