From a79b8e67fcd409168ba0bc3152d69f7937a77b52 Mon Sep 17 00:00:00 2001 From: Rudy Celekli Date: Sun, 25 Oct 2026 11:17:51 -0400 Subject: [PATCH] fix(logs): mask fine-grained github_pat_ tokens The github_token pattern only covered the gh?_ prefixes. Fine-grained personal access tokens (github_pat__), the format GitHub now creates by default, matched nothing in free text and were logged in full. --- internal/logs/sanitizer.go | 4 ++-- internal/logs/sanitizer_test.go | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) 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) } })