Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/logs/sanitizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 "****"
Expand Down
3 changes: 2 additions & 1 deletion internal/logs/sanitizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
Expand Down
Loading