Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Don't scan the --since-commit target (#960)
Bill Rich33d32d2de43f
diff --git a/README.md b/README.mdindex 7be9e020e..cadf50c79 100644--- a/README.md+++ b/README.md@@ -269,9 +269,9 @@ repos:- id: trufflehogname: TruffleHogdescription: Detect secrets in your data.- entry: bash -c 'trufflehog git file://. --only-verified --fail'+ entry: bash -c 'trufflehog git file://. --since-commit main --only-verified --fail'# For running trufflehog in docker, use the following entry instead:- # entry: bash -c 'docker run -v "$(pwd):/workdir" -i --rm trufflesecurity/trufflehog:latest git file:///workdir --only-verified --fail'+ # entry: bash -c 'docker run -v "$(pwd):/workdir" -i --rm trufflesecurity/trufflehog:latest git file:///workdir --since-commit main --only-verified --fail'language: systemstages: ["commit", "push"]```diff --git a/pkg/sources/git/git.go b/pkg/sources/git/git.goindex 5098022e8..a1bf8883e 100644--- a/pkg/sources/git/git.go+++ b/pkg/sources/git/git.go@@ -335,25 +335,21 @@ func (s *Git) ScanCommits(ctx context.Context, repo *git.Repository, path stringurlMetadata := getSafeRemoteURL(repo, "origin")var depth int64- var reachedBase = falsectx.Logger().V(1).Info("scanning repo", "repo", urlMetadata, "base", scanOptions.BaseHash, "head", scanOptions.HeadHash)for commit := range commitChan {- ctx.Logger().V(5).Info("scanning commit", "commit", commit.Hash, "message", commit.Message)- if scanOptions.MaxDepth > 0 && depth >= scanOptions.MaxDepth {- ctx.Logger().V(1).Info("reached max depth", "depth", depth)- break- }- depth++- if reachedBase && commit.Hash != scanOptions.BaseHash {- break- }if len(scanOptions.BaseHash) > 0 {if commit.Hash == scanOptions.BaseHash {ctx.Logger().V(1).Info("reached base commit", "commit", commit.Hash)- reachedBase = true+ break}}+ if scanOptions.MaxDepth > 0 && depth >= scanOptions.MaxDepth {+ ctx.Logger().V(1).Info("reached max depth", "depth", depth)+ break+ }+ depth+++ ctx.Logger().V(5).Info("scanning commit", "commit", commit.Hash, "message", commit.Message)for _, diff := range commit.Diffs {if !scanOptions.Filter.Pass(diff.PathB) {continuediff --git a/pkg/sources/git/git_test.go b/pkg/sources/git/git_test.goindex e7cd00eac..662806bfc 100644--- a/pkg/sources/git/git_test.go+++ b/pkg/sources/git/git_test.go@@ -238,25 +238,13 @@ func TestSource_Chunks_Integration(t *testing.T) {name: "remote repo, limited",repoURL: "https://github.com/dustin-decker/secretsandstuff.git",expectedChunkData: map[string]*byteCompare{- "70001020fab32b1fcf2f1f0e5c66424eae649826-aws": {B: []byte("[default]\naws_access_key_id = AKIAXYZDQCEN4B6JSJQI\naws_secret_access_key = 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\noutput = json\nregion = us-east-2\n")},- "a6f8aa55736d4a85be31a0048a4607396898647a-bump": {B: []byte("\n\nf\n")},+ "70001020fab32b1fcf2f1f0e5c66424eae649826-aws": {B: []byte("[default]\naws_access_key_id = AKIAXYZDQCEN4B6JSJQI\naws_secret_access_key = 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\noutput = json\nregion = us-east-2\n")},},scanOptions: ScanOptions{HeadHash: "70001020fab32b1fcf2f1f0e5c66424eae649826",BaseHash: "a6f8aa55736d4a85be31a0048a4607396898647a",},},- {- name: "remote repo, base ahead of head",- repoURL: "https://github.com/dustin-decker/secretsandstuff.git",- expectedChunkData: map[string]*byteCompare{- "a6f8aa55736d4a85be31a0048a4607396898647a-bump": {B: []byte("\n\nf\n")},- },- scanOptions: ScanOptions{- HeadHash: "a6f8aa55736d4a85be31a0048a4607396898647a",- BaseHash: "70001020fab32b1fcf2f1f0e5c66424eae649826",- },- },{name: "remote repo, main ahead of branch",repoURL: "https://github.com/bill-rich/bad-secrets.git",