Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
cleanup nesting (#1831)
āh̳̕mͭͭͨͩ̐e̘ͬ́͋ͬ̊̓͂d1f2e9d342fc6
diff --git a/pkg/detectors/myfreshworks/myfreshworks.go b/pkg/detectors/myfreshworks/myfreshworks.goindex 25820395d..e5cc2bcd7 100644--- a/pkg/detectors/myfreshworks/myfreshworks.go+++ b/pkg/detectors/myfreshworks/myfreshworks.go@@ -56,25 +56,10 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- client := s.client- if client == nil {- client = defaultClient- }-- req, err := http.NewRequestWithContext(ctx, "GET", "https://"+resIdMatch+".myfreshworks.com/crm/sales/api/sales_accounts/filters", nil)- if err != nil {- continue- }- req.Header.Add("Authorization", fmt.Sprintf("Token token=%s", resMatch))- res, err := client.Do(req)- if err == nil {- defer res.Body.Close()- if res.StatusCode == http.StatusOK {- s1.Verified = true- } else if !(res.StatusCode == http.StatusUnauthorized || res.StatusCode == http.StatusForbidden) {- s1.VerificationError = fmt.Errorf("unexpected HTTP response status %d", res.StatusCode)- }- }+ client := s.getClient()+ isVerified, verificationErr := verifyMyfreshworks(ctx, client, resMatch, resIdMatch)+ s1.Verified = isVerified+ s1.VerificationError = verificationErr}// 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.@@ -89,6 +74,35 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (resultreturn results, nil}+func (s Scanner) getClient() *http.Client {+ if s.client != nil {+ return s.client+ }+ return defaultClient+}++func verifyMyfreshworks(ctx context.Context, client *http.Client, resMatch, resIdMatch string) (bool, error) {+ req, err := http.NewRequestWithContext(ctx, "GET", "https://"+resIdMatch+".myfreshworks.com/crm/sales/api/sales_accounts/filters", nil)+ if err != nil {+ return false, err+ }++ req.Header.Add("Authorization", fmt.Sprintf("Token token=%s", resMatch))+ res, err := client.Do(req)+ if err != nil {+ return false, err+ }+ defer res.Body.Close()++ if res.StatusCode == http.StatusOK {+ return true, nil+ } else if !(res.StatusCode == http.StatusUnauthorized || res.StatusCode == http.StatusForbidden) {+ return false, fmt.Errorf("unexpected HTTP response status %d", res.StatusCode)+ }++ return false, nil+}+func (s Scanner) Type() detectorspb.DetectorType {return detectorspb.DetectorType_Myfreshworks}