Skip to content

Commit 71b341c

Browse files
fixed jirav1 detector email pattern (#3826)
1 parent e967efa commit 71b341c

File tree

2 files changed

+22
-25
lines changed

2 files changed

+22
-25
lines changed

pkg/detectors/jiratoken/v1/jiratoken.go

+21-24
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

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

12+
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
1213
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
1314
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
1415
)
@@ -30,7 +31,7 @@ var (
3031
// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
3132
tokenPat = regexp.MustCompile(detectors.PrefixRegex([]string{"jira"}) + `\b([a-zA-Z-0-9]{24})\b`)
3233
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)
3435
)
3536

3637
const (
@@ -48,31 +49,27 @@ func (s Scanner) Keywords() []string {
4849
func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
4950
dataStr := string(data)
5051

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{})
5453

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+
}
7165

66+
for email := range uniqueEmails {
67+
for token := range uniqueTokens {
68+
for domain := range uniqueDomains {
7269
s1 := detectors.Result{
7370
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)),
7673
ExtraData: map[string]string{
7774
"rotation_guide": "https://howtorotate.com/docs/tutorials/atlassian/",
7875
"version": fmt.Sprintf("%d", s.Version()),
@@ -81,9 +78,9 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
8178

8279
if verify {
8380
client := s.getClient()
84-
isVerified, verificationErr := verifyJiratoken(ctx, client, resEmail, resDomain, resToken)
81+
isVerified, verificationErr := verifyJiratoken(ctx, client, email, domain, token)
8582
s1.Verified = isVerified
86-
s1.SetVerificationError(verificationErr, resToken)
83+
s1.SetVerificationError(verificationErr, token)
8784
}
8885

8986
results = append(results, s1)

pkg/detectors/jiratoken/v1/jiratoken_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var (
1616
invalidTokenPattern = "Z7VoI?J0K4rF#LBfkhO&LAWX"
1717
validDomainPattern = "hereisavalidsubdomain.heresalongdomain.com"
1818
invalidDomainPattern = "?y4r3fs1ewqec12v1e3tl.5Hcsrcehic89saXd.ro@"
19-
validEmailPattern = "xfKF_BZq7@grum.com"
19+
validEmailPattern = "xfkf_bz7@grum.com"
2020
invalidEmailPattern = "xfKF_BZq7/grum.com"
2121
keyword = "jira"
2222
)

0 commit comments

Comments
 (0)