Skip to content

Commit

Permalink
add temporary targeting ability
Browse files Browse the repository at this point in the history
  • Loading branch information
rosecodym committed Aug 29, 2024
1 parent 247b56a commit 4970796
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ var (
githubScanIssueComments = githubScan.Flag("issue-comments", "Include issue descriptions and comments in scan.").Bool()
githubScanPRComments = githubScan.Flag("pr-comments", "Include pull request descriptions and comments in scan.").Bool()
githubScanGistComments = githubScan.Flag("gist-comments", "Include gist comments in scan.").Bool()
githubTarget = githubScan.Flag("target", "scan a target").Hidden().String()

// GitHub Cross Fork Object Reference Experimental Feature
githubExperimentalScan = cli.Command("github-experimental", "Run an experimental GitHub scan. Must specify at least one experimental sub-module to run: object-discovery.")
Expand Down Expand Up @@ -627,6 +628,7 @@ func runSingleScan(ctx context.Context, cmd string, cfg engine.Config) (metrics,
IncludePullRequestComments: *githubScanPRComments,
IncludeGistComments: *githubScanGistComments,
Filter: filter,
Target: *githubTarget,
}
if err := eng.ScanGitHub(ctx, cfg); err != nil {
return scanMetrics, fmt.Errorf("failed to scan Github: %v", err)
Expand Down
21 changes: 21 additions & 0 deletions pkg/engine/github.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package engine

import (
"strings"

gogit "github.com/go-git/go-git/v5"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/source_metadatapb"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"

Expand Down Expand Up @@ -58,6 +61,24 @@ func (e *Engine) ScanGitHub(ctx context.Context, c sources.GithubConfig) error {
return err
}
githubSource.WithScanOptions(scanOptions)

if c.Target != "" {
parts := strings.Split(c.Target, "@")
target := sources.ChunkingTarget{
QueryCriteria: &source_metadatapb.MetaData{
Data: &source_metadatapb.MetaData_Github{
Github: &source_metadatapb.Github{
Link: c.Repos[0],
File: parts[0],
Commit: parts[1],
},
},
},
}
_, err = e.sourceManager.Run(ctx, sourceName, githubSource, target)
return err
}

_, err = e.sourceManager.Run(ctx, sourceName, githubSource)
return err
}
2 changes: 2 additions & 0 deletions pkg/sources/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ type GithubConfig struct {
SkipBinaries bool
// IncludeWikis indicates whether to include repository wikis in the scan.
IncludeWikis bool

Target string
}

// GitHubExperimentalConfig defines the optional configuration for an experimental GitHub source.
Expand Down

0 comments on commit 4970796

Please sign in to comment.