Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Add AnalysisInfo to verified results in detectors for new analyzers (#4556)
Amaan Ullah9ffb50d96fc3
diff --git a/pkg/detectors/artifactory/artifactory.go b/pkg/detectors/artifactory/artifactory.goindex 50a874e0f..856d90fa4 100644--- a/pkg/detectors/artifactory/artifactory.go+++ b/pkg/detectors/artifactory/artifactory.go@@ -98,6 +98,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}s1.SetVerificationError(verificationErr, token)++ if isVerified {+ s1.AnalysisInfo = map[string]string{+ "domain": url,+ "token": token,+ }+ }}}diff --git a/pkg/detectors/atlassian/v1/atlassian.go b/pkg/detectors/atlassian/v1/atlassian.goindex f3666a7b2..f7c2d612f 100644--- a/pkg/detectors/atlassian/v1/atlassian.go+++ b/pkg/detectors/atlassian/v1/atlassian.go@@ -2,10 +2,10 @@ package atlassianimport ("context"+ "encoding/json""fmt""io""net/http"- "encoding/json"regexp "github.com/wasilibs/go-re2"@@ -80,6 +80,12 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results1.ExtraData["Organization"] = orgResponse.Data[0].Attributes.Name}s1.SetVerificationError(verificationErr, match)++ if isVerified {+ s1.AnalysisInfo = map[string]string{+ "key": match,+ }+ }}results = append(results, s1)diff --git a/pkg/detectors/buildkite/v1/buildkite.go b/pkg/detectors/buildkite/v1/buildkite.goindex 52dd66f88..7d4497250 100644--- a/pkg/detectors/buildkite/v1/buildkite.go+++ b/pkg/detectors/buildkite/v1/buildkite.go@@ -59,8 +59,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (resultextraData, isVerified, verificationErr := VerifyBuildKite(ctx, client, resMatch)s1.Verified = isVerifieds1.SetVerificationError(verificationErr, resMatch)-s1.ExtraData = extraData++ if isVerified {+ s1.AnalysisInfo = map[string]string{+ "key": resMatch,+ }+ }}results = append(results, s1)diff --git a/pkg/detectors/buildkite/v2/buildkite.go b/pkg/detectors/buildkite/v2/buildkite.goindex 89c38eff9..b25bf7441 100644--- a/pkg/detectors/buildkite/v2/buildkite.go+++ b/pkg/detectors/buildkite/v2/buildkite.go@@ -52,6 +52,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results1.Verified = isVerifieds1.SetVerificationError(verificationErr, resMatch)s1.ExtraData = extraData++ if isVerified {+ s1.AnalysisInfo = map[string]string{+ "key": resMatch,+ }+ }+}results = append(results, s1)diff --git a/pkg/detectors/harness/harness.go b/pkg/detectors/harness/harness.goindex 416ca817b..14fdcaef2 100644--- a/pkg/detectors/harness/harness.go+++ b/pkg/detectors/harness/harness.go@@ -72,6 +72,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results1.Verified = isVerifieds1.ExtraData = extraDatas1.SetVerificationError(verificationErr, match)++ if isVerified {+ s1.AnalysisInfo = map[string]string{+ "key": match,+ }+ }+}results = append(results, s1)diff --git a/pkg/detectors/mongodb/mongodb.go b/pkg/detectors/mongodb/mongodb.goindex 290e8c373..df507d75f 100644--- a/pkg/detectors/mongodb/mongodb.go+++ b/pkg/detectors/mongodb/mongodb.go@@ -102,6 +102,12 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (resultcontinue}r.SetVerificationError(vErr, password)++ if isVerified {+ r.AnalysisInfo = map[string]string{+ "key": connStr,+ }+ }}results = append(results, r)}diff --git a/pkg/detectors/npmtoken/npmtoken.go b/pkg/detectors/npmtoken/npmtoken.goindex fdd4992f8..b4cb3a422 100644--- a/pkg/detectors/npmtoken/npmtoken.go+++ b/pkg/detectors/npmtoken/npmtoken.go@@ -3,10 +3,11 @@ package npmtokenimport ("context""fmt"- regexp "github.com/wasilibs/go-re2""net/http""strings"+ regexp "github.com/wasilibs/go-re2"+"github.com/trufflesecurity/trufflehog/v3/pkg/common""github.com/trufflesecurity/trufflehog/v3/pkg/detectors""github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"@@ -59,6 +60,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (resultdefer res.Body.Close()if res.StatusCode >= 200 && res.StatusCode < 300 {s1.Verified = true+ s1.AnalysisInfo = map[string]string{+ "key": resMatch,+ }}}}diff --git a/pkg/detectors/npmtokenv2/npmtokenv2.go b/pkg/detectors/npmtokenv2/npmtokenv2.goindex 3e2eb83b7..76f740e8e 100644--- a/pkg/detectors/npmtokenv2/npmtokenv2.go+++ b/pkg/detectors/npmtokenv2/npmtokenv2.go@@ -3,9 +3,10 @@ package npmtokenv2import ("context""fmt"- regexp "github.com/wasilibs/go-re2""net/http"+ regexp "github.com/wasilibs/go-re2"+"github.com/trufflesecurity/trufflehog/v3/pkg/common""github.com/trufflesecurity/trufflehog/v3/pkg/detectors""github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"@@ -60,6 +61,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (resultdefer res.Body.Close()if res.StatusCode >= 200 && res.StatusCode < 300 {s1.Verified = true+ s1.AnalysisInfo = map[string]string{+ "key": resMatch,+ }}}}diff --git a/pkg/detectors/postmark/postmark.go b/pkg/detectors/postmark/postmark.goindex 4848fb123..1c4b5aff8 100644--- a/pkg/detectors/postmark/postmark.go+++ b/pkg/detectors/postmark/postmark.go@@ -51,6 +51,12 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results1.Verified = valids1.ExtraData = extraDatas1.SetVerificationError(err)++ if valid {+ s1.AnalysisInfo = map[string]string{+ "key": resMatch,+ }+ }}results = append(results, s1)diff --git a/pkg/detectors/salesforceoauth2/salesforceoauth2.go b/pkg/detectors/salesforceoauth2/salesforceoauth2.goindex e55bc6738..32728d75a 100644--- a/pkg/detectors/salesforceoauth2/salesforceoauth2.go+++ b/pkg/detectors/salesforceoauth2/salesforceoauth2.go@@ -105,6 +105,15 @@ domainLoop:s1.SetVerificationError(verificationErr, secret)}++ if isVerified {+ s1.AnalysisInfo = map[string]string{+ "domain": domain,+ "client_id": key,+ "client_secret": secret,+ }++ }}results = append(results, s1)