Skip to content

Commit 31dce6b

Browse files
- updated make endpoint regex
- updated verifyMatch to prepend https:// and append /api/v2/ - updated keywords for api_token and mcp_token - replaced FindAllString() instead of FindAllStringSubmatch() - updated FromData to only return results if an endpoint is configured or found - removed duplicate endpoint slice length validation and changed verifyMatch() argument type to be a string instead of a slice of strings - added a trailing empty line in api_token_test.go to pass gofmt checks Co-authored-by: Kashif Khan <[email protected]> Co-authored-by: Jeff Rowell <[email protected]>
1 parent f977a10 commit 31dce6b

File tree

4 files changed

+55
-76
lines changed

4 files changed

+55
-76
lines changed

pkg/detectors/make/api_token/api_token.go

Lines changed: 31 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ var (
2828
// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
2929
keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"make"}) + `\b([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\b`)
3030
// Pattern to match Make.com URLs in the data
31-
urlPat = regexp.MustCompile(`\b(eu|us)[12]\.make\.(com|celonis)\.com`)
31+
urlPat = regexp.MustCompile(`\b(eu|us)[12]\.make\.(com|celonis\.com)`)
3232
)
3333

3434
func (Scanner) CloudEndpoint() string { return "" }
3535

3636
// Keywords are used for efficiently pre-filtering chunks.
3737
// Use identifiers in the secret preferably, or the provider name.
3838
func (s Scanner) Keywords() []string {
39-
return []string{"make"}
39+
return []string{"make.com", "make.celonis.com"}
4040
}
4141

4242
// FromData will find and optionally verify Make secrets in a given set of bytes.
@@ -49,43 +49,35 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
4949
}
5050

5151
// Extract Make URLs from the data
52-
var foundURLs []string
53-
for _, match := range urlPat.FindAllStringSubmatch(dataStr, -1) {
54-
foundURLs = append(foundURLs, match[0])
55-
}
52+
foundURLs := urlPat.FindAllString(dataStr, -1)
5653

5754
// Get endpoints using EndpointCustomizer
5855
endpoints := s.Endpoints(foundURLs...)
5956

