Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Bug fix and add authentication in shallow clone (#595)
Miccahfc18a5ae0c5c
diff --git a/main.go b/main.goindex 118590961..801e30e8a 100644--- a/main.go+++ b/main.go@@ -143,6 +143,12 @@ func run(state overseer.State) {fmt.Println("trufflehog " + version.BuildVersion)}+ if *githubScanToken != "" {+ // NOTE: this kludge is here to do an authenticated shallow commit+ // TODO: refactor to better pass credentials+ os.Setenv("GITHUB_TOKEN", *githubScanToken)+ }+// When setting a base commit, chunks must be scanned in order.if *gitScanSinceCommit != "" {*concurrency = 1diff --git a/pkg/sources/git/git.go b/pkg/sources/git/git.goindex 130f29448..28b431cee 100644--- a/pkg/sources/git/git.go+++ b/pkg/sources/git/git.go@@ -22,6 +22,7 @@ import ("github.com/rs/zerolog"log "github.com/sirupsen/logrus"glgo "github.com/zricethezav/gitleaks/v8/detect/git"+ "golang.org/x/oauth2""golang.org/x/sync/semaphore""google.golang.org/protobuf/proto""google.golang.org/protobuf/types/known/anypb"@@ -496,12 +497,21 @@ func PrepareRepoSinceCommit(uriString, commitHash string) (string, bool, error)return PrepareRepo(uriString)}- owner, repoName, found := strings.Cut(uri.Path, "/")+ uriPath := strings.TrimPrefix(uri.Path, "/")+ owner, repoName, found := strings.Cut(uriPath, "/")if !found {return PrepareRepo(uriString)}client := github.NewClient(nil)+ if token := os.Getenv("GITHUB_TOKEN"); token != "" {+ ts := oauth2.StaticTokenSource(+ &oauth2.Token{AccessToken: token},+ )+ tc := oauth2.NewClient(context.TODO(), ts)+ client = github.NewClient(tc)+ }+commit, _, err := client.Git.GetCommit(context.Background(), owner, repoName, commitHash)if err != nil {return PrepareRepo(uriString)