Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Handle custom detector response and include in extra data (#3411)
Kashif Khanf164ebcd8800
diff --git a/pkg/custom_detectors/custom_detectors.go b/pkg/custom_detectors/custom_detectors.goindex 602e7f89b..7579324dc 100644--- a/pkg/custom_detectors/custom_detectors.go+++ b/pkg/custom_detectors/custom_detectors.go@@ -4,6 +4,7 @@ import ("bytes""context""encoding/json"+ "io""net/http""regexp""strings"@@ -101,10 +102,6 @@ func (c *CustomRegexWebhook) FromData(ctx context.Context, verify bool, data []bclose(resultsCh)for result := range resultsCh {- // NOTE: I don't believe this is being set anywhere else, hence the map assignment.- result.ExtraData = map[string]string{- "name": c.GetName(),- }results = append(results, result)}@@ -129,6 +126,7 @@ func (c *CustomRegexWebhook) createResults(ctx context.Context, match map[stringDetectorType: detectorspb.DetectorType_CustomRegex,DetectorName: c.GetName(),Raw: []byte(raw),+ ExtraData: map[string]string{},}if !verify {@@ -166,14 +164,34 @@ func (c *CustomRegexWebhook) createResults(ctx context.Context, match map[string}req.Header.Add(key, strings.TrimLeft(value, "\t\n\v\f\r "))}- res, err := httpClient.Do(req)+ resp, err := httpClient.Do(req)if err != nil {continue}- // TODO: Read response body.- res.Body.Close()- if res.StatusCode == http.StatusOK {+ defer func() {+ _, _ = io.Copy(io.Discard, resp.Body)+ _ = resp.Body.Close()+ }()++ if resp.StatusCode == http.StatusOK {+ // mark the result as verifiedresult.Verified = true++ body, err := io.ReadAll(resp.Body)+ if err != nil {+ continue+ }++ // TODO: handle different content-type responses seperatly when implement custom detector configurations+ responseStr := string(body)+ // truncate to 200 characters if response length exceeds 200+ if len(responseStr) > 200 {+ responseStr = responseStr[:200]+ }++ // store the processed response in ExtraData+ result.ExtraData["response"] = responseStr+break}}diff --git a/pkg/detectors/meraki/meraki.go b/pkg/detectors/meraki/meraki.goindex 9aed559f4..e326e84ce 100644--- a/pkg/detectors/meraki/meraki.go+++ b/pkg/detectors/meraki/meraki.go@@ -4,10 +4,11 @@ import ("context""encoding/json""fmt"- regexp "github.com/wasilibs/go-re2""io""net/http"+ 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"