Skip to content

Find, verify, and analyze leaked credentials

Fixes for a few finegrained token issues (#3194)

Dustin Deckerfc4829a387a6
diff --git a/pkg/analyzer/analyzers/github/finegrained/finegrained.go b/pkg/analyzer/analyzers/github/finegrained/finegrained.go
index c71097669..ba5fd6e34 100644
--- a/pkg/analyzer/analyzers/github/finegrained/finegrained.go
+++ b/pkg/analyzer/analyzers/github/finegrained/finegrained.go
@@ -8,7 +8,6 @@ import (
"fmt"
"log"
"os"
- "sort"
"strings"
"github.com/fatih/color"
@@ -428,11 +427,6 @@ func getDependabotAlertsPermission(client *gh.Client, repo *gh.Repository, curre
// Risk: Extremely Low
// GET /repos/{owner}/{repo}/dependabot/alerts
_, resp, err := client.Dependabot.ListRepoAlerts(context.Background(), *repo.Owner.Login, *repo.Name, &gh.ListAlertsOptions{})
- if err != nil {
- if !strings.Contains(err.Error(), "disabled") {
- return NoAccess, err
- }
- }
defer resp.Body.Close()
switch resp.StatusCode {
@@ -1320,14 +1314,14 @@ func PrintFineGrainedToken(cfg *config.Config, info *common.SecretInfo) {
common.PrintGitHubRepos(info.AccessibleRepos)
// Print out the access map
- perms, ok := info.RepoAccessMap.(map[string]Permission)
+ perms, ok := info.RepoAccessMap.([]Permission)
if !ok {
panic("Repo Access Map is not of type Permission")
}
printFineGrainedPermissions(perms, cfg.ShowAll, true)
}
- perms, ok := info.UserAccessMap.(map[string]Permission)
+ perms, ok := info.UserAccessMap.([]Permission)
if !ok {
panic("Repo Access Map is not of type Permission")
}
@@ -1336,31 +1330,23 @@ func PrintFineGrainedToken(cfg *config.Config, info *common.SecretInfo) {
common.PrintGists(info.Gists, cfg.ShowAll)
}
-func printFineGrainedPermissions(accessMap map[string]Permission, showAll bool, repoPermissions bool) {
+func printFineGrainedPermissions(accessMap []Permission, showAll bool, repoPermissions bool) {
permissionCount := 0
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"Permission Type", "Permission" /* Add more column headers if needed */})
- // Extract keys from accessMap into slice
- keys := make([]string, 0, len(accessMap))
- for k := range accessMap {
- keys = append(keys, k)
- }
- // Sort the slice
- sort.Strings(keys)
-
- for _, key := range keys {
- value := accessMap[key]
- if value == Invalid {
+ for _, perm := range accessMap {
+ permStr, _ := perm.ToString()
+ if perm == Invalid {
// don't change permissionCount
} else {
permissionCount++
}
- if !showAll && value == Invalid {
+ if !showAll && perm == Invalid {
continue
} else {
- k, v := permissionFormatter(key, value)
+ k, v := permissionFormatter(permStr, perm)
t.AppendRow([]any{k, v})
}
}