60-
for match := range uniqueMatches {
61-
if len(endpoints) > 0 {
62-
// Create results for each endpoint
63-
for _, endpoint := range endpoints {
64-
s1 := detectors.Result{
65-
DetectorType: detectorspb.DetectorType_MakeApiToken,
66-
Raw: []byte(match),
67-
RawV2: []byte(match + ":" + endpoint),
68-
}
69-
70-
if verify {
71-
client := s.client
72-
if client == nil {
73-
client = defaultClient
74-
}
75-
76-
isVerified, extraData, verificationErr := verifyMatch(ctx, client, match, []string{endpoint})
77-
s1.Verified = isVerified
78-
s1.ExtraData = extraData
79-
s1.SetVerificationError(verificationErr, match)
80-
}
57+
// Skip creating results if no endpoints are available
58+
if len(endpoints) == 0 {
59+
return
60+
}
8161

82-
results = append(results, s1)
83-
}
84-
} else {
85-
// No endpoints configured or found, return unverified result
62+
for match := range uniqueMatches {
63+
// Create results for each endpoint
64+
for _, endpoint := range endpoints {
8665
s1 := detectors.Result{
8766
DetectorType: detectorspb.DetectorType_MakeApiToken,
8867
Raw: []byte(match),
68+
RawV2: []byte(match + ":" + endpoint),
69+
}
70+
71+
if verify {
72+
client := s.client
73+
if client == nil {
74+
client = defaultClient
75+
}
76+
77+
isVerified, extraData, verificationErr := verifyMatch(ctx, client, match, endpoint)
78+
s1.Verified = isVerified
79+
s1.ExtraData = extraData
80+
s1.SetVerificationError(verificationErr, match)
8981
}
9082

9183
results = append(results, s1)
@@ -95,28 +87,16 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
9587
return
9688
}
9789

98-
func verifyMatch(ctx context.Context, client *http.Client, token string, endpoints []string) (bool, map[string]string, error) {
99-
if len(endpoints) == 0 {
100-
return false, nil, nil
101-
}
102-
103-
var lastErr error
104-
for _, endpoint := range endpoints {
105-
verified, err := tryURL(ctx, client, endpoint, token)
106-
if verified {
107-
return true, nil, nil
108-
}
109-
if err != nil {
110-
lastErr = err
111-
continue
112-
}
113-
// Continue to next URL on determinate failures (401)
90+
func verifyMatch(ctx context.Context, client *http.Client, token string, endpoint string) (bool, map[string]string, error) {
91+
verified, err := tryURL(ctx, client, fmt.Sprintf("https://%s/api/v2/", endpoint), token)
92+
if verified {
93+
return true, nil, nil
11494
}
115-
116-
// If we got here, either all endpoints failed or we had errors
117-
if lastErr != nil {
118-
return false, nil, lastErr
95+
if err != nil {
96+
// Indeterminate failure (network error, etc.)
97+
return false, nil, err
11998
}
99+
// Determinate failure (401)
120100
return false, nil, nil
121101
}
122102

pkg/detectors/make/api_token/api_token_integration_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestMake_FromChunk(t *testing.T) {
4545
s: Scanner{},
4646
args: args{
4747
ctx: context.Background(),
48-
data: []byte(fmt.Sprintf("You can find a make secret %s and endpoint https://us2.make.com/api/v2/", secret)),
48+
data: []byte(fmt.Sprintf("You can find a make secret %s and endpoint us2.make.com", secret)),
4949
verify: true,
5050
},
5151
want: []detectors.Result{
@@ -62,7 +62,7 @@ func TestMake_FromChunk(t *testing.T) {
6262
s: Scanner{},
6363
args: args{
6464
ctx: context.Background(),
65-
data: []byte(fmt.Sprintf("You can find a make secret %s and endpoint https://us2.make.com/api/v2/ but not valid", inactiveSecret)), // the secret would satisfy the regex but not pass validation
65+
data: []byte(fmt.Sprintf("You can find a make secret %s and endpoint us2.make.com but not valid", inactiveSecret)), // the secret would satisfy the regex but not pass validation
6666
verify: true,
6767
},
6868
want: []detectors.Result{
@@ -91,7 +91,7 @@ func TestMake_FromChunk(t *testing.T) {
9191
s: Scanner{client: common.SaneHttpClientTimeOut(1 * time.Microsecond)},
9292
args: args{
9393
ctx: context.Background(),
94-
data: []byte(fmt.Sprintf("You can find a make secret %s and endpoint https://us2.make.com/api/v2/", secret)),
94+
data: []byte(fmt.Sprintf("You can find a make secret %s and endpoint us2.make.com", secret)),
9595
verify: true,
9696
},
9797
want: []detectors.Result{
@@ -108,7 +108,7 @@ func TestMake_FromChunk(t *testing.T) {
108108
s: Scanner{client: common.ConstantResponseHttpClient(404, "")},
109109
args: args{
110110
ctx: context.Background(),
111-
data: []byte(fmt.Sprintf("You can find a make secret %s and endpoint https://us2.make.com/api/v2/", secret)),
111+
data: []byte(fmt.Sprintf("You can find a make secret %s and endpoint us2.make.com", secret)),
112112
verify: true,
113113
},
114114
want: []detectors.Result{

pkg/detectors/make/api_token/api_token_test.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,18 @@ func TestMakeApiToken_Pattern(t *testing.T) {
3131
`,
3232
useCloudEndpoint: false,
3333
useFoundEndpoint: true,
34-
want: []string{"bbb94d50-239f-4609-9569-63ea15eb0996:https://eu1.make.com/api/v2/"},
34+
want: []string{"bbb94d50-239f-4609-9569-63ea15eb0996:eu1.make.com"},
3535
},
3636
{
3737
name: "valid pattern with configured endpoint",
3838
input: `
39-
# make api token
39+
# make.com api token
4040
MAKE_TOKEN: bbb94d50-239f-4609-9569-63ea15eb0996
4141
`,
42-
cloudEndpoint: "https://us1.make.com/api/v2/",
42+
cloudEndpoint: "us1.make.com",
4343
useCloudEndpoint: true,
4444
useFoundEndpoint: false,
45-
want: []string{"bbb94d50-239f-4609-9569-63ea15eb0996:https://us1.make.com/api/v2/"},
45+
want: []string{"bbb94d50-239f-4609-9569-63ea15eb0996:us1.make.com"},
4646
},
4747
{
4848
name: "valid pattern with both found and configured endpoints",
@@ -51,12 +51,12 @@ func TestMakeApiToken_Pattern(t *testing.T) {
5151
MAKE_TOKEN: bbb94d50-239f-4609-9569-63ea15eb0996
5252
URL: https://eu1.make.com/api/v2/
5353
`,
54-
cloudEndpoint: "https://us1.make.com/api/v2/",
54+
cloudEndpoint: "us1.make.com",
5555
useCloudEndpoint: true,
5656
useFoundEndpoint: true,
5757
want: []string{
58-
"bbb94d50-239f-4609-9569-63ea15eb0996:https://us1.make.com/api/v2/",
59-
"bbb94d50-239f-4609-9569-63ea15eb0996:https://eu1.make.com/api/v2/",
58+
"bbb94d50-239f-4609-9569-63ea15eb0996:us1.make.com",
59+
"bbb94d50-239f-4609-9569-63ea15eb0996:eu1.make.com",
6060
},
6161
},
6262
{
@@ -66,42 +66,40 @@ func TestMakeApiToken_Pattern(t *testing.T) {
6666
MAKE_TOKEN: bbb94d50-239f-4609-9569-63ea15eb0996
6767
URL: https://eu1.make.com/api/v2/
6868
`,
69-
cloudEndpoint: "https://us1.make.com/api/v2/",
69+
cloudEndpoint: "us1.make.com",
7070
useCloudEndpoint: true,
7171
useFoundEndpoint: false,
7272
want: []string{
73-
"bbb94d50-239f-4609-9569-63ea15eb0996:https://us1.make.com/api/v2/",
73+
"bbb94d50-239f-4609-9569-63ea15eb0996:us1.make.com",
7474
},
7575
},
7676
{
7777
name: "valid pattern with celonis domain",
7878
input: `
7979
# make api token
8080
MAKE_TOKEN: bbb94d50-239f-4609-9569-63ea15eb0996
81-
URL: https://us1.make.celonis.com/api/v2/
81+
URL: us1.make.celonis.com
8282
`,
8383
useCloudEndpoint: false,
8484
useFoundEndpoint: true,
8585
want: []string{
86-
"bbb94d50-239f-4609-9569-63ea15eb0996:https://us1.make.celonis.com/api/v2/",
86+
"bbb94d50-239f-4609-9569-63ea15eb0996:us1.make.celonis.com",
8787
},
8888
},
8989
{
9090
name: "no endpoints configured or found",
9191
input: `
92-
# make api token
92+
# make.com api token
9393
MAKE_TOKEN: bbb94d50-239f-4609-9569-63ea15eb0996
9494
`,
9595
useCloudEndpoint: false,
9696
useFoundEndpoint: false,
97-
want: []string{
98-
"bbb94d50-239f-4609-9569-63ea15eb0996",
99-
},
97+
want: nil,
10098
},
10199
{
102100
name: "invalid pattern",
103101
input: `
104-
# make api token
102+
# make.com api token
105103
MAKE_TOKEN: invalid-token-format
106104
`,
107105
useFoundEndpoint: true,
@@ -157,4 +155,4 @@ func TestMakeApiToken_Pattern(t *testing.T) {
157155
}
158156
})
159157
}
160-
}
158+
}

pkg/detectors/make/mcp_token/mcp_token.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@ var (
2929
// Keywords are used for efficiently pre-filtering chunks.
3030
// Use identifiers in the secret preferably, or the provider name.
3131
func (s Scanner) Keywords() []string {
32-
return []string{"make", "mcp"}
32+
return []string{"make.com", "make.celonis.com"}
3333
}
3434

3535
// FromData will find and optionally verify Makemcptoken secrets in a given set of bytes.
3636
func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (results []detectors.Result, err error) {
3737
dataStr := string(data)
3838

39+
matches := keyPat.FindAllString(dataStr, -1)
3940
uniqueMatches := make(map[string]struct{})
40-
for _, match := range keyPat.FindAllStringSubmatch(dataStr, -1) {
41-
uniqueMatches[match[0]] = struct{}{}
41+
for _, match := range matches {
42+
uniqueMatches[match] = struct{}{}
4243
}
4344

4445
for match := range uniqueMatches {
@@ -84,7 +85,7 @@ func verifyMatch(ctx context.Context, client *http.Client, url string) (bool, ma
8485
case http.StatusOK:
8586
return true, nil, nil
8687
case http.StatusUnauthorized:
87-
// The secret is determinately not verified (invalid token)
88+
// Determinate failure (401)
8889
return false, nil, nil
8990
default:
9091
// Any other status code is an indeterminate failure

0 commit comments

Comments
 (0)