9
9
10
10
regexp "github.com/wasilibs/go-re2"
11
11
12
+ "github.com/trufflesecurity/trufflehog/v3/pkg/common"
12
13
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
13
14
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
14
15
)
30
31
// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
31
32
tokenPat = regexp .MustCompile (detectors .PrefixRegex ([]string {"jira" }) + `\b([a-zA-Z-0-9]{24})\b` )
32
33
domainPat = regexp .MustCompile (detectors .PrefixRegex ([]string {"jira" }) + `\b([a-zA-Z-0-9]{5,24}\.[a-zA-Z-0-9]{3,16}\.[a-zA-Z-0-9]{3,16})\b` )
33
- emailPat = regexp .MustCompile (detectors .PrefixRegex ([]string {"jira" }) + `\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b` )
34
+ emailPat = regexp .MustCompile (detectors .PrefixRegex ([]string {"jira" }) + common . EmailPattern )
34
35
)
35
36
36
37
const (
@@ -48,31 +49,27 @@ func (s Scanner) Keywords() []string {
48
49
func (s Scanner ) FromData (ctx context.Context , verify bool , data []byte ) (results []detectors.Result , err error ) {
49
50
dataStr := string (data )
50
51
51
- tokens := tokenPat .FindAllStringSubmatch (dataStr , - 1 )
52
- domains := domainPat .FindAllStringSubmatch (dataStr , - 1 )
53
- emails := emailPat .FindAllStringSubmatch (dataStr , - 1 )
52
+ var uniqueTokens , uniqueDomains , uniqueEmails = make (map [string ]struct {}), make (map [string ]struct {}), make (map [string ]struct {})
54
53
55
- for _ , email := range emails {
56
- email = strings .Split (email [0 ], " " )
57
- if len (email ) != 2 {
58
- continue
59
- }
60
- resEmail := strings .TrimSpace (email [1 ])
61
- for _ , token := range tokens {
62
- if len (token ) != 2 {
63
- continue
64
- }
65
- resToken := strings .TrimSpace (token [1 ])
66
- for _ , domain := range domains {
67
- if len (domain ) != 2 {
68
- continue
69
- }
70
- resDomain := strings .TrimSpace (domain [1 ])
54
+ for _ , token := range tokenPat .FindAllStringSubmatch (dataStr , - 1 ) {
55
+ uniqueTokens [token [1 ]] = struct {}{}
56
+ }
57
+
58
+ for _ , domain := range domainPat .FindAllStringSubmatch (dataStr , - 1 ) {
59
+ uniqueDomains [domain [1 ]] = struct {}{}
60
+ }
61
+
62
+ for _ , email := range emailPat .FindAllStringSubmatch (dataStr , - 1 ) {
63
+ uniqueEmails [strings .ToLower (email [1 ])] = struct {}{}
64
+ }
71
65
66
+ for email := range uniqueEmails {
67
+ for token := range uniqueTokens {
68
+ for domain := range uniqueDomains {
72
69
s1 := detectors.Result {
73
70
DetectorType : detectorspb .DetectorType_JiraToken ,
74
- Raw : []byte (resToken ),
75
- RawV2 : []byte (fmt .Sprintf ("%s:%s:%s" , resEmail , resToken , resDomain )),
71
+ Raw : []byte (token ),
72
+ RawV2 : []byte (fmt .Sprintf ("%s:%s:%s" , email , token , domain )),
76
73
ExtraData : map [string ]string {
77
74
"rotation_guide" : "https://howtorotate.com/docs/tutorials/atlassian/" ,
78
75
"version" : fmt .Sprintf ("%d" , s .Version ()),
@@ -81,9 +78,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
81
78
82
79
if verify {
83
80
client := s .getClient ()
84
- isVerified , verificationErr := verifyJiratoken (ctx , client , resEmail , resDomain , resToken )
81
+ isVerified , verificationErr := verifyJiratoken (ctx , client , email , domain , token )
85
82
s1 .Verified = isVerified
86
- s1 .SetVerificationError (verificationErr , resToken )
83
+ s1 .SetVerificationError (verificationErr , token )
87
84
}
88
85
89
86
results = append (results , s1 )
0 commit comments