Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Copy metadata for line number aware sources (#1011)
Bill Rich8b2e1d36cffa
diff --git a/pkg/engine/engine.go b/pkg/engine/engine.goindex 9eb1f134c..c40137785 100644--- a/pkg/engine/engine.go+++ b/pkg/engine/engine.go@@ -9,6 +9,7 @@ import ("time""github.com/sirupsen/logrus"+ "google.golang.org/protobuf/proto""github.com/trufflesecurity/trufflehog/v3/pkg/common""github.com/trufflesecurity/trufflehog/v3/pkg/context"@@ -181,7 +182,6 @@ func (e *Engine) detectorWorker(ctx context.Context) {for originalChunk := range e.chunks {for chunk := range sources.Chunker(originalChunk) {atomic.AddUint64(&e.bytesScanned, uint64(len(chunk.Data)))- fragStart, mdLine := FragmentFirstLine(chunk)for _, decoder := range e.decoders {var decoderType detectorspb.DecoderTypeswitch decoder.(type) {@@ -230,9 +230,19 @@ func (e *Engine) detectorWorker(ctx context.Context) {results = detectors.CleanResults(results)}for _, result := range results {- SetResultLineNumber(chunk, &result, fragStart, mdLine)+ resultChunk := chunk+ if isGitSource(chunk.SourceType) {+ copyChunk := *chunk+ copyMetaDataClone := proto.Clone(chunk.SourceMetadata)+ if copyMetaData, ok := copyMetaDataClone.(*source_metadatapb.MetaData); ok {+ copyChunk.SourceMetadata = copyMetaData+ }+ fragStart, mdLine := FragmentFirstLine(©Chunk)+ SetResultLineNumber(©Chunk, &result, fragStart, mdLine)+ resultChunk = ©Chunk+ }result.DecoderType = decoderType- e.results <- detectors.CopyMetadata(chunk, result)+ e.results <- detectors.CopyMetadata(resultChunk, result)}if len(results) > 0 {@@ -314,8 +324,6 @@ func FragmentFirstLine(chunk *sources.Chunk) (int64, *int64) {// SetResultLineNumber sets the line number in the provided result.func SetResultLineNumber(chunk *sources.Chunk, result *detectors.Result, fragStart int64, mdLine *int64) {- if isGitSource(chunk.SourceType) {- offset := FragmentLineOffset(chunk, result)- *mdLine = fragStart + offset- }+ offset := FragmentLineOffset(chunk, result)+ *mdLine = fragStart + offset}