Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
refactor(github): improve wiki err handling (#2917)
Richard Gomez4d2c8c6e11be
diff --git a/pkg/sources/git/git.go b/pkg/sources/git/git.goindex 7dc3d6deb..4a85ae4df 100644--- a/pkg/sources/git/git.go+++ b/pkg/sources/git/git.go@@ -415,7 +415,12 @@ func executeClone(ctx context.Context, params cloneParams) (*git.Repository, errcloneURL.User = params.userInfo}- gitArgs := []string{"clone", cloneURL.String(), params.clonePath}+ gitArgs := []string{+ "clone",+ cloneURL.String(),+ params.clonePath,+ "--quiet", // https://git-scm.com/docs/git-clone#Documentation/git-clone.txt-code--quietcode+ }gitArgs = append(gitArgs, params.args...)cloneCmd := exec.Command("git", gitArgs...)@@ -440,15 +445,14 @@ func executeClone(ctx context.Context, params cloneParams) (*git.Repository, err}if err != nil {- err = fmt.Errorf("error executing git clone: %w", err)+ err = fmt.Errorf("error executing git clone: %w, %s", err, output)}logger.V(3).Info("git subcommand finished", "output", output)if cloneCmd.ProcessState == nil {return nil, fmt.Errorf("clone command exited with no output")- }- if cloneCmd.ProcessState != nil && cloneCmd.ProcessState.ExitCode() != 0 {- logger.V(1).Info("git clone failed", "output", output, "error", err)+ } else if cloneCmd.ProcessState.ExitCode() != 0 {+ logger.V(1).Info("git clone failed", "error", err)return nil, fmt.Errorf("could not clone repo: %s, %w", safeURL, err)}diff --git a/pkg/sources/github/github.go b/pkg/sources/github/github.goindex cbe014c49..7b24d6ee5 100644--- a/pkg/sources/github/github.go+++ b/pkg/sources/github/github.go@@ -749,7 +749,12 @@ func (s *Source) scan(ctx context.Context, installationClient *github.Client, ch_, err := s.cloneAndScanRepo(wikiCtx, installationClient, wikiURL, repoInfo, chunksChan)if err != nil {- scanErrs.Add(fmt.Errorf("error scanning wiki: %s", wikiURL))+ // Ignore "Repository not found" errors.+ // It's common for GitHub's API to say a repo has a wiki when it doesn't.+ if !strings.Contains(err.Error(), "not found") {+ scanErrs.Add(fmt.Errorf("error scanning wiki: %w", err))+ }+// Don't return, it still might be possible to scan comments.}}@@ -784,7 +789,7 @@ func (s *Source) cloneAndScanRepo(ctx context.Context, client *github.Client, rectx.Logger().V(2).Info("attempting to clone repo")path, repo, err := s.cloneRepo(ctx, repoURL, client)if err != nil {- return duration, fmt.Errorf("error cloning repo %s: %w", repoURL, err)+ return duration, err}defer os.RemoveAll(path)diff --git a/pkg/sources/github/repo.go b/pkg/sources/github/repo.goindex f1eb88ce5..4cb652c43 100644--- a/pkg/sources/github/repo.go+++ b/pkg/sources/github/repo.go@@ -68,12 +68,12 @@ func (s *Source) cloneRepo(case *sourcespb.GitHub_BasicAuth:path, repo, err = git.CloneRepoUsingToken(ctx, s.conn.GetBasicAuth().GetPassword(), repoURL, s.conn.GetBasicAuth().GetUsername())if err != nil {- return "", nil, fmt.Errorf("error cloning repo %s: %w", repoURL, err)+ return "", nil, err}case *sourcespb.GitHub_Unauthenticated:path, repo, err = git.CloneRepoUsingUnauthenticated(ctx, repoURL)if err != nil {- return "", nil, fmt.Errorf("error cloning repo %s: %w", repoURL, err)+ return "", nil, err}case *sourcespb.GitHub_GithubApp:@@ -84,7 +84,7 @@ func (s *Source) cloneRepo(path, repo, err = git.CloneRepoUsingToken(ctx, s.githubToken, repoURL, s.githubUser)if err != nil {- return "", nil, fmt.Errorf("error cloning repo %s: %w", repoURL, err)+ return "", nil, err}case *sourcespb.GitHub_Token:@@ -93,10 +93,10 @@ func (s *Source) cloneRepo(}path, repo, err = git.CloneRepoUsingToken(ctx, s.githubToken, repoURL, s.githubUser)if err != nil {- return "", nil, fmt.Errorf("error cloning repo %s: %w", repoURL, err)+ return "", nil, err}default:- return "", nil, fmt.Errorf("unhandled credential type for repo %s", repoURL)+ return "", nil, fmt.Errorf("unhandled credential type for repo %s: %T", repoURL, s.conn.GetCredential())}return path, repo, nil}