Skip to content

Find, verify, and analyze leaked credentials

Improve finegrained token support (#3179)

Dustin Decker29de521ed0ba
diff --git a/pkg/analyzer/analyzers/github/common/github.go b/pkg/analyzer/analyzers/github/common/github.go
index 77727a229..eaaf40dd3 100644
--- a/pkg/analyzer/analyzers/github/common/github.go
+++ b/pkg/analyzer/analyzers/github/common/github.go
@@ -14,31 +14,40 @@ import (
"github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers"
)
-func checkFineGrained(token string, oauthScopes []analyzers.Permission) (string, bool) {
+type TokenType string
+
+const (
+ TokenTypeFineGrainedPAT TokenType = "Fine-Grained GitHub Personal Access Token"
+ TokenTypeClassicPAT TokenType = "Classic GitHub Personal Access Token"
+ TokenTypeUserToServer TokenType = "GitHub User-to-Server Token"
+ TokenTypeGitHubToken TokenType = "GitHub Token"
+)
+
+func checkFineGrained(token string, oauthScopes []analyzers.Permission) (TokenType, bool) {
// For details on token prefixes, see:
// https://github.blog/2021-04-05-behind-githubs-new-authentication-token-formats/
// Special case for ghu_ prefix tokens (ex: in a codespace) that don't have the X-OAuth-Scopes header
if strings.HasPrefix(token, "ghu_") {
- return "GitHub User-to-Server Token", true
+ return TokenTypeUserToServer, true
}
// Handle github_pat_ tokens
if strings.HasPrefix(token, "github_pat") {
- return "Fine-Grained GitHub Personal Access Token", true
+ return TokenTypeFineGrainedPAT, true
}
// Handle classic PATs
if strings.HasPrefix(token, "ghp_") {
- return "Classic GitHub Personal Access Token", false
+ return TokenTypeClassicPAT, false
}
// Catch-all for any other types
// If resp.Header "X-OAuth-Scopes" doesn't exist, then we have fine-grained permissions
if len(oauthScopes) > 0 {
- return "GitHub Token", false
+ return TokenTypeGitHubToken, false
}
- return "GitHub Token", true
+ return TokenTypeGitHubToken, true
}
type Permission int
@@ -55,7 +64,7 @@ type SecretInfo struct {
}
type TokenMetadata struct {
- Type string
+ Type TokenType
FineGrained bool
User *gh.User
Expiration time.Time
diff --git a/pkg/analyzer/analyzers/github/finegrained/finegrained.go b/pkg/analyzer/analyzers/github/finegrained/finegrained.go
index c663a0c7a..c71097669 100644
--- a/pkg/analyzer/analyzers/github/finegrained/finegrained.go
+++ b/pkg/analyzer/analyzers/github/finegrained/finegrained.go
@@ -6,7 +6,6 @@ import (
"context"
"errors"
"fmt"
- "io"
"log"
"os"
"sort"
@@ -108,12 +107,12 @@ func permissionFormatter(key, val any) (string, string) {
}
func notImplementedRepoPerm(client *gh.Client, repo *gh.Repository, currentAccess string) (Permission, error) {
- return Invalid, ErrInvalid
+ return NoAccess, nil
}
// notImplementedAcctPerm is a placeholder function that returns a "NOT_IMPLEMENTED" status when a GitHub account permission is not yet implemented.
func notImplementedAcctPerm(client *gh.Client, user *gh.User) (Permission, error) {
- return Invalid, ErrInvalid
+ return NoAccess, nil
}
func getMetadataPermission(client *gh.Client, repo *gh.Repository, currentAccess string) (Permission, error) {
@@ -122,7 +121,7 @@ func getMetadataPermission(client *gh.Client, repo *gh.Repository, currentAccess
_, resp, err := client.Repositories.ListCollaborators(context.Background(), *repo.Owner.Login, *repo.Name, nil)
if err != nil {
if resp.StatusCode == 403 {
- return Invalid, ErrInvalid
+ return NoAccess, nil
}
return Invalid, err
}
@@ -138,7 +137,7 @@ func getActionsPermission(client *gh.Client, repo *gh.Repository, currentAccess
_, resp, err := client.Actions.ListArtifacts(context.Background(), *repo.Owner.Login, *repo.Name, nil)
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -163,7 +162,7 @@ func getActionsPermission(client *gh.Client, repo *gh.Repository, currentAccess
} else {
// Will only land here if already tested one public repo and got a 403.
if currentAccess == "UNKNOWN" {
- return Invalid, ErrInvalid
+ return NoAccess, nil
}
// Risk: Very, very low.
// -> Unless the user has a workflow file named (see RANDOM_STRING above), this will always return 404 for users with READ_WRITE permissions.
@@ -171,7 +170,7 @@ func getActionsPermission(client *gh.Client, repo *gh.Repository, currentAccess
resp, err := client.Actions.CreateWorkflowDispatchEventByFileName(context.Background(), *repo.Owner.Login, *repo.Name, RANDOM_STRING, gh.CreateWorkflowDispatchEventRequest{})
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 404:
return ActionsWrite, nil
case 200:
@@ -191,7 +190,7 @@ func getAdministrationPermission(client *gh.Client, repo *gh.Repository, current
_, resp, err := client.Repositories.GetActionsPermissions(context.Background(), *repo.Owner.Login, *repo.Name)
switch resp.StatusCode {
case 403, 404:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -219,24 +218,11 @@ func getCodeScanningAlertsPermission(client *gh.Client, repo *gh.Repository, cur
// Risk: Extremely Low
// -> GET request to /repos/{owner}/{repo}/code-scanning/alerts
_, resp, err := client.CodeScanning.ListAlertsForRepo(context.Background(), *repo.Owner.Login, *repo.Name, nil)
- if err != nil {
- return Invalid, err
- }
defer resp.Body.Close()
- bodyBytes, err := io.ReadAll(resp.Body)
- if err != nil {
- log.Fatal(err)
- }
- body := string(bodyBytes)
-
- if strings.Contains(body, "Code scanning is not enabled for this repository") {
- return Invalid, errors.New("code scanning is not enabled")
- }
-
switch {
case resp.StatusCode == 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case resp.StatusCode == 404:
break
case resp.StatusCode >= 200 && resp.StatusCode <= 299:
@@ -268,7 +254,7 @@ func getCodespacesPermission(client *gh.Client, repo *gh.Repository, currentAcce
_, resp, err := client.Codespaces.ListInRepo(context.Background(), *repo.Owner.Login, *repo.Name, nil)
switch resp.StatusCode {
case 403, 404:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -304,7 +290,7 @@ func getCodespacesMetadataPermission(client *gh.Client, repo *gh.Repository, cur
resp, err := client.Do(context.Background(), req, nil)
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
return CodespacesMetadataRead, nil
default:
@@ -318,7 +304,7 @@ func getCodespacesSecretsPermission(client *gh.Client, repo *gh.Repository, curr
_, resp, err := client.Codespaces.GetRepoSecret(context.Background(), *repo.Owner.Login, *repo.Name, RANDOM_STRING)
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 404:
return CodespacesSecretsWrite, nil
case 200:
@@ -339,7 +325,7 @@ func getCommitStatusesPermission(client *gh.Client, repo *gh.Repository, current
_, resp, err := client.Repositories.ListStatuses(context.Background(), *repo.Owner.Login, *repo.Name, RANDOM_STRING, nil)
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 404:
break
default:
@@ -362,7 +348,7 @@ func getCommitStatusesPermission(client *gh.Client, repo *gh.Repository, current
} else {
// Will only land here if already tested one public repo and got a 403.
if currentAccess == "UNKNOWN" {
- return Invalid, ErrInvalid
+ return NoAccess, nil
}
// Risk: Extremely Low
// -> We're POSTing a commit status to a commit that cannot exist. This should always return 422 if valid access.
@@ -371,7 +357,7 @@ func getCommitStatusesPermission(client *gh.Client, repo *gh.Repository, current
switch resp.StatusCode {
case 403:
// All we know is we don't have READ_WRITE
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 422:
return CommitStatusesWrite, nil
default:
@@ -391,7 +377,7 @@ func getContentsPermission(client *gh.Client, repo *gh.Repository, currentAccess
_, resp, err := client.Repositories.ListCommits(context.Background(), *repo.Owner.Login, *repo.Name, &gh.CommitsListOptions{})
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
case 409:
@@ -419,7 +405,7 @@ func getContentsPermission(client *gh.Client, repo *gh.Repository, currentAccess
} else {
// Will only land here if already tested one public repo and got a 403.
if currentAccess == "UNKNOWN" {
- return Invalid, ErrInvalid
+ return NoAccess, nil
}
// Risk: Low-Medium
// -> We're creating a file with an invalid payload. Worst case is a file with a random string and no content is created. But this should never happen.
@@ -427,10 +413,9 @@ func getContentsPermission(client *gh.Client, repo *gh.Repository, currentAccess
_, resp, err := client.Repositories.CreateFile(context.Background(), *repo.Owner.Login, *repo.Name, RANDOM_STRING, &gh.RepositoryContentFileOptions{})
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
- log.Fatal("This should never happen. We are creating a file with an invalid payload.")
- return ContentsWrite, nil
+ panic("This should never happen. We are creating a file with an invalid payload.")
case 400, 422:
return ContentsWrite, nil
default:
@@ -443,20 +428,16 @@ 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{})
- switch resp.StatusCode {
- case 403:
- defer resp.Body.Close()
-
- bodyBytes, err := io.ReadAll(resp.Body)
- if err != nil {
- log.Fatal(err)
+ if err != nil {
+ if !strings.Contains(err.Error(), "disabled") {
+ return NoAccess, err
}
- body := string(bodyBytes)
+ }
+ defer resp.Body.Close()
- if strings.Contains(body, "Dependabot alerts are disabled for this repository.") {
- return Invalid, errors.New("dependabot alerts are disabled")
- }
- return Invalid, ErrInvalid
+ switch resp.StatusCode {
+ case 403:
+ return NoAccess, nil
case 200:
break
default:
@@ -484,7 +465,7 @@ func getDependabotSecretsPermission(client *gh.Client, repo *gh.Repository, curr
_, resp, err := client.Dependabot.ListRepoSecrets(context.Background(), *repo.Owner.Login, *repo.Name, &gh.ListOptions{})
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -514,7 +495,7 @@ func getDeploymentsPermission(client *gh.Client, repo *gh.Repository, currentAcc
_, resp, err := client.Repositories.ListDeployments(context.Background(), *repo.Owner.Login, *repo.Name, &gh.DeploymentsListOptions{})
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -543,29 +524,29 @@ func getEnvironmentsPermission(client *gh.Client, repo *gh.Repository, currentAc
// GET /repos/{owner}/{repo}/environments
envResp, resp, _ := client.Repositories.ListEnvironments(context.Background(), *repo.Owner.Login, *repo.Name, &gh.EnvironmentListOptions{})
if resp.StatusCode != 200 {
- return Invalid, errors.New("unknown status code")
+ return NoAccess, nil
}
// If no environments exist, then we return UNKNOWN
if len(envResp.Environments) == 0 {
- return Invalid, errors.New("no environments found")
+ return NoAccess, nil
}
// Risk: Extremely Low
// GET /repositories/{repository_id}/environments/{environment_name}/variables
- _, resp, err := client.Actions.ListEnvVariables(context.Background(), *repo.Owner.Login, *repo.Name, *envResp.Environments[0].Name, &gh.ListOptions{})
+ _, resp, _ = client.Actions.ListEnvVariables(context.Background(), *repo.Owner.Login, *repo.Name, *envResp.Environments[0].Name, &gh.ListOptions{})
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
- return Invalid, err
+ return Invalid, nil
}
// Risk: Very Low
// -> We're updating an environment variable with an invalid payload. Even if we did, the name would be (see RANDOM_STRING above) and the value would be nil.
// PATCH /repositories/{repository_id}/environments/{environment_name}/variables/{variable_name}
- resp, err = client.Actions.UpdateEnvVariable(context.Background(), *repo.Owner.Login, *repo.Name, *envResp.Environments[0].Name, &gh.ActionsVariable{Name: RANDOM_STRING})
+ resp, err := client.Actions.UpdateEnvVariable(context.Background(), *repo.Owner.Login, *repo.Name, *envResp.Environments[0].Name, &gh.ActionsVariable{Name: RANDOM_STRING})
switch resp.StatusCode {
case 403:
return EnvironmentsRead, nil
@@ -588,7 +569,7 @@ func getIssuesPermission(client *gh.Client, repo *gh.Repository, currentAccess s
_, resp, err := client.Issues.ListByRepo(context.Background(), *repo.Owner.Login, *repo.Name, &gh.IssueListByRepoOptions{})
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200, 301:
break
default:
@@ -613,7 +594,7 @@ func getIssuesPermission(client *gh.Client, repo *gh.Repository, currentAccess s
} else {
// Will only land here if already tested one public repo and got a 403.
if currentAccess == "UNKNOWN" {
- return Invalid, ErrInvalid
+ return NoAccess, nil
}
// Risk: Very Low
// -> We're editing an issue label that does not exist. Even if we did, the name would be (see RANDOM_STRING above).
@@ -621,7 +602,7 @@ func getIssuesPermission(client *gh.Client, repo *gh.Repository, currentAccess s
_, resp, err := client.Issues.EditLabel(context.Background(), *repo.Owner.Login, *repo.Name, RANDOM_STRING, &gh.Label{})
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 404:
return IssuesWrite, nil
case 200:
@@ -640,7 +621,7 @@ func getPagesPermission(client *gh.Client, repo *gh.Repository, currentAccess st
_, resp, err := client.Repositories.GetPagesInfo(context.Background(), *repo.Owner.Login, *repo.Name)
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200, 404:
break
default:
@@ -669,7 +650,7 @@ func getPagesPermission(client *gh.Client, repo *gh.Repository, currentAccess st
} else {
// Will only land here if already tested one public repo and got a 403.
if currentAccess == "UNKNOWN" {
- return Invalid, ErrInvalid
+ return NoAccess, nil
}
// Risk: Very Low
// -> We're cancelling a GitHub Pages deployment that does not exist (see RANDOM_STRING above).
@@ -681,7 +662,7 @@ func getPagesPermission(client *gh.Client, repo *gh.Repository, currentAccess st
resp, err := client.Do(context.Background(), req, nil)
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 404:
return PagesWrite, nil
case 200:
@@ -700,7 +681,7 @@ func getPullRequestsPermission(client *gh.Client, repo *gh.Repository, currentAc
_, resp, err := client.PullRequests.List(context.Background(), *repo.Owner.Login, *repo.Name, &gh.PullRequestListOptions{})
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -725,7 +706,7 @@ func getPullRequestsPermission(client *gh.Client, repo *gh.Repository, currentAc
} else {
// Will only land here if already tested one public repo and got a 403.
if currentAccess == "UNKNOWN" {
- return Invalid, ErrInvalid
+ return NoAccess, nil
}
// Risk: Very Low
// -> We're creating a pull request with an invalid payload.
@@ -733,7 +714,7 @@ func getPullRequestsPermission(client *gh.Client, repo *gh.Repository, currentAc
_, resp, err := client.PullRequests.Create(context.Background(), *repo.Owner.Login, *repo.Name, &gh.NewPullRequest{})
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 422:
return PullRequestsWrite, nil
case 200:
@@ -753,7 +734,7 @@ func getRepoSecurityPermission(client *gh.Client, repo *gh.Repository, currentAc
_, resp, err := client.SecurityAdvisories.ListRepositorySecurityAdvisories(context.Background(), *repo.Owner.Login, *repo.Name, nil)
switch resp.StatusCode {
case 403, 404:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -782,7 +763,7 @@ func getRepoSecurityPermission(client *gh.Client, repo *gh.Repository, currentAc
} else {
// Will only land here if already tested one public repo and got a 403.
if currentAccess == "UNKNOWN" {
- return Invalid, ErrInvalid
+ return NoAccess, nil
}
// Risk: Very Low
// -> We're creating a security advisory with an invalid payload.
@@ -794,7 +775,7 @@ func getRepoSecurityPermission(client *gh.Client, repo *gh.Repository, currentAc
resp, err := client.Do(context.Background(), req, nil)
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 422:
return RepoSecurityWrite, nil
case 200:
@@ -812,7 +793,7 @@ func getSecretScanningPermission(client *gh.Client, repo *gh.Repository, current
_, resp, err := client.SecretScanning.ListAlertsForRepo(context.Background(), *repo.Owner.Login, *repo.Name, nil)
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200, 404:
break
default:
@@ -842,7 +823,7 @@ func getSecretsPermission(client *gh.Client, repo *gh.Repository, currentAccess
_, resp, err := client.Actions.ListRepoSecrets(context.Background(), *repo.Owner.Login, *repo.Name, &gh.ListOptions{})
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -872,7 +853,7 @@ func getVariablesPermission(client *gh.Client, repo *gh.Repository, currentAcces
_, resp, err := client.Actions.ListRepoVariables(context.Background(), *repo.Owner.Login, *repo.Name, &gh.ListOptions{})
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -902,7 +883,7 @@ func getWebhooksPermission(client *gh.Client, repo *gh.Repository, currentAccess
_, resp, err := client.Repositories.ListHooks(context.Background(), *repo.Owner.Login, *repo.Name, &gh.ListOptions{})
switch resp.StatusCode {
case 403, 404:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -952,7 +933,7 @@ func getBlockUserPermission(client *gh.Client, user *gh.User) (Permission, error
_, resp, err := client.Users.ListBlockedUsers(context.Background(), nil)
switch resp.StatusCode {
case 403, 404:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -982,7 +963,7 @@ func getCodespacesUserPermission(client *gh.Client, user *gh.User) (Permission,
_, resp, err := client.Codespaces.ListUserSecrets(context.Background(), nil)
switch resp.StatusCode {
case 403, 404:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -1012,7 +993,7 @@ func getEmailPermission(client *gh.Client, user *gh.User) (Permission, error) {
_, resp, err := client.Users.ListEmails(context.Background(), nil)
switch resp.StatusCode {
case 403, 404:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -1041,7 +1022,7 @@ func getFollowersPermission(client *gh.Client, user *gh.User) (Permission, error
_, resp, err := client.Users.ListFollowers(context.Background(), "", nil)
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -1070,7 +1051,7 @@ func getGPGKeysPermission(client *gh.Client, user *gh.User) (Permission, error)
_, resp, err := client.Users.ListGPGKeys(context.Background(), "", nil)
switch resp.StatusCode {
case 403, 404:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -1101,7 +1082,7 @@ func getGistsPermission(client *gh.Client, user *gh.User) (Permission, error) {
_, resp, err := client.Gists.Create(context.Background(), &gh.Gist{})
switch resp.StatusCode {
case 403, 404:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 422:
return GistsWrite, nil
case 200, 201, 204:
@@ -1118,7 +1099,7 @@ func getGitKeysPermission(client *gh.Client, user *gh.User) (Permission, error)
_, resp, err := client.Users.ListKeys(context.Background(), "", nil)
switch resp.StatusCode {
case 403, 404:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -1152,7 +1133,7 @@ func getLimitsPermission(client *gh.Client, user *gh.User) (Permission, error) {
resp, err := client.Do(context.Background(), req, nil)
switch resp.StatusCode {
case 403:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200, 204:
break
default:
@@ -1186,7 +1167,7 @@ func getPlanPermission(client *gh.Client, user *gh.User) (Permission, error) {
_, resp, err := client.Billing.GetActionsBillingUser(context.Background(), *user.Login)
switch resp.StatusCode {
case 403, 404:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
return PlanRead, nil
default:
@@ -1205,7 +1186,7 @@ func getProfilePermission(client *gh.Client, user *gh.User) (Permission, error)
resp, err := client.Do(context.Background(), req, nil)
switch resp.StatusCode {
case 403, 404:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 422:
return ProfileWrite, nil
case 200, 201, 204:
@@ -1222,7 +1203,7 @@ func getSigningKeysPermission(client *gh.Client, user *gh.User) (Permission, err
_, resp, err := client.Users.ListSSHSigningKeys(context.Background(), "", nil)
switch resp.StatusCode {
case 403, 404:
- return Invalid, ErrInvalid
+ return NoAccess, nil
case 200:
break
default:
@@ -1302,13 +1283,21 @@ func AnalyzeFineGrainedToken(client *gh.Client, meta *common.TokenMetadata, shal
if err != nil {
return nil, err
}
- repoAccessMap = append(repoAccessMap, perms...)
+ for _, perm := range perms {
+ if perm != Invalid && perm != NoAccess {
+ repoAccessMap = append(repoAccessMap, perm)
+ }
+ }
perms, err = analyzeUserPermissions(client, meta.User)
if err != nil {
return nil, err
}
- userAccessMap = append(userAccessMap, perms...)
+ for _, perm := range perms {
+ if perm != Invalid && perm != NoAccess {
+ userAccessMap = append(userAccessMap, perm)
+ }
+ }
}
return &common.SecretInfo{
diff --git a/pkg/analyzer/analyzers/github/finegrained/finegrained.yaml b/pkg/analyzer/analyzers/github/finegrained/finegrained.yaml
index dd3de36f8..2908601c7 100644
--- a/pkg/analyzer/analyzers/github/finegrained/finegrained.yaml
+++ b/pkg/analyzer/analyzers/github/finegrained/finegrained.yaml
@@ -1,5 +1,6 @@
# Please generate a yaml list of all of the strings permission_name:access_level for all of the permissions and access levels that can be emitted from the test functions. The strings should be lower snake case with a colon joining the permission name and access level. The only access levels I want are "read" and "write"
permissions:
+ - no_access
- actions:read
- actions:write
- administration:read
diff --git a/pkg/analyzer/analyzers/github/finegrained/finegrained_permissions.go b/pkg/analyzer/analyzers/github/finegrained/finegrained_permissions.go
index 07ff6126a..75ff96104 100644
--- a/pkg/analyzer/analyzers/github/finegrained/finegrained_permissions.go
+++ b/pkg/analyzer/analyzers/github/finegrained/finegrained_permissions.go
@@ -7,6 +7,7 @@ type Permission int
const (
Invalid Permission = iota
+ NoAccess Permission = iota
ActionsRead Permission = iota
ActionsWrite Permission = iota
AdministrationRead Permission = iota
@@ -89,6 +90,7 @@ const (
var (
PermissionStrings = map[Permission]string{
+ NoAccess: "no_access",
ActionsRead: "actions:read",
ActionsWrite: "actions:write",
AdministrationRead: "administration:read",
@@ -170,6 +172,7 @@ var (
}
StringToPermission = map[string]Permission{
+ "no_access": NoAccess,
"actions:read": ActionsRead,
"actions:write": ActionsWrite,
"administration:read": AdministrationRead,
@@ -251,165 +254,167 @@ var (
}
PermissionIDs = map[Permission]int{
- ActionsRead: 1,
- ActionsWrite: 2,
- AdministrationRead: 3,
- AdministrationWrite: 4,
- CodeScanningAlertsRead: 5,
- CodeScanningAlertsWrite: 6,
- CodespacesRead: 7,
- CodespacesWrite: 8,
- CodespacesLifecycleRead: 9,
- CodespacesLifecycleWrite: 10,
- CodespacesMetadataRead: 11,
- CodespacesMetadataWrite: 12,
- CodespacesSecretsRead: 13,
- CodespacesSecretsWrite: 14,
- CommitStatusesRead: 15,
- CommitStatusesWrite: 16,
- ContentsRead: 17,
- ContentsWrite: 18,
- CustomPropertiesRead: 19,
- CustomPropertiesWrite: 20,
- DependabotAlertsRead: 21,
- DependabotAlertsWrite: 22,
- DependabotSecretsRead: 23,
- DependabotSecretsWrite: 24,
- DeploymentsRead: 25,
- DeploymentsWrite: 26,
- EnvironmentsRead: 27,
- EnvironmentsWrite: 28,
- IssuesRead: 29,
- IssuesWrite: 30,
- MergeQueuesRead: 31,
- MergeQueuesWrite: 32,
- MetadataRead: 33,
- MetadataWrite: 34,
- PagesRead: 35,
- PagesWrite: 36,
- PullRequestsRead: 37,
- PullRequestsWrite: 38,
- RepoSecurityRead: 39,
- RepoSecurityWrite: 40,
- SecretScanningRead: 41,
- SecretScanningWrite: 42,
- SecretsRead: 43,
- SecretsWrite: 44,
- VariablesRead: 45,
- VariablesWrite: 46,
- WebhooksRead: 47,
- WebhooksWrite: 48,
- WorkflowsRead: 49,
- WorkflowsWrite: 50,
- BlockUserRead: 51,
- BlockUserWrite: 52,
- CodespaceUserSecretsRead: 53,
- CodespaceUserSecretsWrite: 54,
- EmailRead: 55,
- EmailWrite: 56,
- FollowersRead: 57,
- FollowersWrite: 58,
- GpgKeysRead: 59,
- GpgKeysWrite: 60,
- GistsRead: 61,
- GistsWrite: 62,
- GitKeysRead: 63,
- GitKeysWrite: 64,
- LimitsRead: 65,
- LimitsWrite: 66,
- PlanRead: 67,
- PlanWrite: 68,
- PrivateInvitesRead: 69,
- PrivateInvitesWrite: 70,
- ProfileRead: 71,
- ProfileWrite: 72,
- SigningKeysRead: 73,
- SigningKeysWrite: 74,
- StarringRead: 75,
- StarringWrite: 76,
- WatchingRead: 77,
- WatchingWrite: 78,
+ NoAccess: 1,
+ ActionsRead: 2,
+ ActionsWrite: 3,
+ AdministrationRead: 4,
+ AdministrationWrite: 5,
+ CodeScanningAlertsRead: 6,
+ CodeScanningAlertsWrite: 7,
+ CodespacesRead: 8,
+ CodespacesWrite: 9,
+ CodespacesLifecycleRead: 10,
+ CodespacesLifecycleWrite: 11,
+ CodespacesMetadataRead: 12,
+ CodespacesMetadataWrite: 13,
+ CodespacesSecretsRead: 14,
+ CodespacesSecretsWrite: 15,
+ CommitStatusesRead: 16,
+ CommitStatusesWrite: 17,
+ ContentsRead: 18,
+ ContentsWrite: 19,
+ CustomPropertiesRead: 20,
+ CustomPropertiesWrite: 21,
+ DependabotAlertsRead: 22,
+ DependabotAlertsWrite: 23,
+ DependabotSecretsRead: 24,
+ DependabotSecretsWrite: 25,
+ DeploymentsRead: 26,
+ DeploymentsWrite: 27,
+ EnvironmentsRead: 28,
+ EnvironmentsWrite: 29,
+ IssuesRead: 30,
+ IssuesWrite: 31,
+ MergeQueuesRead: 32,
+ MergeQueuesWrite: 33,
+ MetadataRead: 34,
+ MetadataWrite: 35,
+ PagesRead: 36,
+ PagesWrite: 37,
+ PullRequestsRead: 38,
+ PullRequestsWrite: 39,
+ RepoSecurityRead: 40,
+ RepoSecurityWrite: 41,
+ SecretScanningRead: 42,
+ SecretScanningWrite: 43,
+ SecretsRead: 44,
+ SecretsWrite: 45,
+ VariablesRead: 46,
+ VariablesWrite: 47,
+ WebhooksRead: 48,
+ WebhooksWrite: 49,
+ WorkflowsRead: 50,
+ WorkflowsWrite: 51,
+ BlockUserRead: 52,
+ BlockUserWrite: 53,
+ CodespaceUserSecretsRead: 54,
+ CodespaceUserSecretsWrite: 55,
+ EmailRead: 56,
+ EmailWrite: 57,
+ FollowersRead: 58,
+ FollowersWrite: 59,
+ GpgKeysRead: 60,
+ GpgKeysWrite: 61,
+ GistsRead: 62,
+ GistsWrite: 63,
+ GitKeysRead: 64,
+ GitKeysWrite: 65,
+ LimitsRead: 66,
+ LimitsWrite: 67,
+ PlanRead: 68,
+ PlanWrite: 69,
+ PrivateInvitesRead: 70,
+ PrivateInvitesWrite: 71,
+ ProfileRead: 72,
+ ProfileWrite: 73,
+ SigningKeysRead: 74,
+ SigningKeysWrite: 75,
+ StarringRead: 76,
+ StarringWrite: 77,
+ WatchingRead: 78,
+ WatchingWrite: 79,
}
IdToPermission = map[int]Permission{
- 1: ActionsRead,
- 2: ActionsWrite,
- 3: AdministrationRead,
- 4: AdministrationWrite,
- 5: CodeScanningAlertsRead,
- 6: CodeScanningAlertsWrite,
- 7: CodespacesRead,
- 8: CodespacesWrite,
- 9: CodespacesLifecycleRead,
- 10: CodespacesLifecycleWrite,
- 11: CodespacesMetadataRead,
- 12: CodespacesMetadataWrite,
- 13: CodespacesSecretsRead,
- 14: CodespacesSecretsWrite,
- 15: CommitStatusesRead,
- 16: CommitStatusesWrite,
- 17: ContentsRead,
- 18: ContentsWrite,
- 19: CustomPropertiesRead,
- 20: CustomPropertiesWrite,
- 21: DependabotAlertsRead,
- 22: DependabotAlertsWrite,
- 23: DependabotSecretsRead,
- 24: DependabotSecretsWrite,
- 25: DeploymentsRead,
- 26: DeploymentsWrite,
- 27: EnvironmentsRead,
- 28: EnvironmentsWrite,
- 29: IssuesRead,
- 30: IssuesWrite,
- 31: MergeQueuesRead,
- 32: MergeQueuesWrite,
- 33: MetadataRead,
- 34: MetadataWrite,
- 35: PagesRead,
- 36: PagesWrite,
- 37: PullRequestsRead,
- 38: PullRequestsWrite,
- 39: RepoSecurityRead,
- 40: RepoSecurityWrite,
- 41: SecretScanningRead,
- 42: SecretScanningWrite,
- 43: SecretsRead,
- 44: SecretsWrite,
- 45: VariablesRead,
- 46: VariablesWrite,
- 47: WebhooksRead,
- 48: WebhooksWrite,
- 49: WorkflowsRead,
- 50: WorkflowsWrite,
- 51: BlockUserRead,
- 52: BlockUserWrite,
- 53: CodespaceUserSecretsRead,
- 54: CodespaceUserSecretsWrite,
- 55: EmailRead,
- 56: EmailWrite,
- 57: FollowersRead,
- 58: FollowersWrite,
- 59: GpgKeysRead,
- 60: GpgKeysWrite,
- 61: GistsRead,
- 62: GistsWrite,
- 63: GitKeysRead,
- 64: GitKeysWrite,
- 65: LimitsRead,
- 66: LimitsWrite,
- 67: PlanRead,
- 68: PlanWrite,
- 69: PrivateInvitesRead,
- 70: PrivateInvitesWrite,
- 71: ProfileRead,
- 72: ProfileWrite,
- 73: SigningKeysRead,
- 74: SigningKeysWrite,
- 75: StarringRead,
- 76: StarringWrite,
- 77: WatchingRead,
- 78: WatchingWrite,
+ 1: NoAccess,
+ 2: ActionsRead,
+ 3: ActionsWrite,
+ 4: AdministrationRead,
+ 5: AdministrationWrite,
+ 6: CodeScanningAlertsRead,
+ 7: CodeScanningAlertsWrite,
+ 8: CodespacesRead,
+ 9: CodespacesWrite,
+ 10: CodespacesLifecycleRead,
+ 11: CodespacesLifecycleWrite,
+ 12: CodespacesMetadataRead,
+ 13: CodespacesMetadataWrite,
+ 14: CodespacesSecretsRead,
+ 15: CodespacesSecretsWrite,
+ 16: CommitStatusesRead,
+ 17: CommitStatusesWrite,
+ 18: ContentsRead,
+ 19: ContentsWrite,
+ 20: CustomPropertiesRead,
+ 21: CustomPropertiesWrite,
+ 22: DependabotAlertsRead,
+ 23: DependabotAlertsWrite,
+ 24: DependabotSecretsRead,
+ 25: DependabotSecretsWrite,
+ 26: DeploymentsRead,
+ 27: DeploymentsWrite,
+ 28: EnvironmentsRead,
+ 29: EnvironmentsWrite,
+ 30: IssuesRead,
+ 31: IssuesWrite,
+ 32: MergeQueuesRead,
+ 33: MergeQueuesWrite,
+ 34: MetadataRead,
+ 35: MetadataWrite,
+ 36: PagesRead,
+ 37: PagesWrite,
+ 38: PullRequestsRead,
+ 39: PullRequestsWrite,
+ 40: RepoSecurityRead,
+ 41: RepoSecurityWrite,
+ 42: SecretScanningRead,
+ 43: SecretScanningWrite,
+ 44: SecretsRead,
+ 45: SecretsWrite,
+ 46: VariablesRead,
+ 47: VariablesWrite,
+ 48: WebhooksRead,
+ 49: WebhooksWrite,
+ 50: WorkflowsRead,
+ 51: WorkflowsWrite,
+ 52: BlockUserRead,
+ 53: BlockUserWrite,
+ 54: CodespaceUserSecretsRead,
+ 55: CodespaceUserSecretsWrite,
+ 56: EmailRead,
+ 57: EmailWrite,
+ 58: FollowersRead,
+ 59: FollowersWrite,
+ 60: GpgKeysRead,
+ 61: GpgKeysWrite,
+ 62: GistsRead,
+ 63: GistsWrite,
+ 64: GitKeysRead,
+ 65: GitKeysWrite,
+ 66: LimitsRead,
+ 67: LimitsWrite,
+ 68: PlanRead,
+ 69: PlanWrite,
+ 70: PrivateInvitesRead,
+ 71: PrivateInvitesWrite,
+ 72: ProfileRead,
+ 73: ProfileWrite,
+ 74: SigningKeysRead,
+ 75: SigningKeysWrite,
+ 76: StarringRead,
+ 77: StarringWrite,
+ 78: WatchingRead,
+ 79: WatchingWrite,
}
)
diff --git a/pkg/analyzer/analyzers/github/finegrained/finegrained_test.go b/pkg/analyzer/analyzers/github/finegrained/finegrained_test.go
new file mode 100644
index 000000000..2e2decc8a
--- /dev/null
+++ b/pkg/analyzer/analyzers/github/finegrained/finegrained_test.go
@@ -0,0 +1,54 @@
+package finegrained
+
+import (
+ "testing"
+ "time"
+
+ gh "github.com/google/go-github/v63/github"
+
+ "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers"
+ analyzerCommon "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/analyzers/github/common"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/analyzer/config"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/common"
+ "github.com/trufflesecurity/trufflehog/v3/pkg/context"
+)
+
+func TestAnalyzer_Analyze(t *testing.T) {
+ ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
+ defer cancel()
+
+ analyzerSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "analyzers1")
+ if err != nil {
+ t.Fatalf("could not get test secrets from GCP: %s", err)
+ }
+
+ tests := []struct {
+ name string
+ key string
+ wantErr bool
+ }{
+ {
+ name: "finegrained - github-allrepos-actionsRW-contentsRW-issuesRW",
+ key: analyzerSecrets.MustGetField("GITHUB_FINEGRAINED_ALLREPOS_ACTIONS_RW_CONTENTS_RW_ISSUES_RW"),
+ wantErr: false,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ cfg := &config.Config{}
+ key := tt.key
+ client := gh.NewClient(analyzers.NewAnalyzeClient(cfg)).WithAuthToken(key)
+
+ md, err := analyzerCommon.GetTokenMetadata(key, client)
+ if err != nil {
+ t.Fatalf("could not get token metadata: %s", err)
+ }
+
+ _, err = AnalyzeFineGrainedToken(client, md, cfg.Shallow)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("Analyzer.Analyze() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ })
+ }
+}
diff --git a/pkg/analyzer/analyzers/github/github.go b/pkg/analyzer/analyzers/github/github.go
index f2243cdad..f09f509c7 100644
--- a/pkg/analyzer/analyzers/github/github.go
+++ b/pkg/analyzer/analyzers/github/github.go
@@ -37,22 +37,10 @@ func secretInfoToAnalyzerResult(info *common.SecretInfo) *analyzers.AnalyzerResu
if info == nil {
return nil
}
- // Metadata *TokenMetadata
- // Type string
- // FineGrained bool
- // User *gh.User
- // Expiration time.Time
- // OauthScopes []analyzers.Permission
- // Repos []*gh.Repository
- // Gists []*gh.Gist
- // AccessibleRepos []*gh.Repository
- // RepoAccessMap map[string]string
- // UserAccessMap map[string]string
result := &analyzers.AnalyzerResult{
Metadata: map[string]any{
- "type": info.Metadata.Type,
- "fine_grained": info.Metadata.FineGrained,
- "expiration": info.Metadata.Expiration,
+ "type": info.Metadata.Type,
+ "expiration": info.Metadata.Expiration,
},
}
result.Bindings = append(result.Bindings, secretInfoToUserBindings(info)...)
@@ -89,6 +77,22 @@ func userToResource(user *gh.User) *analyzers.Resource {
}
func secretInfoToRepoBindings(info *common.SecretInfo) []analyzers.Binding {
+ var perms []analyzers.Permission
+ switch info.Metadata.Type {
+ case common.TokenTypeClassicPAT:
+ perms = info.Metadata.OauthScopes
+ case common.TokenTypeFineGrainedPAT:
+ fineGrainedPermissions := info.RepoAccessMap.([]finegrained.Permission)
+ for _, perm := range fineGrainedPermissions {
+ permName, _ := perm.ToString()
+ perms = append(perms, analyzers.Permission{Value: permName})
+ }
+ default:
+ if len(info.Metadata.OauthScopes) > 0 {
+ perms = info.Metadata.OauthScopes
+ }
+ }
+
repos := info.Repos
if len(info.AccessibleRepos) > 0 {
repos = info.AccessibleRepos
@@ -101,7 +105,7 @@ func secretInfoToRepoBindings(info *common.SecretInfo) []analyzers.Binding {
Type: "repository",
Parent: userToResource(repo.Owner),
}
- bindings = append(bindings, analyzers.BindAllPermissions(resource, info.Metadata.OauthScopes...)...)
+ bindings = append(bindings, analyzers.BindAllPermissions(resource, perms...)...)
}
return bindings
}
@@ -133,8 +137,9 @@ func AnalyzePermissions(cfg *config.Config, key string) (*common.SecretInfo, err
if md.FineGrained {
return finegrained.AnalyzeFineGrainedToken(client, md, cfg.Shallow)
+ } else {
+ return classic.AnalyzeClassicToken(client, md)
}
- return classic.AnalyzeClassicToken(client, md)
}
func AnalyzeAndPrintPermissions(cfg *config.Config, key string) {
diff --git a/pkg/analyzer/analyzers/github/github_test.go b/pkg/analyzer/analyzers/github/github_test.go
index c4e812bd4..ebd39b8d4 100644
--- a/pkg/analyzer/analyzers/github/github_test.go
+++ b/pkg/analyzer/analyzers/github/github_test.go
@@ -18,12 +18,374 @@ func TestAnalyzer_Analyze(t *testing.T) {
t.Fatalf("could not get test secrets from GCP: %s", err)
}
+ analyzerSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "analyzers1")
+ if err != nil {
+ t.Fatalf("could not get test secrets from GCP: %s", err)
+ }
+
tests := []struct {
name string
key string
want string // JSON string
wantErr bool
}{
+ {
+ name: "finegrained - github-allrepos-actionsRW-contentsRW-issuesRW",
+ key: analyzerSecrets.MustGetField("GITHUB_FINEGRAINED_ALLREPOS_ACTIONS_RW_CONTENTS_RW_ISSUES_RW"),
+ wantErr: false,
+ want: `{
+ "AnalyzerType": 0,
+ "Bindings": [
+ {
+ "Resource": {
+ "Name": "private",
+ "FullyQualifiedName": "github.com/sirdetectsalot/private",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "actions:write",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "private",
+ "FullyQualifiedName": "github.com/sirdetectsalot/private",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "contents:write",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "private",
+ "FullyQualifiedName": "github.com/sirdetectsalot/private",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "issues:write",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "private",
+ "FullyQualifiedName": "github.com/sirdetectsalot/private",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "metadata:read",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "private",
+ "FullyQualifiedName": "github.com/sirdetectsalot/private",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "actions:write",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "private",
+ "FullyQualifiedName": "github.com/sirdetectsalot/private",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "contents:write",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "private",
+ "FullyQualifiedName": "github.com/sirdetectsalot/private",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "deployments:read",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "private",
+ "FullyQualifiedName": "github.com/sirdetectsalot/private",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "issues:write",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "private",
+ "FullyQualifiedName": "github.com/sirdetectsalot/private",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "metadata:read",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "public",
+ "FullyQualifiedName": "github.com/sirdetectsalot/public",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "actions:write",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "public",
+ "FullyQualifiedName": "github.com/sirdetectsalot/public",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "contents:write",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "public",
+ "FullyQualifiedName": "github.com/sirdetectsalot/public",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "issues:write",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "public",
+ "FullyQualifiedName": "github.com/sirdetectsalot/public",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "metadata:read",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "public",
+ "FullyQualifiedName": "github.com/sirdetectsalot/public",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "actions:write",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "public",
+ "FullyQualifiedName": "github.com/sirdetectsalot/public",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "contents:write",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "public",
+ "FullyQualifiedName": "github.com/sirdetectsalot/public",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "deployments:read",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "public",
+ "FullyQualifiedName": "github.com/sirdetectsalot/public",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "issues:write",
+ "Parent": null
+ }
+ },
+ {
+ "Resource": {
+ "Name": "public",
+ "FullyQualifiedName": "github.com/sirdetectsalot/public",
+ "Type": "repository",
+ "Metadata": null,
+ "Parent": {
+ "Name": "sirdetectsalot",
+ "FullyQualifiedName": "github.com/sirdetectsalot",
+ "Type": "user",
+ "Metadata": null,
+ "Parent": null
+ }
+ },
+ "Permission": {
+ "Value": "metadata:read",
+ "Parent": null
+ }
+ }
+ ],
+ "UnboundedResources": null,
+ "Metadata": {
+ "expiration": "0001-01-01T00:00:00Z",
+ "type": "Fine-Grained GitHub Personal Access Token"
+ }
+ }`,
+ },
{
name: "v2 ghp",
key: testSecrets.MustGetField("GITHUB_VERIFIED_GHP"),
@@ -60,7 +422,6 @@ func TestAnalyzer_Analyze(t *testing.T) {
},
"Permission": {
"Value": "notifications",
- "AccessLevel": "",
"Parent": null
}
}
@@ -68,7 +429,6 @@ func TestAnalyzer_Analyze(t *testing.T) {
"UnboundedResources": null,
"Metadata": {
"expiration": "0001-01-01T00:00:00Z",
- "fine_grained": false,
"type": "Classic GitHub Personal Access Token"
}
}`,