Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
fix(detectors): avoid race (#3028)
Richard Gomezb883645856cd
diff --git a/pkg/detectors/caflou/caflou.go b/pkg/detectors/caflou/caflou.goindex c831d56f5..75a6f4a61 100644--- a/pkg/detectors/caflou/caflou.go+++ b/pkg/detectors/caflou/caflou.go@@ -3,23 +3,26 @@ package caflouimport ("context""fmt"- regexp "github.com/wasilibs/go-re2""net/http""strings""time"+ 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")-type Scanner struct{}+type Scanner struct {+ client *http.Client+}// Ensure the Scanner satisfies the interface at compile time.var _ detectors.Detector = (*Scanner)(nil)var (- client = common.SaneHttpClient()+ defaultClient = common.SaneHttpClientTimeOut(time.Second * 10)// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.keyPat = regexp.MustCompile(detectors.PrefixRegex([]string{"caflou"}) + `\b([a-bA-Z0-9\S]{155})\b`)@@ -49,8 +52,11 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result}if verify {- timeout := 10 * time.Second- client.Timeout = timeout+ client := s.client+ if client == nil {+ client = defaultClient+ }+req, err := http.NewRequestWithContext(ctx, "GET", "https://app.caflou.com/api/v1/accounts", nil)if err != nil {continuediff --git a/pkg/detectors/ldap/ldap.go b/pkg/detectors/ldap/ldap.goindex ce87f8fc2..ff0f29d8f 100644--- a/pkg/detectors/ldap/ldap.go+++ b/pkg/detectors/ldap/ldap.go@@ -16,13 +16,17 @@ import ("github.com/trufflesecurity/trufflehog/v3/pkg/pb/detectorspb")-type Scanner struct{+type Scanner struct {detectors.DefaultMultiPartCredentialProvider}// Ensure the Scanner satisfies the interface at compile time.var _ detectors.Detector = (*Scanner)(nil)+func init() {+ ldap.DefaultTimeout = 5 * time.Second+}+var (// Make sure that your group is surrounded in boundary characters such as below to reduce false positives.uriPat = regexp.MustCompile(`\b(?i)ldaps?://[\S]+\b`)@@ -127,8 +131,6 @@ func isErrDeterminate(err error) bool {func verifyLDAP(username, password string, ldapURL *url.URL) error {// Tests with non-TLS, TLS, and STARTTLS- ldap.DefaultTimeout = 5 * time.Second-uri := ldapURL.String()switch ldapURL.Scheme {