Skip to content

Find, verify, and analyze leaked credentials

fix missing api key, tighten up regex pattern, use response body check (#1438)

Zubair Khanb38857edb46b
diff --git a/pkg/detectors/shortcut/shortcut.go b/pkg/detectors/shortcut/shortcut.go
index e5dd33a3d..f5032853f 100644
--- a/pkg/detectors/shortcut/shortcut.go
+++ b/pkg/detectors/shortcut/shortcut.go
@@ -2,7 +2,7 @@ package shortcut
import (
"context"
- "io"
+ "github.com/go-errors/errors"
"net/http"
"regexp"
"strings"
@@ -21,7 +21,7 @@ var (
client = common.SaneHttpClient()
// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
- keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"shortcut"}) + `\b([0-9a-f-]{36})\b`)
+ keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"shortcut"}) + `\b([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\b`)
)
// Keywords are used for efficiently pre-filtering chunks.
@@ -48,23 +48,33 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
if verify {
- req, err := http.NewRequestWithContext(ctx, "GET", "https://api.app.shortcut.com/api/v3/projects", nil)
+ req, err := http.NewRequestWithContext(ctx, "GET", "https://api.app.shortcut.com/api/v3/member", nil)
if err != nil {
continue
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Shortcut-Token", resMatch)
res, err := client.Do(req)
- if err == nil {
- defer res.Body.Close()
- bodyBytes, err := io.ReadAll(res.Body)
- if err != nil {
- continue
- }
- body := string(bodyBytes)
- if strings.Contains(body, "app_url") {
+ if err != nil {
+ return nil, errors.WrapPrefix(err, "Error making request", 0)
+ }
+
+ verifiedBodyResponse, err := common.ResponseContainsSubstring(res.Body, "name")
+ res.Body.Close()
+
+ if err != nil {
+ return nil, err
+ }
+
+ if err == nil {
+ if res.StatusCode >= 200 && res.StatusCode < 300 && verifiedBodyResponse {
s1.Verified = true
+ } else {
+ // This function will check false positives for common test words, but also it will make sure the key appears 'random' enough to be a real key.
+ if detectors.IsKnownFalsePositive(resMatch, detectors.DefaultFalsePositives, true) {
+ continue
+ }
}
}
}
diff --git a/pkg/detectors/shortcut/shortcut_test.go b/pkg/detectors/shortcut/shortcut_test.go
index e3926646a..940d1b027 100644
--- a/pkg/detectors/shortcut/shortcut_test.go
+++ b/pkg/detectors/shortcut/shortcut_test.go
@@ -19,7 +19,7 @@ import (
func TestShortcut_FromChunk(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()
- testSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "detectors2")
+ testSecrets, err := common.GetSecret(ctx, "trufflehog-testing", "detectors5")
if err != nil {
t.Fatalf("could not get test secrets from GCP: %s", err)
}