Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Add Detector Description to JSON output (#3404)
ahravc3ff1794b18b
diff --git a/pkg/detectors/detectors.go b/pkg/detectors/detectors.goindex 14eccba8e..de05193f2 100644--- a/pkg/detectors/detectors.go+++ b/pkg/detectors/detectors.go@@ -166,6 +166,8 @@ type ResultWithMetadata struct {Result// Data from the sources.Chunk which this result was emitted forData []byte+ // DetectorDescription is the description of the Detector.+ DetectorDescription string// DecoderType is the type of decoder that was used to generate this result's data.DecoderType detectorspb.DecoderType}diff --git a/pkg/engine/engine.go b/pkg/engine/engine.goindex d4af8d5a2..4d07cbe4a 100644--- a/pkg/engine/engine.go+++ b/pkg/engine/engine.go@@ -1156,6 +1156,7 @@ func (e *Engine) processResult(secret := detectors.CopyMetadata(&data.chunk, res)secret.DecoderType = data.decoder+ secret.DetectorDescription = data.detector.Detector.Description()if !res.Verified && res.Raw != nil {isFp, _ := isFalsePositive(res)diff --git a/pkg/output/github_actions.go b/pkg/output/github_actions.goindex a88a7e4e3..f9457e68c 100644--- a/pkg/output/github_actions.go+++ b/pkg/output/github_actions.go@@ -18,9 +18,10 @@ type GitHubActionsPrinter struct{ mu sync.Mutex }func (p *GitHubActionsPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata) error {out := gitHubActionsOutputFormat{- DetectorType: r.Result.DetectorType.String(),- DecoderType: r.DecoderType.String(),- Verified: r.Result.Verified,+ DetectorType: r.Result.DetectorType.String(),+ DetectorDescription: r.DetectorDescription,+ DecoderType: r.DecoderType.String(),+ Verified: r.Result.Verified,}meta, err := structToMap(r.SourceMetadata.Data)@@ -71,9 +72,10 @@ func (p *GitHubActionsPrinter) Print(_ context.Context, r *detectors.ResultWithM}type gitHubActionsOutputFormat struct {- DetectorType,- DecoderType string- Verified bool- StartLine int64- Filename string+ DetectorType string+ DetectorDescription string+ DecoderType string+ Verified bool+ StartLine int64+ Filename string}diff --git a/pkg/output/json.go b/pkg/output/json.goindex 49a297402..d98e78909 100644--- a/pkg/output/json.go+++ b/pkg/output/json.go@@ -37,6 +37,8 @@ func (p *JSONPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata)DetectorType detectorspb.DetectorType// DetectorName is the string name of the DetectorType.DetectorName string+ // DetectorDescription is the description of the Detector.+ DetectorDescription string// DecoderName is the string name of the DecoderType.DecoderName stringVerified bool@@ -52,20 +54,21 @@ func (p *JSONPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata)ExtraData map[string]stringStructuredData *detectorspb.StructuredData}{- SourceMetadata: r.SourceMetadata,- SourceID: r.SourceID,- SourceType: r.SourceType,- SourceName: r.SourceName,- DetectorType: r.DetectorType,- DetectorName: r.DetectorType.String(),- DecoderName: r.DecoderType.String(),- Verified: r.Verified,- VerificationError: verificationErr,- Raw: string(r.Raw),- RawV2: string(r.RawV2),- Redacted: r.Redacted,- ExtraData: r.ExtraData,- StructuredData: r.StructuredData,+ SourceMetadata: r.SourceMetadata,+ SourceID: r.SourceID,+ SourceType: r.SourceType,+ SourceName: r.SourceName,+ DetectorType: r.DetectorType,+ DetectorName: r.DetectorType.String(),+ DetectorDescription: r.DetectorDescription,+ DecoderName: r.DecoderType.String(),+ Verified: r.Verified,+ VerificationError: verificationErr,+ Raw: string(r.Raw),+ RawV2: string(r.RawV2),+ Redacted: r.Redacted,+ ExtraData: r.ExtraData,+ StructuredData: r.StructuredData,}out, err := json.Marshal(v)if err != nil {diff --git a/pkg/output/plain.go b/pkg/output/plain.goindex 91e4c8abb..c6a987161 100644--- a/pkg/output/plain.go+++ b/pkg/output/plain.go@@ -29,12 +29,13 @@ type PlainPrinter struct{ mu sync.Mutex }func (p *PlainPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata) error {out := outputFormat{- DetectorType: r.Result.DetectorType.String(),- DecoderType: r.DecoderType.String(),- Verified: r.Result.Verified,- VerificationError: r.Result.VerificationError(),- MetaData: r.SourceMetadata,- Raw: strings.TrimSpace(string(r.Result.Raw)),+ DetectorType: r.Result.DetectorType.String(),+ DecoderType: r.DecoderType.String(),+ Verified: r.Result.Verified,+ VerificationError: r.Result.VerificationError(),+ MetaData: r.SourceMetadata,+ Raw: strings.TrimSpace(string(r.Result.Raw)),+ DetectorDescription: r.DetectorDescription,}meta, err := structToMap(out.MetaData.Data)@@ -115,4 +116,5 @@ type outputFormat struct {VerificationError errorRaw string*source_metadatapb.MetaData+ DetectorDescription string}