Skip to content

Find, verify, and analyze leaked credentials

analyzer/github: include is_fine_grained metadata and make gist enumeration non-fatal (#5332)

Dave Hubbard64d939a56362
diff --git a/pkg/analyzer/analyzers/github/classic/classictoken.go b/pkg/analyzer/analyzers/github/classic/classictoken.go
index 72b451ccc..6afcc5a8e 100644
--- a/pkg/analyzer/analyzers/github/classic/classictoken.go
+++ b/pkg/analyzer/analyzers/github/classic/classictoken.go
@@ -95,9 +95,11 @@ func AnalyzeClassicToken(client *gh.Client, meta *common.TokenMetadata) (*common
}
}
+ // Gist enumeration is supplemental -- a rate-limit or transient failure
+ // should not discard the already-gathered metadata, repos, and permissions.
gists, err := common.GetAllGistsForUser(client)
if err != nil {
- return nil, fmt.Errorf("enumerating gists for classic PAT: %w", err)
+ gists = nil
}
return &common.SecretInfo{
diff --git a/pkg/analyzer/analyzers/github/finegrained/finegrained.go b/pkg/analyzer/analyzers/github/finegrained/finegrained.go
index d5588172e..43289f1b7 100644
--- a/pkg/analyzer/analyzers/github/finegrained/finegrained.go
+++ b/pkg/analyzer/analyzers/github/finegrained/finegrained.go
@@ -1447,9 +1447,11 @@ func AnalyzeFineGrainedToken(client *gh.Client, meta *common.TokenMetadata, shal
return nil, err
}
+ // Gist enumeration is supplemental -- a rate-limit or transient failure
+ // should not discard the already-gathered metadata, repos, and permissions.
allGists, err := common.GetAllGistsForUser(client)
if err != nil {
- return nil, err
+ allGists = nil
}
accessibleRepos := make([]*gh.Repository, 0)
for _, repo := range allRepos {
diff --git a/pkg/analyzer/analyzers/github/github.go b/pkg/analyzer/analyzers/github/github.go
index 315384c05..32954582d 100644
--- a/pkg/analyzer/analyzers/github/github.go
+++ b/pkg/analyzer/analyzers/github/github.go
@@ -50,9 +50,10 @@ func secretInfoToAnalyzerResult(info *common.SecretInfo) *analyzers.AnalyzerResu
result := &analyzers.AnalyzerResult{
AnalyzerType: analyzers.AnalyzerTypeGitHub,
Metadata: map[string]any{
- "owner": info.Metadata.User.Login,
- "type": info.Metadata.Type,
- "expiration": info.Metadata.Expiration,
+ "owner": info.Metadata.User.Login,
+ "type": info.Metadata.Type,
+ "expiration": info.Metadata.Expiration,
+ "is_fine_grained": info.Metadata.FineGrained,
},
}
result.Bindings = append(result.Bindings, secretInfoToUserBindings(info)...)
diff --git a/pkg/analyzer/analyzers/github/github_test.go b/pkg/analyzer/analyzers/github/github_test.go
index f086b4717..2016b4234 100644
--- a/pkg/analyzer/analyzers/github/github_test.go
+++ b/pkg/analyzer/analyzers/github/github_test.go
@@ -432,7 +432,8 @@ func TestAnalyzer_Analyze(t *testing.T) {
"Metadata": {
"owner": "sirdetectsalot",
"expiration": "2026-03-24T15:27:38+05:00",
- "type": "Fine-Grained GitHub Personal Access Token"
+ "type": "Fine-Grained GitHub Personal Access Token",
+ "is_fine_grained": true
}
}`,
},
@@ -480,7 +481,8 @@ func TestAnalyzer_Analyze(t *testing.T) {
"Metadata": {
"owner": "truffle-sandbox",
"expiration": "0001-01-01T00:00:00Z",
- "type": "Classic GitHub Personal Access Token"
+ "type": "Classic GitHub Personal Access Token",
+ "is_fine_grained": false
}
}`,
wantErr: false,