diff --git a/internal/logs/sanitizer.go b/internal/logs/sanitizer.go index 24dacba8d..0c54058a4 100644 --- a/internal/logs/sanitizer.go +++ b/internal/logs/sanitizer.go @@ -38,12 +38,12 @@ func NewSecretSanitizer(core zapcore.Core) *SecretSanitizer { // registerDefaultPatterns registers patterns for common secret formats func (s *SecretSanitizer) registerDefaultPatterns() { - // GitHub tokens (ghp_, gho_, ghu_, ghs_, ghr_) + // GitHub tokens (ghp_, gho_, ghu_, ghs_, ghr_, and fine-grained github_pat_) // Open-ended length ({36,}): the new stateless token format can be ~520 chars, // and an alphanumeric run has no \b boundary mid-token to stop a fixed upper bound. s.patterns = append(s.patterns, &secretPattern{ name: "github_token", - regex: regexp.MustCompile(`\b(gh[poushr]_[A-Za-z0-9]{36,})\b`), + regex: regexp.MustCompile(`\b(gh[poushr]_[A-Za-z0-9]{36,}|github_pat_[A-Za-z0-9]+_[A-Za-z0-9]{30,})\b`), maskFunc: func(token string) string { if len(token) <= 7 { return "****" diff --git a/internal/logs/sanitizer_test.go b/internal/logs/sanitizer_test.go index 15db58ee3..eebd8a4e5 100644 --- a/internal/logs/sanitizer_test.go +++ b/internal/logs/sanitizer_test.go @@ -23,11 +23,12 @@ func TestSanitizer_GitHubTokens(t *testing.T) { }{ {"classic ghp_ (40 chars)", "ghp_1234567890abcdefghijABCDEFGHIJ123456"}, {"installation ghs_ (40 chars)", "ghs_1234567890abcdefghijABCDEFGHIJ123456"}, + {"fine-grained github_pat_", "github_pat_11ABCDEFG0123456789abcd_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { out := s.sanitizeString("token=" + tt.token) - if strings.Contains(out, tt.token) { + if strings.Contains(out, tt.token[12:]) { t.Fatalf("token leaked unmasked: %q", out) } })