Skip to content

Commit 9ffb50d

Browse files
authored
Add AnalysisInfo to verified results in detectors for new analyzers (#4556)
1 parent df31a0e commit 9ffb50d

File tree

10 files changed

+65
-4
lines changed

10 files changed

+65
-4
lines changed

pkg/detectors/artifactory/artifactory.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
9898
}
9999

100100
s1.SetVerificationError(verificationErr, token)
101+
102+
if isVerified {
103+
s1.AnalysisInfo = map[string]string{
104+
"domain": url,
105+
"token": token,
106+
}
107+
}
101108
}
102109
}
103110

pkg/detectors/atlassian/v1/atlassian.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package atlassian
22

33
import (
44
"context"
5+
"encoding/json"
56
"fmt"
67
"io"
78
"net/http"
8-
"encoding/json"
99

1010
regexp "github.com/wasilibs/go-re2"
1111

@@ -80,6 +80,12 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
8080
s1.ExtraData["Organization"] = orgResponse.Data[0].Attributes.Name
8181
}
8282
s1.SetVerificationError(verificationErr, match)
83+
84+
if isVerified {
85+
s1.AnalysisInfo = map[string]string{
86+
"key": match,
87+
}
88+
}
8389
}
8490

8591
results = append(results, s1)

pkg/detectors/buildkite/v1/buildkite.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
5959
extraData, isVerified, verificationErr := VerifyBuildKite(ctx, client, resMatch)
6060
s1.Verified = isVerified
6161
s1.SetVerificationError(verificationErr, resMatch)
62-
6362
s1.ExtraData = extraData
63+
64+
if isVerified {
65+
s1.AnalysisInfo = map[string]string{
66+
"key": resMatch,
67+
}
68+
}
6469
}
6570

6671
results = append(results, s1)

pkg/detectors/buildkite/v2/buildkite.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
5252
s1.Verified = isVerified
5353
s1.SetVerificationError(verificationErr, resMatch)
5454
s1.ExtraData = extraData
55+
56+
if isVerified {
57+
s1.AnalysisInfo = map[string]string{
58+
"key": resMatch,
59+
}
60+
}
61+
5562
}
5663

5764
results = append(results, s1)

pkg/detectors/harness/harness.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
7272
s1.Verified = isVerified
7373
s1.ExtraData = extraData
7474
s1.SetVerificationError(verificationErr, match)
75+
76+
if isVerified {
77+
s1.AnalysisInfo = map[string]string{
78+
"key": match,
79+
}
80+
}
81+
7582
}
7683

7784
results = append(results, s1)

pkg/detectors/mongodb/mongodb.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
102102
continue
103103
}
104104
r.SetVerificationError(vErr, password)
105+
106+
if isVerified {
107+
r.AnalysisInfo = map[string]string{
108+
"key": connStr,
109+
}
110+
}
105111
}
106112
results = append(results, r)
107113
}

pkg/detectors/npmtoken/npmtoken.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package npmtoken
33
import (
44
"context"
55
"fmt"
6-
regexp "github.com/wasilibs/go-re2"
76
"net/http"
87
"strings"
98

9+
regexp "github.com/wasilibs/go-re2"
10+
1011
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
1112
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
1213
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
@@ -59,6 +60,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
5960
defer res.Body.Close()
6061
if res.StatusCode >= 200 && res.StatusCode < 300 {
6162
s1.Verified = true
63+
s1.AnalysisInfo = map[string]string{
64+
"key": resMatch,
65+
}
6266
}
6367
}
6468
}

pkg/detectors/npmtokenv2/npmtokenv2.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package npmtokenv2
33
import (
44
"context"
55
"fmt"
6-
regexp "github.com/wasilibs/go-re2"
76
"net/http"
87

8+
regexp "github.com/wasilibs/go-re2"
9+
910
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
1011
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
1112
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
@@ -60,6 +61,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
6061
defer res.Body.Close()
6162
if res.StatusCode >= 200 && res.StatusCode < 300 {
6263
s1.Verified = true
64+
s1.AnalysisInfo = map[string]string{
65+
"key": resMatch,
66+
}
6367
}
6468
}
6569
}

pkg/detectors/postmark/postmark.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
5151
s1.Verified = valid
5252
s1.ExtraData = extraData
5353
s1.SetVerificationError(err)
54+
55+
if valid {
56+
s1.AnalysisInfo = map[string]string{
57+
"key": resMatch,
58+
}
59+
}
5460
}
5561

5662
results = append(results, s1)

pkg/detectors/salesforceoauth2/salesforceoauth2.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ domainLoop:
105105

106106
s1.SetVerificationError(verificationErr, secret)
107107
}
108+
109+
if isVerified {
110+
s1.AnalysisInfo = map[string]string{
111+
"domain": domain,
112+
"client_id": key,
113+
"client_secret": secret,
114+
}
115+
116+
}
108117
}
109118

110119
results = append(results, s1)

0 commit comments

Comments
 (0)