Skip to content

Find, verify, and analyze leaked credentials

fix: reject --include-repos/--exclude-repos with --repo in github scan (#5112)

Kashif Khan1675e1743f7a
diff --git a/main.go b/main.go
index 5d768b3b2..c6d63d5e4 100644
--- a/main.go
+++ b/main.go
@@ -882,6 +882,13 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
if len(*githubScanOrgs) > 0 && len(*githubScanRepos) > 0 {
return scanMetrics, fmt.Errorf("invalid config: you cannot specify both organizations and repositories at the same time")
}
+ // --include-repos/--exclude-repos only filter repos enumerated from an org/user scan;
+ // explicit --repo entries bypass that filtering step entirely (see enumerate() in
+ // pkg/sources/github/github.go), so combining them with --repo would silently no-op
+ // the filters instead of erroring.
+ if len(*githubScanRepos) > 0 && (len(*githubIncludeRepos) > 0 || len(*githubExcludeRepos) > 0) {
+ return scanMetrics, fmt.Errorf("invalid config: --include-repos and --exclude-repos only apply to organization or user scans and cannot be used with --repo")
+ }
if err := validateClonePath(*githubClonePath, *githubNoCleanup); err != nil {
return scanMetrics, err
diff --git a/pkg/sources/sources.go b/pkg/sources/sources.go
index 88b11b85a..444207c9d 100644
--- a/pkg/sources/sources.go
+++ b/pkg/sources/sources.go
@@ -309,9 +309,13 @@ type GithubConfig struct {
Repos []string
// Orgs is the list of organizations to scan.
Orgs []string
- // ExcludeRepos is a list of repositories to exclude from the scan.
+ // ExcludeRepos is a list of repositories to exclude from an org/user scan.
+ // It only filters repos enumerated via Orgs; it has no effect when Repos is set
+ // explicitly, since explicit repos bypass the filtering step entirely.
ExcludeRepos []string
- // IncludeRepos is a list of repositories to include in the scan.
+ // IncludeRepos is a list of repositories to include in an org/user scan.
+ // It only filters repos enumerated via Orgs; it has no effect when Repos is set
+ // explicitly, since explicit repos bypass the filtering step entirely.
IncludeRepos []string
// Filter is the filter to use to scan the source.
Filter *common.Filter