Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
fix: fixed verification logic & endpoint for AyrShare (#3452)
Sahil Silare3499df65f291
diff --git a/pkg/detectors/ayrshare/ayrshare.go b/pkg/detectors/ayrshare/ayrshare.goindex db2f43ccc..c4204ca7b 100644--- a/pkg/detectors/ayrshare/ayrshare.go+++ b/pkg/detectors/ayrshare/ayrshare.go@@ -2,11 +2,14 @@ package ayrshareimport ("context"+ "encoding/json""fmt"- regexp "github.com/wasilibs/go-re2"+ "io""net/http""strings"+ regexp "github.com/wasilibs/go-re2"+"github.com/trufflesecurity/trufflehog/v3/pkg/common""github.com/trufflesecurity/trufflehog/v3/pkg/detectors""github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"@@ -21,7 +24,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{"ayrshare"}) + `\b([A-Z]{7}-[A-Z0-9]{7}-[A-Z0-9]{7}-[A-Z0-9]{7})\b`)+ keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"ayrshare"}) + `\b([A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8}-[A-Z0-9]{8})\b`))// Keywords are used for efficiently pre-filtering chunks.@@ -48,17 +51,36 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- req, err := http.NewRequestWithContext(ctx, "GET", "https://app.ayrshare.com/api/analytics/links", nil)+ req, err := http.NewRequestWithContext(ctx, "GET", "https://app.ayrshare.com/api/user", nil)if err != nil {continue}req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", resMatch))res, err := client.Do(req)if err == nil {- defer res.Body.Close()- if res.StatusCode >= 200 && res.StatusCode < 300 {+ defer func() {+ _, _ = io.Copy(io.Discard, res.Body)+ _ = res.Body.Close()+ }()++ if res.StatusCode == http.StatusOK {s1.Verified = true+ bodyBytes, err := io.ReadAll(res.Body)+ if err != nil {+ continue+ }++ var responseBody map[string]interface{}+ if err := json.Unmarshal(bodyBytes, &responseBody); err == nil {+ if email, ok := responseBody["email"].(string); ok {+ s1.ExtraData = map[string]string{+ "email": email,+ }+ }+ }}+ } else {+ s1.SetVerificationError(err, resMatch)}}