Skip to content

Find, verify, and analyze leaked credentials

Only scan org with --org flag. (#931)

ahrava72b9feb354f
diff --git a/pkg/sources/github/github.go b/pkg/sources/github/github.go
index a954bcc2f..18cbea9ab 100644
--- a/pkg/sources/github/github.go
+++ b/pkg/sources/github/github.go
@@ -325,9 +325,6 @@ func (s *Source) enumerateWithToken(ctx context.Context, apiEndpoint, token stri
if err := s.addRepos(ctx, org, s.getReposByOrg); err != nil {
log.WithError(err).Errorf("error fetching repos for org: %s", org)
}
- if err := s.addRepos(ctx, ghUser.GetLogin(), s.getReposByUser); err != nil {
- log.WithError(err).Errorf("error fetching repos for user: %s", ghUser.GetLogin())
- }
if s.conn.ScanUsers {
err := s.addMembersByOrg(ctx, org)
@@ -358,6 +355,15 @@ func (s *Source) enumerateWithToken(ctx context.Context, apiEndpoint, token stri
log.WithError(err).Error("error fetching repos by org")
}
+ if err := s.addRepos(ctx, ghUser.GetLogin(), s.getReposByUser); err != nil {
+ log.WithError(err).Errorf("error fetching repos for user: %s", ghUser.GetLogin())
+ }
+
+ // TODO: Test it actually works to list org gists like this.
+ if err := s.addGistsByUser(ctx, org); err != nil {
+ log.WithError(err).Errorf("error fetching gists by org: %s", org)
+ }
+
if s.conn.ScanUsers {
err := s.addMembersByOrg(ctx, org)
if err != nil {
@@ -366,24 +372,20 @@ func (s *Source) enumerateWithToken(ctx context.Context, apiEndpoint, token stri
}
}
}
- }
- if s.conn.ScanUsers {
- log.Infof("Adding repos from %d members in %d organizations.", len(s.members), len(s.orgs))
- s.addReposForMembers(ctx)
- } else {
// If we enabled ScanUsers above, we've already added the gists for the current user and users from the orgs.
// So if we don't have ScanUsers enabled, add the user gists as normal.
if err := s.addGistsByUser(ctx, ghUser.GetLogin()); err != nil {
log.WithError(err).Errorf("error fetching gists for user %s", ghUser.GetLogin())
}
- for _, org := range s.orgs {
- // TODO: Test it actually works to list org gists like this.
- if err := s.addGistsByUser(ctx, org); err != nil {
- log.WithError(err).Errorf("error fetching gists by org: %s", org)
- }
- }
}
+
+ if s.conn.ScanUsers {
+ log.Infof("Adding repos from %d members in %d organizations.", len(s.members), len(s.orgs))
+ s.addReposForMembers(ctx)
+ return nil
+ }
+
return nil
}
diff --git a/pkg/sources/github/github_test.go b/pkg/sources/github/github_test.go
index c057fd700..a337cb98b 100644
--- a/pkg/sources/github/github_test.go
+++ b/pkg/sources/github/github_test.go
@@ -316,18 +316,13 @@ func TestEnumerateWithToken_IncludeRepos(t *testing.T) {
Reply(200).
JSON(map[string]string{"login": "super-secret-user"})
- gock.New("https://api.github.com").
- Get("/users/super-secret-user/gists").
- Reply(200).
- JSON([]map[string]string{{"clone_url": ""}})
-
s := initTestSource(nil)
s.repos = []string{"some-special-repo"}
err := s.enumerateWithToken(context.TODO(), "https://api.github.com", "token")
assert.Nil(t, err)
- assert.Equal(t, 2, len(s.repos))
- assert.Equal(t, []string{"some-special-repo", ""}, s.repos)
+ assert.Equal(t, 1, len(s.repos))
+ assert.Equal(t, []string{"some-special-repo"}, s.repos)
assert.True(t, gock.IsDone())
}