@@ -2,11 +2,14 @@ package ayrshare
22
33import (
44 "context"
5+ "encoding/json"
56 "fmt"
6- regexp "github.com/wasilibs/go-re2 "
7+ "io "
78 "net/http"
89 "strings"
910
11+ regexp "github.com/wasilibs/go-re2"
12+
1013 "github.com/trufflesecurity/trufflehog/v3/pkg/common"
1114 "github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
1215 "github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb"
2124 client = common .SaneHttpClient ()
2225
2326 // Make sure that your group is surrounded in boundary characters such as below to reduce false positives.
24- keyPat = regexp .MustCompile (detectors .PrefixRegex ([]string {"ayrshare" }) + `\b([A-Z]{7 }-[A-Z0-9]{7 }-[A-Z0-9]{7 }-[A-Z0-9]{7 })\b` )
27+ 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` )
2528)
2629
2730// Keywords are used for efficiently pre-filtering chunks.
@@ -48,17 +51,36 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
4851 }
4952
5053 if verify {
51- req , err := http .NewRequestWithContext (ctx , "GET" , "https://app.ayrshare.com/api/analytics/links " , nil )
54+ req , err := http .NewRequestWithContext (ctx , "GET" , "https://app.ayrshare.com/api/user " , nil )
5255 if err != nil {
5356 continue
5457 }
5558 req .Header .Add ("Authorization" , fmt .Sprintf ("Bearer %s" , resMatch ))
5659 res , err := client .Do (req )
5760 if err == nil {
58- defer res .Body .Close ()
59- if res .StatusCode >= 200 && res .StatusCode < 300 {
61+ defer func () {
62+ _ , _ = io .Copy (io .Discard , res .Body )
63+ _ = res .Body .Close ()
64+ }()
65+
66+ if res .StatusCode == http .StatusOK {
6067 s1 .Verified = true
68+ bodyBytes , err := io .ReadAll (res .Body )
69+ if err != nil {
70+ continue
71+ }
72+
73+ var responseBody map [string ]interface {}
74+ if err := json .Unmarshal (bodyBytes , & responseBody ); err == nil {
75+ if email , ok := responseBody ["email" ].(string ); ok {
76+ s1 .ExtraData = map [string ]string {
77+ "email" : email ,
78+ }
79+ }
80+ }
6181 }
82+ } else {
83+ s1 .SetVerificationError (err , resMatch )
6284 }
6385 }
6486
0 commit comments