Skip to content

Commit d1317d6

Browse files
updated tickettailor detector (#3766)
1 parent 6ceb490 commit d1317d6

File tree

2 files changed

+44
-28
lines changed

2 files changed

+44
-28
lines changed

pkg/detectors/tickettailor/tickettailor.go

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ package tickettailor
22

33
import (
44
"context"
5-
b64 "encoding/base64"
65
"fmt"
7-
regexp "github.com/wasilibs/go-re2"
6+
"io"
87
"net/http"
9-
"strings"
8+
9+
regexp "github.com/wasilibs/go-re2"
1010

1111
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
1212
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
@@ -22,7 +22,7 @@ var (
2222
client = common.SaneHttpClient()
2323

2424
// Make sure that your group is surrounded in boundary characters such as below to reduce false positives
25-
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"tickettailor"}) + `\b(sk[a-fA-Z0-9_]{45})\b`)
25+
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"tickettailor"}) + `\b(sk_[0-9]{4}_[0-9]{6}_[a-f0-9]{32})`)
2626
)
2727

2828
// Keywords are used for efficiently pre-filtering chunks.
@@ -35,35 +35,22 @@ func (s Scanner) Keywords() []string {
3535
func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
3636
dataStr := string(data)
3737

38-
matches := keyPat.FindAllStringSubmatch(dataStr, -1)
38+
uniqueKeyMatches := make(map[string]struct{})
3939

40-
for _, match := range matches {
41-
if len(match) != 2 {
42-
continue
43-
}
44-
resMatch := strings.TrimSpace(match[1])
40+
for _, match := range keyPat.FindAllStringSubmatch(dataStr, -1) {
41+
uniqueKeyMatches[match[1]] = struct{}{}
42+
}
4543

44+
for key := range uniqueKeyMatches {
4645
s1 := detectors.Result{
4746
DetectorType: detectorspb.DetectorType_Tickettailor,
48-
Raw: []byte(resMatch),
47+
Raw: []byte(key),
4948
}
5049

5150
if verify {
52-
data := fmt.Sprintf("%s:", resMatch)
53-
sEnc := b64.StdEncoding.EncodeToString([]byte(data))
54-
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.tickettailor.com/v1/orders", nil)
55-
if err != nil {
56-
continue
57-
}
58-
req.Header.Add("Accept", "application/vnd.tickettailor+json; version=3")
59-
req.Header.Add("Authorization", fmt.Sprintf("Basic %s", sEnc))
60-
res, err := client.Do(req)
61-
if err == nil {
62-
defer res.Body.Close()
63-
if res.StatusCode >= 200 && res.StatusCode < 300 {
64-
s1.Verified = true
65-
}
66-
}
51+
isVerified, verificationErr := verifyTicketTailor(ctx, client, key)
52+
s1.Verified = isVerified
53+
s1.SetVerificationError(verificationErr)
6754
}
6855

6956
results = append(results, s1)
@@ -79,3 +66,32 @@ func (s Scanner) Type() detectorspb.DetectorType {
7966
func (s Scanner) Description() string {
8067
return "Tickettailor is an online ticketing platform that allows event organizers to sell tickets. Tickettailor API keys can be used to manage events, orders, and tickets programmatically."
8168
}
69+
70+
func verifyTicketTailor(ctx context.Context, client *http.Client, apiKey string) (bool, error) {
71+
req, err := http.NewRequestWithContext(ctx, "GET", "https://api.tickettailor.com/v1/orders", nil)
72+
if err != nil {
73+
return false, err
74+
}
75+
76+
req.Header.Add("Accept", "application/json")
77+
// as per API docs we only need to use apiKey as username in basic auth and leave password as empty: https://developers.tickettailor.com/#authentication
78+
req.SetBasicAuth(apiKey, "")
79+
resp, err := client.Do(req)
80+
if err != nil {
81+
return false, nil
82+
}
83+
84+
defer func() {
85+
_, _ = io.Copy(io.Discard, resp.Body)
86+
_ = resp.Body.Close()
87+
}()
88+
89+
switch resp.StatusCode {
90+
case http.StatusOK:
91+
return true, nil
92+
case http.StatusUnauthorized, http.StatusForbidden:
93+
return false, nil
94+
default:
95+
return false, fmt.Errorf("unexpected status code: %d", resp.StatusCode)
96+
}
97+
}

pkg/detectors/tickettailor/tickettailor_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212
)
1313

1414
var (
15-
validPattern = "skOFK3Yf_WW6E3TND0PXT5L4LPeOfVG7cEE_CdL2Y92fWNR"
16-
invalidPattern = "skOFK3Yf_WW6E3TND0PXT5L?LPeOfVG7cEE_CdL2Y92fWNR"
15+
validPattern = "sk_6551_225099_d9a4d4b7d506fba4d2cbb2ed803d088b"
16+
invalidPattern = "sk_1234_225099_WW6E3TND0PXT5L?LPeOfVG7c2Y92fWNR"
1717
keyword = "tickettailor"
1818
)
1919

0 commit comments

Comments
 (0)